strings.utflen -> utf8.RuneCount, RuneCountInString
R=r
DELTA=94 (52 added, 33 deleted, 9 changed)
OCL=20547
CL=20552
diff --git a/src/lib/utf8.go b/src/lib/utf8.go
index 9ece25f..7c1c8fb 100644
--- a/src/lib/utf8.go
+++ b/src/lib/utf8.go
@@ -107,8 +107,7 @@
return RuneError, 1, false
}
-func DecodeRuneInStringInternal(s string, i int) (rune, size int, short bool) {
- n := len(s) - i;
+func DecodeRuneInStringInternal(s string, i int, n int) (rune, size int, short bool) {
if n < 1 {
return RuneError, 0, true;
}
@@ -188,7 +187,7 @@
}
export func FullRuneInString(s string, i int) bool {
- rune, size, short := DecodeRuneInStringInternal(s, i);
+ rune, size, short := DecodeRuneInStringInternal(s, i, len(s) - i);
return !short
}
@@ -200,7 +199,7 @@
export func DecodeRuneInString(s string, i int) (rune, size int) {
var short bool;
- rune, size, short = DecodeRuneInStringInternal(s, i);
+ rune, size, short = DecodeRuneInStringInternal(s, i, len(s) - i);
return;
}
@@ -248,3 +247,31 @@
return 4;
}
+export func RuneCount(p *[]byte) int {
+ i := 0;
+ var n int;
+ for n = 0; i < len(p); n++ {
+ if p[i] < RuneSelf {
+ i++;
+ } else {
+ rune, size := DecodeRune(p[i:len(p)]);
+ i += size;
+ }
+ }
+ return n;
+}
+
+export func RuneCountInString(s string, i int, l int) int {
+ ei := i + l;
+ n := 0;
+ for n = 0; i < ei; n++ {
+ if s[i] < RuneSelf {
+ i++;
+ } else {
+ rune, size, short := DecodeRuneInStringInternal(s, i, ei - i);
+ i += size;
+ }
+ }
+ return n;
+}
+