-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStringF.py
45 lines (34 loc) · 948 Bytes
/
StringF.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
31
32
33
34
35
36
37
38
39
40
41
42
43
def custom_format(source):
#Using the © format
#first space after a © doesn't count and is removed.
result = ""
temp = ""
escaped = False
var_mode = False
import string
for char in source:
if escaped:
escaped = False
result += char
continue
elif char == "\\":
escaped = True
result += char
continue
if var_mode:
if char in string.ascii_letters:
temp += char
continue
else:
result += variables.get(temp, '©' + temp)
temp = ""
var_mode = False
if char == " ":
continue
if char == "©":
var_mode = True
continue
result += char
if var_mode:
result += variables.get(temp, '©' + temp)
return result