Documentation ¶
Index ¶
- type LineReader
- type TextReader
- func (r *TextReader) Bytes() []byte
- func (r *TextReader) Consume() []byte
- func (r *TextReader) End() (n int64, err error)
- func (r *TextReader) Err() error
- func (t *TextReader) Is(s string) (ok bool)
- func (t *TextReader) IsAny(f func(rune) bool) (ok bool)
- func (t *TextReader) IsEOF() (ok bool)
- func (t *TextReader) IsRune(r rune) (ok bool)
- func (t *TextReader) MustNext() (r rune)
- func (r *TextReader) N() int64
- func (t *TextReader) Next() (r rune)
- func (t *TextReader) Peek() (r rune)
- func (t *TextReader) Skip(f func(rune) bool) (ok bool)
- func (t *TextReader) Until(v rune) (ok bool)
- func (t *TextReader) UntilAny(f func(rune) bool) (ok bool)
- func (t *TextReader) UntilEOF() (ok bool)
- func (t *TextReader) UntilEOL() (ok bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LineReader ¶
type LineReader struct { R io.Reader // Underlying reader. // contains filtered or unexported fields }
LineReader wraps an io.Reader to keep track of lines.
func NewLineReader ¶
func NewLineReader(r io.Reader) *LineReader
NewLineReader returns a LineReader initialized with Line and Column set to 1.
func (*LineReader) Position ¶
func (r *LineReader) Position(offset int64) (line, column int)
Position returns the line and column from a byte offset.
BUG: Column is in units of bytes rather than characters.
type TextReader ¶
type TextReader struct {
// contains filtered or unexported fields
}
TextReader wraps an io.Reader to provide primitive methods for parsing text.
func NewTextReader ¶
func NewTextReader(r io.Reader) *TextReader
NewTextReader returns a TextReader that reads r.
func (*TextReader) End ¶
func (r *TextReader) End() (n int64, err error)
End returns the number of bytes read, and the first error that occurred.
func (*TextReader) Err ¶
func (r *TextReader) Err() error
Err returns the first error that occurred while reading, if any.
func (*TextReader) Is ¶
func (t *TextReader) Is(s string) (ok bool)
Is compares s to the next characters in the reader. If they are equal, then the cursor is advanced, and true is returned. Otherwise, the cursor is not advanced, and false is returned.
func (*TextReader) IsAny ¶
func (t *TextReader) IsAny(f func(rune) bool) (ok bool)
IsAny advances the cursor while the next character matches f, or until the end of the reader. Returns the characters read, and whether a non-EOF error occurred.
func (*TextReader) IsEOF ¶
func (t *TextReader) IsEOF() (ok bool)
IsEOF returns true if the cursor is at the end of the reader.
func (*TextReader) IsRune ¶
func (t *TextReader) IsRune(r rune) (ok bool)
IsRune compares r to the next character in the reader. If they are equal, then the cursor is advanced, and true is returned. Otherwise, the cursor is not advanced, and false is returned.
func (*TextReader) MustNext ¶
func (t *TextReader) MustNext() (r rune)
MustNext is like Next, but sets the error to io.ErrUnexpectedEOF if the end of the reader is reached.
func (*TextReader) N ¶
func (r *TextReader) N() int64
N returns the number of bytes read from the underlying reader.
func (*TextReader) Next ¶
func (t *TextReader) Next() (r rune)
Next returns the next rune from the reader, and advances the cursor by the length of the rune. Returns r < 0 if an error occurred.
func (*TextReader) Peek ¶
func (t *TextReader) Peek() (r rune)
Peek returns the next rune without advancing the cursor. Returns r < 0 if an error occurred.
func (*TextReader) Skip ¶
func (t *TextReader) Skip(f func(rune) bool) (ok bool)
Skip advances the cursor until a character does not match f. Returns whether a non-EOF error occurred.
func (*TextReader) Until ¶
func (t *TextReader) Until(v rune) (ok bool)
Until advances the cursor until a character matches v. Returns the characters read, and whether an errored occurred.
func (*TextReader) UntilAny ¶
func (t *TextReader) UntilAny(f func(rune) bool) (ok bool)
UntilAny advances the cursor until a character matches f. Returns the characters read, and whether an errored occurred.
func (*TextReader) UntilEOF ¶
func (t *TextReader) UntilEOF() (ok bool)
UntilEOF reads the remaining characters in the reader.
func (*TextReader) UntilEOL ¶
func (t *TextReader) UntilEOL() (ok bool)
UntilEOL advances the cursor until a character matches end-of-line or end-of-file. Returns the characters read, and whether an errored occurred.