builtin: consume matched string length in string.replace_each (#6349)
parent
b10d79c4d9
commit
332f3a924c
|
@ -292,7 +292,7 @@ pub fn (s string) replace_each(vals []string) string {
|
||||||
idx:idx
|
idx:idx
|
||||||
val_idx:rep_i
|
val_idx:rep_i
|
||||||
}
|
}
|
||||||
idx++
|
idx += rep.len
|
||||||
new_len += with.len - rep.len
|
new_len += with.len - rep.len
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,6 +285,11 @@ fn test_replace_each() {
|
||||||
'[b]', '<b>',
|
'[b]', '<b>',
|
||||||
'[/b]', '</b>',
|
'[/b]', '</b>',
|
||||||
]) == '<b>cool</b>'
|
]) == '<b>cool</b>'
|
||||||
|
t := 'aaaaaaaa'
|
||||||
|
y := t.replace_each([
|
||||||
|
'aa', 'b'
|
||||||
|
])
|
||||||
|
assert y == 'bbbb'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_itoa() {
|
fn test_itoa() {
|
||||||
|
|
|
@ -8,7 +8,7 @@ struct HttpbinResponseBody {
|
||||||
files map[string]string
|
files map[string]string
|
||||||
form map[string]string
|
form map[string]string
|
||||||
headers map[string]string
|
headers map[string]string
|
||||||
json ?map[string]string
|
json map[string]string
|
||||||
origin string
|
origin string
|
||||||
url string
|
url string
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ fn http_fetch_mock(_methods []string, _config FetchConfig) ?[]Response {
|
||||||
// Note: httpbin doesn't support head
|
// Note: httpbin doesn't support head
|
||||||
for method in methods {
|
for method in methods {
|
||||||
lmethod := method.to_lower()
|
lmethod := method.to_lower()
|
||||||
config.method = method
|
config.method = method_from_str(method)
|
||||||
res := fetch(url + lmethod, config)?
|
res := fetch(url + lmethod, config)?
|
||||||
// TODO
|
// TODO
|
||||||
// body := json.decode(HttpbinResponseBody,res.text)?
|
// body := json.decode(HttpbinResponseBody,res.text)?
|
||||||
|
|
Loading…
Reference in New Issue