input

package
v0.0.0-...-3bbfcfd Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: EUPL-1.2 Imports: 3 Imported by: 0

Documentation

Overview

Package input provides an abstraction for data to be read.

Index

Constants

View Source
const EOS = rune(-1)

EOS = End of source

Variables

This section is empty.

Functions

func IsEOLEOS

func IsEOLEOS(ch rune) bool

IsEOLEOS returns true if char is either EOS or EOL.

func IsSpace

func IsSpace(ch rune) bool

IsSpace returns true if rune is a whitespace.

Types

type Input

type Input struct {
	// Read-only, will never change
	Src []byte // The source string

	// Read-only, will change
	Ch  rune // current character
	Pos int  // character position in src
	// contains filtered or unexported fields
}

Input is an abstract input source

func NewInput

func NewInput(src []byte) *Input

NewInput creates a new input source.

func (*Input) Accept

func (inp *Input) Accept(s string) bool

Accept checks if the given string is a prefix of the text to be parsed. If successful, advance position and current character. String must only contain bytes < 128. If not successful, everything remains as it is.

func (*Input) EatEOL

func (inp *Input) EatEOL()

EatEOL transforms both "\r" and "\r\n" into "\n".

func (*Input) Next

func (inp *Input) Next() rune

Next reads the next rune into inp.Ch and returns it too.

func (*Input) Peek

func (inp *Input) Peek() rune

Peek returns the rune following the most recently read rune without advancing. If end-of-source was already found peek returns EOS.

func (*Input) PeekN

func (inp *Input) PeekN(n int) rune

PeekN returns the n-th rune after the most recently read rune without advancing. If end-of-source was already found peek returns EOS.

func (*Input) ScanEntity

func (inp *Input) ScanEntity() (res string, success bool)

ScanEntity scans either a named or a numbered entity and returns it as a string.

For numbered entities (like &#123; or &#x123;) html.UnescapeString returns sometimes other values as expected, if the number is not well-formed. This may happen because of some strange HTML parsing rules. But these do not apply to Zettelmarkup. Therefore, I parse the number here in the code.

func (*Input) ScanLineContent

func (inp *Input) ScanLineContent() []byte

ScanLineContent reads the reaining input stream and interprets it as lines of text.

func (*Input) SetPos

func (inp *Input) SetPos(pos int)

SetPos allows to reset the read position.

func (*Input) SkipToEOL

func (inp *Input) SkipToEOL()

SkipToEOL reads until the next end-of-line.

Jump to

Keyboard shortcuts

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