summaryrefslogtreecommitdiff
path: root/src/pkg/strings/strings.go
diff options
context:
space:
mode:
authorPeter Froehlich <peter.hans.froehlich@gmail.com>2009-12-02 20:47:38 -0800
committerPeter Froehlich <peter.hans.froehlich@gmail.com>2009-12-02 20:47:38 -0800
commit0247d93d819700b0bfc6814dc7b1c2afec4648a0 (patch)
tree34efe677ee0f64db58643d216d064b70bc35e016 /src/pkg/strings/strings.go
parentb7bc89750bfcae2432653c3cd79ad5570b9c456d (diff)
downloadgolang-0247d93d819700b0bfc6814dc7b1c2afec4648a0.tar.gz
Runes: turn string into []int
Split: fixed typo in documentation R=rsc, r, r1 http://codereview.appspot.com/157170 Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/pkg/strings/strings.go')
-rw-r--r--src/pkg/strings/strings.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go
index 013af680a..7be98e6c1 100644
--- a/src/pkg/strings/strings.go
+++ b/src/pkg/strings/strings.go
@@ -124,7 +124,7 @@ func genSplit(s, sep string, sepSave, n int) []string {
// Split splits the string s around each instance of sep, returning an array of substrings of s.
// If sep is empty, Split splits s after each UTF-8 sequence.
-// If n > 0, split Splits s into at most n substrings; the last substring will be the unsplit remainder.
+// If n > 0, Split splits s into at most n substrings; the last substring will be the unsplit remainder.
func Split(s, sep string, n int) []string { return genSplit(s, sep, 0, n) }
// SplitAfter splits the string s after each instance of sep, returning an array of substrings of s.
@@ -272,3 +272,14 @@ func Bytes(s string) []byte {
}
return b;
}
+
+// Runes returns a slice of runes (Unicode code points) equivalent to the string s.
+func Runes(s string) []int {
+ t := make([]int, utf8.RuneCountInString(s));
+ i := 0;
+ for _, r := range s {
+ t[i] = r;
+ i++;
+ }
+ return t;
+}