Documentation
¶
Overview ¶
Package runeio implements a mechanism to read a stream of Unicode code points (runes) from an io.Reader, with an internal buffer to push code points back to the front of the stream to allow limited peeking and rewind.
Index ¶
- Constants
- func Must(x rune, err error) rune
- func MustFunc(f func() (rune, error)) func() rune
- type Offset
- type Reader
- func (r *Reader) Buffer(buf []byte, max int)
- func (r *Reader) Last() rune
- func (r *Reader) Next() (rune, error)
- func (r *Reader) Offset() Offset
- func (r *Reader) Peek() (rune, error)
- func (r *Reader) PeekN(dest []rune, n int) (int, error)
- func (r *Reader) Push(x rune)
- func (r *Reader) Skip(n int) error
Constants ¶
const RuneEOF = rune(0xFFFFFF)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader has a useful zero value, but doesn't have a pushback buffer by default.
func NewReaderBuffered ¶
func (*Reader) Buffer ¶
Buffer sets the initial buffer to use when pushing runes back onto the stack with [Next] and the maximum capacity (in bytes) for that stack. If the maximum is less than or equal to the buffer capacity, then it will never grow. (TODO right now it always grows)
Passing a nil buffer will allocate a new buffer.
Buffer panics if it is called after reading has started.
func (*Reader) Last ¶
Last returns the rune most recently returned by [Next]. If [Next] has not yet been called, it panics.
func (*Reader) Next ¶
Next reads a single rune from the input stream or, if runes have been pushed back, reads and removes the most recently pushed rune from the stack. Error may be io.EOF or a read error.
func (*Reader) Peek ¶
Peek returns what the next call to [Next] would return, without advancing the input stream.
func (*Reader) PeekN ¶
PeekN stores in dest what the next n calls to [Next] would return, without advancing the input stream. It returns the number of elements read, ending early in the event of EOF. The first n elements of dest are set to the special value RuneEOF unless updated with a successfully peeked value. The pushback buffer must be able to handle at least n elements, in addition to its existing contents.