mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-08-05 15:50:25 +00:00
Simplify gui_tokenize()
This commit is contained in:
parent
fb00990bab
commit
6b60048d9e
1 changed files with 5 additions and 5 deletions
|
@ -41,25 +41,25 @@ static char **gui_tokenize(const char *input, int32_t *count) {
|
||||||
char **result = (char **)malloc(capacity * sizeof(*result));
|
char **result = (char **)malloc(capacity * sizeof(*result));
|
||||||
char *saveptr;
|
char *saveptr;
|
||||||
|
|
||||||
(*count) = 0; // Set count to zero
|
*count = 0;
|
||||||
auto tok = strtok_r(str, "|", &saveptr);
|
auto tok = strtok_r(str, "|", &saveptr);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((*count) >= capacity)
|
if (*count >= capacity)
|
||||||
result = (char **)realloc(result, (capacity *= 2) * sizeof(*result));
|
result = (char **)realloc(result, (capacity *= 2) * sizeof(*result));
|
||||||
|
|
||||||
result[(*count)++] = tok ? strdup(tok) : tok;
|
result[*count] = tok ? strdup(tok) : tok;
|
||||||
|
|
||||||
if (!tok)
|
if (!tok)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
++(*count);
|
||||||
|
|
||||||
tok = strtok_r(nullptr, "|", &saveptr);
|
tok = strtok_r(nullptr, "|", &saveptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(str);
|
free(str);
|
||||||
|
|
||||||
--(*count); // Since incrementing happens before we check for null above
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue