forked from pyfa-org/Pyfa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strfunctions.py
30 lines (25 loc) · 990 Bytes
/
strfunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
string manipulation module
"""
import re
def sequential_rep(text_, *args):
# type: (basestring, tuple) -> basestring
"""
:param text_: string content
:param args: like <pattern>, <replacement>, <pattern>, <replacement>, ...
:return: if text_ length was zero or invalid parameters then no manipulation to text_
"""
arg_len = len(args)
if arg_len % 2 == 0 and isinstance(text_, str) and len(text_) > 0:
i = 0
while i < arg_len:
text_ = re.sub(args[i], args[i + 1], text_)
i += 2
return text_
def replace_ltgt(text_):
# type: (basestring) -> basestring
"""if fit name contained "<" or ">" then reprace to named html entity by EVE client.
:param text_: string content of fit name from exported by EVE client.
:return: if text_ is not instance of basestring then no manipulation to text_.
"""
return text_.replace("<", "<").replace(">", ">") if isinstance(text_, str) else text_