Add tools - unaccent
This commit is contained in:
parent
2b3ff56196
commit
e6a2cbc3d9
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
# This file is part account_payment_gateway module for Tryton.
|
||||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
|
||||
import unicodedata
|
||||
|
||||
SRC_CHARS = u"""/*+?¿!&$[]{}@#`^<>=~%|\\"""
|
||||
|
||||
def unaccent(text):
|
||||
if not (isinstance(text, str) or isinstance(text, unicode)):
|
||||
return str(text)
|
||||
if isinstance(text, str):
|
||||
text = unicode(text, 'utf-8')
|
||||
text = text.lower()
|
||||
for c in xrange(len(SRC_CHARS)):
|
||||
text = text.replace(SRC_CHARS[c], '')
|
||||
text = text.replace(u'º', '. ')
|
||||
text = text.replace(u'ª', '. ')
|
||||
text = text.replace(u' ', ' ')
|
||||
return unicodedata.normalize('NFKD', text).encode('ASCII', 'ignore')
|
Loading…
Reference in New Issue