rope

package
v0.0.0-...-dbc7887 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2019 License: MIT Imports: 3 Imported by: 5

Documentation

Overview

Package rope implements Ropes, a copy-on-write, string-like data structure that is optimized for efficient modification of large sequences of bytes at the cost of more expensive random-access.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexFunc

func IndexFunc(ro Rope, f func(r rune) bool) int64

IndexFunc returns the byte index of the first rune in the rope for which a function returns true. If the function never returns true, IndexFunc returns -1.

func IndexRune

func IndexRune(ro Rope, r rune) int64

IndexRune returns the byte index of the first occurrence of r in the rope. If the rope does not contain r, IndexRune returns -1.

func LastIndexFunc

func LastIndexFunc(ro Rope, f func(r rune) bool) int64

LastIndexFunc returns the byte index of the last rune in the rope for which a function returns true. If the function never returns true, IndexFunc returns -1.

LastIndexFunc traverses the rope from end to beginning.

Types

type Reader

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

Reader implements io.Reader, io.ByteReader, and io.RuneReader, reading from the contents of a Rope.

func NewReader

func NewReader(rope Rope) *Reader

NewReader returns a new *Reader that reads the contents of the Rope.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Read reads into p and returns the number of bytes read. If there is nothing left to read, Read returns 0 and io.EOF. Read does not return errors other than io.EOF.

func (*Reader) ReadByte

func (r *Reader) ReadByte() (byte, error)

ReadByte returns the next byte. If there are no more bytes to read, ReadByte returns 0 and io.EOF. ReadByte does not return errors other than io.EOF.

func (*Reader) ReadRune

func (r *Reader) ReadRune() (rune, int, error)

ReadRune returns the next rune and it's byte-width. If the next bytes are not valid UTF8, ReadRune returns utf8.RuneError, 1. If there are no more bytes to read, ReadRune returns 0 and io.EOF. ReadRune does not return errors other than io.EOF.

type ReverseReader

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

ReverseReader implements io.Reader, io.ByteReader, and io.RuneReader, reading from the contents of a Rope in reverse.

func NewReverseReader

func NewReverseReader(rope Rope) *ReverseReader

NewReverseReader returns a new *ReverseReader that reads the contents of the Rope in reverse.

func (*ReverseReader) Read

func (r *ReverseReader) Read(p []byte) (int, error)

Read reads into p and returns the number of bytes read. If there is nothing left to read, Read returns 0 and io.EOF. Read does not return errors other than io.EOF.

func (*ReverseReader) ReadByte

func (r *ReverseReader) ReadByte() (byte, error)

ReadByte returns the next byte. If there are no more bytes to read, ReadByte returns 0 and io.EOF. ReadByte does not return errors other than io.EOF.

func (*ReverseReader) ReadRune

func (r *ReverseReader) ReadRune() (rune, int, error)

ReadRune returns the next rune and it's byte-width. If the next bytes are not valid UTF8, ReadRune returns utf8.RuneError, 1. If there are no more bytes to read, ReadRune returns 0 and io.EOF. ReadRune does not return errors other than io.EOF.

type Rope

type Rope interface {
	Len() int64
	String() string
	WriteTo(io.Writer) (int64, error)
}

Rope is a copy-on-write string, optimized for concatenation and splitting.

func Append

func Append(l, r Rope) Rope

Append returns the concatenation of l and then r.

func Delete

func Delete(r Rope, start, n int64) Rope

Delete deletes n bytes from r beginning at index start. Delete panics if start < 0, n < 0, or start+n > r.Len().

func Empty

func Empty() Rope

Empty returns an empty Rope.

func Insert

func Insert(r Rope, i int64, ins Rope) Rope

Insert inserts ins into r at index i. Insert panics if i < 0 or i > r.Len().

func New

func New(text string) Rope

New returns a new Rope of the given string.

func ReadFrom

func ReadFrom(r io.Reader) (Rope, error)

ReadFrom returns a new Rope containing all of the bytes read from a reader until io.EOF. On error, the returned Rope contains any bytes read from the Reader before the error. If no bytes were read, the Rope is empty.

func Slice

func Slice(r Rope, start, end int64) Rope

Slice returns a new Rope containing the bytes between start (inclusive) and end (exclusive). Slice panics if start < 0, end < start, or end > r.Len().

func Split

func Split(r Rope, i int64) (left, right Rope)

Split returns two new Ropes, the first contains the first i bytes, and the second contains the remaining. Split panics if i < 0 || i >= r.Len().

Jump to

Keyboard shortcuts

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