-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_edit.py
More file actions
126 lines (61 loc) · 1.75 KB
/
Copy pathtext_edit.py
File metadata and controls
126 lines (61 loc) · 1.75 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import re,string
__all__ = ["TextUtil"]
class TextUtil:
def __init__(
self,text,
lower=False,upper=False,
trim=False,remove_puncs=False,
remove_numbers=False,
space_by_one=False):
"""
lower : Lower The values
upper : Uppers the values
trim : Remove Whitespaces
remove_puncs : Removes !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
remove_numbers : Removes 0123456789
space_by_ones : add one space in non -linear text
Example {space_by_one}:
from : Hello world Text
to : Hello world Text
"""
self.text = text
self.text = self.text.lower() if lower ==True else self.text
self.text = self.text.upper() if upper ==True else self.text
if trim == True:
self.rstrip()
if remove_puncs == True:
self.filter()
if remove_numbers == True:
self.remove_numbers()
if space_by_one ==True:
self.add_one_space()
def remove(self,values=[]):
"""
Remove Custom Values
Example:
remove(["#","*"])
"""
self.text = re.sub(f"""[{"".join(values)}]""","",self.text)
def filter(self):
""" Remove string.punctuation """
to_remove = string.punctuation
for i in to_remove:
if i in self.text:
self.text = self.text.replace(i,"")
def remove_numbers(self):
digits = string.digits
for i in digits:
if i in self.text:
self.text = self.text.replace(i,"")
def rstrip(self):
self.text = self.text.split(" ")
self.text = "".join(self.text)
def add_one_space(self,token="<>"):
for i in self.text:
if i == " ":
self.text = self.text.replace(i,token)
self.text = self.text.split(token)
self.text = [i for i in self.text if i != '']
self.text = " ".join(self.text)
def __repr__(self):
return self.text