*
* Sorted array routines for CUPS.
*
- * Copyright 2007-2011 by Apple Inc.
+ * Copyright 2007-2012 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* appended at the end of the run of identical elements. For unsorted arrays,
* the element is appended to the end of the array.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
int /* O - 1 on success, 0 on failure */
/*
- * '_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
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 */
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))
* 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);
* The caller is responsible for freeing the memory used by the
* elements themselves.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void
/*
* 'cupsArrayCount()' - Get the number of elements in the array.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
int /* O - Number of elements */
* The current element is undefined until you call @link cupsArrayFind@,
* @link cupsArrayFirst@, or @link cupsArrayIndex@, or @link cupsArrayLast@.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void * /* O - Element */
* The caller is responsible for freeing the memory used by the
* elements themselves.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void
/*
* 'cupsArrayDup()' - Duplicate the array.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
cups_array_t * /* O - Duplicate array */
/*
* 'cupsArrayFind()' - Find an element in the array.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void * /* O - Element found or @code NULL@ */
/*
* 'cupsArrayFirst()' - Get the first element in the array.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void * /* O - First element or @code NULL@ if the array is empty */
* The current element is undefined until you call @link cupsArrayFind@,
* @link cupsArrayFirst@, or @link cupsArrayIndex@, or @link cupsArrayLast@.
*
- * @since CUPS 1.3/Mac OS X 10.5@
+ * @since CUPS 1.3/OS X 10.5@
*/
int /* O - Index of the current element, starting at 0 */
/*
* 'cupsArrayGetInsert()' - Get the index of the last inserted element.
*
- * @since CUPS 1.3/Mac OS X 10.5@
+ * @since CUPS 1.3/OS X 10.5@
*/
int /* O - Index of the last inserted element, starting at 0 */
/*
* 'cupsArrayIndex()' - Get the N-th element in the array.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void * /* O - N-th element or @code NULL@ */
* inserted at the beginning of the run of identical elements. For unsorted
* arrays, the element is inserted at the beginning of the array.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
int /* O - 0 on failure, 1 on success */
/*
* 'cupsArrayLast()' - Get the last element in the array.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void * /* O - Last element or @code NULL@ if the array is empty */
* data pointer argument can safely be omitted when not required so functions
* like @code strcmp@ can be used for sorted string arrays.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
cups_array_t * /* O - Array */
* The hash function ("h") is used to implement cached lookups with the
* specified hash size ("hsize").
*
- * @since CUPS 1.3/Mac OS X 10.5@
+ * @since CUPS 1.3/OS X 10.5@
*/
cups_array_t * /* O - Array */
* The free function ("cf") is used to automatically free/release elements when
* removed or the array is deleted.
*
- * @since CUPS 1.5/Mac OS X 10.7@
+ * @since CUPS 1.5/OS X 10.7@
*/
cups_array_t * /* O - Array */
*/
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 */
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);
}
* @link cupsArrayFirst@, or @link cupsArrayIndex@, or @link cupsArrayLast@
* to set the current element.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void * /* O - Next element or @code NULL@ */
* @link cupsArrayFirst@, or @link cupsArrayIndex@, or @link cupsArrayLast@
* to set the current element.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void * /* O - Previous element or @code NULL@ */
* The caller is responsible for freeing the memory used by the
* removed element.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
int /* O - 1 on success, 0 on failure */
/*
* 'cupsArrayRestore()' - Reset the current element to the last @link cupsArraySave@.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void * /* O - New current element */
*
* The save/restore stack is guaranteed to be at least 32 elements deep.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
int /* O - 1 on success, 0 on failure */
/*
* 'cupsArrayUserData()' - Return the user data for an array.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
void * /* O - User data */
/*
* 'cups_array_add()' - Insert or append an element to the array.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
static int /* O - 1 on success, 0 on failure */