bugfix
[krypto.git] / ocesavac.py
1 import unicodedata
2
3 ABECEDA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4
5 def deaccent(unistr):
6     return ''.join(aChar 
7                    for aChar in unicodedata.normalize('NFD', unistr) 
8                    if not unicodedata.combining(aChar))
9
10 def ocesat(text, mezery=True):
11     text = deaccent(unicode(text)).upper()
12     if mezery:
13         pole = [' ']
14         lastWh = True
15         for c in text:
16             if c in ABECEDA:
17                 pole.append(c)
18                 lastWh = False
19             elif not lastWh:
20                 pole.append(' ')
21                 lastWh = True
22         if not lastWh:
23             pole.append(' ')
24         return ''.join(pole)
25     else: # bez mezer
26         return ''.join([c for c in text if c in ABECEDA])