]> Cypherpunks repositories - gostls13.git/commitdiff
rewrite RuneCountInString to use range.
authorRob Pike <r@golang.org>
Wed, 25 Nov 2009 19:39:34 +0000 (11:39 -0800)
committerRob Pike <r@golang.org>
Wed, 25 Nov 2009 19:39:34 +0000 (11:39 -0800)
R=gri
CC=golang-dev
https://golang.org/cl/160069

src/pkg/utf8/utf8.go

index 969d10ab4459886a1100f9d041263b506353ffd2..4b2e08c4dd30133b7d6ac19868cd5872d151b832 100644 (file)
@@ -273,19 +273,11 @@ func RuneCount(p []byte) int {
 }
 
 // RuneCountInString is like RuneCount but its input is a string.
-func RuneCountInString(s string) int {
-       ei := len(s);
-       i := 0;
-       var n int;
-       for n = 0; i < ei; n++ {
-               if s[i] < RuneSelf {
-                       i++
-               } else {
-                       _, size, _ := decodeRuneInStringInternal(s[i:ei]);
-                       i += size;
-               }
+func RuneCountInString(s string) (n int) {
+       for _ = range s {
+               n++
        }
-       return n;
+       return;
 }
 
 // RuneStart reports whether the byte could be the first byte of