From: Bruno Haible Date: Sun, 18 Jan 2009 23:58:22 +0000 (+0000) Subject: Make string_list_join more useful. X-Git-Tag: v0.18~265 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71afcc0a6cbb2104f37dd0ef846bb2ba12349954;p=thirdparty%2Fgettext.git Make string_list_join more useful. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 3043fe44d..13251cb4f 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,9 @@ +2009-01-18 Bruno Haible + + * str-list.h (string_list_join): Change the separator argument, + allowing an entire separator string. + * str-list.c (string_list_join): Likewise. + 2009-01-18 Bruno Haible Fix a '(null)' in an error message. Bug present since gettext-0.16. diff --git a/gettext-tools/src/str-list.c b/gettext-tools/src/str-list.c index cf9d5834d..a63212cc4 100644 --- a/gettext-tools/src/str-list.c +++ b/gettext-tools/src/str-list.c @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995, 1998, 2000-2004, 2006 Free Software Foundation, Inc. + Copyright (C) 1995, 1998, 2000-2004, 2006, 2009 Free Software Foundation, Inc. This file was written by Peter Miller @@ -176,14 +176,15 @@ string_list_concat_destroy (string_list_ty *slp) /* Return a freshly allocated string obtained by concatenating all the - strings in the list, separated by the separator character, terminated + strings in the list, separated by the separator string, terminated by the terminator character. The terminator character is not added if drop_redundant_terminator is true and the last string already ends with the terminator. */ char * -string_list_join (const string_list_ty *slp, char separator, +string_list_join (const string_list_ty *slp, const char *separator, char terminator, bool drop_redundant_terminator) { + size_t separator_len = strlen (separator); size_t len; size_t j; char *result; @@ -192,8 +193,8 @@ string_list_join (const string_list_ty *slp, char separator, len = 1; for (j = 0; j < slp->nitems; ++j) { - if (separator && j > 0) - ++len; + if (j > 0) + len += separator_len; len += strlen (slp->item[j]); } if (terminator) @@ -202,8 +203,11 @@ string_list_join (const string_list_ty *slp, char separator, pos = 0; for (j = 0; j < slp->nitems; ++j) { - if (separator && j > 0) - result[pos++] = separator; + if (j > 0) + { + memcpy (result + pos, separator, separator_len); + pos += separator_len; + } len = strlen (slp->item[j]); memcpy (result + pos, slp->item[j], len); pos += len; diff --git a/gettext-tools/src/str-list.h b/gettext-tools/src/str-list.h index 2f3ca0a5a..2e879f48d 100644 --- a/gettext-tools/src/str-list.h +++ b/gettext-tools/src/str-list.h @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1996, 1998, 2000-2004 Free Software Foundation, Inc. + Copyright (C) 1995-1996, 1998, 2000-2004, 2009 Free Software Foundation, Inc. This file was written by Peter Miller @@ -69,11 +69,11 @@ extern char *string_list_concat (const string_list_ty *slp); extern char *string_list_concat_destroy (string_list_ty *slp); /* Return a freshly allocated string obtained by concatenating all the - strings in the list, separated by the separator character, terminated + strings in the list, separated by the separator string, terminated by the terminator character. The terminator character is not added if drop_redundant_terminator is true and the last string already ends with the terminator. */ -extern char *string_list_join (const string_list_ty *slp, char separator, +extern char *string_list_join (const string_list_ty *slp, const char *separator, char terminator, bool drop_redundant_terminator); /* Return 1 if s is contained in the list of strings, 0 otherwise. */