iorw

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const EndRune = -1

Variables

View Source
var ErrLimitReached = errors.New("limit reached")

Functions

func ExpandIndexFunc

func ExpandIndexFunc(r Reader, i int, truth bool, f func(rune) bool) int

Returns index where truth was found.

func ExpandLastIndexFunc

func ExpandLastIndexFunc(r Reader, i int, truth bool, f func(rune) bool) int

Returns last index before truth was found.

func HasPrefix

func HasPrefix(r Reader, i int, s []byte) bool

func Index

func Index(r Reader, i int, sep []byte, toLower bool) (int, error)

func IndexCtx

func IndexCtx(ctx context.Context, r Reader, i int, sep []byte, toLower bool) (int, error)

Returns (-1, nil) if not found.

func IndexFunc

func IndexFunc(r Reader, i int, truth bool, f func(rune) bool) (index, size int, err error)

func IsWordRune

func IsWordRune(ru rune) bool

func LastIndexFunc

func LastIndexFunc(r Reader, i int, truth bool, f func(rune) bool) (index, size int, err error)

func LineEndIndex

func LineEndIndex(r Reader, i int) (int, bool, error)

func LineStartIndex

func LineStartIndex(r Reader, i int) (int, error)

func LinesIndexes

func LinesIndexes(r Reader, a, b int) (int, int, bool, error)

func MMLen

func MMLen(rd Reader) int

min/max length

func NewLineIndex

func NewLineIndex(r Reader, i int) (int, int, error)

func NewLineLastIndex

func NewLineLastIndex(r Reader, i int) (int, int, error)

func ReadFullSlice

func ReadFullSlice(rd Reader) ([]byte, error)

Returns a slice (not a copy).

func ReaderIter

func ReaderIter(r Reader, fn func(i int, ru rune) bool) error

Iterate over n+1 runes, with the last rune being eofRune(-1).

func SetString

func SetString(rw ReadWriter, s string) error

func ToLowerAsciiCopy

func ToLowerAsciiCopy(p []byte) []byte

Lower case at byte level without expanding in size the resulting byte slice.

func WordAtIndex

func WordAtIndex(r Reader, index int) ([]byte, int, error)

func WordIsolated

func WordIsolated(r Reader, i, le int) bool

Types

type BytesReadWriter

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

func NewBytesReadWriter

func NewBytesReadWriter(b []byte) *BytesReadWriter

func (*BytesReadWriter) Delete

func (rw *BytesReadWriter) Delete(i, n int) error

func (*BytesReadWriter) Insert

func (rw *BytesReadWriter) Insert(i int, p []byte) error

func (*BytesReadWriter) Max

func (rw *BytesReadWriter) Max() int

func (*BytesReadWriter) Min

func (rw *BytesReadWriter) Min() int

func (*BytesReadWriter) Overwrite

func (rw *BytesReadWriter) Overwrite(i, n int, p []byte) error

func (*BytesReadWriter) ReadLastRuneAt

func (rw *BytesReadWriter) ReadLastRuneAt(i int) (ru rune, size int, err error)

func (*BytesReadWriter) ReadNCopyAt

func (rw *BytesReadWriter) ReadNCopyAt(i, n int) ([]byte, error)

func (*BytesReadWriter) ReadNSliceAt

func (rw *BytesReadWriter) ReadNSliceAt(i, n int) ([]byte, error)

func (*BytesReadWriter) ReadRuneAt

func (rw *BytesReadWriter) ReadRuneAt(i int) (ru rune, size int, err error)

type LimitedReader

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

Limits reading while keeping the original offsets.

func NewLimitedReader

func NewLimitedReader(r Reader, min, max, pad int) *LimitedReader

func NewLimitedReaderLen

func NewLimitedReaderLen(r Reader, offset, n int) *LimitedReader

func (*LimitedReader) Max

func (r *LimitedReader) Max() int

func (*LimitedReader) Min

func (r *LimitedReader) Min() int

func (*LimitedReader) ReadLastRuneAt

func (r *LimitedReader) ReadLastRuneAt(i int) (ru rune, size int, err error)

func (*LimitedReader) ReadNCopyAt

func (r *LimitedReader) ReadNCopyAt(i, n int) ([]byte, error)

func (*LimitedReader) ReadNSliceAt

func (r *LimitedReader) ReadNSliceAt(i, n int) ([]byte, error)

func (*LimitedReader) ReadRuneAt

func (r *LimitedReader) ReadRuneAt(i int) (ru rune, size int, err error)

type ReadWriter

type ReadWriter interface {
	Reader
	Writer
}

type Reader

type Reader interface {
	ReadRuneAt(i int) (ru rune, size int, err error)
	ReadLastRuneAt(i int) (ru rune, size int, err error)

	// there must be at least N bytes available or there will be an error
	ReadNCopyAt(i, n int) ([]byte, error)
	ReadNSliceAt(i, n int) ([]byte, error) // []byte might not be a copy

	Min() int
	Max() int // not inclusive
}

func NewStringReader

func NewStringReader(s string) Reader

type UndoRedo

type UndoRedo struct {
	Type  WriterOp
	Index int
	B     []byte // insert/delete
	B2    []byte // overwrite insert
}

func DeleteUndoRedo

func DeleteUndoRedo(rw ReadWriter, i, n int) (*UndoRedo, error)

func InsertUndoRedo

func InsertUndoRedo(w Writer, i int, p []byte) (*UndoRedo, error)

func OverwriteUndoRedo

func OverwriteUndoRedo(rw ReadWriter, i, length int, p []byte) (*UndoRedo, error)

func (*UndoRedo) Apply

func (ur *UndoRedo) Apply(w Writer, redo bool) error

type Writer

type Writer interface {
	Insert(i int, p []byte) error
	Delete(i, n int) error
	Overwrite(i, n int, p []byte) error
}

type WriterOp

type WriterOp int
const (
	InsertWOp WriterOp = iota
	DeleteWOp
	OverwriteWOp
)

Jump to

Keyboard shortcuts

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