scan

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2025 License: Apache-2.0, MIT Imports: 2 Imported by: 0

Documentation

Overview

Package scan has functions for scanning byte slices.

Index

Constants

This section is empty.

Variables

View Source
var (
	ASCIISpaces = []byte{' ', '\r', '\n', '\x0c', '\t'}
	ASCIIDigits = []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
)

Functions

func ByteIsWS

func ByteIsWS(b byte) bool

Types

type Bytes

type Bytes []byte

Bytes is a byte slice with helper methods for easier scanning.

func (*Bytes) Advance

func (b *Bytes) Advance(n int) bool

func (*Bytes) DropLastLine

func (b *Bytes) DropLastLine(readLimit uint32)

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

func (b *Bytes) Line() Bytes

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

func (b Bytes) Match(p []byte, flags Flags) int

Match returns how many bytes were needed to match pattern p. It returns -1 if p does not match b.

func (*Bytes) Peek

func (b *Bytes) Peek() byte

Peek one byte from b or 0x00 if b is empty.

func (*Bytes) Pop

func (b *Bytes) Pop() byte

Pop one byte from b or 0x00 if b is empty.

func (*Bytes) PopN added in v0.20.0

func (b *Bytes) PopN(n int) []byte

PopN pops n bytes from b or nil if b is empty.

func (*Bytes) PopUntil

func (b *Bytes) PopUntil(stopAt ...byte) Bytes

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

func (b *Bytes) ReadSlice(stopAt byte) Bytes

ReadSlice is the same as PopUntil, but the returned value includes stopAt as well.

func (Bytes) Search added in v0.20.0

func (b Bytes) Search(p []byte, flags Flags) (i int, l int)

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.

func (*Bytes) TrimRWS

func (b *Bytes) TrimRWS()

TrimRWS trims whitespace from the end of the bytes.

func (*Bytes) Uint16 added in v0.20.0

func (b *Bytes) Uint16() (uint16, bool)

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL