regex: fix bug in replace_by_fn (#13344)
parent
b10b65e134
commit
c3573454d1
|
@ -596,6 +596,21 @@ fn test_regex_func(){
|
|||
}
|
||||
}
|
||||
|
||||
fn my_repl_1(re regex.RE, in_txt string, start int, end int) string {
|
||||
s0 := re.get_group_by_id(in_txt,0)
|
||||
println("[$start, $end] => ${s0}")
|
||||
return "a" + s0.to_upper()
|
||||
}
|
||||
|
||||
fn test_regex_func_replace1(){
|
||||
txt := "abbabbbabbbbaabba"
|
||||
query := r"a(b+)"
|
||||
mut re := regex.regex_opt(query) or { panic(err) }
|
||||
result := re.replace_by_fn(txt, my_repl_1)
|
||||
|
||||
assert result == "aBBaBBBaBBBBaaBBa"
|
||||
}
|
||||
|
||||
fn my_repl(re regex.RE, in_txt string, start int, end int) string {
|
||||
s0 := re.get_group_by_id(in_txt,0)[0..1] + "X"
|
||||
s1 := re.get_group_by_id(in_txt,1)[0..1] + "X"
|
||||
|
@ -603,7 +618,6 @@ fn my_repl(re regex.RE, in_txt string, start int, end int) string {
|
|||
return "${s0}${s1}${s2}"
|
||||
}
|
||||
|
||||
|
||||
// test regex replace function
|
||||
fn test_regex_func_replace(){
|
||||
filler := "E il primo dei tre regni dell'Oltretomba cristiano visitato da Dante nel corso del viaggio, con la guida di Virgilio."
|
||||
|
|
|
@ -212,7 +212,7 @@ pub fn (mut re RE) find(in_txt string) (int, int) {
|
|||
[direct_array_access]
|
||||
pub fn (mut re RE) find_from(in_txt string, start int) (int, int) {
|
||||
old_flag := re.flag
|
||||
re.flag |= f_src // enable search mode
|
||||
// re.flag |= f_src // enable search mode
|
||||
|
||||
mut i := start
|
||||
if i < 0 {
|
||||
|
|
Loading…
Reference in New Issue