]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/array.c
Merge changes from CUPS 1.7svn-r10629.
[thirdparty/cups.git] / cups / array.c
index 2fb7701c054cd294681e97f64d3125816906b63a..a84f3e2a2f299e56733bf8e6644d5c5262d5e586 100644 (file)
@@ -138,8 +138,7 @@ cupsArrayAdd(cups_array_t *a,               /* I - Array */
 
 
 /*
- * '_cupsArrayAddStrings()' - Add zero or more comma-delimited strings to an
- *                            array.
+ * '_cupsArrayAddStrings()' - Add zero or more delimited strings to an array.
  *
  * Note: The array MUST be created using the @link _cupsArrayNewStrings@
  * function. Duplicate strings are NOT added. If the string pointer "s" is NULL
@@ -148,7 +147,8 @@ cupsArrayAdd(cups_array_t *a,               /* I - Array */
 
 int                                    /* O - 1 on success, 0 on failure */
 _cupsArrayAddStrings(cups_array_t *a,  /* I - Array */
-                     const char   *s)  /* I - Comma-delimited strings or NULL */
+                     const char   *s,  /* I - Delimited strings or NULL */
+                     char         delim)/* I - Delimiter character */
 {
   char         *buffer,                /* Copy of string */
                *start,                 /* Start of string */
@@ -159,10 +159,21 @@ _cupsArrayAddStrings(cups_array_t *a,     /* I - Array */
   if (!a || !s || !*s)
     return (0);
 
-  if (!strchr(s, ','))
+  if (delim == ' ')
   {
    /*
-    * String doesn't contain a comma, so add it as a single value...
+    * Skip leading whitespace...
+    */
+
+    while (*s && isspace(*s & 255))
+      s ++;
+  }
+
+  if (!strchr(s, delim) ||
+      (delim == ' ' && !strchr(s, '\t') && !strchr(s, '\n')))
+  {
+   /*
+    * String doesn't contain a delimiter, so add it as a single value...
     */
 
     if (!cupsArrayFind(a, (void *)s))
@@ -179,7 +190,14 @@ _cupsArrayAddStrings(cups_array_t *a,      /* I - Array */
       * it...
       */
 
-      if ((end = strchr(start, ',')) != NULL)
+      if (delim == ' ')
+      {
+        while (*end && !isspace(*end & 255))
+          end ++;
+        while (*end && isspace(*end & 255))
+          *end++ = '\0';
+      }
+      else if ((end = strchr(start, delim)) != NULL)
         *end++ = '\0';
       else
         end = start + strlen(start);
@@ -782,7 +800,8 @@ cupsArrayNew3(cups_array_func_t  f, /* I - Comparison function or @code NULL@ fo
  */
 
 cups_array_t *                         /* O - Array */
-_cupsArrayNewStrings(const char *s)    /* I - Comma-delimited strings or NULL */
+_cupsArrayNewStrings(const char *s,    /* I - Delimited strings or NULL */
+                     char       delim) /* I - Delimiter character */
 {
   cups_array_t *a;                     /* Array */
 
@@ -790,7 +809,7 @@ _cupsArrayNewStrings(const char *s) /* I - Comma-delimited strings or NULL */
   if ((a = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0,
                          (cups_acopy_func_t)_cupsStrAlloc,
                         (cups_afree_func_t)_cupsStrFree)) != NULL)
-    _cupsArrayAddStrings(a, s);
+    _cupsArrayAddStrings(a, s, delim);
 
   return (a);
 }