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

Handle line continuations in Deutsche Bahn tickets

This fixes extraction of full station names and seat reservations for very
wide station names and/or very detailed reservation notes on international
tickets.
parent 94079558
......@@ -77,7 +77,7 @@ function parseLegs(text, year, compact) {
for (var i = 0; compact && i < lines.length; ++i)
lines[i] = lines[i].substr(offset[0].length);
for (var i = 0; i < lines.length; ++i) {
for (var i = 0; i < lines.length;) {
// stop when reaching the footer or the next itinerary header
if (isHeaderOrFooter(lines[i]))
return reservations;
......@@ -87,19 +87,43 @@ function parseLegs(text, year, compact) {
res.reservedTicket = JsonLd.newObject("Ticket");
res.reservedTicket.ticketedSeat = JsonLd.newObject("Seat");
// TODO deal with line continuations!
while (i < lines.length && !isHeaderOrFooter(lines[i])) {
if (parseDeparture(res, lines[i], year, compact))
if (parseDeparture(res, lines[i++], year, compact))
break;
}
while (i < lines.length && !isHeaderOrFooter(lines[i])) {
if (parseArrival(res, lines[i], year)) {
++i;
break;
}
// continuation of departure line
var depStation = lines[i].match(/^(\S.*?)(?: |\n|$)/)
if (depStation)
res.reservationFor.departureStation.name = res.reservationFor.departureStation.name + " " + depStation[1];
parseSeat(res, lines[i]);
++i;
}
// handle continuations of the arrival line
while (i < lines.length && !isHeaderOrFooter(lines[i])) {
if (parseArrival(res, lines[i], year))
if (lines[i].match(/^\S.+? *[0-9]{2}\.[0-9]{2}\. +ab [0-9]{2}:[0-9]{2}/)) // next departure line
break;
// continuation of arrival line
var arrStation = lines[i].match(/^(\S.*?)(?: |\n|$)/)
if (arrStation)
res.reservationFor.arrivalStation.name = res.reservationFor.arrivalStation.name + " " + arrStation[1];
parseSeat(res, lines[i]);
++i;
}
if (res.reservationFor.arrivalStation != undefined)
if (res.reservationFor.arrivalStation != undefined) {
reservations.push(res);
} else {
++i;
}
}
return reservations;
......
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