Commit 635bb22a authored by Volker Krause's avatar Volker Krause
Browse files

Rename UicUtil to UicStationCode

More appropriate now that we have other UIC classes too.
parent e9a489da
Pipeline #87886 passed with stage
in 1 minute and 17 seconds
......@@ -12,7 +12,7 @@ ecm_add_test(indexeddatatabletest.cpp LINK_LIBRARIES Qt5::Test)
ecm_add_test(polylinetest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(ifopttest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(uicutiltest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(uicstationcodetest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(uicrailwaycoachtest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(mergeutiltest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test(locationtest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
......
......@@ -4,7 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "../src/lib/uic/uicutil.cpp"
#include "../src/lib/uic/uicstationcode.cpp"
#include <QTest>
......@@ -18,18 +18,18 @@ class UicUtilTest: public QObject
private Q_SLOTS:
void tesIsStationId()
{
QVERIFY(UicUtil::isStationId(u"8501687"));
QVERIFY(UicUtil::isStationId(u"8501687", {80, 85}));
QVERIFY(UicUtil::isStationId(u"008501687", {80, 85}));
QVERIFY(!UicUtil::isStationId(u"850012A", {80, 85}));
QVERIFY(!UicUtil::isStationId(u"8501687", {80, 81}));
QVERIFY(!UicUtil::isStationId(u"008501687"));
QVERIFY(!UicUtil::isStationId(u"851587"));
QVERIFY(!UicUtil::isStationId(u"85016870"));
QVERIFY(UicStationCode::isValid(u"8501687"));
QVERIFY(UicStationCode::isValid(u"8501687", {80, 85}));
QVERIFY(UicStationCode::isValid(u"008501687", {80, 85}));
QVERIFY(!UicStationCode::isValid(u"850012A", {80, 85}));
QVERIFY(!UicStationCode::isValid(u"8501687", {80, 81}));
QVERIFY(!UicStationCode::isValid(u"008501687"));
QVERIFY(!UicStationCode::isValid(u"851587"));
QVERIFY(!UicStationCode::isValid(u"85016870"));
}
};
QTEST_APPLESS_MAIN(UicUtilTest)
#include "uicutiltest.moc"
#include "uicstationcodetest.moc"
......@@ -113,7 +113,7 @@ target_sources(KPublicTransport PRIVATE
networks/certs/network_certs.qrc
uic/uicrailwaycoach.cpp
uic/uicutil.cpp
uic/uicstationcode.cpp
)
ecm_qt_declare_logging_category(KPublicTransport
HEADER logging.h
......
......@@ -6,7 +6,7 @@
#include "hafasparser.h"
#include "logging.h"
#include "uic/uicutil.h"
#include "uic/uicstationcode.h"
#include <KPublicTransport/Location>
......@@ -74,7 +74,7 @@ Line::Mode HafasParser::parseLineMode(int modeId) const
void HafasParser::setLocationIdentifier(Location &loc, const QString &id) const
{
if (!m_standardLocationIdentifierType.isEmpty() && UicUtil::isStationId(id, m_uicCountryCodes)) {
if (!m_standardLocationIdentifierType.isEmpty() && UicStationCode::isValid(id, m_uicCountryCodes)) {
loc.setIdentifier(m_standardLocationIdentifierType, id.right(7));
}
loc.setIdentifier(m_locationIdentifierType, id);
......
......@@ -9,7 +9,7 @@
#include <gtfs/hvt.h>
#include <ifopt/ifoptutil.h>
#include <uic/uicutil.h>
#include <uic/uicstationcode.h>
#include <KPublicTransport/Journey>
#include <KPublicTransport/Location>
......@@ -567,7 +567,7 @@ void OpenJourneyPlannerParser::setLocationIdentifier(Location &loc, const QStrin
if (IfoptUtil::isValid(id)) {
loc.setIdentifier(IfoptUtil::identifierType(), id);
}
if (!m_uicIdentifierType.isEmpty() && UicUtil::isStationId(id)) {
if (!m_uicIdentifierType.isEmpty() && UicStationCode::isValid(id)) {
loc.setIdentifier(m_uicIdentifierType, id);
}
}
......@@ -4,14 +4,14 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "uicutil.h"
#include "uicstationcode.h"
#include <QString>
#include <QStringView>
using namespace KPublicTransport;
bool UicUtil::isStationId(QStringView id, const std::vector<uint8_t> &allowedCountryCodes)
bool UicStationCode::isValid(QStringView id, const std::vector<uint8_t> &allowedCountryCodes)
{
// too short, or not a number
if (id.size() < 7 || std::any_of(id.begin(), id.end(), [](QChar c) { return !c.isDigit() || c.row() > 0; })) {
......
......@@ -4,8 +4,8 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KPUBLICTRANSPORT_UICUTIL_H
#define KPUBLICTRANSPORT_UICUTIL_H
#ifndef KPUBLICTRANSPORT_UICSTATIONCODE_H
#define KPUBLICTRANSPORT_UICSTATIONCODE_H
#include <cstdint>
#include <vector>
......@@ -18,17 +18,17 @@ namespace KPublicTransport {
/** Utility functions for dealing with UIC station codes.
* Also works for the syntactically identical IBNR station codes.
*/
namespace UicUtil
namespace UicStationCode
{
/** Returns @c true if @p id is a valid UIC station code.
* @params allowedCountryCodes if non-empty, only UIC station codes with an UIC country code included
* in that list are considered valid. This list has to be sorted.
*/
bool isStationId(QStringView id, const std::vector<uint8_t> &allowedCountryCodes = {});
bool isValid(QStringView id, const std::vector<uint8_t> &allowedCountryCodes = {});
}
}
#endif // KPUBLICTRANSPORT_UICUTIL_H
#endif // KPUBLICTRANSPORT_UICSTATIONCODE_H
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