forked from pascalweiss/LSFEventScraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LSFTextUtils.py
93 lines (78 loc) · 2.1 KB
/
LSFTextUtils.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
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
__author__ = 'pascal'
class LSFTextUtils:
@staticmethod
def remove_spaces(str):
result = ''
for c in str:
if c != ' ':
result += c
return result
@staticmethod
def remove_new_line_and_tab(str):
name = ''
for c in str:
if c != '\n' and c != '\t':
name += c
return name
@staticmethod
def split_string_at_nth_space(str, space):
space_count = 0
char_count = 0
result = ('','')
for c in str:
char_count += 1
if c == ' ':
space_count += 1
if space_count == space and char_count < len(str):
result = (str[:char_count], str[char_count:])
break
return result
@staticmethod
def correct_time_string(str):
hour = int(str[:2])
if hour > 23:
hour = hour - 24
str = unicode(hour) + u':' + str[3:]
return str
@staticmethod
def split_string_at_last_space(str):
space_position = 0
char_count = 0
for c in str:
if c == ' ':
space_position = char_count
char_count += 1
return (str[:space_position], str[space_position+1:])
@staticmethod
def remove_spaces_at_beginning(str):
result = ''
aux = False
for c in str:
if c != ' ' or aux is True:
result += c
aux = True
return result
@staticmethod
def remove_spaces_at_end(str):
result = ''
idx = 0
last_space = 0
aux = False
for c in str:
if c == ' ':
if aux == False:
last_space = idx
aux = True
else:
aux = False
idx += 1
result = str[0:last_space]
return result
@staticmethod
def rename_TGS(str):
result = ''
if str[0:11] == 'Technologie':
result = 'TGS ' + str[42:]
else:
result = str
return result