Source File
strings.go
Belonging Package
strings
package strings
import (
)
if len() == 0 {
return utf8.RuneCountInString() + 1
}
if len() == 1 {
return bytealg.CountString(, [0])
}
:= 0
for {
:= Index(, )
if == -1 {
return
}
++
= [+len():]
}
}
func ( string, byte) int {
return bytealg.IndexByteString(, )
}
return -1
}
return -1
}
if len() == 1 {
:= rune([0])
if >= utf8.RuneSelf {
= utf8.RuneError
}
if IndexRune(, ) >= 0 {
return 0
}
return -1
}
if len() > 8 {
if , := makeASCIISet(); {
for := len() - 1; >= 0; -- {
if .contains([]) {
return
}
}
return -1
}
}
if len() == 1 {
:= rune([0])
if >= utf8.RuneSelf {
= utf8.RuneError
}
for := len(); > 0; {
, := utf8.DecodeLastRuneInString([:])
-=
if == {
return
}
}
return -1
}
for := len(); > 0; {
, := utf8.DecodeLastRuneInString([:])
-=
if IndexRune(, ) >= 0 {
return
}
}
return -1
}
:= 0
:= uint8(0)
for := 0; < len(); ++ {
:= []
|=
:= int(asciiSpace[])
+= & ^
=
}
return FieldsFunc(, unicode.IsSpace)
for < len() && asciiSpace[[]] != 0 {
++
}
=
for < len() {
if asciiSpace[[]] == 0 {
++
continue
}
[] = [:]
++
for < len() && asciiSpace[[]] != 0 {
++
}
=
}
if < len() { // Last field might end at EOF.
[] = [:]
}
return
}
:= -1 // valid span start if >= 0
for , := range {
if () {
if >= 0 {
= ^
}
} else {
if < 0 {
=
}
}
}
func ( []string, string) string {
switch len() {
case 0:
return ""
case 1:
return [0]
}
:= len() * (len() - 1)
for := 0; < len(); ++ {
+= len([])
}
var Builder
.Grow()
.WriteString([0])
for , := range [1:] {
.WriteString()
.WriteString()
}
return .String()
}
if .Cap() == 0 { // didn't call b.Grow above
return
}
for , := range {
:= ()
if < 0 {
panic("strings: negative Repeat count")
} else if len()*/ != len() {
panic("strings: Repeat count causes overflow")
}
:= len() *
var Builder
.Grow()
.WriteString()
for .Len() < {
if .Len() <= /2 {
.WriteString(.String())
} else {
.WriteString(.String()[:-.Len()])
break
}
}
return .String()
}
func ( string) string {
, := true, false
for := 0; < len(); ++ {
:= []
if >= utf8.RuneSelf {
= false
break
}
= || ('a' <= && <= 'z')
}
if { // optimize for ASCII-only strings.
if ! {
return
}
var Builder
.Grow(len())
for := 0; < len(); ++ {
:= []
if 'a' <= && <= 'z' {
-= 'a' - 'A'
}
.WriteByte()
}
return .String()
}
return Map(unicode.ToUpper, )
}
func ( string) string {
, := true, false
for := 0; < len(); ++ {
:= []
if >= utf8.RuneSelf {
= false
break
}
= || ('A' <= && <= 'Z')
}
if { // optimize for ASCII-only strings.
if ! {
return
}
var Builder
.Grow(len())
for := 0; < len(); ++ {
:= []
if 'A' <= && <= 'Z' {
+= 'a' - 'A'
}
.WriteByte()
}
return .String()
}
return Map(unicode.ToLower, )
}
if .Cap() == 0 { // didn't call b.Grow above
return
}
:= false // previous byte was from an invalid UTF-8 sequence
for := 0; < len(); {
:= []
if < utf8.RuneSelf {
++
= false
.WriteByte()
continue
}
, := utf8.DecodeRuneInString([:])
if == 1 {
++
if ! {
= true
.WriteString()
}
continue
}
= false
.WriteString([ : +])
+=
}
return .String()
}
func ( string, func(rune) bool) string {
:= lastIndexFunc(, , false)
if >= 0 && [] >= utf8.RuneSelf {
, := utf8.DecodeRuneInString([:])
+=
} else {
++
}
return [0:]
}
func ( string, func(rune) bool) string {
return TrimRightFunc(TrimLeftFunc(, ), )
}
func ( *asciiSet) ( byte) bool {
return ([>>5] & (1 << uint(&31))) != 0
}
func ( string) func(rune) bool {
if len() == 1 && [0] < utf8.RuneSelf {
return func( rune) bool {
return == rune([0])
}
}
if , := makeASCIISet(); {
return func( rune) bool {
return < utf8.RuneSelf && .contains(byte())
}
}
return func( rune) bool { return IndexRune(, ) >= 0 }
}
func (, string) string {
if == "" || == "" {
return
}
return TrimFunc(, makeCutsetFunc())
}
func (, string) string {
if == "" || == "" {
return
}
return TrimLeftFunc(, makeCutsetFunc())
}
func (, string) string {
if == "" || == "" {
return
}
return TrimRightFunc(, makeCutsetFunc())
}
:= 0
for ; < len(); ++ {
:= []
return TrimFunc([:], unicode.IsSpace)
}
if asciiSpace[] == 0 {
break
}
}
return [:]
}
if := Count(, ); == 0 {
return // avoid allocation
} else if < 0 || < {
=
}
var Builder
.Grow(len() + *(len()-len()))
:= 0
for := 0; < ; ++ {
:=
if len() == 0 {
if > 0 {
, := utf8.DecodeRuneInString([:])
+=
}
} else {
+= Index([:], )
}
.WriteString([:])
.WriteString()
= + len()
}
.WriteString([:])
return .String()
}
if == {
continue
}
if < {
, = ,
if 'A' <= && <= 'Z' && == +'a'-'A' {
continue
}
return false
}
:= unicode.SimpleFold()
for != && < {
= unicode.SimpleFold()
}
if == {
continue
}
return false
}
return ==
}
if len() <= bytealg.MaxBruteForce {
return bytealg.IndexString(, )
}
:= [0]
:= [1]
:= 0
:= len() - + 1
:= 0
for < {
:= IndexByte([+1:], )
if < 0 {
return -1
}
+= + 1
}
if [+1] == && [:+] == {
return
}
++
:= bytealg.IndexRabinKarp([:], )
if < 0 {
return -1
}
return +
}
}
return -1
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |