Documentation ¶
Overview ¶
Package bytes implements functions for the manipulation of byte slices. It is analogous to the facilities of the strings package.
Index ¶
- Constants
- func Compare(a, b []byte) int
- func Count(s, sep []byte) int
- func Equal(a, b []byte) bool
- func Fields(s []byte) [][]byte
- func FieldsFunc(s []byte, f func(int) 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 int) bool) int
- func IndexRune(s []byte, rune int) int
- func Join(a [][]byte, sep []byte) []byte
- func LastIndex(s, sep []byte) int
- func LastIndexAny(s []byte, chars string) int
- func LastIndexFunc(s []byte, f func(r int) bool) int
- func Map(mapping func(rune int) int, s []byte) []byte
- func Repeat(b []byte, count int) []byte
- func Replace(s, old, new []byte, n int) []byte
- func Runes(s []byte) []int
- 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(_case unicode.SpecialCase, s []byte) []byte
- func ToTitle(s []byte) []byte
- func ToTitleSpecial(_case unicode.SpecialCase, s []byte) []byte
- func ToUpper(s []byte) []byte
- func ToUpperSpecial(_case unicode.SpecialCase, s []byte) []byte
- func Trim(s []byte, cutset string) []byte
- func TrimFunc(s []byte, f func(r int) bool) []byte
- func TrimLeft(s []byte, cutset string) []byte
- func TrimLeftFunc(s []byte, f func(r int) bool) []byte
- func TrimRight(s []byte, cutset string) []byte
- func TrimRightFunc(s []byte, f func(r int) bool) []byte
- func TrimSpace(s []byte) []byte
- type Buffer
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Len() int
- func (b *Buffer) Next(n int) []byte
- func (b *Buffer) Read(p []byte) (n int, err os.Error)
- func (b *Buffer) ReadByte() (c byte, err os.Error)
- func (b *Buffer) ReadBytes(delim byte) (line []byte, err os.Error)
- func (b *Buffer) ReadFrom(r io.Reader) (n int64, err os.Error)
- func (b *Buffer) ReadRune() (r int, size int, err os.Error)
- func (b *Buffer) ReadString(delim byte) (line string, err os.Error)
- func (b *Buffer) Reset()
- func (b *Buffer) String() string
- func (b *Buffer) Truncate(n int)
- func (b *Buffer) UnreadByte() os.Error
- func (b *Buffer) UnreadRune() os.Error
- func (b *Buffer) Write(p []byte) (n int, err os.Error)
- func (b *Buffer) WriteByte(c byte) os.Error
- func (b *Buffer) WriteRune(r int) (n int, err os.Error)
- func (b *Buffer) WriteString(s string) (n int, err os.Error)
- func (b *Buffer) WriteTo(w io.Writer) (n int64, err os.Error)
- Bugs
Constants ¶
const MinRead = 512
MinRead is the minimum slice size passed to a Read call by Buffer.ReadFrom. As long as the Buffer has at least MinRead bytes beyond what is required to hold the contents of r, ReadFrom will not grow the underlying buffer.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare returns an integer comparing the two byte arrays lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b
func Fields ¶
Fields splits the array s around each instance of one or more consecutive white space characters, returning a slice of subarrays of s or an empty list if s contains only white space.
func FieldsFunc ¶
FieldsFunc interprets s as a sequence of UTF-8-encoded Unicode code points. It splits the array s at each run of code points c satisfying f(c) and returns a slice of subarrays of s. If no code points in s satisfy f(c), an empty slice is returned.
func Index ¶
Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
func 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.
func IndexByte ¶
IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.
func IndexFunc ¶
IndexFunc interprets s as a sequence of UTF-8-encoded Unicode code points. It returns the byte index in s of the first Unicode code point satisfying f(c), or -1 if none do.
func IndexRune ¶
IndexRune interprets s as a sequence of UTF-8-encoded Unicode 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.
func Join ¶
Join concatenates the elements of a to create a single byte array. The separator sep is placed between elements in the resulting array.
func LastIndex ¶
LastIndex returns the index of the last instance of sep in s, or -1 if sep is not present in s.
func 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.
func LastIndexFunc ¶
LastIndexFunc interprets s as a sequence of UTF-8-encoded Unicode code points. It returns the byte index in s of the last Unicode code point satisfying f(c), or -1 if none do.
func Map ¶
Map returns a copy of the byte array 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. The characters in s and the output are interpreted as UTF-8-encoded Unicode code points.
func Replace ¶
Replace returns a copy of the slice s with the first n non-overlapping instances of old replaced by new. If n < 0, there is no limit on the number of replacements.
func 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.
func 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.
func 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:
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
func 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. 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
func Title ¶
Title returns a copy of s with all Unicode letters that begin words mapped to their title case.
func ToLower ¶
ToUpper returns a copy of the byte array s with all Unicode letters mapped to their lower case.
func ToLowerSpecial ¶
func ToLowerSpecial(_case unicode.SpecialCase, s []byte) []byte
ToLowerSpecial returns a copy of the byte array s with all Unicode letters mapped to their lower case, giving priority to the special casing rules.
func ToTitle ¶
ToTitle returns a copy of the byte array s with all Unicode letters mapped to their title case.
func ToTitleSpecial ¶
func ToTitleSpecial(_case unicode.SpecialCase, s []byte) []byte
ToTitleSpecial returns a copy of the byte array s with all Unicode letters mapped to their title case, giving priority to the special casing rules.
func ToUpper ¶
ToUpper returns a copy of the byte array s with all Unicode letters mapped to their upper case.
func ToUpperSpecial ¶
func ToUpperSpecial(_case unicode.SpecialCase, s []byte) []byte
ToUpperSpecial returns a copy of the byte array s with all Unicode letters mapped to their upper case, giving priority to the special casing rules.
func Trim ¶
Trim returns a subslice of s by slicing off all leading and trailing UTF-8-encoded Unicode code points contained in cutset.
func TrimFunc ¶
TrimFunc returns a subslice of s by slicing off all leading and trailing UTF-8-encoded Unicode code points c that satisfy f(c).
func TrimLeft ¶
TrimLeft returns a subslice of s by slicing off all leading UTF-8-encoded Unicode code points contained in cutset.
func TrimLeftFunc ¶
TrimLeftFunc returns a subslice of s by slicing off all leading UTF-8-encoded Unicode code points c that satisfy f(c).
func TrimRight ¶
TrimRight returns a subslice of s by slicing off all trailing UTF-8-encoded Unicode code points that are contained in cutset.
func TrimRightFunc ¶
TrimRightFunc returns a subslice of s by slicing off all trailing UTF-8 encoded Unicode code points c that satisfy f(c).
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
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.
func NewBuffer ¶
NewBuffer creates and initializes a new Buffer using buf as its initial contents. It is intended to prepare a Buffer to read existing data. It can also be used to size 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 preferable to NewBuffer. In particular, passing a non-empty buf to NewBuffer and then writing to the Buffer will overwrite buf, not append to it.
func NewBufferString ¶
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. See the warnings about NewBuffer; similar issues apply here.
func (*Buffer) Bytes ¶
Bytes returns a slice of the contents of the unread portion of the buffer; len(b.Bytes()) == b.Len(). If the caller changes the contents of the returned slice, the contents of the buffer will change provided there are no intervening method calls on the Buffer.
func (*Buffer) Len ¶
Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()).
func (*Buffer) Next ¶
Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.
func (*Buffer) Read ¶
Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is os.EOF even if len(p) is zero; otherwise it is nil.
func (*Buffer) ReadByte ¶
ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error os.EOF.
func (*Buffer) ReadBytes ¶
ReadBytes reads until the first occurrence of delim in the input, returning a slice containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often os.EOF). ReadBytes returns err != nil if and only if the returned data does not end in delim.
func (*Buffer) ReadFrom ¶
ReadFrom reads data from r until EOF and appends it to the buffer. The return value n is the number of bytes read. Any error except os.EOF encountered during the read is also returned.
func (*Buffer) ReadRune ¶
ReadRune reads and returns the next UTF-8-encoded Unicode code point from the buffer. If no bytes are available, the error returned is os.EOF. If the bytes are an erroneous UTF-8 encoding, it consumes one byte and returns U+FFFD, 1.
func (*Buffer) ReadString ¶
ReadString reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often os.EOF). ReadString returns err != nil if and only if the returned data does not end in delim.
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset resets the buffer so it has no content. b.Reset() is the same as b.Truncate(0).
func (*Buffer) String ¶
String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".
func (*Buffer) Truncate ¶
Truncate discards all but the first n unread bytes from the buffer. It is an error to call b.Truncate(n) with n > b.Len().
func (*Buffer) UnreadByte ¶
UnreadByte unreads the last byte returned by the most recent read operation. If write has happened since the last read, UnreadByte returns an error.
func (*Buffer) UnreadRune ¶
UnreadRune unreads the last rune returned by ReadRune. If the most recent read or write operation on the buffer was not a ReadRune, UnreadRune returns an error. (In this regard it is stricter than UnreadByte, which will unread the last byte from any read operation.)
func (*Buffer) Write ¶
Write appends the contents of p to the buffer. The return value n is the length of p; err is always nil.
func (*Buffer) WriteByte ¶
WriteByte appends the byte c to the buffer. The returned error is always nil, but is included to match bufio.Writer's WriteByte.
func (*Buffer) WriteRune ¶
WriteRune appends the UTF-8 encoding of Unicode code point r to the buffer, returning its length and an error, which is always nil but is included to match bufio.Writer's WriteRune.
func (*Buffer) WriteString ¶
WriteString appends the contents of s to the buffer. The return value n is the length of s; err is always nil.
Notes ¶
Bugs ¶
The rule Title uses for word boundaries does not handle Unicode punctuation properly.