From 0cee3ce29542e4f5fb3efe38db4154e826ed731b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Thu, 15 Mar 2007 08:23:05 +0100 Subject: [PATCH] =?UTF-8?q?Replace=20=C3=86=20with=20AE=20in=20file/direct?= =?UTF-8?q?ory=20names.=20(#2512)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NEWS.txt | 4 +++- picard/util/__init__.py | 18 +++++++++++------- test/test_utils.py | 2 ++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index 4585bd1e4..5b231c36a 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,7 +1,9 @@ Version 0.9.0alpha5 - 2007-03-XX + * New Features: + * Replace Æ with AE in file/directory names. (#2512) * Bug Fixes: * Fixed fileId generator (caused problems with drag&drop - if files with multiple formats are used). (#2457, #2513) + if files with multiple formats are used). Version 0.9.0alpha4 - 2007-03-09 * Bug Fixes: diff --git a/picard/util/__init__.py b/picard/util/__init__.py index 310149f11..c37a42b8b 100644 --- a/picard/util/__init__.py +++ b/picard/util/__init__.py @@ -143,18 +143,22 @@ def sanitize_date(datestr): date.append(num) return ("", "%04d", "%04d-%02d", "%04d-%02d-%02d")[len(date)] % tuple(date) +_unaccent_dict = {u'Æ': u'AE', u'æ': 'ae'} _re_latin_letter = re.compile(r"^(LATIN [A-Z]+ LETTER [A-Z]+) WITH") def unaccent(string): """Remove accents ``string``.""" result = [] for char in string: - try: - name = unicodedata.name(char) - match = _re_latin_letter.search(name) - if match: - char = unicodedata.lookup(match.group(1)) - except: - pass + if char in _unaccent_dict: + char = _unaccent_dict[char] + else: + try: + name = unicodedata.name(char) + match = _re_latin_letter.search(name) + if match: + char = unicodedata.lookup(match.group(1)) + except: + pass result.append(char) return "".join(result) diff --git a/test/test_utils.py b/test/test_utils.py index 00fea7336..bb680a674 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -12,6 +12,8 @@ class UnaccentTest(unittest.TestCase): self.failUnlessEqual(util.unaccent(u"Björk"), u"Bjork") self.failUnlessEqual(util.unaccent(u"Trentemøller"), u"Trentemoller") self.failUnlessEqual(util.unaccent(u"小室哲哉"), u"小室哲哉") + self.failUnlessEqual(util.unaccent(u"Ænima"), u"AEnima") + self.failUnlessEqual(util.unaccent(u"ænima"), u"aenima") def test_incorrect(self): self.failIfEqual(util.unaccent(u"Björk"), u"Björk")