1 /*******************************************************************************
3 This file is part of mDictionary.
5 mDictionary is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 mDictionary is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 /*! /file AccentsNormalizer.h
23 \brief Common funcionality for all classes that need to remove accents from strings
25 \author Bartosz Szatkowski <bulislaw@linux.com>
28 #ifndef ACCENTSNORMALIZER_H
29 #define ACCENTSNORMALIZER_H
36 class AccentsNormalizer {
38 QMap<QChar, QRegExp> letters;
41 QString removeAccents(QString string) {
42 string = string.toLower();
43 QString normalized = string.normalized(QString::NormalizationForm_KD);
44 foreach(QChar let, letters.keys())
45 normalized.replace(letters[let], QString(let));
47 normalized.replace(noLetter, "");
48 //qDebug() << "NORMALIZED: " << normalized;
52 letters['a'] = QRegExp(QString::fromUtf8("[ÀàÁáÂÂâÃãÄäÅåæÆĀāĂ㥹]"), Qt::CaseInsensitive);
53 letters['c'] = QRegExp(QString::fromUtf8("[ÇçÈçŒĆćĈĉĊċČč]"), Qt::CaseInsensitive);
54 letters['d'] = QRegExp(QString::fromUtf8("[ÐĐđĎď]"), Qt::CaseInsensitive);
55 letters['e'] = QRegExp(QString::fromUtf8("[ÈéèÉÊêËëĒēĔĕĖėĘęĚěē]"), Qt::CaseInsensitive);
56 letters['f'] = QRegExp(QString::fromUtf8("[ſ]"), Qt::CaseInsensitive);
57 letters['g'] = QRegExp(QString::fromUtf8("[ĠġĢģĜĝĞğ]"), Qt::CaseInsensitive);
58 letters['h'] = QRegExp(QString::fromUtf8("[ħĤĥĦ]"), Qt::CaseInsensitive);
59 letters['i'] = QRegExp(QString::fromUtf8("[ÌìÍíÎîÏïİijĨĩĪīĬĭĮį]"), Qt::CaseInsensitive);
60 letters['j'] = QRegExp(QString::fromUtf8("[Ĵĵ]"), Qt::CaseInsensitive);
61 letters['k'] = QRegExp(QString::fromUtf8("[Ķķĸ]"), Qt::CaseInsensitive);
62 letters['l'] = QRegExp(QString::fromUtf8("[ŀŁłĹĺĻļĽľĿ]"), Qt::CaseInsensitive);
63 letters['n'] = QRegExp(QString::fromUtf8("[ÑñŃńŅņŇňʼnŊŋ]"), Qt::CaseInsensitive);
64 letters['o'] = QRegExp(QString::fromUtf8("[ÒòÓóÔÕõÖöØøŐőœŌōŎŏ]"), Qt::CaseInsensitive);
65 letters['r'] = QRegExp(QString::fromUtf8("[ŕŖŖŗŘř]"), Qt::CaseInsensitive);
66 letters['s'] = QRegExp(QString::fromUtf8("[ߊšŚśŜŝŞş]"), Qt::CaseInsensitive);
67 letters['t'] = QRegExp(QString::fromUtf8("[ŢţŤťŦŧ]"), Qt::CaseInsensitive);
68 letters['u'] = QRegExp(QString::fromUtf8("[ÙùÚúÛûÜüŰűŲųŨũŪūŬŮů]"), Qt::CaseInsensitive);
69 letters['w'] = QRegExp(QString::fromUtf8("[Ŵŵ]"), Qt::CaseInsensitive);
70 letters['y'] = QRegExp(QString::fromUtf8("[ÿÝýŶŷŸ]"), Qt::CaseInsensitive);
71 letters['z'] = QRegExp(QString::fromUtf8("[ŹźŻżŽž]"), Qt::CaseInsensitive);
72 noLetter = QRegExp("[^a-z ]", Qt::CaseInsensitive);
76 #endif // ACCENTSNORMALIZER_H