KItinerary

textdocumentprocessor.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "textdocumentprocessor.h"
8 
9 #include <KItinerary/ExtractorFilter>
10 
11 #include <QByteArray>
12 #include <QStringView>
13 
14 #include <algorithm>
15 #include <cctype>
16 
17 using namespace KItinerary;
18 
19 bool TextDocumentProcessor::canHandleData(const QByteArray &encodedData, QStringView fileName) const
20 {
21  return std::none_of(encodedData.begin(), encodedData.end(), [](unsigned char c) { return std::iscntrl(c) && !std::isspace(c); })
22  || fileName.endsWith(QLatin1String(".txt"), Qt::CaseInsensitive);
23 }
24 
26 {
28  node.setContent(QString::fromUtf8(encodedData));
29  return node;
30 }
31 
33 {
34  return filter.matches(node.content<QString>());
35 }
Classes for reservation/travel data models, data extraction and data augmentation.
QString fromUtf8(const char *str, int size)
Determines whether an extractor is applicable to a given email.
CaseInsensitive
QByteArray::iterator begin()
A node in the extracted document object tree.
bool matches(const QString &data) const
Check if data matches this filter.
bool canHandleData(const QByteArray &encodedData, QStringView fileName) const override
Fast check whether the given encoded data can possibly be processed by this instance.
QJSValue content
The decoded content of this node.
void setContent(const QVariant &content)
Set decoded content.
bool endsWith(QStringView str, Qt::CaseSensitivity cs) const const
bool matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const override
Checks whether the given filter matches node.
ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const override
Create a document node from raw data.
QByteArray::iterator end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jan 17 2022 23:06:16 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.