1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-26 12:14:49 +00:00

Fix error in string.replace-all

This commit is contained in:
Calvin Rose
2018-09-29 20:01:57 -04:00
parent e963672977
commit f41dab8f6c
5 changed files with 33 additions and 4 deletions

View File

@@ -605,6 +605,11 @@ static void kmp_deinit(struct kmp_state *state) {
free(state->lookup);
}
static void kmp_seti(struct kmp_state *state, int32_t i) {
state->i = i;
state->j = 0;
}
static int32_t kmp_next(struct kmp_state *state) {
int32_t i = state->i;
int32_t j = state->j;
@@ -880,6 +885,7 @@ static int cfun_replaceall(JanetArgs args) {
janet_buffer_push_bytes(&b, s.kmp.text + lastindex, result - lastindex);
janet_buffer_push_bytes(&b, s.subst, s.substlen);
lastindex = result + s.kmp.patlen;
kmp_seti(&s.kmp, lastindex);
}
janet_buffer_push_bytes(&b, s.kmp.text + lastindex, s.kmp.textlen - lastindex);
ret = janet_string(b.data, b.count);