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

Implement stop place level comparison of IFOPT identifiers

Will be needed for Location comparison and Location merging.
parent 7b904337
......@@ -44,6 +44,20 @@ private Q_SLOTS:
QFETCH(bool, valid);
QCOMPARE(IfoptUtil::isValid(ifopt), valid);
}
void testStopPlace()
{
QCOMPARE(IfoptUtil::stopPlace(s("de:08115:4512:5:B")), s("de:08115:4512"));
QCOMPARE(IfoptUtil::stopPlace(s("de:08115:4512:5")), s("de:08115:4512"));
QCOMPARE(IfoptUtil::stopPlace(s("de:08115:4512")), s("de:08115:4512"));
}
void testIsSameStopPlace()
{
QVERIFY(IfoptUtil::isSameStopPlace(s("de:08115:4512:5:B"), s("de:08115:4512")));
QVERIFY(IfoptUtil::isSameStopPlace(s("de:08115:4512:5:B"), s("de:08115:4512:2:1")));
QVERIFY(!IfoptUtil::isSameStopPlace(s("de:08115:4512:5:B"), s("de:08115:4513:2:1")));
}
};
QTEST_APPLESS_MAIN(IfoptTest)
......
......@@ -30,3 +30,17 @@ bool IfoptUtil::isValid(QStringView ifopt)
return elementCount >= 3 && elementCount <= 5 && ifopt[0].isLetter() && ifopt[1].isLetter() && ifopt[2] == QLatin1Char(':');
}
QStringView IfoptUtil::stopPlace(QStringView ifopt)
{
qsizetype pos = 0;
for (int i = 0; i < 3; i++) {
pos = ifopt.indexOf(QLatin1Char(':'), pos) + 1;
}
return ifopt.left(pos - 1);
}
bool IfoptUtil::isSameStopPlace(QStringView lhs, QStringView rhs)
{
return stopPlace(lhs) == stopPlace(rhs);
}
......@@ -21,6 +21,12 @@ namespace IfoptUtil
/** Check if @p ifopt is a valid IFOPT identifier. */
bool isValid(QStringView ifopt);
/** Returns the stop place identifier for the given (valid!) IFOPT identifier @p ifopt. */
QStringView stopPlace(QStringView ifopt);
/** Checks whether two valid IFOPT ids refer to the same stop place. */
bool isSameStopPlace(QStringView lhs, QStringView rhs);
}
}
......
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