rope

package
v0.0.0-...-3194d9e Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: MIT Imports: 5 Imported by: 0

README

rope GoDoc

import "github.com/fvbommel/util/rope"

Package rope implements a "heavy-weight string", which represents very long strings more efficiently (especially when many concatenations are performed).

It may also need less memory if it contains repeated substrings, or if you use several large strings that are similar to each other.

Rope values are immutable, so each operation returns its result instead of modifying the receiver. This immutability also makes them thread-safe.

Documentation

Overview

Package rope implements a "heavy-weight string", which represents very long strings more efficiently (especially when many concatenations are performed).

It may also need less memory if it contains repeated substrings, or if you use several large strings that are similar to each other.

Rope values are immutable, so each operation returns its result instead of modifying the receiver. This immutability also makes them thread-safe.

Index

Constants

This section is empty.

Variables

View Source
var MarkGoStringedRope = true

MarkGoStringedRope is a flag that, when enabled, prepends "/*Rope*/ " to the result of Rope.GoString(). This can be useful when debugging code using interface{} values, where Ropes and strings can coexist.

This should only ever be changed from init() functions, to ensure there are no data races.

Functions

This section is empty.

Types

type Reader

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

Reader is an io.Reader that reads from a Rope.

func NewReader

func NewReader(rope Rope) *Reader

NewReader returns a Reader that reads from the specified Rope.

func (*Reader) Read

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

Read implements io.Reader.

type Rope

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

Rope implements a non-contiguous string. The zero value is an empty rope.

func New

func New(arg string) Rope

New returns a Rope representing a given string.

func (Rope) Append

func (r Rope) Append(rhs ...Rope) Rope

Append returns the Rope representing the arguments appended to this rope.

func (Rope) AppendString

func (r Rope) AppendString(rhs ...string) Rope

AppendString is like Append, but accepts strings.

func (Rope) At

func (r Rope) At(idx int64) byte

At returns the byte at index idx. The index must be >= 0 and < r.Len().

func (Rope) Bytes

func (r Rope) Bytes() []byte

Bytes returns the string represented by this Rope as a []byte.

func (Rope) Depth

func (r Rope) Depth() uint32

Depth returns the depth of the directed acyclic graph the Rope consists of internally

func (Rope) DropPostfix

func (r Rope) DropPostfix(end int64) Rope

DropPostfix returns the prefix of a rope ending at end. It's analogous to str[:end].

If end <= 0, an empty Rope is returned.

func (Rope) DropPrefix

func (r Rope) DropPrefix(start int64) Rope

DropPrefix returns a postfix of a rope, starting at index. It's analogous to str[start:].

If start >= r.Len(), an empty Rope is returned.

func (Rope) GoString

func (r Rope) GoString() string

GoString materializes the Rope as a quoted string value.

func (Rope) Len

func (r Rope) Len() int64

Len returns the length of the string represented by the Rope.

func (Rope) ReadAt

func (r Rope) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements io.ReaderAt.

func (Rope) Rebalance

func (r Rope) Rebalance() Rope

Rebalance rebalances a rope.

func (Rope) Repeat

func (r Rope) Repeat(count int64) Rope

Repeat returns the receiver, repeated a number of times.

func (Rope) Slice

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

Slice returns the substring of a Rope, analogous to str[start:end]. It is equivalent to r.DropPostfix(end).DropPrefix(start).

If start >= end, start >= r.Len() or end == 0, an empty Rope is returned.

func (Rope) String

func (r Rope) String() string

String materializes the Rope as a string value.

func (Rope) Walk

func (r Rope) Walk(f func(string) error) error

Walk passes the Rope, piece-by-piece, to f. If f returns an error Walk() returns that error without calling f again.

func (Rope) WriteTo

func (r Rope) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the value of this Rope to the provided writer.

Jump to

Keyboard shortcuts

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