Commit b2eeae2f authored by Volker Krause's avatar Volker Krause
Browse files

Compare location names space-insensitively

parent 1fca64a6
Pipeline #201415 passed with stage
in 4 minutes and 53 seconds
......@@ -115,6 +115,8 @@ private Q_SLOTS:
QTest::newRow("random-suffix-1") << QStringLiteral("Berlin") << QStringLiteral("Berlin (tief)") << true << false;
QTest::newRow("random-suffix-2") << QStringLiteral("München Hbf") << QStringLiteral("München Hbf Gl.27-36") << true << false;
QTest::newRow("random-suffix-3") << QStringLiteral("Berlin") << QStringLiteral("Berlin+City") << true << false;
QTest::newRow("space-insensitive") << QStringLiteral("Frankfurt(Main)Hbf") << QStringLiteral("Frankfurt (Main) Hbf") << true << true;
}
void testLocationNameCompare()
......
......@@ -224,6 +224,30 @@ static QString applyTransliterations(const QString &s)
return res;
}
static bool compareSpaceCaseInsenstive(const QString &lhs, const QString &rhs)
{
auto lit = lhs.begin();
auto rit = rhs.begin();
while (true) {
while ((*lit).isSpace() && lit != lhs.end()) {
++lit;
}
while ((*rit).isSpace() && rit != rhs.end()) {
++rit;
}
if (lit == lhs.end() || rit == rhs.end()) {
break;
}
if ((*lit).toCaseFolded() != (*rit).toCaseFolded()) {
return false;
}
++lit;
++rit;
}
return lit == lhs.end() && rit == rhs.end();
}
static bool isSameLocationName(const QString &lhs, const QString &rhs, LocationUtil::Accuracy accuracy)
{
if (lhs.isEmpty() || rhs.isEmpty()) {
......@@ -240,8 +264,8 @@ static bool isSameLocationName(const QString &lhs, const QString &rhs, LocationU
const auto rhsNormalized = stripDiacritics(rhs);
const auto lhsTransliterated = applyTransliterations(lhs);
const auto rhsTransliterated = applyTransliterations(rhs);
if (lhsNormalized.compare(rhsNormalized, Qt::CaseInsensitive) == 0 || lhsNormalized.compare(rhsTransliterated, Qt::CaseInsensitive) == 0
|| lhsTransliterated.compare(rhsNormalized, Qt::CaseInsensitive) == 0 || lhsTransliterated.compare(rhsTransliterated, Qt::CaseInsensitive) == 0) {
if (compareSpaceCaseInsenstive(lhsNormalized, rhsNormalized) || compareSpaceCaseInsenstive(lhsNormalized, rhsTransliterated)
|| compareSpaceCaseInsenstive(lhsTransliterated, rhsNormalized) || compareSpaceCaseInsenstive(lhsTransliterated, rhsTransliterated)) {
return true;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment