Documentation
¶
Overview ¶
Package scan has functions for scanning byte slices.
Index ¶
- Variables
- func ByteIsWS(b byte) bool
- type Bytes
- func (b *Bytes) Advance(n int) bool
- func (b *Bytes) DropLastLine(readLimit uint32)
- func (b *Bytes) Line() Bytes
- func (b Bytes) Match(p []byte, flags Flags) int
- func (b *Bytes) Peek() byte
- func (b *Bytes) Pop() byte
- func (b *Bytes) PopN(n int) []byte
- func (b *Bytes) PopUntil(stopAt ...byte) Bytes
- func (b *Bytes) ReadSlice(stopAt byte) Bytes
- func (b Bytes) Search(p []byte, flags Flags) (i int, l int)
- func (b *Bytes) TrimLWS()
- func (b *Bytes) TrimRWS()
- func (b *Bytes) Uint16() (uint16, bool)
- type Flags
Constants ¶
This section is empty.
Variables ¶
var ( ASCIISpaces = []byte{' ', '\r', '\n', '\x0c', '\t'} ASCIIDigits = []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} )
Functions ¶
Types ¶
type Bytes ¶
type Bytes []byte
Bytes is a byte slice with helper methods for easier scanning.
func (*Bytes) DropLastLine ¶
DropLastLine drops the last incomplete line from b.
mimetype limits itself to ReadLimit bytes when performing a detection. This means, for file formats like CSV for NDJSON, the last line of the input can be an incomplete line. If b length is less than readLimit, it means we received an incomplete file and proceed with dropping the last line.
func (*Bytes) Line ¶
Line returns the first line from b and advances b with the length of the line. One new line character is trimmed after the line if it exists.
func (Bytes) Match ¶ added in v0.20.0
Match returns how many bytes were needed to match pattern p. It returns -1 if p does not match b.
func (*Bytes) PopUntil ¶
PopUntil will advance b until, but not including, the first occurence of stopAt character. If no occurence is found, then it will advance until the end of b. The returned Bytes is a slice of all the bytes that we're advanced over.
func (*Bytes) ReadSlice ¶ added in v0.18.1
ReadSlice is the same as PopUntil, but the returned value includes stopAt as well.
func (Bytes) Search ¶ added in v0.20.0
Search for occurences of pattern p inside b at any index. It returns the index where p was found in b and how many bytes were needed for matching the pattern.
func (*Bytes) TrimLWS ¶
func (b *Bytes) TrimLWS()
TrimLWS trims whitespace from beginning of the bytes.
type Flags ¶ added in v0.20.0
type Flags int
const ( // CompactWS will make one whitespace from pattern to match one or more spaces from input. CompactWS Flags = 1 << iota // IgnoreCase will match lower case from pattern with lower case from input. // IgnoreCase will match upper case from pattern with both lower and upper case from input. // This flag is not really well named, IgnoreCase // FullWord ensures the input ends with a full word (it's followed by spaces.) FullWord )