phantie / mutable-string

Mutable, change-friendly, feature-rich String.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mutable-string

extension over array of unicode characters: fast inserts, deletions, replacements, slices, etc. supports all the str class methods if does not provide custom implementation itself. works for py3.7+.

Create:

    from rstring import String
    String() # empty
    String('123') # or String.from_str
    String(array('u', '123')) # or String.from_unicode_array
    String(b'123', encoding='utf8') # or String.from_encoding
    String(str(i) for i in range(1, 5) if i < 4)  # or String.from_iterable

Convert back to str:

    assert str(String('123')) == '123'

It implements all magic methods of str. And much more:

char_index, char_indices, chars, clear, contains (__contains__), copy, drain, extend, insert, insert_str, 
is_empty (!__bool__), lines, map, pop, push, push_str, rchar_index, remove, removeprefix (strip_prefix), 
removesuffix (strip_suffix), repeat (__mul__), replace_range, retain (filter), rsplit_once, split_at,
split_inclusive, split_off, split_once, take_from, truncate, __str__ ( as_str to_str), reverse, trim,
trimr, triml, trim_num, trimr_num, triml_num.

Refer to source and tests for more.

Classmethods:

new, from_str, from_iterable, from_unicode_array, from_encoding, from_utf8, has_custom_impl

Install:

pip install git+https://github.com/phantie/mutable-string.git -U

About

Mutable, change-friendly, feature-rich String.

License:MIT License


Languages

Language:Python 100.0%