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

Static methods

staticinlineclone(_b:Slice<GoUInt8>):Slice<GoUInt8>

Clone returns a copy of b[:len(b)]. The result may have additional unused capacity. Clone(nil) returns nil.

staticinlinecompare(_a:Slice<GoUInt8>, _b:Slice<GoUInt8>):GoInt

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. A nil argument is equivalent to an empty slice.

staticinlinecontains(_b:Slice<GoUInt8>, _subslice:Slice<GoUInt8>):Bool

Contains reports whether subslice is within b.

staticinlinecontainsAny(_b:Slice<GoUInt8>, _chars:GoString):Bool

ContainsAny reports whether any of the UTF-8-encoded code points in chars are within b.

staticinlinecontainsFunc(_b:Slice<GoUInt8>, _f:GoInt32 ‑> Bool):Bool

ContainsFunc reports whether any of the UTF-8-encoded code points r within b satisfy f(r).

staticinlinecontainsRune(_b:Slice<GoUInt8>, _r:GoInt32):Bool

ContainsRune reports whether the rune is contained in the UTF-8-encoded byte slice b.

staticinlinecount(_s:Slice<GoUInt8>, _sep:Slice<GoUInt8>):GoInt

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.

staticinlinecut(_s:Slice<GoUInt8>, _sep:Slice<GoUInt8>):{_2:Bool, _1:Slice<GoUInt8>, _0:Slice<GoUInt8>}

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, nil, false.

Cut returns slices of the original slice s, not copies.

staticinlinecutPrefix(_s:Slice<GoUInt8>, _prefix:Slice<GoUInt8>):{_1:Bool, _0:Slice<GoUInt8>}

CutPrefix returns s without the provided leading prefix byte slice and reports whether it found the prefix. If s doesn't start with prefix, CutPrefix returns s, false. If prefix is the empty byte slice, CutPrefix returns s, true.

CutPrefix returns slices of the original slice s, not copies.

staticinlinecutSuffix(_s:Slice<GoUInt8>, _suffix:Slice<GoUInt8>):{_1:Bool, _0:Slice<GoUInt8>}

CutSuffix returns s without the provided ending suffix byte slice and reports whether it found the suffix. If s doesn't end with suffix, CutSuffix returns s, false. If suffix is the empty byte slice, CutSuffix returns s, true.

CutSuffix returns slices of the original slice s, not copies.

staticinlineequal(_a:Slice<GoUInt8>, _b:Slice<GoUInt8>):Bool

Equal reports whether a and b are the same length and contain the same bytes. A nil argument is equivalent to an empty slice.

staticinlineequalFold(_s:Slice<GoUInt8>, _t:Slice<GoUInt8>):Bool

EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under simple Unicode case-folding, which is a more general form of case-insensitivity.

staticinlinefields(_s:Slice<GoUInt8>):Slice<Slice<GoUInt8>>

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.

staticinlinefieldsFunc(_s:Slice<GoUInt8>, _f:GoInt32 ‑> Bool):Slice<Slice<GoUInt8>>

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.

FieldsFunc makes no guarantees about the order in which it calls f(c) and assumes that f always returns the same value for a given c.

staticinlinehasPrefix(_s:Slice<GoUInt8>, _prefix:Slice<GoUInt8>):Bool

HasPrefix tests whether the byte slice s begins with prefix.

staticinlinehasSuffix(_s:Slice<GoUInt8>, _suffix:Slice<GoUInt8>):Bool

HasSuffix tests whether the byte slice s ends with suffix.

staticinlineindex(_s:Slice<GoUInt8>, _sep:Slice<GoUInt8>):GoInt

Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.

staticinlineindexAny(_s:Slice<GoUInt8>, _chars:GoString):GoInt

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.

staticinlineindexByte(_b:Slice<GoUInt8>, _c:GoUInt8):GoInt

IndexByte returns the index of the first instance of c in b, or -1 if c is not present in b.

staticinlineindexFunc(_s:Slice<GoUInt8>, _f:GoInt32 ‑> Bool):GoInt

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.

staticinlineindexRune(_s:Slice<GoUInt8>, _r:GoInt32):GoInt

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.

staticinlinejoin(_s:Slice<Slice<GoUInt8>>, _sep:Slice<GoUInt8>):Slice<GoUInt8>

Join concatenates the elements of s to create a new byte slice. The separator sep is placed between elements in the resulting slice.

staticinlinelastIndex(_s:Slice<GoUInt8>, _sep:Slice<GoUInt8>):GoInt

LastIndex returns the index of the last instance of sep in s, or -1 if sep is not present in s.

staticinlinelastIndexAny(_s:Slice<GoUInt8>, _chars:GoString):GoInt

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.

staticinlinelastIndexByte(_s:Slice<GoUInt8>, _c:GoUInt8):GoInt

LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.

staticinlinelastIndexFunc(_s:Slice<GoUInt8>, _f:GoInt32 ‑> Bool):GoInt

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.

staticinlinemap_(_mapping:GoInt32 ‑> GoInt32, _s:Slice<GoUInt8>):Slice<GoUInt8>

Map returns a copy of the byte slice s with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the byte slice with no replacement. The characters in s and the output are interpreted as UTF-8-encoded code points.

staticinlinenewBuffer(_buf:Slice<GoUInt8>):Ref<Buffer>

NewBuffer creates and initializes a new Buffer using buf as its initial contents. The new Buffer takes ownership of buf, and the caller should not use buf after this call. NewBuffer is intended to prepare a Buffer to read existing data. It can also be used to set the initial size of the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.

In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.

staticinlinenewBufferString(_s:GoString):Ref<Buffer>

NewBufferString creates and initializes a new Buffer using string s as its initial contents. It is intended to prepare a buffer to read an existing string.

In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.

staticinlinenewReader(_b:Slice<GoUInt8>):Ref<Reader>

NewReader returns a new Reader reading from b.

staticinlinerepeat(_b:Slice<GoUInt8>, _count:GoInt):Slice<GoUInt8>

Repeat returns a new byte slice consisting of count copies of b.

It panics if count is negative or if the result of (len(b) * count) overflows.

staticinlinereplace(_s:Slice<GoUInt8>, _old:Slice<GoUInt8>, _new_:Slice<GoUInt8>, _n:GoInt):Slice<GoUInt8>

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 < 0, there is no limit on the number of replacements.

staticinlinereplaceAll(_s:Slice<GoUInt8>, _old:Slice<GoUInt8>, _new_:Slice<GoUInt8>):Slice<GoUInt8>

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.

staticinlinerunes(_s:Slice<GoUInt8>):Slice<GoInt32>

Runes interprets s as a sequence of UTF-8-encoded code points. It returns a slice of runes (Unicode code points) equivalent to s.

staticinlinesplit(_s:Slice<GoUInt8>, _sep:Slice<GoUInt8>):Slice<Slice<GoUInt8>>

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.

To split around the first instance of a separator, see Cut.

staticinlinesplitAfter(_s:Slice<GoUInt8>, _sep:Slice<GoUInt8>):Slice<Slice<GoUInt8>>

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.

staticinlinesplitAfterN(_s:Slice<GoUInt8>, _sep:Slice<GoUInt8>, _n:GoInt):Slice<Slice<GoUInt8>>

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:

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

staticinlinesplitN(_s:Slice<GoUInt8>, _sep:Slice<GoUInt8>, _n:GoInt):Slice<Slice<GoUInt8>>

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. The count determines the number of subslices to return:

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

To split around the first instance of a separator, see Cut.

staticinlinetitle(_s:Slice<GoUInt8>):Slice<GoUInt8>

Title treats s as UTF-8-encoded bytes and returns a copy with all Unicode letters that begin words mapped to their title case.

Deprecated: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead.

staticinlinetoLower(_s:Slice<GoUInt8>):Slice<GoUInt8>

ToLower returns a copy of the byte slice s with all Unicode letters mapped to their lower case.

staticinlinetoLowerSpecial(_c:SpecialCase, _s:Slice<GoUInt8>):Slice<GoUInt8>

ToLowerSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their lower case, giving priority to the special casing rules.

staticinlinetoTitle(_s:Slice<GoUInt8>):Slice<GoUInt8>

ToTitle treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their title case.

staticinlinetoTitleSpecial(_c:SpecialCase, _s:Slice<GoUInt8>):Slice<GoUInt8>

ToTitleSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their title case, giving priority to the special casing rules.

staticinlinetoUpper(_s:Slice<GoUInt8>):Slice<GoUInt8>

ToUpper returns a copy of the byte slice s with all Unicode letters mapped to their upper case.

staticinlinetoUpperSpecial(_c:SpecialCase, _s:Slice<GoUInt8>):Slice<GoUInt8>

ToUpperSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their upper case, giving priority to the special casing rules.

staticinlinetoValidUTF8(_s:Slice<GoUInt8>, _replacement:Slice<GoUInt8>):Slice<GoUInt8>

ToValidUTF8 treats s as UTF-8-encoded bytes and returns a copy with each run of bytes representing invalid UTF-8 replaced with the bytes in replacement, which may be empty.

staticinlinetrim(_s:Slice<GoUInt8>, _cutset:GoString):Slice<GoUInt8>

Trim returns a subslice of s by slicing off all leading and trailing UTF-8-encoded code points contained in cutset.

staticinlinetrimFunc(_s:Slice<GoUInt8>, _f:GoInt32 ‑> Bool):Slice<GoUInt8>

TrimFunc returns a subslice of s by slicing off all leading and trailing UTF-8-encoded code points c that satisfy f(c).

staticinlinetrimLeft(_s:Slice<GoUInt8>, _cutset:GoString):Slice<GoUInt8>

TrimLeft returns a subslice of s by slicing off all leading UTF-8-encoded code points contained in cutset.

staticinlinetrimLeftFunc(_s:Slice<GoUInt8>, _f:GoInt32 ‑> Bool):Slice<GoUInt8>

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).

staticinlinetrimPrefix(_s:Slice<GoUInt8>, _prefix:Slice<GoUInt8>):Slice<GoUInt8>

TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.

staticinlinetrimRight(_s:Slice<GoUInt8>, _cutset:GoString):Slice<GoUInt8>

TrimRight returns a subslice of s by slicing off all trailing UTF-8-encoded code points that are contained in cutset.

staticinlinetrimRightFunc(_s:Slice<GoUInt8>, _f:GoInt32 ‑> Bool):Slice<GoUInt8>

TrimRightFunc returns a subslice of s by slicing off all trailing UTF-8-encoded code points c that satisfy f(c).

staticinlinetrimSpace(_s:Slice<GoUInt8>):Slice<GoUInt8>

TrimSpace returns a subslice of s by slicing off all leading and trailing white space, as defined by Unicode.

staticinlinetrimSuffix(_s:Slice<GoUInt8>, _suffix:Slice<GoUInt8>):Slice<GoUInt8>

TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.