Documentation
¶
Overview ¶
Package rope stores text as a persistent tree of chunks of UTF-8: an AVL tree whose leaves own up to 4 KB of the text each, and whose nodes sum the bytes, runes, UTF-16 units and newlines below them, as Zed's rope sums its chunks. An edit copies the chunks it touches and the path to them and shares the rest of the tree with the text before it, so a version of the text is a pointer, kept as long as wanted and read from any goroutine while others are made. ui.TextBuffer and ui/editor's buffers keep their text in it.
Index ¶
- Constants
- func ByteOfRune(n *Node, index int) int
- func ByteOfUnit(n *Node, index int) int
- func Check(n *Node) error
- func Chunks(n *Node, a, b int, fn func(s string) bool)
- func CountRunes(s string) int
- func LineStart(n *Node, line int) int
- func Read(n *Node, start, end int, out *strings.Builder)
- func RuneOfUnit(n *Node, index int) int
- func Split(n *Node, at int) (*Node, *Node)
- func WriteTo(n *Node, w io.Writer) (int64, error)
- type Node
- type Summary
- type Text
- func (t Text) ByteAt(off int) byte
- func (t Text) Chunks(a, b int, fn func(s string) bool)
- func (t Text) EachLine(from, to int, fn func(i, start int, s string) bool)
- func (t Text) EachLineBack(from, to int, fn func(i, start int, s string) bool)
- func (t Text) FromUTF16(u int) int
- func (t Text) Len() int
- func (t Text) Line(i int) string
- func (t Text) LineCount() int
- func (t Text) LineEnd(line int) int
- func (t Text) LineOf(off int) int
- func (t Text) LineStart(line int) int
- func (t Text) Replace(a, b int, s string) Text
- func (t Text) Root() *Node
- func (t Text) RuneAt(off int) (rune, int)
- func (t Text) RuneBefore(off int) (rune, int)
- func (t Text) Same(u Text) bool
- func (t Text) Slice(a, b int) string
- func (t Text) String() string
- func (t Text) UTF16(off int) int
Constants ¶
const ChunkBytes = 4096
ChunkBytes is the most bytes a leaf holds.
Variables ¶
This section is empty.
Functions ¶
func ByteOfRune ¶
ByteOfRune returns the byte rune index starts at.
func ByteOfUnit ¶
ByteOfUnit returns the byte of UTF-16 unit index, rounded down to a rune.
func Check ¶
Check reports what is wrong with the tree, for tests: an oversized or miscounted leaf, or an unbalanced or miscounted branch.
func CountRunes ¶
CountRunes counts the runes of s, ASCII eight bytes at a time, as most code and logs are.
func RuneOfUnit ¶
RuneOfUnit returns the rune holding UTF-16 unit index, or after it.
Types ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a node of the tree: a leaf holding text, or a branch of two. A nil node is the empty text.
func Build ¶
Build returns a tree of s, owning its bytes, so that a small surviving fragment cannot pin a large input string.
type Summary ¶
type Summary struct{ Bytes, Runes, Units, Lines int }
Summary counts a text: its bytes, runes, UTF-16 units and newlines.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text is a version of a text, read by bytes and lines, as code editing counts. Its zero value is the empty text.
func (Text) EachLine ¶
EachLine calls fn with lines from to to, exclusive, and the byte each starts at, reading them a batch at a time rather than finding each in the tree, until fn returns false. Batches of long lines are short, so that fn stopping early leaves little copied for nothing.
func (Text) EachLineBack ¶
EachLineBack calls fn with lines from down to to, inclusive, as EachLine does going up.
func (Text) RuneBefore ¶
RuneBefore returns the rune ending at off and its size.