mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Runes: turn string into []int
Split: fixed typo in documentation R=rsc, r, r1 https://golang.org/cl/157170
This commit is contained in:
parent
c0efa07c65
commit
1eba218e44
4 changed files with 116 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue