mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
js: add basic support for running tests, fix string.replace_each (#11314)
This commit is contained in:
parent
403da9f36e
commit
bdf11d969a
8 changed files with 178 additions and 28 deletions
|
@ -357,9 +357,9 @@ pub fn (s string) replace_each(vals []string) string {
|
|||
// vals: ['rep1, 'with1', 'rep2', 'with2']
|
||||
rep := vals[rep_i]
|
||||
with := vals[rep_i + 1]
|
||||
|
||||
for {
|
||||
idx = s_.index_after(rep, idx)
|
||||
|
||||
if idx == -1 {
|
||||
break
|
||||
}
|
||||
|
@ -371,6 +371,7 @@ pub fn (s string) replace_each(vals []string) string {
|
|||
}
|
||||
// We need to remember both the position in the string,
|
||||
// and which rep/with pair it refers to.
|
||||
|
||||
idxs << RepIndex{
|
||||
idx: idx
|
||||
val_idx: rep_i
|
||||
|
@ -380,6 +381,7 @@ pub fn (s string) replace_each(vals []string) string {
|
|||
new_len += with.len - rep.len
|
||||
}
|
||||
}
|
||||
|
||||
// Dont change the string if there's nothing to replace
|
||||
if idxs.len == 0 {
|
||||
return s.clone()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue