]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Make string_list_join more useful.
authorBruno Haible <bruno@clisp.org>
Sun, 18 Jan 2009 23:58:22 +0000 (23:58 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:58 +0000 (12:15 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/str-list.c
gettext-tools/src/str-list.h

index 3043fe44d5c2c72345294fa82bc0ac85052413f0..13251cb4f5d2ed155d66e3057e869853a0ed5113 100644 (file)
@@ -1,3 +1,9 @@
+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.
index cf9d5834d1ca90476e19741eeaa95c7b5f3c66f7..a63212cc45ce4d294e93079a946a8302b3e355c4 100644 (file)
@@ -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 <millerp@canb.auug.org.au>
 
@@ -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;
index 2f3ca0a5a09bd9ba2cc630e4b33fe1bbdc2b5856..2e879f48de359058ff0b6737b2063b6213e8eaf0 100644 (file)
@@ -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 <millerp@canb.auug.org.au>
 
@@ -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.  */