Commit 773e7798 authored by Rob Pike's avatar Rob Pike

rewrite RuneCountInString to use range.

R=gri
CC=golang-dev
https://golang.org/cl/160069
parent f65427a8
...@@ -273,19 +273,11 @@ func RuneCount(p []byte) int { ...@@ -273,19 +273,11 @@ func RuneCount(p []byte) int {
} }
// RuneCountInString is like RuneCount but its input is a string. // RuneCountInString is like RuneCount but its input is a string.
func RuneCountInString(s string) int { func RuneCountInString(s string) (n int) {
ei := len(s); for _ = range s {
i := 0; n++
var n int;
for n = 0; i < ei; n++ {
if s[i] < RuneSelf {
i++
} else {
_, size, _ := decodeRuneInStringInternal(s[i:ei]);
i += size;
}
} }
return n; return;
} }
// RuneStart reports whether the byte could be the first byte of // RuneStart reports whether the byte could be the first byte of
......
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