diff --git a/src/bytes/iter.go b/src/bytes/iter.go index e3af4d2f13927d..b2abb2c9ba3dc6 100644 --- a/src/bytes/iter.go +++ b/src/bytes/iter.go @@ -31,23 +31,18 @@ func Lines(s []byte) iter.Seq[[]byte] { } } -// explodeSeq returns an iterator over the runes in s. -func explodeSeq(s []byte, yield func([]byte) bool) { - for len(s) > 0 { - _, size := utf8.DecodeRune(s) - if !yield(s[:size:size]) { - return - } - s = s[size:] - } -} - // splitSeq is SplitSeq or SplitAfterSeq, configured by how many // bytes of sep to include in the results (none or all). func splitSeq(s, sep []byte, sepSave int) iter.Seq[[]byte] { return func(yield func([]byte) bool) { if len(sep) == 0 { - explodeSeq(s, yield) + for len(s) > 0 { + _, size := utf8.DecodeRune(s) + if !yield(s[:size:size]) { + return + } + s = s[size:] + } return } for { diff --git a/src/strings/iter.go b/src/strings/iter.go index a42e78ee09fce1..69fe031739628c 100644 --- a/src/strings/iter.go +++ b/src/strings/iter.go @@ -31,23 +31,18 @@ func Lines(s string) iter.Seq[string] { } } -// explodeSeq returns an iterator over the runes in s. -func explodeSeq(s string, yield func(string) bool) { - for len(s) > 0 { - _, size := utf8.DecodeRuneInString(s) - if !yield(s[:size]) { - return - } - s = s[size:] - } -} - // splitSeq is SplitSeq or SplitAfterSeq, configured by how many // bytes of sep to include in the results (none or all). func splitSeq(s, sep string, sepSave int) iter.Seq[string] { return func(yield func(string) bool) { if len(sep) == 0 { - explodeSeq(s, yield) + for len(s) > 0 { + _, size := utf8.DecodeRuneInString(s) + if !yield(s[:size]) { + return + } + s = s[size:] + } return } for {