Source File
bytes.go
Belonging Package
bytes
package bytes
import (
)
func ( []byte, rune) int {
switch {
case 0 <= && < utf8.RuneSelf:
return IndexByte(, byte())
case == utf8.RuneError:
for := 0; < len(); {
, := utf8.DecodeRune([:])
if == utf8.RuneError {
return
}
+=
}
return -1
case !utf8.ValidRune():
return -1
default:
var [utf8.UTFMax]byte
:= utf8.EncodeRune([:], )
return Index(, [:])
}
}
for _, = range {
if == utf8.RuneError {
return 0
}
}
return -1
}
if bytealg.IndexByteString(, [0]) >= 0 {
return 0
}
return -1
}
if len() == 1 {
:= rune([0])
if >= utf8.RuneSelf {
= utf8.RuneError
}
return IndexRune(, )
}
if len() > 8 {
if , := makeASCIISet(); {
for , := range {
if .contains() {
return
}
}
return -1
}
}
var int
for := 0; < len(); += {
:= rune([])
if < utf8.RuneSelf {
if bytealg.IndexByteString(, []) >= 0 {
return
}
= 1
continue
}
, = utf8.DecodeRune([:])
if bytealg.MaxLen >= {
if bytealg.IndexString(, string()) >= 0 {
return
}
continue
}
}
for , := range {
if == {
return
}
}
}
return -1
}
return -1
}
if len() > 8 {
if , := makeASCIISet(); {
for := len() - 1; >= 0; -- {
if .contains([]) {
return
}
}
return -1
}
}
if len() == 1 {
:= rune([0])
if >= utf8.RuneSelf {
for _, = range {
if == utf8.RuneError {
return 0
}
}
return -1
}
if bytealg.IndexByteString(, [0]) >= 0 {
return 0
}
return -1
}
if len() == 1 {
:= rune([0])
if >= utf8.RuneSelf {
= utf8.RuneError
}
for := len(); > 0; {
, := utf8.DecodeLastRune([:])
-=
if == {
return
}
}
return -1
}
for := len(); > 0; {
:= rune([-1])
if < utf8.RuneSelf {
if bytealg.IndexByteString(, [-1]) >= 0 {
return - 1
}
--
continue
}
, := utf8.DecodeLastRune([:])
-=
if bytealg.MaxLen >= {
if bytealg.IndexString(, string()) >= 0 {
return
}
continue
}
}
for , := range {
if == {
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.
[] = [:len():len()]
}
return
}
func ( []byte) []byte {
, := true, false
for := 0; < len(); ++ {
:= []
if >= utf8.RuneSelf {
= false
break
}
= || ('A' <= && <= 'Z')
}
if { // optimize for ASCII-only byte slices.
if ! {
return append([]byte(""), ...)
}
:= make([]byte, len())
for := 0; < len(); ++ {
:= []
if 'A' <= && <= 'Z' {
+= 'a' - 'A'
}
[] =
}
return
}
return Map(unicode.ToLower, )
}
func (, []byte) []byte {
:= make([]byte, 0, len()+len())
:= false // previous byte was from an invalid UTF-8 sequence
for := 0; < len(); {
:= []
if < utf8.RuneSelf {
++
= false
= append(, byte())
continue
}
, := utf8.DecodeRune([:])
if == 1 {
++
if ! {
= true
= append(, ...)
}
continue
}
= false
= append(, [:+]...)
+=
}
return
}
func ( []byte, func( rune) bool) []byte {
:= lastIndexFunc(, , false)
if >= 0 && [] >= utf8.RuneSelf {
, := utf8.DecodeRune([:])
+=
} else {
++
}
return [0:]
}
func ( []byte, func( rune) bool) []byte {
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 {
for , := range {
if == {
return true
}
}
return false
}
}
func ( []byte, string) []byte {
return TrimFunc(, makeCutsetFunc())
}
func ( []byte, string) []byte {
return TrimLeftFunc(, makeCutsetFunc())
}
func ( []byte, string) []byte {
return TrimRightFunc(, makeCutsetFunc())
}
:= 0
for ; < len(); ++ {
:= []
return TrimFunc([:], unicode.IsSpace)
}
if asciiSpace[] == 0 {
break
}
}
return nil
}
return [:]
}
= Count(, )
}
if == {
continue
}
if < {
, = ,
if 'A' <= && <= 'Z' && == +'a'-'A' {
continue
}
return false
}
:= unicode.SimpleFold()
for != && < {
= unicode.SimpleFold()
}
if == {
continue
}
return false
}
:= bytealg.IndexRabinKarpBytes([:], )
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. |