File indexing completed on 2024-05-12 17:18:06
0001 # -*- coding: UTF-8 -*- 0002 0003 """ 0004 Accent equivalence in regular expression patterns. 0005 0006 @author: Sébastien Renard <sebastien.renard@digitalfox.org> 0007 @license: GPLv3 0008 """ 0009 0010 import re 0011 0012 accents={} 0013 accents["e"] = "[%s]" % "|".join(['e', 'é', 'è', 'ê', 'E', 'É', 'È', 'Ê']) 0014 accents["é"] = "[%s]" % "|".join(['é', 'è', 'ê', 'É', 'È', 'Ê']) 0015 accents["è"] = "[%s]" % "|".join(['é', 'è', 'ê', 'É', 'È', 'Ê']) 0016 accents["ê"] = "[%s]" % "|".join(['é', 'è', 'ê', 'É', 'È', 'Ê']) 0017 accents["a"] = "[%s]" % "|".join(['a', 'à', 'â', 'A', 'À', 'Â']) 0018 accents["à"] = "[%s]" % "|".join(['à', 'â', 'À', 'Â']) 0019 accents["â"] = "[%s]" % "|".join(['à', 'â', 'À', 'Â']) 0020 accents["u"] = "[%s]" % "|".join(['u', 'ù', 'û', 'U', 'Ù', 'Û']) 0021 accents["ù"] = "[%s]" % "|".join(['ù', 'û', 'Ù', 'Û']) 0022 accents["û"] = "[%s]" % "|".join(['ù', 'û', 'Ù', 'Û']) 0023 accentPattern=re.compile("@([%s])" % "|".join(list(accents.keys()))) 0024 0025 0026 def patternAccents(pattern): 0027 """Replace every C{@x} in the pattern by the value C{accents["x"]}.""" 0028 0029 for accentMatch in accentPattern.finditer(pattern): 0030 letter=accentMatch.group(1) 0031 pattern=pattern.replace("@%s" % letter, accents[letter]) 0032 0033 return pattern 0034