fix_replace

pull/769/head
leonlau 2019-06-28 23:17:54 +08:00 committed by Alexander Medvednikov
parent b6b313d246
commit b0bc53730c
2 changed files with 3 additions and 1 deletions

View File

@ -75,7 +75,7 @@ pub fn (s string) cstr() byteptr {
pub fn (s string) replace(rep, with string) string { pub fn (s string) replace(rep, with string) string {
if s.len == 0 || rep.len == 0 { if s.len == 0 || rep.len == 0 {
return '' return s
} }
if !s.contains(rep) { if !s.contains(rep) {
return s return s

View File

@ -165,6 +165,8 @@ fn test_replace() {
assert b.replace('B', '') == 'onetwothree' assert b.replace('B', '') == 'onetwothree'
b = '**char' b = '**char'
assert b.replace('*char', 'byteptr') == '*byteptr' assert b.replace('*char', 'byteptr') == '*byteptr'
mut c :='abc'
assert c.replace('','-') == c
} }
fn test_itoa() { fn test_itoa() {