+2009-01-18 Bruno Haible <bruno@clisp.org>
+
+ * 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 <bruno@clisp.org>
Fix a '(null)' in an error message. Bug present since gettext-0.16.
/* 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 <millerp@canb.auug.org.au>
/* 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;
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)
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;
/* 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 <millerp@canb.auug.org.au>
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. */