Skip to content

Commit

Permalink
strings, bytes: document behavior of Replace when old is empty
Browse files Browse the repository at this point in the history
Fixes #8143.

LGTM=r
R=rsc, bradfitz, r
CC=golang-codereviews
https://golang.org/cl/135760043
  • Loading branch information
cespare authored and robpike committed Aug 25, 2014
1 parent 958a610 commit 2c121b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/pkg/bytes/bytes.go
Expand Up @@ -605,6 +605,9 @@ func Runes(s []byte) []rune {

// Replace returns a copy of the slice s with the first n
// non-overlapping instances of old replaced by new.
// If old is empty, it matches at the beginning of the slice
// and after each UTF-8 sequence, yielding up to k+1 replacements
// for a k-rune slice.
// If n < 0, there is no limit on the number of replacements.
func Replace(s, old, new []byte, n int) []byte {
m := 0
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/strings/strings.go
Expand Up @@ -635,6 +635,9 @@ func TrimSuffix(s, suffix string) string {

// Replace returns a copy of the string s with the first n
// non-overlapping instances of old replaced by new.
// If old is empty, it matches at the beginning of the string
// and after each UTF-8 sequence, yielding up to k+1 replacements
// for a k-rune string.
// If n < 0, there is no limit on the number of replacements.
func Replace(s, old, new string, n int) string {
if old == new || n == 0 {
Expand Down

0 comments on commit 2c121b6

Please sign in to comment.