scanner

package
v0.0.0-...-d0409d6 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2022 License: Unlicense Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const RuneNotFound rune = -1

RuneNotFound is a marker used either by FindFunc to mark it didn't find anything or returned when there is no relevant rune to find

Variables

This section is empty.

Functions

This section is empty.

Types

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner reads out a string rune by rune

func New

func New(s string) *Scanner

New returns a new rune scanner

func (*Scanner) Current

func (r *Scanner) Current() rune

Current returns the current rune

func (*Scanner) Decr

func (r *Scanner) Decr() rune

Decr is the inverse of Incr, decrements the position and returns the current rune it returns RuneNotFound and doesn't decrement if it hits the start

func (*Scanner) Empty

func (r *Scanner) Empty() bool

NotEmpty returns if r has any more runes

func (*Scanner) FindFunc

func (r *Scanner) FindFunc(fn func(r rune) bool) (char rune, at int)

FindFunc works like strings.IndexFunc it searches for the next rune that satisfies the condition function and sets the pointer to that point + 1 so the next call returns the next rune returns RuneNotFound and -1 if it doesn't find anything returns the rune and its position of it if it finds one

func (*Scanner) HasLengthRemaining

func (r *Scanner) HasLengthRemaining(length int) bool

HasLengthRemaining returns if r has length more runes remaining

func (*Scanner) Incr

func (r *Scanner) Incr() rune

Incr increments the position and returns the current rune it returns RuneNotFound and doesn't increment if it hits the end

func (*Scanner) Peek

func (r *Scanner) Peek() rune

Peek returns the rune at pos + i

func (*Scanner) PeekBy

func (r *Scanner) PeekBy(i int) rune

PeekBy returns the rune i after pos if present

func (*Scanner) Pos

func (r *Scanner) Pos() int

Pos returns the current position

func (*Scanner) Remainder

func (r *Scanner) Remainder() string

Remainder returns anything not scanned

func (*Scanner) Remaining

func (r *Scanner) Remaining() int

Remaining returns how many runes are remaining

func (*Scanner) Runes

func (r *Scanner) Runes() []rune

Runes returns the runes

func (*Scanner) Seek

func (r *Scanner) Seek(i int) bool

Seek sets the pos to i

func (*Scanner) SeekBy

func (r *Scanner) SeekBy(i int) bool

SeekBy shifts the pos by i

func (*Scanner) String

func (r *Scanner) String() string

String returns the string

Jump to

Keyboard shortcuts

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