Rope

Rope implementation, providing more efficient modification if there's lots of text.

The Rope structure acts as a slice, a view into the rope's contents. If additional text is added to a node stored inside, the change will not be reflected by the rope.

rope.init is guaranteed to be valid and empty.

Constructors

this
this(const(char)[] text)

Create a rope holding given text.

this
this(Rope left, Rope right)

Create a rope concatenating two other ropes.

this
this(inout(RopeNode)* node)

Create a rope from given node.

this
this(Rope rope)

Copy a Rope.

Members

Functions

back
char back()

Get the last *byte* from the rope.

byDchar
auto byDchar()

Iterate the rope by characters.

byNode
auto byNode()

Perform deep-first search through leaf nodes of the rope.

column
ptrdiff_t column(size_t index)

Get the column the given index is on.

countCharacters
size_t countCharacters()

Count characters in the string. Iterates the whole rope.

diff
DiffRegion diff(Rope other)

Find the difference between the two ropes, in terms of a single contiguous region.

empty
bool empty()

If true, the rope is empty.

front
char front()

Get the first *byte* from the rope.

insert
Rope insert(size_t index, Rope value)

Insert a new node into the rope.

isBalanced
bool isBalanced(int maxDistance)
isLeaf
bool isLeaf()

True if the node is a leaf.

leafFrom
Rope leafFrom(size_t start)

Get a leaf node that is a subrope starting with the given index. The length of the node may vary, and does not have to reach the end of the rope.

left
Rope left()

Get the left side of the rope

lineByIndex
Rope lineByIndex(size_t index)

Get line in the rope by a byte index.

lineEndByIndex
size_t lineEndByIndex(size_t index)

Get the index of the start or end of the line — from index of any character on the same line.

lineStartByIndex
size_t lineStartByIndex(size_t index)

Get the index of the start or end of the line — from index of any character on the same line.

opAssign
ref opAssign(char[] str)
ref opAssign(RopeNode* node)

Assign a new value to the rope.

opBinary
Rope opBinary(Rope that)

Concatenate two ropes together.

opBinary
Rope opBinary(const(char)[] text)
opBinaryRight
Rope opBinaryRight(const(char)[] text)

Concatenate with a string.

opDollar
size_t opDollar()

Get the rope's length.

opEquals
bool opEquals(char[] str)

Compare the text to a string.

opEquals
bool opEquals(Rope str)

Compare two ropes.

opIndex
Rope opIndex()

Return a mutable slice.

opIndex
char opIndex(size_t index)

Get character at given index.

opIndex
Rope opIndex(size_t[2] slice)

Slice the rope.

opOpAssign
Rope opOpAssign(const(char)[] value)

Append text to the rope.

opOpAssign
Rope opOpAssign(Rope value)

Append another rope to the rope.

opSlice
size_t[2] opSlice(size_t left, size_t right)
Undocumented in source. Be warned that the author may not have intended to support it.
popBack
void popBack()

Remove the last byte from the rope.

popFront
void popFront()

Remove the first byte from the rope.

rebalance
Rope rebalance()
replace
Rope replace(size_t low, size_t high, Rope value)

Replace value between two indexes with a new one.

replace
Rope replace(String oldValue, Rope value)

Replace given substring with a new value

right
Rope right()

Get the right side of the rope

save
Rope save()
Undocumented in source. Be warned that the author may not have intended to support it.
split
Rope split(size_t index)

Split the rope, creating a new root node that connects the left and right side of the split.

toHash
size_t toHash()

Get a hash of the rope.

toString
void toString(Writer w)

Put the rope's contents inside given output range.

toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.
toStringz
immutable(char)* toStringz()
Undocumented in source. Be warned that the author may not have intended to support it.
toStringzMutable
char* toStringzMutable()
Undocumented in source. Be warned that the author may not have intended to support it.
value
const(char)[] value()

Get the value of this rope. Only works for leaf nodes.

Static functions

merge
Rope merge(Rope[] leaves)

Structs

DiffRegion
struct DiffRegion
Undocumented in source.

Variables

depth
int depth;

Depth of the node.

leafText
const(char)[] leafText;

Content of the rope if it's a leaf. Not sliced; to get the text with the slice applied, use value.

length
size_t length;

Start and length of the rope, in UTF-8 bytes.

node
const(RopeNode)* node;

Content of the rope, if it contains children.

start
size_t start;

Start and length of the rope, in UTF-8 bytes.

See Also

Meta