README

buffruneio

Tests Status GoDoc

Buffruneio provides rune-based buffered input.

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

Examples

import (
    "fmt"
    "github.com/pelletier/go-buffruneio"
    "strings"
)

reader := buffruneio.NewReader(strings.NewReader("abcd"))
fmt.Println(reader.ReadRune()) // 'a'
fmt.Println(reader.ReadRune()) // 'b'
fmt.Println(reader.ReadRune()) // 'c'
reader.UnreadRune()
reader.UnreadRune()
fmt.Println(reader.ReadRune()) // 'b'
fmt.Println(reader.ReadRune()) // 'c'

Documentation

The documentation and additional examples are available at godoc.org.

Contribute

Feel free to report bugs and patches using GitHub's pull requests system on pelletier/go-buffruneio. Any feedback is much appreciated!

LICENSE

Copyright (c) 2016 - 2018 Thomas Pelletier

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

    Package buffruneio provides rune-based buffered input.

    Index

    Constants

    View Source
    const EOF = -1

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

      Variables

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

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

        Functions

        This section is empty.

        Types

        type Reader

        type Reader struct {
        	// contains filtered or unexported fields
        }

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

          func NewReader

          func NewReader(input io.Reader) *Reader

            NewReader returns a new Reader reading the given input.

            func (*Reader) Forget

            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

              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

                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

                  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.

                    Source Files