Commit 2bc569b5 authored by Volker Krause's avatar Volker Krause
Browse files

Extract station ids from UIC 918-3 codes

For some reason, this only includes stations on the outbound trip, not
on the return trip...
parent 913ba84b
......@@ -66,6 +66,8 @@ public:
const char *id() const { return m_data + 1; }
const char *data() const { return m_data + 8; }
QString toString() const { return QString::fromUtf8(data(), size()); }
private:
const char *m_data = nullptr;
int m_size = 0;
......@@ -304,11 +306,41 @@ Person Uic9183Parser::person() const
sblock = b.findSubBlock("023");
if (!sblock.isNull()) {
Person p;
p.setName(QString::fromUtf8(sblock.data(), sblock.size()));
p.setName(sblock.toString());
return p;
}
}
return {};
}
QString Uic9183Parser::outboundDepartureStationId() const
{
const auto b = Vendor0080BLBlock(d->findBlock("0080BL"));
if (b.isValid()) {
// S035 contains the IBNR, possible with leading '80' country code and leading 0 stripped
const auto sblock = b.findSubBlock("035");
if (!sblock.isNull() && sblock.size() <= 7) {
QString ibnr = QStringLiteral("ibnr:8000000");
const auto s = sblock.toString();
return ibnr.replace(ibnr.size() - s.size(), s.size(), s);
}
}
return {};
}
QString Uic9183Parser::outboundArrivalStationId() const
{
const auto b = Vendor0080BLBlock(d->findBlock("0080BL"));
if (b.isValid()) {
// S036 contains the IBNR, possible with leading '80' country code and leading 0 stripped
const auto sblock = b.findSubBlock("036");
if (!sblock.isNull() && sblock.size() <= 7) {
QString ibnr = QStringLiteral("ibnr:8000000");
const auto s = sblock.toString();
return ibnr.replace(ibnr.size() - s.size(), s.size(), s);
}
}
return {};
}
#include "moc_uic9183parser.cpp"
......@@ -42,6 +42,9 @@ class KITINERARY_EXPORT Uic9183Parser
Q_GADGET
Q_PROPERTY(QString pnr READ pnr)
Q_PROPERTY(KItinerary::Person person READ person)
Q_PROPERTY(QString outboundDepartureStationId READ outboundDepartureStationId)
Q_PROPERTY(QString outboundArrivalStationId READ outboundArrivalStationId)
public:
Uic9183Parser();
Uic9183Parser(const Uic9183Parser&);
......@@ -56,6 +59,11 @@ public:
/** The person this ticket is issued to. */
Person person() const;
/** Station identifier for the departure station of the outbound trip. */
QString outboundDepartureStationId() const;
/** Station identifier for the arrival station of the outbound trip. */
QString outboundArrivalStationId() const;
private:
QExplicitlySharedDataPointer<Uic9183ParserPrivate> d;
};
......
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