ropey.Rope
- class ropey.Rope
A utf8 text rope.
The time complexity of nearly all edit and query operations on Rope are worst-case O(log N) in the length of the rope. Rope is designed to work efficiently even for huge (in the gigabytes) and pathological (all on one line) texts.
- Attributes
text
Content of the Rope as a string.
Methods
append
(other, /)Appends a Rope to the end of this one, consuming the other Rope.
byte_to_char
(byte_idx, /)Returns the char index of the given byte.
byte_to_line
(byte_idx, /)Returns the line index of the given byte.
Total size of the Rope’s text buffer space, in bytes.
char_to_byte
(char_idx, /)Returns the byte index of the given char.
char_to_line
(char_idx, /)Returns the line index of the given char.
from_file
(f, /)Creates a Rope from a file.
from_reader
(reader, /)Creates a Rope from the output of a reader.
from_str
(s, /)Creates a Rope from a string slice.
insert
(char_idx, text, /)Inserts text at char index char_idx.
insert_char
(char_idx, ch, /)Inserts a single char ch at char index char_idx.
Total number of bytes in the Rope.
Total number of chars in the Rope.
Total number of lines in the Rope.
Total number of utf16 code units that would be in Rope if it were encoded as utf16.
remove
(char_range, /)Removes the text in the given char index range.
Shrinks the Rope’s capacity to the minimum possible.
split_off
(char_idx, /)Splits the Rope at char_idx, returning the right part of the split.
write_to
(writer, /)Writes to content of the Rope to a writer.
write_to_file
(f, /)Writes to content of the Rope to a file.
remove_range
remove_range_from
remove_range_full
remove_range_to
- append(other, /)
Appends a Rope to the end of this one, consuming the other Rope.
Note In Python, the other Rope is cloned due to PyO3 restrictions.
- Parameters
other – other Rope
Rope
- byte_to_char(byte_idx, /)
Returns the char index of the given byte.
- byte_to_line(byte_idx, /)
Returns the line index of the given byte.
- char_to_byte(char_idx, /)
Returns the byte index of the given char.
- char_to_line(char_idx, /)
Returns the line index of the given char.
- static from_reader(reader, /)
Creates a Rope from the output of a reader.
- Parameters
reader – reader
- Returns
Rope
Rope
- static from_str(s, /)
Creates a Rope from a string slice.
- insert(char_idx, text, /)
Inserts text at char index char_idx.
- insert_char(char_idx, ch, /)
Inserts a single char ch at char index char_idx.
- len_utf16_cu()
Total number of utf16 code units that would be in Rope if it were encoded as utf16.
- Returns
number of utf16 code units
int
- remove(char_range, /)
Removes the text in the given char index range.
- In the Python slice:
start: int or None, None sets start to 0
stop: int or None, None sets stop to self.len_chars()
step: unused
- Parameters
char_range (slice) – range
- shrink_to_fit()
Shrinks the Rope’s capacity to the minimum possible.
- split_off(char_idx, /)
Splits the Rope at char_idx, returning the right part of the split.
- write_to(writer, /)
Writes to content of the Rope to a writer.
- Parameters
writer – writer