This commit is contained in:
2025-09-27 15:16:26 +02:00
parent 5af7c5276a
commit 3b1bb9d531
63 changed files with 1087 additions and 407 deletions

View File

@ -1,5 +1,6 @@
#include <stddef.h>
#include <string/string.h>
#include <dlmalloc/malloc.h>
size_t string_len(const char *s) {
size_t l = 0;
@ -130,3 +131,35 @@ int string_strncmp( const char * s1, const char * s2, size_t n )
return ( *(unsigned char *)s1 - *(unsigned char *)s2 );
}
}
#define STRING_TOKENIZEALLOC_TOK_SIZE 0xff
char *string_tokenizealloc(char *s, char *delim) {
static int curridx = 0;
if (!s || !delim || !s[curridx]) {
return NULL;
}
char *w = (char *)dlmalloc(sizeof(char) * STRING_TOKENIZEALLOC_TOK_SIZE);
string_memset(w, 0, sizeof(char) * STRING_TOKENIZEALLOC_TOK_SIZE);
int i = curridx, k = 0, j = 0;
while (s[i] != '\0') {
j = 0;
while (delim[j] != '\0') {
if (s[i] != delim[j]) {
w[k] = s[i];
} else {
goto it;
}
j++;
}
i++;
k++;
}
it: {
w[i] = 0;
curridx = i + 1;
return w;
}
}