File indexing completed on 2024-12-29 04:51:00
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "iatabcbpdocumentprocessor.h" 0008 0009 #include "iata/iatabcbp.h" 0010 #include "iata/iatabcbpparser.h" 0011 0012 #include <KItinerary/ExtractorResult> 0013 0014 using namespace KItinerary; 0015 0016 bool IataBcbpDocumentProcessor::canHandleData(const QByteArray &encodedData, [[maybe_unused]] QStringView fileName) const 0017 { 0018 return IataBcbp::maybeIataBcbp(encodedData); 0019 } 0020 0021 ExtractorDocumentNode IataBcbpDocumentProcessor::createNodeFromData(const QByteArray &encodedData) const 0022 { 0023 ExtractorDocumentNode node; 0024 IataBcbp ticket(QString::fromUtf8(encodedData)); 0025 if (ticket.isValid()) { 0026 node.setContent(ticket); 0027 } 0028 return node; 0029 } 0030 0031 void IataBcbpDocumentProcessor::preExtract(ExtractorDocumentNode &node, [[maybe_unused]] const ExtractorEngine *engine) const 0032 { 0033 const auto bcbp = node.content<IataBcbp>(); 0034 node.addResult(IataBcbpParser::parse(bcbp, node.contextDateTime())); 0035 } 0036 0037 bool IataBcbpDocumentProcessor::matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const 0038 { 0039 const auto bcbp = node.content<IataBcbp>(); 0040 const auto ums = bcbp.uniqueMandatorySection(); 0041 const auto ucs = bcbp.uniqueConditionalSection(); 0042 if (matchesGadget(filter, &ums) || matchesGadget(filter, &ucs)) { 0043 return true; 0044 } 0045 const auto legCount = ums.numberOfLegs(); 0046 for (int i = 0; i < legCount; ++i) { 0047 const auto rms = bcbp.repeatedMandatorySection(i); 0048 const auto rcs = bcbp.repeatedConditionalSection(i); 0049 if (matchesGadget(filter, &rms) || matchesGadget(filter, &rcs)) { 0050 return true; 0051 } 0052 } 0053 return false; 0054 }