KItinerary

airportnametokenizer.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 "airportnametokenizer_p.h"
8
9using namespace KItinerary;
10
11AirportNameTokenizer::AirportNameTokenizer(QStringView text)
12 : m_text(text)
13{
14 advance();
15}
16
17AirportNameTokenizer::~AirportNameTokenizer() = default;
18
19bool AirportNameTokenizer::hasNext()
20{
21 return m_end > m_begin && m_begin >= 0 && m_end >= 0 && m_end <= m_text.size();
22}
23
24QStringView AirportNameTokenizer::next()
25{
26 Q_ASSERT(hasNext());
27 const auto s = m_text.mid(m_begin, m_end - m_begin);
28 advance();
29 return s;
30}
31
32void AirportNameTokenizer::advance()
33{
34 m_begin = m_end;
35 for (;m_begin < m_text.size(); ++m_begin) {
36 if (!isSeparator(m_text.at(m_begin))) {
37 break;
38 }
39 }
40
41 m_end = m_begin + 1;
42 for (;m_end < m_text.size(); ++m_end) {
43 if (isSeparator(m_text.at(m_end))) {
44 break;
45 }
46 }
47
48 if ((m_end - m_begin) < MIN_LENGTH) {
49 m_begin = m_end;
50 }
51 if (!hasNext() && m_end < m_text.size()) {
52 advance();
53 }
54}
55
56bool AirportNameTokenizer::isSeparator(QChar c) const
57{
58 return c.isSpace() || c.isNumber() || c.isPunct() || !c.isPrint();
59}
60
61QStringList AirportNameTokenizer::toStringList()
62{
64 while (hasNext()) {
65 l.push_back(next().toString());
66 }
67 return l;
68}
char * toString(const EngineQuery &query)
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
QAction * next(const QObject *recvr, const char *slot, QObject *parent)
bool isNumber(char32_t ucs4)
bool isPrint(char32_t ucs4)
bool isPunct(char32_t ucs4)
bool isSpace(char32_t ucs4)
void push_back(parameter_type value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:52:36 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.