From b0bc53730ce6295ec81f6b66de5e09afdf3321c9 Mon Sep 17 00:00:00 2001 From: leonlau Date: Fri, 28 Jun 2019 23:17:54 +0800 Subject: [PATCH] fix_replace --- builtin/string.v | 2 +- builtin/string_test.v | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/string.v b/builtin/string.v index 868f999c29..27b0bdbd32 100644 --- a/builtin/string.v +++ b/builtin/string.v @@ -75,7 +75,7 @@ pub fn (s string) cstr() byteptr { pub fn (s string) replace(rep, with string) string { if s.len == 0 || rep.len == 0 { - return '' + return s } if !s.contains(rep) { return s diff --git a/builtin/string_test.v b/builtin/string_test.v index bcfc086a8e..3c142ebc07 100644 --- a/builtin/string_test.v +++ b/builtin/string_test.v @@ -165,6 +165,8 @@ fn test_replace() { assert b.replace('B', '') == 'onetwothree' b = '**char' assert b.replace('*char', 'byteptr') == '*byteptr' + mut c :='abc' + assert c.replace('','-') == c } fn test_itoa() {