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