int status = 1; /* Status of add */
+ DEBUG_printf(("_cupsArrayAddStrings(a=%p, s=\"%s\", delim='%c')", a, s,
+ delim));
+
if (!a || !s || !*s)
+ {
+ DEBUG_puts("1_cupsArrayAddStrings: Returning 0");
return (0);
+ }
if (delim == ' ')
{
* Skip leading whitespace...
*/
+ DEBUG_puts("1_cupsArrayAddStrings: Skipping leading whitespace.");
+
while (*s && isspace(*s & 255))
s ++;
+
+ DEBUG_printf(("1_cupsArrayAddStrings: Remaining string \"%s\".", s));
}
- if (!strchr(s, delim) ||
- (delim == ' ' && !strchr(s, '\t') && !strchr(s, '\n')))
+ if (!strchr(s, delim) &&
+ (delim != ' ' || (!strchr(s, '\t') && !strchr(s, '\n'))))
{
/*
* String doesn't contain a delimiter, so add it as a single value...
*/
+ DEBUG_puts("1_cupsArrayAddStrings: No delimiter seen, adding a single "
+ "value.");
+
if (!cupsArrayFind(a, (void *)s))
status = cupsArrayAdd(a, (void *)s);
}
else if ((buffer = strdup(s)) == NULL)
+ {
+ DEBUG_puts("1_cupsArrayAddStrings: Unable to duplicate string.");
status = 0;
+ }
else
{
for (start = end = buffer; *end; start = end)
else
end = start + strlen(start);
+ DEBUG_printf(("1_cupsArrayAddStrings: Adding \"%s\", end=\"%s\"", start,
+ end));
+
if (!cupsArrayFind(a, start))
status &= cupsArrayAdd(a, start);
}
free(buffer);
}
+ DEBUG_printf(("1_cupsArrayAddStrings: Returning %d.", status));
+
return (status);
}
#include "string-private.h"
#include "debug-private.h"
-#include "array.h"
+#include "array-private.h"
#include "dir.h"
cupsArrayDelete(array);
cupsArrayDelete(dup_array);
+ /*
+ * Test the array with string functions...
+ */
+
+ fputs("_cupsArrayNewStrings(\"foo bar\", ' '): ", stdout);
+ array = _cupsArrayNewStrings("foo bar", ' ');
+ if (!array)
+ {
+ status = 1;
+ puts("FAIL (unable to create array)");
+ }
+ else if (cupsArrayCount(array) != 2)
+ {
+ status = 1;
+ printf("FAIL (got %d elements, expected 2)\n", cupsArrayCount(array));
+ }
+ else if (strcmp(text = (char *)cupsArrayFirst(array), "bar"))
+ {
+ status = 1;
+ printf("FAIL (first element \"%s\", expected \"bar\")\n", text);
+ }
+ else if (strcmp(text = (char *)cupsArrayNext(array), "foo"))
+ {
+ status = 1;
+ printf("FAIL (first element \"%s\", expected \"foo\")\n", text);
+ }
+ else
+ puts("PASS");
+
+ fputs("_cupsArrayAddStrings(array, \"foo2,bar2\", ','): ", stdout);
+ _cupsArrayAddStrings(array, "foo2,bar2", ',');
+
+ if (cupsArrayCount(array) != 4)
+ {
+ status = 1;
+ printf("FAIL (got %d elements, expected 4)\n", cupsArrayCount(array));
+ }
+ else if (strcmp(text = (char *)cupsArrayFirst(array), "bar"))
+ {
+ status = 1;
+ printf("FAIL (first element \"%s\", expected \"bar\")\n", text);
+ }
+ else if (strcmp(text = (char *)cupsArrayNext(array), "bar2"))
+ {
+ status = 1;
+ printf("FAIL (first element \"%s\", expected \"bar2\")\n", text);
+ }
+ else if (strcmp(text = (char *)cupsArrayNext(array), "foo"))
+ {
+ status = 1;
+ printf("FAIL (first element \"%s\", expected \"foo\")\n", text);
+ }
+ else if (strcmp(text = (char *)cupsArrayNext(array), "foo2"))
+ {
+ status = 1;
+ printf("FAIL (first element \"%s\", expected \"foo2\")\n", text);
+ }
+ else
+ puts("PASS");
+
+ cupsArrayDelete(array);
+
/*
* Summarize the results and return...
*/