Skip to content

Commit

Permalink
Fix bug in String.split
Browse files Browse the repository at this point in the history
  • Loading branch information
bamless committed Jul 6, 2024
1 parent ea2be7d commit 84c2c52
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ JSR_NATIVE(jsr_Generator_string) {
const Prototype* proto = &gen->closure->fn->proto;
JStarBuffer str;
jsrBufferInit(vm, &str);
jsrBufferAppendf(&str, "<Generator %s.%s@%p>", proto->module->name->data, proto->name->data, (void*)gen);
jsrBufferAppendf(&str, "<Generator %s.%s@%p>", proto->module->name->data, proto->name->data,
(void*)gen);
jsrBufferPush(&str);
return true;
}
Expand Down Expand Up @@ -1091,13 +1092,17 @@ JSR_NATIVE(jsr_String_split) {
const char* last = str;

if(delimSize < size) {
for(size_t i = 0; i <= size - delimSize; i++) {
size_t i = 0;
while(i <= size - delimSize) {
if(memcmp(str + i, delimiter, delimSize) == 0) {
jsrPushStringSz(vm, last, str + i - last);
jsrListAppend(vm, -2);
jsrPop(vm);

last = str + i + delimSize;
i += delimSize;
} else {
i++;
}
}
}
Expand Down

0 comments on commit 84c2c52

Please sign in to comment.