bytes, strings: add ReplaceAll

Credit to Harald Nordgren for the proposal in
https://golang.org/cl/137456 and #27864.

Fixes #27864

Change-Id: I80546683b0623124fe4627a71af88add2f6c1c27
Reviewed-on: https://go-review.googlesource.com/137855
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Brad Fitzpatrick 2018-09-26 20:19:11 +00:00
parent 5a8c11ce3e
commit ebdc0b8d68
4 changed files with 30 additions and 0 deletions

View file

@ -1243,6 +1243,12 @@ func TestReplace(t *testing.T) {
if s := Replace(tt.in, tt.old, tt.new, tt.n); s != tt.out {
t.Errorf("Replace(%q, %q, %q, %d) = %q, want %q", tt.in, tt.old, tt.new, tt.n, s, tt.out)
}
if tt.n == -1 {
s := ReplaceAll(tt.in, tt.old, tt.new)
if s != tt.out {
t.Errorf("ReplaceAll(%q, %q, %q) = %q, want %q", tt.in, tt.old, tt.new, s, tt.out)
}
}
}
}