From 6295f48ab7916060652ef79c311e57291fd121cc Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 13 Aug 2014 17:15:56 +0200 Subject: [PATCH] Add removeDiacritics function to CalamaresUtils. --- src/libcalamares/utils/CalamaresUtils.cpp | 46 +++++++++++++++++++++++ src/libcalamares/utils/CalamaresUtils.h | 2 + 2 files changed, 48 insertions(+) diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index 10e38d3de..0d74d6fd6 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -157,4 +157,50 @@ installTranslator( QObject* parent ) QCoreApplication::installTranslator( translator ); } + +QString +removeDiacritics( const QString& string ) +{ + const QString diacriticLetters = QString::fromUtf8( + "ŠŒŽšœžŸ¥µÀ" + "ÁÂÃÄÅÆÇÈÉÊ" + "ËÌÍÎÏÐÑÒÓÔ" + "ÕÖØÙÚÛÜÝßà" + "áâãäåæçèéê" + "ëìíîïðñòóô" + "õöøùúûüýÿÞ" + "þČčĆćĐ𩹮" + "ž" + ); + const QStringList noDiacriticLetters = { + "S", "OE", "Z", "s", "oe", "z", "Y", "Y", "u", "A", + "A", "A", "A", "A", "A", "AE", "C", "E", "E", "E", + "E", "I", "I", "I", "I", "DH", "N", "O", "O", "O", + "O", "O", "O", "U", "U", "U", "U", "Y", "s", "a", + "a", "a", "a", "a", "a", "ae", "c", "e", "e", "e", + "e", "i", "i", "i", "i", "dh", "n", "o", "o", "o", + "o", "o", "o", "u", "u", "u", "u", "y", "y", "TH", + "th", "C", "c", "C", "c", "DJ", "dj", "S", "s", "Z", + "z" + }; + + QString output; + foreach ( QChar c, string ) + { + int i = diacriticLetters.indexOf( c ); + if ( i < 0 ) + { + output.append( c ); + } + else + { + QString replacement = noDiacriticLetters[ i ]; + output.append( replacement ); + } + } + + return output; +} + + } diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index 8b22b4f90..c0839f96f 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -41,6 +41,8 @@ namespace CalamaresUtils */ DLLEXPORT void setAppDataDir( const QDir& dir ); DLLEXPORT bool isAppDataDirOverridden(); + + DLLEXPORT QString removeDiacritics( const QString& string ); } #endif // CALAMARESUTILS_H