Renamed to simplifyAccents (actually the chars are not removed, but replaced)

This commit is contained in:
Klaus Basan
2018-09-14 19:00:30 +02:00
parent c26af17b2f
commit c3cf39e102
5 changed files with 10 additions and 10 deletions

View File

@@ -83,7 +83,7 @@ namespace BlackMisc
{ {
QString r = remarksIn; QString r = remarksIn;
r.replace(':', ' '); r.replace(':', ' ');
r = asciiOnlyString(removeAccents(remarksIn)); r = asciiOnlyString(simplifyAccents(remarksIn));
return r; return r;
} }

View File

@@ -208,7 +208,7 @@ namespace BlackMisc
void CCountry::setSimplifiedNameIfNotSame() void CCountry::setSimplifiedNameIfNotSame()
{ {
const QString simplified = removeAccents(m_name); const QString simplified = simplifyAccents(m_name);
m_simplifiedName = m_name == simplified ? "" : simplified; m_simplifiedName = m_name == simplified ? "" : simplified;
} }
} // namespace } // namespace

View File

@@ -91,7 +91,7 @@ namespace BlackMisc
void CUser::setRealName(const QString &realname) void CUser::setRealName(const QString &realname)
{ {
QString rn(removeAccents(decode(realname).simplified())); QString rn(simplifyAccents(decode(realname).simplified()));
if (rn.isEmpty()) if (rn.isEmpty())
{ {
m_realname.clear(); m_realname.clear();

View File

@@ -99,8 +99,8 @@ namespace BlackMisc
const QString bStr = str1.length() >= str2.length() ? str2 : str1; const QString bStr = str1.length() >= str2.length() ? str2 : str1;
// starts/ends with // starts/ends with
float s1 = aStr.length(); const double s1 = aStr.length();
float s2 = bStr.length(); const double s2 = bStr.length();
if (aStr.endsWith(bStr, cs)) { return qRound(s1 / s2 * 100); } if (aStr.endsWith(bStr, cs)) { return qRound(s1 / s2 * 100); }
if (aStr.startsWith(bStr, cs)) { return qRound(s1 / s2 * 100); } if (aStr.startsWith(bStr, cs)) { return qRound(s1 / s2 * 100); }
@@ -108,7 +108,7 @@ namespace BlackMisc
if (aStr.contains(bStr, cs)) { return qRound(s1 / s2 * 100); } if (aStr.contains(bStr, cs)) { return qRound(s1 / s2 * 100); }
// char by char // char by char
float points = 0; double points = 0;
for (int p = 0; p < aStr.length(); p++) for (int p = 0; p < aStr.length(); p++)
{ {
if (p < bStr.length() && aStr[p] == bStr[p]) if (p < bStr.length() && aStr[p] == bStr[p])
@@ -150,7 +150,7 @@ namespace BlackMisc
QString h; QString h;
for (int i = 0; i < bytes.size(); i++) for (int i = 0; i < bytes.size(); i++)
{ {
int b = static_cast<int>(bytes.at(i)); const int b = static_cast<int>(bytes.at(i));
h.append(intToHex(b, 2)); h.append(intToHex(b, 2));
} }
return h; return h;
@@ -163,7 +163,7 @@ namespace BlackMisc
while (pos + 1 < hexString.length()) while (pos + 1 < hexString.length())
{ {
bool ok; bool ok;
QString h = hexString.mid(pos, 2); const QString h = hexString.mid(pos, 2);
int hex = h.toInt(&ok, 16); int hex = h.toInt(&ok, 16);
Q_ASSERT_X(ok, Q_FUNC_INFO, "Invalid hex"); Q_ASSERT_X(ok, Q_FUNC_INFO, "Invalid hex");
if (!ok) { return QByteArray(); } if (!ok) { return QByteArray(); }
@@ -219,7 +219,7 @@ namespace BlackMisc
} }
// http://www.codegur.online/14009522/how-to-remove-accents-diacritic-marks-from-a-string-in-qt // http://www.codegur.online/14009522/how-to-remove-accents-diacritic-marks-from-a-string-in-qt
QString removeAccents(const QString &candidate) QString simplifyAccents(const QString &candidate)
{ {
static const QString diacriticLetters = QString::fromUtf8("ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ"); static const QString diacriticLetters = QString::fromUtf8("ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ");
static 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", "D", "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", "o", "n", "o", "o", "o", "o", "o", "o", "u", "u", "u", "u", "y", "y"}); static 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", "D", "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", "o", "n", "o", "o", "o", "o", "o", "o", "u", "u", "u", "u", "y", "y"});

View File

@@ -220,7 +220,7 @@ namespace BlackMisc
BLACKMISC_EXPORT QStringList textCodecNames(bool simpleNames, bool mibNames); BLACKMISC_EXPORT QStringList textCodecNames(bool simpleNames, bool mibNames);
//! Remove accents / diacritic marks from a string //! Remove accents / diacritic marks from a string
BLACKMISC_EXPORT QString removeAccents(const QString &candidate); BLACKMISC_EXPORT QString simplifyAccents(const QString &candidate);
//! Case insensitive string compare //! Case insensitive string compare
BLACKMISC_EXPORT bool caseInsensitiveStringCompare(const QString &c1, const QString &c2); BLACKMISC_EXPORT bool caseInsensitiveStringCompare(const QString &c1, const QString &c2);