tb finally works
This commit is contained in:
@ -135,15 +135,21 @@ int string_strncmp( const char * s1, const char * s2, size_t n )
|
||||
#define STRING_TOKENIZEALLOC_TOK_SIZE 0xff
|
||||
|
||||
char *string_tokenizealloc(char *s, char *delim) {
|
||||
static int curridx = 0;
|
||||
if (!s || !delim || !s[curridx]) {
|
||||
static char *saved = NULL;
|
||||
|
||||
if (s) {
|
||||
saved = s;
|
||||
}
|
||||
|
||||
if (!delim || !saved) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (s[curridx] && string_strchr(delim, s[curridx])) {
|
||||
curridx++;
|
||||
while (*saved && string_strchr(delim, *saved)) {
|
||||
saved++;
|
||||
}
|
||||
if (!s[curridx]) {
|
||||
|
||||
if (!*saved) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -151,17 +157,17 @@ char *string_tokenizealloc(char *s, char *delim) {
|
||||
string_memset(w, 0, sizeof(char) * STRING_TOKENIZEALLOC_TOK_SIZE);
|
||||
|
||||
int k = 0;
|
||||
while (s[curridx] && !string_strchr(delim, s[curridx])) {
|
||||
while (*saved && !string_strchr(delim, *saved)) {
|
||||
if (k >= STRING_TOKENIZEALLOC_TOK_SIZE - 1) {
|
||||
break;
|
||||
}
|
||||
w[k++] = s[curridx++];
|
||||
w[k++] = *saved++;
|
||||
}
|
||||
|
||||
w[k] = '\0';
|
||||
|
||||
if (s[curridx]) {
|
||||
curridx++;
|
||||
if (*saved) {
|
||||
saved++;
|
||||
}
|
||||
|
||||
return w;
|
||||
|
Reference in New Issue
Block a user