go-buffruneio: github.com/pelletier/go-buffruneio Index | Files

package buffruneio

import "github.com/pelletier/go-buffruneio"

Package buffruneio provides rune-based buffered input.


Package Files



const EOF = -1

EOF is a rune value indicating end-of-file.


var ErrNoRuneToUnread = errors.New("no rune to unwind")

ErrNoRuneToUnread is the error returned when UnreadRune is called with nothing to unread.

type Reader Uses

type Reader struct {
    // contains filtered or unexported fields

A Reader implements rune-based input for an underlying byte stream.

func NewReader Uses

func NewReader(input io.Reader) *Reader

NewReader returns a new Reader reading the given input.

func (*Reader) Forget Uses

func (rd *Reader) Forget()

Forget discards buffered runes before the current input position. Calling Forget makes it impossible to UnreadRune earlier than the current input position but is necessary to avoid unbounded buffer growth.

func (*Reader) PeekRunes Uses

func (rd *Reader) PeekRunes(n int) []rune

PeekRunes returns the next n runes in the input, without advancing the current input position.

If the input has fewer than n runes and then returns an io.EOF error, PeekRune returns a slice containing the available runes followed by EOF. On other hand, if the input ends early with a non-io.EOF error, PeekRune returns a slice containing only the available runes, with no terminating EOF.

func (*Reader) ReadRune Uses

func (rd *Reader) ReadRune() (rune, int, error)

ReadRune reads and returns the next rune from the input. The rune is also saved in an internal buffer, in case UnreadRune is called. To avoid unbounded buffer growth, the caller must call Forget at appropriate intervals.

At end of file, ReadRune returns EOF, 0, nil. On read errors other than io.EOF, ReadRune returns EOF, 0, err.

func (*Reader) UnreadRune Uses

func (rd *Reader) UnreadRune() error

UnreadRune rewinds the input by one rune, undoing the effect of a single ReadRune call. UnreadRune may be called multiple times to rewind a sequence of ReadRune calls, up to the last time Forget was called or the beginning of the input.

If there are no ReadRune calls left to undo, UnreadRune returns ErrNoRuneToUnread.

Package buffruneio imports 4 packages (graph) and is imported by 4 packages. Updated 2020-11-14. Refresh now. Tools for package owners.