-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathturkish.py
47 lines (41 loc) · 1.3 KB
/
turkish.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
class TurkishText:
"""Class for handling lowercase/uppercase conversions of Turkish characters..
Attributes:
text -- Turkish text to be handled
"""
text = ""
lowercase = ['ı', 'ğ', 'ü', 'ş', 'i', 'ö', 'ç']
uppercase = ['I', 'Ğ', 'Ü', 'Ş', 'İ', 'Ö', 'Ç']
def __init__(self, text):
self.text = text
def upper(self):
"""Converts the text into uppercase letters.
Returns string.
"""
res = ""
for i in self.text:
if i in self.lowercase:
res += self.uppercase[self.lowercase.index(i)]
else:
res += i.upper()
return res
def lower(self):
"""Converts the text into lowercase letters.
Returns string.
"""
res = ""
for i in self.text:
if i in self.uppercase:
res += self.lowercase[self.uppercase.index(i)]
else:
res += i.lower()
return res
def capitalize(self):
"""Converts each first letter to uppercase, and the rest to lowercase letters.
Returns string.
"""
m = self.text.split()
res = ""
for i in m:
res += TurkishText(i[0]).upper() + TurkishText(i[1:]).lower() + " "
return res[:-1:]