fix #3217 (string.replace)

pull/3208/head
BigBlack 2019-12-27 12:20:06 +08:00 committed by Alexander Medvednikov
parent e20ca28d5c
commit 98b81252b7
2 changed files with 4 additions and 1 deletions

View File

@ -152,7 +152,7 @@ pub fn (s string) replace(rep, with string) string {
break break
} }
idxs << idx idxs << idx
idx++ idx += rep.len
} }
// Dont change the string if there's nothing to replace // Dont change the string if there's nothing to replace
if idxs.len == 0 { if idxs.len == 0 {

View File

@ -220,6 +220,9 @@ fn test_replace() {
assert b.replace('charptr', 'byteptr') == '*byteptr' assert b.replace('charptr', 'byteptr') == '*byteptr'
c :='abc' c :='abc'
assert c.replace('','-') == c assert c.replace('','-') == c
v :='a b c d'
assert v.replace(' ',' ') == 'a b c d'
} }
fn test_replace_each() { fn test_replace_each() {