Commit 19c1b163 authored by Robert Griesemer's avatar Robert Griesemer

bytes, strings: improve documentation for Count functions

Fixes #9659.

Change-Id: If364d5984a0c9a48858ae524b1560f633e621826
Reviewed-on: https://go-review.googlesource.com/3181Reviewed-by: default avatarRob Pike <r@golang.org>
parent 494b4ce2
...@@ -23,7 +23,7 @@ func equalPortable(a, b []byte) bool { ...@@ -23,7 +23,7 @@ func equalPortable(a, b []byte) bool {
return true return true
} }
// explode splits s into a slice of UTF-8 sequences, one per Unicode character (still slices of bytes), // explode splits s into a slice of UTF-8 sequences, one per Unicode code point (still slices of bytes),
// up to a maximum of n byte slices. Invalid UTF-8 sequences are chopped into individual bytes. // up to a maximum of n byte slices. Invalid UTF-8 sequences are chopped into individual bytes.
func explode(s []byte, n int) [][]byte { func explode(s []byte, n int) [][]byte {
if n <= 0 { if n <= 0 {
...@@ -47,6 +47,7 @@ func explode(s []byte, n int) [][]byte { ...@@ -47,6 +47,7 @@ func explode(s []byte, n int) [][]byte {
} }
// Count counts the number of non-overlapping instances of sep in s. // Count counts the number of non-overlapping instances of sep in s.
// If sep is an empty slice, Count returns 1 + the number of Unicode code points in s.
func Count(s, sep []byte) int { func Count(s, sep []byte) int {
n := len(sep) n := len(sep)
if n == 0 { if n == 0 {
......
...@@ -78,6 +78,7 @@ func hashStrRev(sep string) (uint32, uint32) { ...@@ -78,6 +78,7 @@ func hashStrRev(sep string) (uint32, uint32) {
} }
// Count counts the number of non-overlapping instances of sep in s. // Count counts the number of non-overlapping instances of sep in s.
// If sep is an empty string, Count returns 1 + the number of Unicode code points in s.
func Count(s, sep string) int { func Count(s, sep string) int {
n := 0 n := 0
// special cases // special cases
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment