From: Rob Pike Date: Wed, 25 Nov 2009 19:39:34 +0000 (-0800) Subject: rewrite RuneCountInString to use range. X-Git-Tag: weekly.2009-12-07~123 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=773e77981debb88069a055e64aab9853c593ec6e;p=gostls13.git rewrite RuneCountInString to use range. R=gri CC=golang-dev https://golang.org/cl/160069 --- diff --git a/src/pkg/utf8/utf8.go b/src/pkg/utf8/utf8.go index 969d10ab44..4b2e08c4dd 100644 --- a/src/pkg/utf8/utf8.go +++ b/src/pkg/utf8/utf8.go @@ -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