Module strings.textscanner stdlib

strings.textscanner
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
0
Imported by:
2
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

This section is empty.

Imported by

Aliases

This section is empty.

Constants

This section is empty.

Sum types

This section is empty.

Functions

#fn new

fn new(input string) TextScanner

new returns a stack allocated instance of TextScanner.

Structs

#struct TextScanner

pub struct TextScanner {
pub:
	input string
	ilen  int
mut:
	pos int // current position; pos is *always* kept in [0,ilen]
}

TextScanner simplifies writing small scanners/parsers by providing safe methods to scan texts character by character, peek for the next characters, go back, etc.

#fn (&TextScanner) free

unsafe
fn (mut ss &TextScanner) free()

free frees all allocated resources.

#fn (&TextScanner) remaining

inline
fn (ss &TextScanner) remaining() int

remaining returns how many characters remain from current position.

#fn (&TextScanner) next

direct_array_accessinline
fn (mut ss &TextScanner) next() int

next returns the next character code from the input text.

next returns -1 if it can't reach the next character.

next advances the scanner position.

#fn (&TextScanner) skip

inline
fn (mut ss &TextScanner) skip()

skip skips one character ahead; skip is slightly faster than next.

skip does not return a result.

#fn (&TextScanner) skip_n

inline
fn (mut ss &TextScanner) skip_n(n int)

skip_n skips ahead n characters, stopping at the end of the input.

#fn (&TextScanner) peek

direct_array_accessinline
fn (ss &TextScanner) peek() int

peek returns the next character code from the input text.

peek returns -1 if it can't peek the next character.

unlike next, peek does not change the state of the scanner.

#fn (&TextScanner) peek_n

direct_array_accessinline
fn (ss &TextScanner) peek_n(n int) int

peek_n returns the character code from the input text at position + n.

peek_n returns -1 if it can't peek n characters ahead.

ts.peek_n(0) == ts.current() .

ts.peek_n(1) == ts.peek() .

#fn (&TextScanner) back

inline
fn (mut ss &TextScanner) back()

back goes back one character from the current scanner position.

#fn (&TextScanner) back_n

fn (mut ss &TextScanner) back_n(n int)

back_n goes back n characters from the current scanner position.

#fn (&TextScanner) peek_back

direct_array_accessinline
fn (ss &TextScanner) peek_back() int

peek_back returns the previous character code from the input text.

peek_back returns -1 if it can't peek the previous character.

unlike back, peek_back does not change the state of the scanner.

#fn (&TextScanner) peek_back_n

direct_array_accessinline
fn (ss &TextScanner) peek_back_n(n int) int

peek_back_n returns the character code from the input text at position - n.

peek_back_n returns -1 if it can't peek n characters back.

ts.peek_back_n(0) == ts.current() ts.peek_back_n(1) == ts.peek_back()

#fn (&TextScanner) current

direct_array_accessinline
fn (mut ss &TextScanner) current() int

current returns the current character code from the input text.

current returns -1 at the start of the input text.

Note: after c := ts.next(), ts.current() will also return c.

#fn (&TextScanner) reset

fn (mut ss &TextScanner) reset()

reset resets the internal state of the scanner After calling .reset(), .next() will start reading again from the start of the input text.

#fn (&TextScanner) goto_end

fn (mut ss &TextScanner) goto_end()

goto_end has the same effect as for ts.next() != -1 {} i.e. after calling .goto_end(), the scanner will be at the end of the input text. Further .next() calls will return -1, unless you go back.

Interfaces

This section is empty.

Enums

This section is empty.