Crate gostd_bytes

Source
Expand description

Package bytes implements functions for the manipulation of byte slices. It is analogous to the facilities of the strings package.

zh-cn bytes包实现了操作[]byte的常用函数。本包的函数和strings包的函数相当类似。

Structs§

Buffer
A Buffer is a variable-sized buffer of bytes with Read and Write methods. The zero value for Buffer is an empty buffer ready to use.
Reader
A Reader implements the io.Reader, io.ReaderAt, io.ByteReader, io.ByteScanner, io.RuneReader, io.RuneScanner, io.Seeker, and io.WriterTo interfaces by reading from a string. The zero value for Reader operates like a Reader of an empty string.
Replacer
Replacer replaces a list of slices with replacements. It is safe for concurrent use by multiple goroutines.

Functions§

Compare
Compare returns an integer comparing two byte slices lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
Contains
Contains reports whether subslice is within b.
ContainsAny
ContainsAny reports whether any of the UTF-8-encoded code points in chars are within b.
ContainsRune
ContainsRune reports whether the rune is contained in the UTF-8-encoded byte slice b.
Count
Count counts the number of non-overlapping instances of sep in s. If sep is an empty slice, Count returns 1 + the number of UTF-8-encoded code points in s.
Cut
Cut slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, “”, false.
Fields
Fields interprets s as a sequence of UTF-8-encoded code points. It splits the slice s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of subslices of s or an empty slice if s contains only white space.
FieldsFunc
FieldsFunc interprets s as a sequence of UTF-8-encoded code points. It splits the slice s at each run of code points c satisfying f(c) and returns a slice of subslices of s. If all code points in s satisfy f(c), or len(s) == 0, an empty slice is returned.
HasPrefix
HasPrefix tests whether the byte slice s begins with prefix.
HasSuffix
HasSuffix tests whether the byte slice s ends with suffix.
Index
Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
IndexAny
IndexAny interprets s as a sequence of UTF-8-encoded Unicode code points. It returns the byte index of the first occurrence in s of any of the Unicode code points in chars. It returns -1 if chars is empty or if there is no code point in common.
IndexByte
IndexByte returns the index of the first instance of c in b, or -1 if c is not present in b.
IndexFunc
IndexFunc interprets s as a sequence of UTF-8-encoded code points. It returns the byte index in s of the first Unicode code point satisfying f(c), or -1 if none do.
IndexRune
IndexRune interprets s as a sequence of UTF-8-encoded code points. It returns the byte index of the first occurrence in s of the given rune. It returns -1 if rune is not present in s. If r is utf8.RuneError, it returns the first instance of any invalid UTF-8 byte sequence.
Join
Join concatenates the elements of s to create a new byte slice. The separator sep is placed between elements in the resulting slice.
LastIndex
LastIndex returns the index of the last instance of sep in s, or -1 if sep is not present in s.
LastIndexAny
LastIndexAny interprets s as a sequence of UTF-8-encoded Unicode code points. It returns the byte index of the last occurrence in s of any of the Unicode code points in chars. It returns -1 if chars is empty or if there is no code point in common.
LastIndexByte
LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.
LastIndexFunc
LastIndexFunc interprets s as a sequence of UTF-8-encoded code points. It returns the byte index in s of the last Unicode code point satisfying f(c), or -1 if none do.
Map
Map returns a copy of the string s with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the string with no replacement.
Repeat
Repeat returns a new string consisting of count copies of the string s.
Replace
Replace returns a copy of the slice s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the slice and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune slice. If n = -1, there is no limit on the number of replacements.
ReplaceAll
ReplaceAll returns a copy of the slice s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the slice and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune slice.
Split
Split slices s into all subslices separated by sep and returns a slice of the subslices between those separators. If sep is empty, Split splits after each UTF-8 sequence. It is equivalent to SplitN with a count of -1.
SplitAfter
SplitAfter slices s into all subslices after each instance of sep and returns a slice of those subslices. If sep is empty, SplitAfter splits after each UTF-8 sequence. It is equivalent to SplitAfterN with a count of -1.
SplitAfterN
SplitAfterN slices s into subslices after each instance of sep and returns a slice of those subslices. If sep is empty, SplitAfterN splits after each UTF-8 sequence. The count determines the number of subslices to return:
SplitN
SplitN slices s into subslices separated by sep and returns a slice of the subslices between those separators. If sep is empty, SplitN splits after each UTF-8 sequence.
ToLower
ToLower returns s with all Unicode letters mapped to their lower case.
ToUpper
ToUpper returns s with all Unicode letters mapped to their upper case.
Trim
Trim returns a subslice of s by slicing off all leading and trailing UTF-8-encoded code points contained in cutset.
TrimFunc
TrimFunc returns a subslice of s by slicing off all leading and trailing UTF-8-encoded code points c that satisfy f(c).
TrimLeft
TrimLeft returns a subslice of s by slicing off all leading UTF-8-encoded code points contained in cutset.
TrimLeftFunc
TrimLeftFunc treats s as UTF-8-encoded bytes and returns a subslice of s by slicing off all leading UTF-8-encoded code points c that satisfy f(c).
TrimPrefix
TrimPrefix returns s without the provided leading prefix slices. If s doesn’t start with prefix, s is returned unchanged.
TrimRight
TrimRight returns a subslice of s by slicing off all trailing UTF-8-encoded code points that are contained in cutset.
TrimRightFunc
TrimRightFunc returns a subslice of s by slicing off all trailing UTF-8-encoded code points c that satisfy f(c).
TrimSpace
TrimSpace returns a subslice of s by slicing off all leading and trailing white space, as defined by Unicode.
TrimSuffix
TrimSuffix returns s without the provided trailing suffix string. If s doesn’t end with suffix, s is returned unchanged.