runes

package
v0.0.0-...-2842cdc Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: ISC Imports: 8 Imported by: 0

Documentation

Overview

Package runes provides unbounded, file-backed rune buffers and io-package-style interfaces for reading and writing rune slices.

Index

Constants

View Source
const MinRead = bytes.MinRead

MinRead is the minimum rune buffer size passed to a Read call.

Variables

This section is empty.

Functions

func Copy

func Copy(dst Writer, src Reader) (int64, error)

Copy copies from src into dst until either EOF is reached or an error occurs. It returns the number of runes written or the first error encountered, if any.

A successful Copy returns err == nil, not err == io.EOF.

If dst implements the ReaderFrom interface, the copy is implemented by calling dst.ReadFrom.

func ReadAll

func ReadAll(r Reader) ([]rune, error)

ReadAll reads runes from the reader until an error or io.EOF is encountered. It returns all of the runes read. On success, the error is nil, not io.EOF.

func UTF8Reader

func UTF8Reader(r Reader) io.Reader

UTF8Reader returns a buffering io.Reader that reads UTF8 from r.

Types

type Buffer

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

A Buffer is an unbounded rune buffer backed by a file.

func NewBuffer

func NewBuffer(blockSize int) *Buffer

NewBuffer returns a new, empty buffer. No more than blockSize runes are cached in memory.

func NewBufferReaderWriterAt

func NewBufferReaderWriterAt(blockSize int, f ReaderWriterAt) *Buffer

NewBufferReaderWriterAt is like NewBuffer but uses the given ReaderWriterAt as its backing store. If the ReaderWriterAt implements io.Closer, it is closed when the buffer is closed. If the ReaderWriterAt is an *os.File, the file is removed when the buffer is closed.

func (*Buffer) Close

func (b *Buffer) Close() error

Close closes the buffer and removes it's backing file.

func (*Buffer) Delete

func (b *Buffer) Delete(n, offs int64) error

Delete deletes runes from the buffer starting at the given offset. It is an error to delete out of the range of the buffer.

func (*Buffer) Insert

func (b *Buffer) Insert(p []rune, offs int64) error

Insert inserts runes into the buffer at the given offset. It is an error to insert at a point than is out of the range of the buffer.

func (*Buffer) Read

func (b *Buffer) Read(n int, offs int64) ([]rune, error)

Read reads runes from the buffer beginning at a given offset. It is an error to read out of the range of the buffer.

func (*Buffer) Reader

func (b *Buffer) Reader(offs int64) Reader

Reader returns a Reader that reads from the Buffer beginning at the given offset. The returned Reader need not be closed. The Buffer must not be modified between Read calls on the returned Reader.

func (*Buffer) ReaderFrom

func (b *Buffer) ReaderFrom(offs int64) ReaderFrom

ReaderFrom returns a ReaderFrom that inserts into the Buffer beginning at the given offset.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the buffer to empty.

func (*Buffer) Rune

func (b *Buffer) Rune(offs int64) (rune, error)

Rune returns the rune at the given offset. If the rune is out of range it panics.

func (*Buffer) Size

func (b *Buffer) Size() int64

Size returns the number of runes in the buffer.

func (*Buffer) Writer

func (b *Buffer) Writer(offs int64) Writer

Writer returns a Writer that inserts into the Buffer beginning at the given offset. The returned Writer need not be closed.

type Reader

type Reader interface {
	Read([]rune) (int, error)
}

Reader wraps the basic Read method. It behaves like io.Reader but it accepts a slice of runes instead of a slice of bytes, and returns the number of runes read instead of the number of bytes read.

func ByteReader

func ByteReader(s []byte) Reader

ByteReader returns a Reader that reads runes from a []byte.

func EmptyReader

func EmptyReader() Reader

EmptyReader returns a Reader that is empty. All calls to read return 0, io.EOF.

func LimitReader

func LimitReader(r Reader, n int64) Reader

LimitReader returns a Reader that reads no more than n runes from r.

func RunesReader

func RunesReader(r io.RuneReader) Reader

RunesReader returns a Reader that reads from an io.RuneReader.

func SliceReader

func SliceReader(rs []rune) Reader

SliceReader returns a Reader that reads runes from a slice.

func StringReader

func StringReader(s string) Reader

StringReader returns a Reader that reads runes from a string.

type ReaderFrom

type ReaderFrom interface {
	ReadFrom(Reader) (int64, error)
}

ReaderFrom wraps the ReadFrom method. It reads runes from the reader until there are no more runes to read.

type ReaderWriterAt

type ReaderWriterAt interface {
	io.ReaderAt
	io.WriterAt
}

A ReaderWriterAt implements the io.ReaderAt and io.WriterAt interfaces.

type Writer

type Writer interface {
	Write([]rune) (int, error)
}

Writer wraps the basic Write method. It behaves like io.Writer but it accepts a slice of runes instead of a slice of bytes.

func UTF8Writer

func UTF8Writer(w io.Writer) Writer

UTF8Writer returns a Writer that writes UTF8 to w.

Jump to

Keyboard shortcuts

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