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
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.
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
__getitem__to get a slice or single character
Should return the text contents.
Set the text contents.
Return the text contents.
Replace the position or slice with text.
Delete the chracter or slice of text.
Get a character or a slice of text.
Called to apply the changes to the text.
The changes is a sorted list of (start, end, text) tuples.
Append text at the end of the document.
Insert text at pos.
text_changed(position, removed, added)¶
_update_text(). The default implementation does nothing.