Documentation
¶
Overview ¶
Package runes provides rune related utilities
Index ¶
- type BytesReader
- func (r *BytesReader) Len() int
- func (r *BytesReader) Read(b []byte) (n int, err error)
- func (r *BytesReader) ReadAt(b []byte, off int64) (n int, err error)
- func (r *BytesReader) ReadByte() (byte, error)
- func (r *BytesReader) ReadByteSlice(index, count int64) (slice []byte, err error)
- func (r *BytesReader) ReadNextRuneFrom(index int64) (ch rune, size int, err error)
- func (r *BytesReader) ReadPrevRuneFrom(index int64) (ch rune, size int, err error)
- func (r *BytesReader) ReadRune() (ch rune, size int, err error)
- func (r *BytesReader) ReadRuneAt(index int64) (ch rune, size int, err error)
- func (r *BytesReader) ReadRuneSlice(index, count int64) (slice []rune, size int, err error)
- func (r *BytesReader) ReadString(index, count int64) (slice string, err error)
- func (r *BytesReader) Reset(b []byte)
- func (r *BytesReader) Seek(offset int64, whence int) (int64, error)
- func (r *BytesReader) Size() int64
- func (r *BytesReader) UnreadByte() error
- func (r *BytesReader) UnreadRune() error
- func (r *BytesReader) WriteTo(w io.Writer) (n int64, err error)
- type Reader
- func (r *Reader) Len() int
- func (r *Reader) Read(b []byte) (n int, err error)
- func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)
- func (r *Reader) ReadByte() (byte, error)
- func (r *Reader) ReadByteSlice(index, count int64) (slice []byte, err error)
- func (r *Reader) ReadNextRuneFrom(index int64) (ch rune, size int, err error)
- func (r *Reader) ReadPrevRuneFrom(index int64) (ch rune, size int, err error)
- func (r *Reader) ReadRune() (ch rune, size int, err error)
- func (r *Reader) ReadRuneAt(index int64) (ch rune, size int, err error)
- func (r *Reader) ReadRuneSlice(index, count int64) (slice []rune, size int, err error)
- func (r *Reader) ReadString(index, count int64) (slice string, err error)
- func (r *Reader) Reset(runes []rune)
- func (r *Reader) Seek(offset int64, whence int) (int64, error)
- func (r *Reader) Size() int64
- func (r *Reader) UnreadByte() error
- func (r *Reader) UnreadRune() error
- func (r *Reader) WriteTo(w io.Writer) (n int64, err error)
- type RuneReader
- type StringReader
- func (r *StringReader) Len() int
- func (r *StringReader) Read(b []byte) (n int, err error)
- func (r *StringReader) ReadAt(b []byte, off int64) (n int, err error)
- func (r *StringReader) ReadByte() (byte, error)
- func (r *StringReader) ReadByteSlice(index, count int64) (slice []byte, err error)
- func (r *StringReader) ReadNextRuneFrom(index int64) (ch rune, size int, err error)
- func (r *StringReader) ReadPrevRuneFrom(index int64) (ch rune, size int, err error)
- func (r *StringReader) ReadRune() (ch rune, size int, err error)
- func (r *StringReader) ReadRuneAt(index int64) (ch rune, size int, err error)
- func (r *StringReader) ReadRuneSlice(index, count int64) (slice []rune, size int, err error)
- func (r *StringReader) ReadString(index, count int64) (slice string, err error)
- func (r *StringReader) Reset(s string)
- func (r *StringReader) Seek(offset int64, whence int) (int64, error)
- func (r *StringReader) Size() int64
- func (r *StringReader) UnreadByte() error
- func (r *StringReader) UnreadRune() error
- func (r *StringReader) WriteTo(w io.Writer) (n int64, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BytesReader ¶
type BytesReader struct {
// contains filtered or unexported fields
}
A BytesReader implements the io.Reader, io.ReaderAt, io.WriterTo, io.Seeker, io.ByteScanner, and io.RuneScanner interfaces by reading from a byte slice. Unlike a [Buffer], a BytesReader is read-only and supports seeking. The zero value for BytesReader operates like a BytesReader of an empty slice.
func NewBytesReader ¶
func NewBytesReader(b []byte) *BytesReader
NewBytesReader returns a new [BytesReader.BytesReader] reading from b.
func (*BytesReader) Len ¶
func (r *BytesReader) Len() int
Len returns the number of bytes of the unread portion of the slice.
func (*BytesReader) Read ¶
func (r *BytesReader) Read(b []byte) (n int, err error)
Read implements the io.Reader interface.
func (*BytesReader) ReadAt ¶
func (r *BytesReader) ReadAt(b []byte, off int64) (n int, err error)
ReadAt implements the io.ReaderAt interface.
func (*BytesReader) ReadByte ¶
func (r *BytesReader) ReadByte() (byte, error)
ReadByte implements the io.ByteReader interface.
func (*BytesReader) ReadByteSlice ¶ added in v1.1.0
func (r *BytesReader) ReadByteSlice(index, count int64) (slice []byte, err error)
func (*BytesReader) ReadNextRuneFrom ¶
func (r *BytesReader) ReadNextRuneFrom(index int64) (ch rune, size int, err error)
ReadNextRuneFrom is a convenience method combining Seek and ReadRune into one operation. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart)
ReadNextRuneFrom was added by go-corelibs
func (*BytesReader) ReadPrevRuneFrom ¶
func (r *BytesReader) ReadPrevRuneFrom(index int64) (ch rune, size int, err error)
ReadPrevRuneFrom is a convenience method combining Seek and ReadRune into one operation. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart)
ReadPrevRuneFrom was added by go-corelibs
func (*BytesReader) ReadRune ¶
func (r *BytesReader) ReadRune() (ch rune, size int, err error)
ReadRune implements the io.RuneReader interface.
func (*BytesReader) ReadRuneAt ¶
func (r *BytesReader) ReadRuneAt(index int64) (ch rune, size int, err error)
ReadRuneAt is a convenience method combining Seek and ReadRune into one operation. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart)
ReadRuneAt was added by go-corelibs
func (*BytesReader) ReadRuneSlice ¶
func (r *BytesReader) ReadRuneSlice(index, count int64) (slice []rune, size int, err error)
ReadRuneSlice is a convenience method combining Seek and then ReadRune operations accumulating the requested count of runes, starting at the index given. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart). The count argument is exclusive, meaning start at the index and stop at index+count, equivalent to the slice index syntax of bytes[index:index+count]
ReadRuneSlice was added by go-corelibs
func (*BytesReader) ReadString ¶ added in v1.1.0
func (r *BytesReader) ReadString(index, count int64) (slice string, err error)
func (*BytesReader) Reset ¶
func (r *BytesReader) Reset(b []byte)
Reset resets the [BytesReader.BytesReader] to be reading from b.
func (*BytesReader) Seek ¶
func (r *BytesReader) Seek(offset int64, whence int) (int64, error)
Seek implements the io.Seeker interface.
func (*BytesReader) Size ¶
func (r *BytesReader) Size() int64
Size returns the original length of the underlying byte slice. Size is the number of bytes available for reading via BytesReader.ReadAt. The result is unaffected by any method calls except BytesReader.Reset.
func (*BytesReader) UnreadByte ¶
func (r *BytesReader) UnreadByte() error
UnreadByte complements BytesReader.ReadByte in implementing the io.ByteScanner interface.
func (*BytesReader) UnreadRune ¶
func (r *BytesReader) UnreadRune() error
UnreadRune complements BytesReader.ReadRune in implementing the io.RuneScanner interface.
func (*BytesReader) WriteTo ¶
func (r *BytesReader) WriteTo(w io.Writer) (n int64, err error)
WriteTo implements the io.WriterTo interface.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader implements the io.Reader, io.ReaderAt, io.WriterTo, io.Seeker, io.ByteScanner, and io.RuneScanner interfaces by reading from a rune slice. Unlike a [Buffer], a Reader is read-only and supports seeking. The zero value for Reader operates like a Reader of an empty slice.
func NewRunesReader ¶
NewRunesReader returns a new [Reader.Reader] reading from b.
func (*Reader) ReadAt ¶
ReadAt implements the io.ReaderAt interface.
func (*Reader) ReadByte ¶
ReadByte implements the io.ByteReader interface.
func (*Reader) ReadByteSlice ¶ added in v1.1.0
func (*Reader) ReadNextRuneFrom ¶
ReadNextRuneFrom is a convenience method combining Seek and ReadRune into one operation. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart)
ReadNextRuneFrom was added by go-corelibs
func (*Reader) ReadPrevRuneFrom ¶
ReadPrevRuneFrom is a convenience method combining Seek and ReadRune into one operation. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart)
ReadPrevRuneFrom was added by go-corelibs
func (*Reader) ReadRune ¶
ReadRune implements the io.RuneReader interface.
func (*Reader) ReadRuneAt ¶
ReadRuneAt is a convenience method combining Seek and ReadRune into one operation. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart)
ReadRuneAt was added by go-corelibs
func (*Reader) ReadRuneSlice ¶
ReadRuneSlice is a convenience method combining Seek and then ReadRune operations accumulating the requested count of runes, starting at the index given. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart). The count argument is exclusive, meaning start at the index and stop at index+count, equivalent to the slice index syntax of bytes[index:index+count]
The size returned is the number of runes returned, not the number of bytes.
ReadRuneSlice was added by go-corelibs
func (*Reader) ReadString ¶ added in v1.1.0
func (*Reader) Size ¶
Size returns the original length of the underlying byte slice. Size is the number of bytes available for reading via Reader.ReadAt. The result is unaffected by any method calls except Reader.Reset.
func (*Reader) UnreadByte ¶
UnreadByte complements Reader.ReadByte in implementing the io.ByteScanner interface.
func (*Reader) UnreadRune ¶
UnreadRune complements Reader.ReadRune in implementing the io.RuneScanner interface.
type RuneReader ¶
type RuneReader interface {
io.Reader
io.ReaderAt
io.WriterTo
io.Seeker
io.ByteScanner
io.RuneScanner
// Len returns the byte length of the underlying memory
Len() int
// Size returns the length of the underlying slice
Size() int64
// ReadRuneAt seeks to the index given and reads the rune at that position
ReadRuneAt(index int64) (ch rune, size int, err error)
// ReadPrevRuneFrom seeks to the index given and reads the rune previous to
// that position
ReadPrevRuneFrom(index int64) (ch rune, size int, err error)
// ReadNextRuneFrom seeks to the index given and reads the next rune after
// that position
ReadNextRuneFrom(index int64) (ch rune, size int, err error)
// ReadRuneSlice seeks to the index given, and starts accumulating runes,
// up to the count requested, returning a slice and the total size
//
// For byte and string readers, size is the number of bytes in the rune
// slice. For the rune reader, the size is always 1, which works because the
// underlying data type is just a slice of runes (no decoding of multi-bytes
// needed)
ReadRuneSlice(index, count int64) (slice []rune, size int, err error)
// ReadByteSlice is like ReadRuneSlice, but for byte slices
ReadByteSlice(index, count int64) (slice []byte, err error)
// ReadString is like ReadRuneSlice, but for a string
ReadString(index, count int64) (slice string, err error)
}
RuneReader defines the interface for additional rune-specific features when reading data from a string, bytes or rune slices
func NewRuneReader ¶
func NewRuneReader[V []rune | []byte | string](input V) (rb RuneReader)
NewRuneReader is a generic wrapper around constructing a NewBytesReader, NewStringReader or NewRunesReader depending on the input type given and returned as a RuneReader
type StringReader ¶
type StringReader struct {
// contains filtered or unexported fields
}
A StringReader implements the io.Reader, io.ReaderAt, io.ByteReader, io.ByteScanner, io.RuneReader, io.RuneScanner, io.Seeker, and io.WriterTo interfaces by reading from a string. The zero value for StringReader operates like a StringReader of an empty string.
func NewStringReader ¶
func NewStringReader(s string) *StringReader
NewStringReader returns a new StringReader reading from s. It is similar to bytes.NewBufferString but more efficient and non-writable.
func (*StringReader) Len ¶
func (r *StringReader) Len() int
Len returns the number of bytes of the unread portion of the string.
func (*StringReader) Read ¶
func (r *StringReader) Read(b []byte) (n int, err error)
Read implements the io.Reader interface.
func (*StringReader) ReadAt ¶
func (r *StringReader) ReadAt(b []byte, off int64) (n int, err error)
ReadAt implements the io.ReaderAt interface.
func (*StringReader) ReadByte ¶
func (r *StringReader) ReadByte() (byte, error)
ReadByte implements the io.ByteReader interface.
func (*StringReader) ReadByteSlice ¶ added in v1.1.0
func (r *StringReader) ReadByteSlice(index, count int64) (slice []byte, err error)
func (*StringReader) ReadNextRuneFrom ¶
func (r *StringReader) ReadNextRuneFrom(index int64) (ch rune, size int, err error)
ReadNextRuneFrom is a convenience method combining Seek and ReadRune into one operation. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart)
ReadNextRuneFrom was added by go-corelibs
func (*StringReader) ReadPrevRuneFrom ¶
func (r *StringReader) ReadPrevRuneFrom(index int64) (ch rune, size int, err error)
ReadPrevRuneFrom is a convenience method combining Seek and ReadRune into one operation. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart)
ReadPrevRuneFrom was added by go-corelibs
func (*StringReader) ReadRune ¶
func (r *StringReader) ReadRune() (ch rune, size int, err error)
ReadRune implements the io.RuneReader interface.
func (*StringReader) ReadRuneAt ¶
func (r *StringReader) ReadRuneAt(index int64) (ch rune, size int, err error)
ReadRuneAt is a convenience method combining Seek and ReadRune into one operation. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart)
ReadRuneAt was added by go-corelibs
func (*StringReader) ReadRuneSlice ¶
func (r *StringReader) ReadRuneSlice(index, count int64) (slice []rune, size int, err error)
ReadRuneSlice is a convenience method combining Seek and then ReadRune operations accumulating the requested count of runes, starting at the index given. The index argument is always relative to the start of the slice, equivalent to Seek(index, io.SeekStart). The count argument is exclusive, meaning start at the index and stop at index+count, equivalent to the slice index syntax of bytes[index:index+count]
ReadRuneSlice was added by go-corelibs
func (*StringReader) ReadString ¶ added in v1.1.0
func (r *StringReader) ReadString(index, count int64) (slice string, err error)
func (*StringReader) Reset ¶
func (r *StringReader) Reset(s string)
Reset resets the StringReader to be reading from s.
func (*StringReader) Seek ¶
func (r *StringReader) Seek(offset int64, whence int) (int64, error)
Seek implements the io.Seeker interface.
func (*StringReader) Size ¶
func (r *StringReader) Size() int64
Size returns the original length of the underlying string. Size is the number of bytes available for reading via StringReader.ReadAt. The returned value is always the same and is not affected by calls to any other method.
func (*StringReader) UnreadByte ¶
func (r *StringReader) UnreadByte() error
UnreadByte implements the io.ByteScanner interface.
func (*StringReader) UnreadRune ¶
func (r *StringReader) UnreadRune() error
UnreadRune implements the io.RuneScanner interface.
func (*StringReader) WriteTo ¶
func (r *StringReader) WriteTo(w io.Writer) (n int64, err error)
WriteTo implements the io.WriterTo interface.