Runes: turn string into []int

Split: fixed typo in documentation

R=rsc, r, r1
https://golang.org/cl/157170
This commit is contained in:
Peter Froehlich 2009-12-02 20:47:38 -08:00 committed by Russ Cox
parent c0efa07c65
commit 1eba218e44
4 changed files with 116 additions and 1 deletions

View file

@ -333,3 +333,16 @@ func AddByte(s []byte, t byte) []byte {
s[lens] = t;
return s;
}
// Runes returns a slice of runes (Unicode code points) equivalent to s.
func Runes(s []byte) []int {
t := make([]int, utf8.RuneCount(s));
i := 0;
for len(s) > 0 {
r, l := utf8.DecodeRune(s);
t[i] = r;
i++;
s = s[l:];
}
return t;
}