diff options
Diffstat (limited to 'libgo/go/strings/replace.go')
-rw-r--r-- | libgo/go/strings/replace.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libgo/go/strings/replace.go b/libgo/go/strings/replace.go index f63b1792c56..54c9323e048 100644 --- a/libgo/go/strings/replace.go +++ b/libgo/go/strings/replace.go @@ -364,17 +364,18 @@ func makeSingleStringReplacer(pattern string, value string) *singleStringReplace func (r *singleStringReplacer) Replace(s string) string { var buf []byte - i := 0 + i, matched := 0, false for { match := r.finder.next(s[i:]) if match == -1 { break } + matched = true buf = append(buf, s[i:i+match]...) buf = append(buf, r.value...) i += match + len(r.finder.pattern) } - if buf == nil { + if !matched { return s } buf = append(buf, s[i:]...) |