mirror of
https://github.com/golang/go
synced 2024-11-22 22:10:03 -07:00
document strings
R=rsc DELTA=9 (4 added, 0 deleted, 5 changed) OCL=25793 CL=25795
This commit is contained in:
parent
63985b489b
commit
0f7306b78c
@ -2,11 +2,13 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// A package of simple functions to manipulate strings.
|
||||||
package strings
|
package strings
|
||||||
|
|
||||||
import "utf8"
|
import "utf8"
|
||||||
|
|
||||||
// Split string into array of UTF-8 sequences (still strings)
|
// Explode splits s into an array of UTF-8 sequences, one per Unicode character (still strings).
|
||||||
|
// Invalid UTF-8 sequences become correct encodings of U+FFF8.
|
||||||
func Explode(s string) []string {
|
func Explode(s string) []string {
|
||||||
a := make([]string, utf8.RuneCountInString(s, 0, len(s)));
|
a := make([]string, utf8.RuneCountInString(s, 0, len(s)));
|
||||||
j := 0;
|
j := 0;
|
||||||
@ -19,7 +21,7 @@ func Explode(s string) []string {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count non-overlapping instances of sep in s.
|
// Count counts the number of non-overlapping instances of sep in s.
|
||||||
func Count(s, sep string) int {
|
func Count(s, sep string) int {
|
||||||
if sep == "" {
|
if sep == "" {
|
||||||
return utf8.RuneCountInString(s, 0, len(s))+1
|
return utf8.RuneCountInString(s, 0, len(s))+1
|
||||||
@ -35,7 +37,7 @@ func Count(s, sep string) int {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return index of first instance of sep in s.
|
// Index returns the index of the first instance of sep in s.
|
||||||
func Index(s, sep string) int {
|
func Index(s, sep string) int {
|
||||||
if sep == "" {
|
if sep == "" {
|
||||||
return 0
|
return 0
|
||||||
@ -49,7 +51,8 @@ func Index(s, sep string) int {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split string into list of strings at separators
|
// Split returns the array representing the substrings of s separated by string sep. Adjacent
|
||||||
|
// occurrences of sep produce empty substrings. If sep is empty, it is the same as Explode.
|
||||||
func Split(s, sep string) []string {
|
func Split(s, sep string) []string {
|
||||||
if sep == "" {
|
if sep == "" {
|
||||||
return Explode(s)
|
return Explode(s)
|
||||||
@ -71,7 +74,8 @@ func Split(s, sep string) []string {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join list of strings with separators between them.
|
// Join concatenates the elements of a to create a single string. The separator string
|
||||||
|
// sep is placed between elements in the resulting string.
|
||||||
func Join(a []string, sep string) string {
|
func Join(a []string, sep string) string {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return ""
|
return ""
|
||||||
|
Loading…
Reference in New Issue
Block a user