1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

regex: bug fix on find groups indexes (#12152)

This commit is contained in:
penguindark
2021-10-12 05:03:23 +02:00
committed by GitHub
parent 3c8be0db72
commit 0fafefc078
2 changed files with 75 additions and 4 deletions

View File

@@ -194,6 +194,11 @@ pub fn (mut re RE) find(in_txt string) (int, int) {
if s >= 0 && e > s {
// println("find match in: ${i+s},${i+e} [${in_txt[i+s..i+e]}]")
// re.flag = old_flag
mut gi := 0
for gi < re.groups.len {
re.groups[gi] += i
gi++
}
return i + s, i + e
}
i++
@@ -229,6 +234,11 @@ pub fn (mut re RE) find_from(in_txt string, start int) (int, int) {
if s >= 0 && e > s {
// println("find match in: ${i+s},${i+e} [${in_txt[i+s..i+e]}]")
re.flag = old_flag
mut gi := 0
for gi < re.groups.len {
re.groups[gi] += i
gi++
}
return i + s, i + e
} else {
i++
@@ -354,12 +364,12 @@ pub fn (mut re RE) replace_by_fn(in_txt string, repl_fn FnReplace) string {
if last_end < s {
res.write_string(in_txt[last_end..s])
}
/*
for g_i in 0 .. re.group_count {
re.groups[g_i << 1] += i
re.groups[(g_i << 1) + 1] += i
}
*/
repl := repl_fn(re, in_txt, s, e)
// println("repl res: $repl")
res.write_string(repl)
@@ -416,12 +426,12 @@ pub fn (mut re RE) replace(in_txt string, repl_str string) string {
if last_end < s {
res.write_string(in_txt[last_end..s])
}
/*
for g_i in 0 .. re.group_count {
re.groups[g_i << 1] += i
re.groups[(g_i << 1) + 1] += i
}
*/
// repl := repl_fn(re, in_txt, s, e)
repl := re.parsed_replace_string(in_txt, repl_str)
// println("repl res: $repl")