KItinerary

textdocumentprocessor.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "textdocumentprocessor.h"
8#include "genericpriceextractorhelper_p.h"
9
10#include <KItinerary/ExtractorFilter>
11
12#include <QByteArray>
13#include <QStringView>
14
15#include <algorithm>
16#include <cctype>
17
18using namespace Qt::Literals::StringLiterals;
19using namespace KItinerary;
20
21bool TextDocumentProcessor::canHandleData(const QByteArray &encodedData, QStringView fileName) const
22{
23 return std::none_of(encodedData.begin(), encodedData.end(), [](unsigned char c) { return std::iscntrl(c) && !std::isspace(c); })
24 || fileName.endsWith(".txt"_L1, Qt::CaseInsensitive);
25}
26
28{
30 node.setContent(QString::fromUtf8(encodedData));
31 return node;
32}
33
35{
36 return filter.matches(node.content<QString>());
37}
38
39void TextDocumentProcessor::postExtract(ExtractorDocumentNode &node, [[maybe_unused]] const ExtractorEngine *engine) const
40{
41 GenericPriceExtractorHelper::postExtract(node.content<QString>(), node);
42}
A node in the extracted document object tree.
QJSValue content
The decoded content of this node.
void setContent(const QVariant &content)
Set decoded content.
Semantic data extraction engine.
Determines whether an extractor is applicable to a given email.
void postExtract(ExtractorDocumentNode &node, const ExtractorEngine *engine) const override
Called after extractors have been applied to node.
bool canHandleData(const QByteArray &encodedData, QStringView fileName) const override
Fast check whether the given encoded data can possibly be processed by this instance.
ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const override
Create a document node from raw data.
bool matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const override
Checks whether the given filter matches node.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
iterator begin()
iterator end()
QString fromUtf8(QByteArrayView str)
bool endsWith(QChar ch) const const
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:45:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.