Revision 5147
Added by Aaron Marcuse-Kubitza about 12 years ago
strings.py | ||
---|---|---|
69 | 69 |
|
70 | 70 |
def overlaps(str0, str1): return str0.find(str1) >= 0 or str1.find(str0) >= 0 |
71 | 71 |
|
72 |
def flip_map(map_): |
|
73 |
''' |
|
74 |
For use with replace_all(), replace_all_re(). |
|
75 |
@param map_ [(from_, to), ...] |
|
76 |
@return [(to, from_), ...] |
|
77 |
''' |
|
78 |
return [(to, from_) for from_, to in map_] |
|
79 |
|
|
80 |
def replace_all(map_, str_): |
|
81 |
''' |
|
82 |
@param map_ [(from_, to), ...] |
|
83 |
''' |
|
84 |
for from_, to in map_: str_ = str_.replace(from_, to) |
|
85 |
return str_ |
|
86 |
|
|
87 |
def replace_all_re(map_, str_): |
|
88 |
''' |
|
89 |
@param map_ [(from_, to), ...] |
|
90 |
''' |
|
91 |
for from_, to in map_: str_ = re.sub(from_, to, str_) |
|
92 |
return str_ |
|
93 |
|
|
72 | 94 |
##### Escaping |
73 | 95 |
|
74 | 96 |
def esc_quotes(str_, quote='"', esc='\\', quote_esc=None): |
Also available in: Unified diff
strings.py: Added replace_all() and replace_all_re(), as well as flip_map() for use with maps for these functions