Skip to content

Commit

Permalink
Make split_cstr func work with multi-char delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
iWas-Coder committed Dec 7, 2024
1 parent 93629e6 commit 6f64d63
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/carbon_strlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ CBN_StrList carbon_strlist_create(u8 unique) {
CBN_StrList carbon_strlist_from_splitted_cstr(const char *s, const char *delim) {
CBN_StrList sl = carbon_strlist_create(false);
char *s_copy = carbon_string_dup(s);
char *sub = strtok(s_copy, delim);
while (sub) {
carbon_strlist_push(&sl, sub);
sub = strtok(0, delim);
usz delim_len = strlen(delim);
char *start = s_copy;
char *found;
while ((found = strstr(start, delim))) {
*found = 0;
carbon_strlist_push(&sl, start);
start = found + delim_len;
}
if (*start) carbon_strlist_push(&sl, start);
CARBON_FREE(s_copy);
return sl;
}
Expand Down

0 comments on commit 6f64d63

Please sign in to comment.