Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 5e4efa68 authored by Volker Krause's avatar Volker Krause

Improve terminal extractor

Deals with French and duplicated information.
parent f7da5a3f
......@@ -41,6 +41,7 @@ private Q_SLOTS:
QTest::newRow("no terminal") << s("Paris Charles de Gaulle") << s("Paris Charles de Gaulle") << s("");
QTest::newRow("CDG 1") << s("PARIS, FR (CHARLES DE GAULLE), TERMINAL 2E") << s("PARIS, FR (CHARLES DE GAULLE)") << s("2E");
QTest::newRow("CDG 2") << s("Paris Charles de Gaulle (Terminal 2D)") << s("Paris Charles de Gaulle") << s("2D");
QTest::newRow("CDG 3") << s("PARIS FR CHARLES DE GAULLE TERMINAL 2G - AEROGARE 2 TERMINAL G") << s("PARIS FR CHARLES DE GAULLE") << s("2G");
QTest::newRow("LHR") << s("London/Heathrow-Terminal 2") << s("London/Heathrow") << s("2");
QTest::newRow("MAD") << s("MADRID, ES (BARAJAS), TERMINAL 4S") << s("MADRID, ES (BARAJAS)") << s("4S");
QTest::newRow("DTW") << s("DETROIT, MI (METROPOLITAN WAYNE CO), TERMINAL EM") << s("DETROIT, MI (METROPOLITAN WAYNE CO)") << s("EM");
......
......@@ -43,15 +43,24 @@ static QString trimAirportName(const QStringRef &in)
static std::tuple<QString, QString> splitAirportName(const QString &name)
{
static QRegularExpression patterns[] = {
QRegularExpression(QStringLiteral("^(.*) \\(terminal (.*)\\)$"), QRegularExpression::CaseInsensitiveOption),
QRegularExpression(QStringLiteral("^(.*) \\((.*) terminal\\)$"), QRegularExpression::CaseInsensitiveOption),
QRegularExpression(QStringLiteral("^(.*)[ -]terminal (.*)$"), QRegularExpression::CaseInsensitiveOption),
QRegularExpression(QStringLiteral("^(.*) \\((?:terminal|aerogare) (.*)\\)$"), QRegularExpression::CaseInsensitiveOption),
QRegularExpression(QStringLiteral("^(.*) \\((.*) (?:terminal|aerogare)\\)$"), QRegularExpression::CaseInsensitiveOption),
QRegularExpression(QStringLiteral("^(.*)[ -](?:terminal|aerogare) (.*)$"), QRegularExpression::CaseInsensitiveOption),
};
for (const auto &re : patterns) {
const auto match = re.match(name);
if (match.hasMatch()) {
return std::make_tuple(trimAirportName(match.capturedRef(1)), match.captured(2));
const auto name = trimAirportName(match.capturedRef(1));
// try to recurse, sometimes this is indeed repeated...
QString recName, recTerminal;
std::tie(recName, recTerminal) = splitAirportName(name);
if (recName == name || recTerminal.isEmpty()) {
return std::make_tuple(trimAirportName(match.capturedRef(1)), match.captured(2));
} else {
return std::make_tuple(recName, recTerminal);
}
break;
}
}
......
Markdown is supported
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