Annotation of embedaddon/php/TSRM/tsrm_strtok_r.c, revision 1.1.1.1
1.1 misho 1: #include <stdio.h>
2:
3: #include "tsrm_config_common.h"
4: #include "tsrm_strtok_r.h"
5:
6: static inline int in_character_class(char ch, const char *delim)
7: {
8: while (*delim) {
9: if (*delim == ch) {
10: return 1;
11: }
12: delim++;
13: }
14: return 0;
15: }
16:
17: char *tsrm_strtok_r(char *s, const char *delim, char **last)
18: {
19: char *token;
20:
21: if (s == NULL) {
22: s = *last;
23: }
24:
25: while (*s && in_character_class(*s, delim)) {
26: s++;
27: }
28: if (!*s) {
29: return NULL;
30: }
31:
32: token = s;
33:
34: while (*s && !in_character_class(*s, delim)) {
35: s++;
36: }
37: if (!*s) {
38: *last = s;
39: } else {
40: *s = '\0';
41: *last = s + 1;
42: }
43: return token;
44: }
45:
46: #if 0
47:
48: main()
49: {
50: char foo[] = "/foo/bar//\\barbara";
51: char *last;
52: char *token;
53:
54: token = tsrm_strtok_r(foo, "/\\", &last);
55: while (token) {
56: printf ("Token = '%s'\n", token);
57: token = tsrm_strtok_r(NULL, "/\\", &last);
58: }
59:
60: return 0;
61: }
62:
63: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>