亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內(nèi)置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結(jié)構(gòu)heap) container/list(容器數(shù)據(jù)結(jié)構(gòu)list) container/ring(容器數(shù)據(jù)結(jié)構(gòu)ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數(shù)據(jù)庫/sql) database/sql/driver(數(shù)據(jù)庫/sql/driver) debug debug/dwarf(調(diào)試/dwarf) debug/elf(調(diào)試/elf) debug/gosym(調(diào)試/gosym) debug/macho(調(diào)試/macho) debug/pe(調(diào)試/pe) debug/plan9obj(調(diào)試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數(shù)解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調(diào)色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達(dá)式) regexp/syntax runtime runtime(運(yùn)行時) runtime/debug(調(diào)試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉(zhuǎn)換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調(diào)用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
characters

  • import "bytes"

  • 概述

  • 索引

  • 示例

概述

包字節(jié)實現(xiàn)了對字節(jié)片的操作。它類似于字符串包的設(shè)施。

索引

Constants(常量)

Variables(變量)

func Compare(a, b []byte) int

func Contains(b, subslice []byte) bool

func ContainsAny(b []byte, chars string) bool

func ContainsRune(b []byte, r rune) bool

func Count(s, sep []byte) int

func Equal(a, b []byte) bool

func EqualFold(s, t []byte) bool

func Fields(s []byte) [][]byte

func FieldsFunc(s []byte, f func(rune) bool) [][]byte

func HasPrefix(s, prefix []byte) bool

func HasSuffix(s, suffix []byte) bool

func Index(s, sep []byte) int

func IndexAny(s []byte, chars string) int

func IndexByte(s []byte, c byte) int

func IndexFunc(s []byte, f func(r rune) bool) int

func IndexRune(s []byte, r rune) int

func Join(s [][]byte, sep []byte) []byte

func LastIndex(s, sep []byte) int

func LastIndexAny(s []byte, chars string) int

func LastIndexByte(s []byte, c byte) int

func LastIndexFunc(s []byte, f func(r rune) bool) int

func Map(mapping func(r rune) rune, s []byte) []byte

func Repeat(b []byte, count int) []byte

func Replace(s, old, new []byte, n int) []byte

func Runes(s []byte) []rune

func Split(s, sep []byte) [][]byte

func SplitAfter(s, sep []byte) [][]byte

func SplitAfterN(s, sep []byte, n int) [][]byte

func SplitN(s, sep []byte, n int) [][]byte

func Title(s []byte) []byte

func ToLower(s []byte) []byte

func ToLowerSpecial(c unicode.SpecialCase, s []byte) []byte

func ToTitle(s []byte) []byte

func ToTitleSpecial(c unicode.SpecialCase, s []byte) []byte

func ToUpper(s []byte) []byte

func ToUpperSpecial(c unicode.SpecialCase, s []byte) []byte

func Trim(s []byte, cutset string) []byte

func TrimFunc(s []byte, f func(r rune) bool) []byte

func TrimLeft(s []byte, cutset string) []byte

func TrimLeftFunc(s []byte, f func(r rune) bool) []byte

func TrimPrefix(s, prefix []byte) []byte

func TrimRight(s []byte, cutset string) []byte

func TrimRightFunc(s []byte, f func(r rune) bool) []byte

func TrimSpace(s []byte) []byte

func TrimSuffix(s, suffix []byte) []byte

type Buffer

  • func NewBuffer(buf []byte) *Buffer

  • func NewBufferString(s string) *Buffer

  • func (b *Buffer) Bytes() []byte

  • func (b *Buffer) Cap() int

  • func (b *Buffer) Grow(n int)

  • func (b *Buffer) Len() int

  • func (b *Buffer) Next(n int) []byte

  • func (b *Buffer) Read(p []byte) (n int, err error)

  • func (b *Buffer) ReadByte() (byte, error)

  • func (b *Buffer) ReadBytes(delim byte) (line []byte, err error)

  • func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)

  • func (b *Buffer) ReadRune() (r rune, size int, err error)

  • func (b *Buffer) ReadString(delim byte) (line string, err error)

  • func (b *Buffer) Reset()

  • func (b *Buffer) String() string

  • func (b *Buffer) Truncate(n int)

  • func (b *Buffer) UnreadByte() error

  • func (b *Buffer) UnreadRune() error

  • func (b *Buffer) Write(p []byte) (n int, err error)

  • func (b *Buffer) WriteByte(c byte) error

  • func (b *Buffer) WriteRune(r rune) (n int, err error)

  • func (b *Buffer) WriteString(s string) (n int, err error)

  • func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)

type Reader

  • func NewReader(b []byte) *Reader

  • func (r *Reader) Len() int

  • func (r *Reader) Read(b []byte) (n int, err error)

  • func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)

  • func (r *Reader) ReadByte() (byte, error)

  • func (r *Reader) ReadRune() (ch rune, size int, err error)

  • func (r *Reader) Reset(b []byte)

  • func (r *Reader) Seek(offset int64, whence int) (int64, error)

  • func (r *Reader) Size() int64

  • func (r *Reader) UnreadByte() error

  • func (r *Reader) UnreadRune() error

  • func (r *Reader) WriteTo(w io.Writer) (n int64, err error)

Bugs

示例

Buffer

Buffer.Grow

Buffer (Reader)

Compare

Compare (Search)

Contains

Count

EqualFold

Fields

FieldsFunc

HasPrefix

HasSuffix

Index

IndexAny

IndexFunc

IndexRune

Join

LastIndex

Map

Repeat

Replace

Split

SplitAfter

SplitAfterN

SplitN

Title

ToLower

ToTitle

ToUpper

Trim

TrimPrefix

TrimSpace

TrimSuffix

包文件

buffer.go bytes.go bytes_amd64.go bytes_decl.go reader.go

常量

MinRead是由Buffer.ReadFrom傳遞給Read調(diào)用的最小切片大小。只要緩沖區(qū)的最小讀取字節(jié)數(shù)超過了保存r內(nèi)容所需的字節(jié)數(shù),ReadFrom將不會增長底層緩沖區(qū)。

const MinRead = 512

變量

如果無法分配內(nèi)存以將數(shù)據(jù)存儲在緩沖區(qū)中,則 ErrTooLarge 會傳遞給panic。

var ErrTooLarge = errors.New("bytes.Buffer: too large")

func Compare

func Compare(a, b []byte) int

Compare  按字典順序返回一個比較兩個字節(jié)片段的整數(shù)。如果a == b,結(jié)果將為0,如果 a <b 則返回-1,如果 a> b 則返回+1。零參數(shù)相當(dāng)于一個空片。

示例

package mainimport ("bytes")func main() {// 通過將比較結(jié)果與零比較來解釋比較結(jié)果。var a, b []byteif bytes.Compare(a, b) < 0 {// a 小于 b}if bytes.Compare(a, b) <= 0 {// a 小于或等于 b}if bytes.Compare(a, b) > 0 {// a 大于 b}if bytes.Compare(a, b) >= 0 {// a 大于或等于 b}// 為了比較平等,優(yōu)先選擇等于比較。if bytes.Equal(a, b) {// a 等于 b}if !bytes.Equal(a, b) {// a 不等于 b}}

示例(搜索)

package mainimport ("bytes""sort")func main() {// 二進(jìn)制搜索查找匹配的字節(jié)片。var needle []bytevar haystack [][]byte // 假設(shè)排序
	i := sort.Search(len(haystack), func(i int) bool {// 返回 haystack[i] >= needle。return bytes.Compare(haystack[i], needle) >= 0})if i < len(haystack) && bytes.Equal(haystack[i], needle) {// 找到了}}

func Contains

func Contains(b, subslice []byte) bool

包含報告 sublice 是否在 b 之內(nèi)。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Println(bytes.Contains([]byte("seafood"), []byte("foo")))
	fmt.Println(bytes.Contains([]byte("seafood"), []byte("bar")))
	fmt.Println(bytes.Contains([]byte("seafood"), []byte("")))
	fmt.Println(bytes.Contains([]byte(""), []byte("")))}

func ContainsAny

func ContainsAny(b []byte, chars string) bool

ContainsAny 報告字符中的任何 UTF-8 編碼的 Unicode 代碼點(diǎn)是否在 b 中。

func ContainsRune

func ContainsRune(b []byte, r rune) bool

ContainsRune 報告 Unicode 代碼點(diǎn) r 是否在 b 之內(nèi)。

func Count

func Count(s, sep []byte) int

Count 計算s中不重疊實例的數(shù)量。如果 sep 為空片段,則 Count 返回1 + s中的 Unicode 代碼點(diǎn)數(shù)。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Println(bytes.Count([]byte("cheese"), []byte("e")))
	fmt.Println(bytes.Count([]byte("five"), []byte(""))) // before & after each rune}

func Equal

func Equal(a, b []byte) bool

Equal 返回一個布爾值,報告 a 和 b 是否是相同的長度并且包含相同的字節(jié)。零參數(shù)相當(dāng)于一個空片。

fuc EqualFold

func EqualFold(s, t []byte) bool

EqualFold 報告無論 s 和 t,解釋為 UTF-8 字符串,在 Unicode 大小寫折疊下是否相等。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Println(bytes.EqualFold([]byte("Go"), []byte("go")))}

func Fields

func Fields(s []byte) [][]byte

字段在一個或多個連續(xù)空白字符的每個實例周圍分割切片,如果 s 僅包含空格,則返回 s 的子片段或空列表。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("Fields are: %q", bytes.Fields([]byte("  foo bar  baz   ")))}

func FieldsFunc

func FieldsFunc(s []byte, f func(rune) bool) [][]byte

FieldsFunc 將s解釋為 UTF-8 編碼的 Unicode 代碼點(diǎn)序列。它在每次滿足 f(c) 的代碼點(diǎn) c 運(yùn)行時分割片 s 并返回s的一個子片段。如果s中的所有代碼點(diǎn)滿足 f(c) 或len(s) == 0,則返回空片。FieldsFunc 不保證它調(diào)用f(c)的順序。如果f沒有為給定的 c 返回一致的結(jié)果,那么 FieldsFunc 可能會崩潰。

示例

package mainimport ("bytes""fmt""unicode")func main() {
	f := func(c rune) bool {return !unicode.IsLetter(c) && !unicode.IsNumber(c)}
	fmt.Printf("Fields are: %q", bytes.FieldsFunc([]byte("  foo1;bar2,baz3..."), f))}

func HasPrefix

func HasPrefix(s, prefix []byte) bool

HasPrefix測試字節(jié)片是否以前綴開頭。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Println(bytes.HasPrefix([]byte("Gopher"), []byte("Go")))
	fmt.Println(bytes.HasPrefix([]byte("Gopher"), []byte("C")))
	fmt.Println(bytes.HasPrefix([]byte("Gopher"), []byte("")))}

func HasSuffix

func HasSuffix(s, suffix []byte) bool

HasSuffix 測試字節(jié)片段是否以后綴結(jié)尾。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Println(bytes.HasSuffix([]byte("Amigo"), []byte("go")))
	fmt.Println(bytes.HasSuffix([]byte("Amigo"), []byte("O")))
	fmt.Println(bytes.HasSuffix([]byte("Amigo"), []byte("Ami")))
	fmt.Println(bytes.HasSuffix([]byte("Amigo"), []byte("")))}

func Index

func Index(s, sep []byte) int

索引返回 s 中第一個 sep 實例的索引,如果 s 中不存在 sep,則返回-1。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Println(bytes.Index([]byte("chicken"), []byte("ken")))
	fmt.Println(bytes.Index([]byte("chicken"), []byte("dmr")))}

func IndexAny

func IndexAny(s []byte, chars string) int

IndexAny 將 s 解釋為 UTF-8 編碼的 Unicode 代碼點(diǎn)序列。它返回字符中任何 Unicode 代碼點(diǎn)的 s 中第一次出現(xiàn)的字節(jié)索引。如果字符為空或者沒有共同的代碼點(diǎn),則返回-1。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Println(bytes.IndexAny([]byte("chicken"), "aeiouy"))
	fmt.Println(bytes.IndexAny([]byte("crwth"), "aeiouy"))}

func IndexByte

func IndexByte(s []byte, c byte) int

IndexByte 返回 s 的第一個實例的索引,如果 c 不存在于 s 中,則返回 -1。

func IndexFunc

func IndexFunc(s []byte, f func(r rune) bool) int

IndexFunc 將 s 解釋為一系列UTF-8編碼的Unicode代碼點(diǎn)。它返回滿足 f(c) 的第一個 Unicode 代碼點(diǎn)的 s 中的字節(jié)索引,否則返回 -1。

示例

package mainimport ("bytes""fmt""unicode")func main() {
	f := func(c rune) bool {return unicode.Is(unicode.Han, c)}
	fmt.Println(bytes.IndexFunc([]byte("Hello, 世界"), f))
	fmt.Println(bytes.IndexFunc([]byte("Hello, world"), f))}

func IndexRune

func IndexRune(s []byte, r rune) int

IndexRune將 s 解釋為一系列UTF-8編碼的Unicode代碼點(diǎn)。它返回給定符文的 s 中第一個出現(xiàn)的字節(jié)索引。如果符文不在 s 中,它會返回-1。如果 r 是utf8.RuneError,它將返回任何無效的UTF-8字節(jié)序列的第一個實例。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Println(bytes.IndexRune([]byte("chicken"), 'k'))
	fmt.Println(bytes.IndexRune([]byte("chicken"), 'd'))}

func Join

func Join(s [][]byte, sep []byte) []byte

Join 連接 s的元素以創(chuàng)建一個新的字節(jié)片。分隔符 sep 放置在生成的切片中的元素之間。

示例

package mainimport ("bytes""fmt")func main() {
	s := [][]byte{[]byte("foo"), []byte("bar"), []byte("baz")}
	fmt.Printf("%s", bytes.Join(s, []byte(", ")))}

func LastIndex

func LastIndex(s, sep []byte) int

LastIndex 返回 s 中最后一個 sep 實例的索引,如果 sep 中不存在 s,則返回-1。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Println(bytes.Index([]byte("go gopher"), []byte("go")))
	fmt.Println(bytes.LastIndex([]byte("go gopher"), []byte("go")))
	fmt.Println(bytes.LastIndex([]byte("go gopher"), []byte("rodent")))}

func LastIndexAny

func LastIndexAny(s []byte, chars string) int

LastIndexAny 將 s 解釋為UTF-8編碼的 Unicode 代碼點(diǎn)序列。它返回字符中任何 Unicode 代碼點(diǎn)的最后一次出現(xiàn)的字節(jié)索引。如果字符為空或者沒有共同的代碼點(diǎn),則返回-1。

func LastIndexByte

func LastIndexByte(s []byte, c byte) int

LastIndexByte 返回 s 的最后一個實例的索引,如果 c 不存在于 s 中,則返回-1。

func LastIndexFunc

func LastIndexFunc(s []byte, f func(r rune) bool) int

LastIndexFunc 將 s 解釋為UTF-8編碼的 Unicode 代碼點(diǎn)序列。它返回滿足 f(c) 的最后一個 Unicode 代碼點(diǎn)的 s 中的字節(jié)索引,否則返回-1。

func Map

func Map(mapping func(r rune) rune, s []byte) []byte

Map 根據(jù)映射函數(shù)返回字節(jié)切片s的所有字符修改后的副本。如果映射返回負(fù)值,則字符將從字符串中刪除而不會被替換。 s 和輸出中的字符被解釋為 UTF-8 編碼的 Unicode 代碼點(diǎn)。

示例

package mainimport ("bytes""fmt")func main() {
	rot13 := func(r rune) rune {switch {case r >= 'A' && r <= 'Z':return 'A' + (r-'A'+13)%26case r >= 'a' && r <= 'z':return 'a' + (r-'a'+13)%26}return r}
	fmt.Printf("%s", bytes.Map(rot13, []byte("'Twas brillig and the slithy gopher...")))}

func Repeat

func Repeat(b []byte, count int) []byte

重復(fù)返回由 b 的計數(shù)副本組成的新字節(jié)片段。

如果 count 為負(fù)數(shù)或者 (len(b) * count) 的結(jié)果溢出,它會發(fā)生混亂。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("ba%s", bytes.Repeat([]byte("na"), 2))}

func Replace

func Replace(s, old, new []byte, n int) []byte

Replace 將返回 slice 的一個副本,其中前 n 個非重疊的舊實例將被 new 替換。如果 old 是空的,它會在切片的開頭和每個 UTF-8 序列之后進(jìn)行匹配,最多可產(chǎn)生  k-1 切片的 k+1 替換。如果 n<0,則替換次數(shù)沒有限制。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("%s\n", bytes.Replace([]byte("oink oink oink"), []byte("k"), []byte("ky"), 2))
	fmt.Printf("%s\n", bytes.Replace([]byte("oink oink oink"), []byte("oink"), []byte("moo"), -1))}

func Runes

func Runes(s []byte) []rune

符文返回相當(dāng)于 s 的一段符文(Unicode 代碼點(diǎn))。

func Split

func Split(s, sep []byte) [][]byte

將切片分割成由 sep 分隔的所有子切片,并返回這些分隔符之間的一部分子切片。如果 sep 為空,Split會在每個UTF-8序列之后分裂。它相當(dāng)于 SplitN,計數(shù)為 -1 。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("%q\n", bytes.Split([]byte("a,b,c"), []byte(",")))
	fmt.Printf("%q\n", bytes.Split([]byte("a man a plan a canal panama"), []byte("a ")))
	fmt.Printf("%q\n", bytes.Split([]byte(" xyz "), []byte("")))
	fmt.Printf("%q\n", bytes.Split([]byte(""), []byte("Bernardo O'Higgins")))}

func SplitAfter

func SplitAfter(s, sep []byte) [][]byte

SplitAfter 在 sep 的每個實例之后切片到所有 sublices 中,并返回這些 sublices 的一部分。如果 sep 為空,則 SplitAfter 會在每個 UTF-8 序列后分割。它相當(dāng)于 SplitAfterN ,計數(shù)為 -1 。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("%q\n", bytes.SplitAfter([]byte("a,b,c"), []byte(",")))}

func SplitAfterN

func SplitAfterN(s, sep []byte, n int) [][]byte

在每個 sep 實例之后,SplitAfterN 將 s 分割成子項,并返回這些子項的一部分。如果 sep 為空,則 SplitAfterN 在每個 UTF-8 序列之后分割。計數(shù)確定要返回的子備份數(shù)量:

n > 0: 至多n個子模板;最后一個子切片將成為未分割的剩余部分。
n == 0: the result is nil (zero subslices)n < 0: 所有sublices

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("%q\n", bytes.SplitAfterN([]byte("a,b,c"), []byte(","), 2))}

func SplitN

func SplitN(s, sep []byte, n int) [][]byte

將 SplitN 切片成由 sep 分隔的子片段,并返回這些分隔片之間的一部分子片段。如果 sep 為空, SplitN 會在每個UTF-8序列之后分裂。計數(shù)確定要返回的子備份數(shù)量:

n > 0: at most n subslices; the last subslice will be the unsplit remainder.n == 0: the result is nil (zero subslices)n < 0: all subslices

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("%q\n", bytes.SplitN([]byte("a,b,c"), []byte(","), 2))
	z := bytes.SplitN([]byte("a,b,c"), []byte(","), 0)
	fmt.Printf("%q (nil = %v)\n", z, z == nil)}

func Title

func Title(s []byte) []byte

標(biāo)題返回一個 s 的副本,其中包含所有 Unicode 字母,這些字母開始被映射到其標(biāo)題大小寫。

BUG(rsc):規(guī)則標(biāo)題用于單詞邊界的規(guī)則不能正確處理 Unicode 標(biāo)點(diǎn)符號。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("%s", bytes.Title([]byte("her royal highness")))}

func ToLower

func ToLower(s []byte) []byte

ToLower 返回所有 Unicode 字母映射為小寫字節(jié)片段的副本。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("%s", bytes.ToLower([]byte("Gopher")))}

func ToLowerSpecial

func ToLowerSpecial(c unicode.SpecialCase, s []byte) []byte

ToLowerSpecial 返回所有 Unicode 字母映射到小寫字節(jié)的字節(jié)切片的副本,優(yōu)先考慮特殊的外殼規(guī)則。

func ToTitle

func ToTitle(s []byte) []byte

ToTitle 返回字節(jié)切片 s 的副本,并將所有 Unicode 字母映射到它們的標(biāo)題大小寫。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("%s\n", bytes.ToTitle([]byte("loud noises")))
	fmt.Printf("%s\n", bytes.ToTitle([]byte("хлеб")))}

func ToTitleSpecial

func ToTitleSpecial(c unicode.SpecialCase, s []byte) []byte

ToTitleSpecial 返回字節(jié)片段 s 的副本,并將所有 Unicode 字母映射到它們的標(biāo)題大小寫,優(yōu)先考慮特殊外殼規(guī)則。

func ToUpper

func ToUpper(s []byte) []byte

ToUpper 返回字節(jié)切片 s 的副本,并將所有 Unicode 字母映射為大寫字母。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("%s", bytes.ToUpper([]byte("Gopher")))}

func ToUpperSpecial

func ToUpperSpecial(c unicode.SpecialCase, s []byte) []byte

ToUpperSpecial 返回字節(jié)切片 s 的副本,其中所有 Unicode 字母都映射為大寫字母,優(yōu)先考慮特殊外殼規(guī)則。

func Trim

func Trim(s []byte, cutset string) []byte

Trim 通過切割 cutset 中包含的所有前導(dǎo)和尾隨 UTF-8 編碼的 Unicode 代碼點(diǎn)來返回 s 的子片段。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("[%q]", bytes.Trim([]byte(" !!! Achtung! Achtung! !!! "), "! "))}

func TrimFunc

func TrimFunc(s []byte, f func(r rune) bool) []byte

TrimFunc 通過分割所有滿足f(c)的前導(dǎo)和尾隨 UTF-8 編碼的 Unicode 代碼點(diǎn) c 來返回 s 的子片段。

func TrimLeft

func TrimLeft(s []byte, cutset string) []byte

TrimLeft 通過切割 cutset 中包含的所有主要UTF-8編碼的 Unicode 代碼點(diǎn)來返回 s 的子片段。

func TrimLeftFunc

func TrimLeftFunc(s []byte, f func(r rune) bool) []byte

TrimLeftFunc 通過分割所有滿足 f(c) 的 UTF-8 編碼的 Unicode 編碼點(diǎn) c 來返回 s 的子片段。

func TrimPrefix

func TrimPrefix(s, prefix []byte) []byte

TrimPrefix 在沒有提供的前導(dǎo)前綴字符串的情況下返回 s 。如果 s 不是以前綴開始,則 s 不變。

示例

package mainimport ("bytes""fmt")func main() {var b = []byte("Goodbye,, world!")
	b = bytes.TrimPrefix(b, []byte("Goodbye,"))
	b = bytes.TrimPrefix(b, []byte("See ya,"))
	fmt.Printf("Hello%s", b)}

func TrimRight

func TrimRight(s []byte, cutset string) []byte

TrimRight 通過切割 cutset 中包含的所有尾隨 UTF-8 編碼的 Unicode 代碼點(diǎn)來返回 s 的子片段。

func TrimRightFunc

func TrimRightFunc(s []byte, f func(r rune) bool) []byte

TrimRightFunc 通過分割所有滿足 f(c) 的 UTF-8 編碼的 Unicode 代碼點(diǎn) c 來返回 s 的子片段。

func TrimSpace

func TrimSpace(s []byte) []byte

TrimSpace 根據(jù) Unicode 定義的所有前導(dǎo)和尾隨空白區(qū)域來返回 s 的子片段。

示例

package mainimport ("bytes""fmt")func main() {
	fmt.Printf("%s", bytes.TrimSpace([]byte(" \t\n a lone gopher \n\t\r\n")))}

func TrimSuffix

func TrimSuffix(s, suffix []byte) []byte

TrimSuffix 在沒有提供尾隨后綴字符串的情況下返回 s 。如果 s 不以后綴結(jié)尾,則 s 不變。

示例

package mainimport ("bytes""os")func main() {var b = []byte("Hello, goodbye, etc!")
	b = bytes.TrimSuffix(b, []byte("goodbye, etc!"))
	b = bytes.TrimSuffix(b, []byte("gopher"))
	b = append(b, bytes.TrimSuffix([]byte("world!"), []byte("x!"))...)
	os.Stdout.Write(b)}

type Buffer

緩沖區(qū)是一個可變大小的帶有讀和寫方法的字節(jié)緩沖區(qū)。Buffer 的零值是一個準(zhǔn)備使用的空緩沖區(qū)。

type Buffer struct {        // 包含過濾或未導(dǎo)出的字段}

示例

package mainimport ("bytes""fmt""os")func main() {var b bytes.Buffer // 緩沖區(qū)不需要初始化。
	b.Write([]byte("Hello "))
	fmt.Fprintf(&b, "world!")
	b.WriteTo(os.Stdout)}

示例(Reader)

package mainimport ("bytes""encoding/base64""io""os")func main() {// 緩沖區(qū)可以將字符串或[]字節(jié)轉(zhuǎn)換為io.Reader。
	buf := bytes.NewBufferString("R29waGVycyBydWxlIQ==")
	dec := base64.NewDecoder(base64.StdEncoding, buf)
	io.Copy(os.Stdout, dec)}

func NewBuffer

func NewBuffer(buf []byte) *Buffer

NewBuffer 使用 buf 作為其初始內(nèi)容創(chuàng)建并初始化新的 Buffer。新的緩沖區(qū)取得了 buf 的所有權(quán),并且調(diào)用者在調(diào)用之后不應(yīng)該使用 buf 。NewBuffer 旨在準(zhǔn)備一個緩沖區(qū)來讀取現(xiàn)有數(shù)據(jù)。它也可以用來調(diào)整寫入的內(nèi)部緩沖區(qū)大小。要做到這一點(diǎn),buf 應(yīng)該具有所需的容量,但長度為零。

在大多數(shù)情況下,新的(緩沖區(qū))(或者只是聲明一個緩沖區(qū)變量)足以初始化緩沖區(qū)。

func NewBufferString

func NewBufferString(s string) *Buffer

NewBufferString 使用字符串 s 作為其初始內(nèi)容創(chuàng)建并初始化一個新的 Buffer。它旨在準(zhǔn)備一個緩沖區(qū)來讀取現(xiàn)有的字符串。

在大多數(shù)情況下,新的(緩沖區(qū))(或者只是聲明一個緩沖區(qū)變量)足以初始化緩沖區(qū)。

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

字節(jié)返回一段長度 b.Len(),其中包含緩沖區(qū)的未讀部分。該切片僅在下一次緩沖區(qū)修改之前有效(即,直到下一次調(diào)用 Read,Write,Reset或Truncate 之類的方法)。至少在下一次緩沖區(qū)修改之前,切片會對緩沖區(qū)內(nèi)容進(jìn)行別名,因此切片的即時更改將影響將來讀取的結(jié)果。

func (*Buffer) Cap

func (b *Buffer) Cap() int

Cap 返回緩沖區(qū)底層字節(jié)片段的容量,即分配給緩沖區(qū)數(shù)據(jù)的總空間。

func (*Buffer) Grow

func (b *Buffer) Grow(n int)

如果有必要,增長緩沖區(qū)的容量以保證另外n個字節(jié)的空間。在Grow(n)之后,至少可以將n個字節(jié)寫入緩沖區(qū)而無需其他分配。如果n是負(fù)數(shù),Grow 會陷入混亂。如果緩沖區(qū)不能增長,它會與 ErrTooLarge 一起發(fā)生混亂。

示例

package mainimport ("bytes""fmt")func main() {var b bytes.Buffer
	b.Grow(64)
	bb := b.Bytes()
	b.Write([]byte("64 bytes or fewer"))
	fmt.Printf("%q", bb[:b.Len()])}

func (*Buffer) Len

func (b *Buffer) Len() int

Len 返回緩沖區(qū)未讀部分的字節(jié)數(shù);b.Len() == len(b.Bytes())。

func (*Buffer) Next

func (b *Buffer) Next(n int) []byte

接下來返回包含來自緩沖區(qū)的下n個字節(jié)的切片,如同字節(jié)已由 Read 返回一樣推進(jìn)緩沖區(qū)。如果緩沖區(qū)中少于n個字節(jié),則 Next 返回整個緩沖區(qū)。切片只有在下次調(diào)用讀取或?qū)懭敕椒〞r才有效。

func (*Buffer) Read

func (b *Buffer) Read(p []byte) (n int, err error)

Read 從緩沖區(qū)中讀取下一個 len(p) 字節(jié),或者直到緩沖區(qū)被耗盡。返回值n是讀取的字節(jié)數(shù)。如果緩沖區(qū)沒有數(shù)據(jù)要返回,則 err 為 io.EOF(除非len(p)為零); 否則為零。

func (*Buffer) ReadByte

func (b *Buffer) ReadByte() (byte, error)

ReadByte 讀取并返回緩沖區(qū)中的下一個字節(jié)。如果沒有可用的字節(jié),則返回錯誤 io.EOF。

func (*Buffer) ReadBytes

func (b *Buffer) ReadBytes(delim byte) (line []byte, err error)

ReadBytes 一直讀取,直到輸入中delim第一次出現(xiàn)時停止 ,并返回一個包含小于等于分隔符數(shù)據(jù)的片段。如果ReadBytes在查找分隔符之前遇到錯誤,它將返回錯誤之前讀取的數(shù)據(jù)和錯誤本身(通常為 io.EOF )。當(dāng)且僅當(dāng)返回的數(shù)據(jù)不以分隔符結(jié)束時,ReadBytes 才返回 err != nil。

func (*Buffer) ReadFrom

func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom 從 r 讀取數(shù)據(jù)直到 EOF 并將其附加到緩沖區(qū),根據(jù)需要生長緩沖區(qū)。返回值n是讀取的字節(jié)數(shù)。讀取過程中遇到的除 io.EOF 外的任何錯誤也會返回。如果緩沖區(qū)變得過大,ReadFrom 將與 ErrTooLarge 一起發(fā)生混亂。

func (*Buffer) ReadRune

func (b *Buffer) ReadRune() (r rune, size int, err error)

ReadRune 讀取并返回緩沖區(qū)中的下一個UTF-8編碼的 Unicode 代碼點(diǎn)。如果沒有字節(jié)可用,返回的錯誤是io.EOF。如果字節(jié)是錯誤的UTF-8編碼,則它將消耗一個字節(jié)并返回U + FFFD,1。

func (*Buffer) ReadString

func (b *Buffer) ReadString(delim byte) (line string, err error)

ReadString 讀取,直到輸入中第一次出現(xiàn) delim ,返回一個包含數(shù)據(jù)的字符串直到并包含分隔符。如果ReadString 在查找分隔符之前遇到錯誤,它將返回在錯誤之前讀取的數(shù)據(jù)和錯誤本身(通常為 io.EOF )。當(dāng)且僅當(dāng)返回的數(shù)據(jù)沒有以分隔符結(jié)束時,ReadString 返回 err!= nil。

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset將緩沖區(qū)重置為空,但它保留了未來寫入使用的底層存儲。重置與Truncate(0) 相同。

func (*Buffer) String

func (b *Buffer) String() string

字符串以字符串形式返回緩沖區(qū)未讀部分的內(nèi)容。如果 Buffer 是一個零指針,它將返回“<nil>”。

func (*Buffer) Truncate

func (b *Buffer) Truncate(n int)

截斷從緩沖區(qū)丟棄除前 n 個未讀字節(jié)以外的所有字節(jié),但繼續(xù)使用相同的分配存儲。如果 n 是負(fù)數(shù)或大于緩沖區(qū)的長度,它會發(fā)生混亂。

func (*Buffer) UnreadByte

func (b *Buffer) UnreadByte() error

UnreadByte 讀取最近成功讀取操作返回的最后一個字節(jié),該操作至少讀取一個字節(jié)。如果自上次讀取后發(fā)生寫入,如果上次讀取返回錯誤,或者讀取讀取的是零字節(jié),則 UnreadByte 返回錯誤。

func (*Buffer) UnreadRune

func (b *Buffer) UnreadRune() error

UnreadRune 未讀取 ReadRune 返回的最后一個符文。如果緩沖區(qū)上的最新讀取或?qū)懭氩僮鞑皇浅晒Φ腞eadRune,則 UnreadRune 將返回錯誤。(在這方面,它比 UnreadByte 更嚴(yán)格,它將讀取任何讀操作的最后一個字節(jié)。)

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (n int, err error)

寫入將 p 的內(nèi)容附加到緩沖區(qū),根據(jù)需要增加緩沖區(qū)。返回值n是 p 的長度; err 總是零。如果緩沖區(qū)變得過大,Write 會與 ErrTooLarge 混淆。

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(c byte) error

WriteByte 將字節(jié) c 附加到緩沖區(qū),根據(jù)需要生長緩沖區(qū)。返回的錯誤始終為零,但包含在內(nèi)以匹配 bufio.Writer 的 WriteByte 。如果緩沖區(qū)變得太大,WriteByte 會與 ErrTooLarge 一起發(fā)生混亂。

func (*Buffer) WriteRune

func (b *Buffer) WriteRune(r rune) (n int, err error)

WriteRune 將 Unicode 代碼點(diǎn) r 的UTF-8 編碼附加到緩沖區(qū),返回其長度和錯誤,該錯誤總是為零,但包含在內(nèi)以匹配 bufio.Writer 的 WriteRune。緩沖區(qū)根據(jù)需要增長;如果它變得太大,WriteRune 將會與 ErrTooLarge 混淆。

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string) (n int, err error)

WriteString將 s 的內(nèi)容附加到緩沖區(qū),根據(jù)需要增加緩沖區(qū)。返回值 n 是 s 的長度;err 總是零。如果緩沖區(qū)變得太大,WriteString 會與 ErrTooLarge 混淆。

func (*Buffer) WriteTo

func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)

WriteTo 將數(shù)據(jù)寫入 w 直到緩沖區(qū)耗盡或發(fā)生錯誤。返回值n是寫入的字節(jié)數(shù);它總是適合 int ,但它是 int64 來匹配 io.WriterTo 接口。寫入過程中遇到的任何錯誤也會返回。

type Reader

Reader 通過從字節(jié)片段讀取來實現(xiàn) io.Reader,io.ReaderAt,io.WriterTo,io.Seeker,io.ByteScanner和io.RuneScanner 接口。與緩沖區(qū)不同,Reader 是只讀的并支持搜索。

type Reader struct {        // 包含過濾或未導(dǎo)出的字段}

func NewReader

func NewReader(b []byte) *Reader

NewReader從 b 返回新的 Reader 讀數(shù)。

func (*Reader) Len

func (r *Reader) Len() int

Len 返回切片的未讀部分的字節(jié)數(shù)。

func (*Reader) Read

func (r *Reader) Read(b []byte) (n int, err error)

func (*Reader) ReadAt

func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)

func (*Reader) ReadByte

func (r *Reader) ReadByte() (byte, error)

func (*Reader) ReadRune

func (r *Reader) ReadRune() (ch rune, size int, err error)

func (*Reader) Reset

func (r *Reader) Reset(b []byte)

Reset 將Reader(讀取器)重置為從 b 中讀取。

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (int64, error)

Seek 實現(xiàn)了 io.Seeker 接口。

func (*Reader) Size

func (r *Reader) Size() int64

Size 返回基礎(chǔ)字節(jié)片的原始長度。大小是可通過 ReadAt 讀取的字節(jié)數(shù)。返回的值總是相同的,不受調(diào)用任何其他方法的影響。

func (*Reader) UnreadByte

func (r *Reader) UnreadByte() error

func (*Reader) UnreadRune

func (r *Reader) UnreadRune() error

func (*Reader) WriteTo

func (r *Reader) WriteTo(w io.Writer) (n int64, err error)

WriteTo 實現(xiàn) io.WriterTo 接口。

錯誤

  • ?   標(biāo)題用于單詞邊界的規(guī)則不能正確處理Unicode標(biāo)點(diǎn)符號。

Previous article: Next article: