1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-12 19:15:13 +00:00

Simplify gui_tokenize()

This commit is contained in:
Samuel Gomes 2022-10-24 02:59:51 +05:30
parent fb00990bab
commit 6b60048d9e

View file

@ -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;
} }