The mutablestring module#
The AbstractMutableString is the base of a parce Document.
It is a text string that is mutable via item and slice methods, the += operator
and some methods like insert()
and append()
.
If you make modifications while inside a context (using the Python context manager protocol), the modifications (that may not overlap then) are only applied when the context exits for the last time.
- class AbstractMutableString(text='')[source]#
Bases:
object
Abstract base class of a MutableString.
Defines the interface for interacting with the mutable string.
The only thing to implement is where the contents are actually stored, which is an implementation detail. To make a mutable string object work, you should at least implement:
text()
which should return the full text as a string._update_text(changes)
to update the text according to the changes. Those changes are a sorted iterable of (start, end, text) tuples, and will never overlap. All start/end positions refer to the original state of the text.
For efficiency reasons, you might want to reimplement:
set_text()
to replace all text in one go__len__()
to get the length of the text_get_text()
called by__getitem__
to get a slice or single character