-
Notifications
You must be signed in to change notification settings - Fork 7
/
OgreStringUtils.py
26 lines (25 loc) · 955 Bytes
/
OgreStringUtils.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
class OgreStringUtils:
def trim(string, left=True, right=True):
"""
Removes any whitespace characters, be it standard space or
TABs and so on.
@remarks
The user may specify whether they want to trim only the
beginning or the end of the String ( the default action is
to trim both).
"""
lspaces=0;
rspaces=0;
if (left):
for i in range (len(string)):
if not (string[i] == ' ' or string[i] == '\t' or string[i] == '\r' or string[i] == '\n'):
break;
else:
lspaces += 1;
if (right):
for i in reversed(range(len(string))):
if not (string[i] == ' ' or string[i] == '\t' or string[i] == '\r' or string[i] == '\n'):
break;
else:
rspaces += 1;
return string[lspaces:len(string)-rspaces];