summaryrefslogtreecommitdiff
path: root/unidecode/__init__.py
diff options
context:
space:
mode:
authorTomaz Solc <avian@toybox.zemanta.com>2008-09-05 16:51:19 +0200
committerTomaz Solc <avian@toybox.zemanta.com>2008-09-05 16:51:19 +0200
commitb2cedd05e3ce012098c23fbb263dc382ac45a302 (patch)
tree9b95fa5a01a64e0cab8c34f8ea4744f786eb0875 /unidecode/__init__.py
downloadunidecode-b2cedd05e3ce012098c23fbb263dc382ac45a302.tar.gz
Initial import.
Diffstat (limited to 'unidecode/__init__.py')
-rw-r--r--unidecode/__init__.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/unidecode/__init__.py b/unidecode/__init__.py
new file mode 100644
index 0000000..7b914ba
--- /dev/null
+++ b/unidecode/__init__.py
@@ -0,0 +1,40 @@
+Char = {}
+
+NULLMAP = [ '' * 0x100 ]
+
+def unidecode(string):
+ retval = []
+
+ for char in string:
+ o = ord(char)
+
+ if o < 0x80:
+ retval.append(char)
+ continue
+
+ h = o >> 8
+ l = o & 0xff
+
+ c = Char.get(h, None)
+
+ if c == None:
+ try:
+ mod = __import__('unidecode.x%02x'%(h), [], [], ['data'])
+ except ImportError:
+ Char[h] = NULLMAP
+ retval.append('')
+ continue
+
+ Char[h] = mod.data
+
+ try:
+ retval.append( mod.data[l] )
+ except IndexError:
+ retval.append( '' )
+ else:
+ try:
+ retval.append( c[l] )
+ except IndexError:
+ retval.append( '' )
+
+ return ''.join(retval)