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 KItinerary;
19
20bool TextDocumentProcessor::canHandleData(const QByteArray &encodedData, QStringView fileName) const
21{
22 return std::none_of(encodedData.begin(), encodedData.end(),
23 [](unsigned char c) {
24 return std::iscntrl(c) && !std::isspace(c);
25 }) ||
27}
28
30{
32 node.setContent(QString::fromUtf8(encodedData));
33 return node;
34}
35
37{
38 return filter.matches(node.content<QString>());
39}
40
41void TextDocumentProcessor::postExtract(ExtractorDocumentNode &node, [[maybe_unused]] const ExtractorEngine *engine) const
42{
43 GenericPriceExtractorHelper::postExtract(node.content<QString>(), node);
44}
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 Tue Mar 26 2024 11:14:49 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.