aboutsummaryrefslogtreecommitdiff
path: root/src/buffer2array.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2006-08-06 13:53:53 +0000
committerWarren Dukes <warren.dukes@gmail.com>2006-08-06 13:53:53 +0000
commit8e53406774e973e2a5793ccfe5069c514a82fb8a (patch)
treeea3b90b06bf7a66fbfb035262d079185b09d480c /src/buffer2array.c
parent31de97a42b384ffd2ce7051248cefc075e935522 (diff)
renamce cstrtok to buffer2array. please don't rename functions; especially to names that look extremely std-lib-ish. also, don't use isspace, apparently it's local dependent and potentially consideres ' ' or '\t' not to be a space, or considers other characters to be a space.
git-svn-id: https://svn.musicpd.org/mpd/trunk@4574 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/buffer2array.c')
-rw-r--r--src/buffer2array.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/buffer2array.c b/src/buffer2array.c
index 3bdb6654..38ced19d 100644
--- a/src/buffer2array.c
+++ b/src/buffer2array.c
@@ -23,7 +23,15 @@
#include <string.h>
#include <ctype.h>
-int cstrtok(char *buffer, char *array[], const int max)
+
+inline static
+int
+isWhiteSpace(char c)
+{
+ return (c == ' ' || c == '\t');
+}
+
+int buffer2array(char *buffer, char *array[], const int max)
{
int i = 0;
char *c = buffer;
@@ -48,18 +56,18 @@ int cstrtok(char *buffer, char *array[], const int max)
escape = (*(c++) != '\\') ? 0 : !escape;
}
} else {
- while (isspace(*c))
+ while (isWhiteSpace(*c))
++c;
array[i++] = c++;
if (*c == '\0')
return i;
- while (!isspace(*c) && *c != '\0')
+ while (!isWhiteSpace(*c) && *c != '\0')
++c;
}
if (*c == '\0')
return i;
*(c++) = '\0';
- while (isspace(*c))
+ while (isWhiteSpace(*c))
++c;
}
return i;
@@ -78,37 +86,37 @@ int main()
int i, max;
b = strdup("lsinfo \"/some/dir/name \\\"test\\\"\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir/name \"test\"", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"/some/dir/name \\\"test\\\" something else\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir/name \"test\" something else", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"/some/dir\\\\name\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir\\name", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"/some/dir name\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir name", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"\\\"/some/dir\\\"\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("\"/some/dir\"", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"\\\"/some/dir\\\" x\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("\"/some/dir\" x", a[1]) );
assert( !a[2] );