File indexing completed on 2024-12-29 04:51:06

0001 /*
0002    SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 function parsePNR(text) {
0008     var reservations = new Array();
0009 
0010     var passengers = new Array();
0011     var pos = 0;
0012     while (true) {
0013         var passenger = text.substr(pos).match(/\d\.1(.+?)\/([\w\s]+?)(?:\*|  |\n)/);
0014         if (!passenger)
0015             break;
0016         pos += passenger.index + passenger[0].length;
0017 
0018         var person = JsonLd.newObject("Person");
0019         person.familyName = passenger[1];
0020         person.givenName = passenger[2];
0021         passengers.push(person);
0022     }
0023 
0024     pos = 0;
0025     var legs = new Array();
0026     while (true) {
0027         var leg = text.substr(pos).match(/\d. ([A-Z0-9]{2}) +(\d{1,4}) [A-Z]{1,2} {1,2}(\d{2}[A-Z]{3}) ([A-Z]{3})([A-Z]{3}) [A-Z]{2}\d  (\d{4})  [ #](\d{4}).*\n(?:\s*OPERATED BY (.*?)\n)?/);
0028         if (!leg)
0029             break;
0030         pos += leg.index + leg[0].length;
0031 
0032         var res = JsonLd.newFlightReservation();
0033         res.reservationFor.airline.iataCode = leg[1];
0034         res.reservationFor.airline.name = leg[8];
0035         res.reservationFor.flightNumber = leg[2];
0036         res.reservationFor.departureAirport.iataCode = leg[4];
0037         res.reservationFor.arrivalAirport.iataCode = leg[5];
0038         res.reservationFor.departureTime = JsonLd.toDateTime(leg[3] + leg[6], "ddMMMhhmm", "en");
0039         res.reservationFor.arrivalTime = JsonLd.toDateTime(leg[3] + leg[7], "ddMMMhhmm", "en");
0040         legs.push(res);
0041     }
0042 
0043     for (var i = 0; i < legs.length; ++i) {
0044         for (var j = 0; j < passengers.length; ++j) {
0045             var res = JsonLd.clone(legs[i]);
0046             res.underName = passengers[j];
0047             reservations.push(res);
0048         }
0049     }
0050     return reservations;
0051 }