Revision 2221
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/strings.py | ||
---|---|---|
12 | 12 |
if str_ == '': return [] |
13 | 13 |
else: return str_.split(sep) |
14 | 14 |
|
15 |
def remove_prefix(prefix, str_): |
|
16 |
if str_.startswith(prefix): return str_[len(prefix):] |
|
15 |
def remove_prefix(prefix, str_, removed_ref=None): |
|
16 |
if removed_ref == None: removed_ref = [False] |
|
17 |
|
|
18 |
removed_ref[0] = str_.startswith(prefix) |
|
19 |
if removed_ref[0]: return str_[len(prefix):] |
|
17 | 20 |
else: return str_ |
18 | 21 |
|
19 | 22 |
def remove_prefixes(prefixes, str_): |
... | ... | |
22 | 25 |
|
23 | 26 |
def with_prefixes(prefixes, str_): return (p+str_ for p in prefixes) |
24 | 27 |
|
25 |
def remove_suffix(suffix, str_): |
|
26 |
if str_.endswith(suffix): return str_[:-len(suffix)] |
|
28 |
def remove_suffix(suffix, str_, removed_ref=None): |
|
29 |
if removed_ref == None: removed_ref = [False] |
|
30 |
|
|
31 |
removed_ref[0] = str_.endswith(suffix) |
|
32 |
if removed_ref[0]: return str_[:-len(suffix)] |
|
27 | 33 |
else: return str_ |
28 | 34 |
|
29 | 35 |
def contains_any(haystack, needles): |
Also available in: Unified diff
strings.py: remove_prefix(), remove_suffix(): Added removed_ref param