-
-
Save hmert/733975 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#-*-coding:utf-8-*- | |
# Code stolen and modified from Emre Sevinç: | |
# http://github.com/emres/turkish-deasciifier | |
def set_char_at(string, pos, c): | |
return string[0:pos] + c + string[pos+1:] | |
def turkish_accent(c): | |
return { | |
u'ç': u'c', | |
u'Ç': u'C', | |
u'ğ': u'g', | |
u'Ğ': u'G', | |
u'ö': u'o', | |
u'Ö': u'O', | |
u'ü': u'u', | |
u'Ü': u'U', | |
u'ı': u'i', | |
u'İ': u'I', | |
u'ş': u's', | |
u'Ş': u'S', | |
}.get(c, c) | |
def turkish_asciify(string): | |
u"""Return an ascii string from a unicode Turkish string. | |
>>> turkish_asciify(u'abcığüşöçiIİĞÜŞÖÇ') | |
'abcigusociIIGUSOC' | |
""" | |
for i in range(len(string)): | |
string = set_char_at(string, i, turkish_accent(string[i])) | |
return str(string) | |
if __name__ == "__main__": | |
import doctest | |
doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment