File indexing completed on 2024-12-29 04:50:10

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KITINERARY_AIRPORTNAMETOKENIZER_H
0008 #define KITINERARY_AIRPORTNAMETOKENIZER_H
0009 
0010 #include <QStringList>
0011 #include <QStringView>
0012 
0013 namespace KItinerary {
0014 
0015 /** Split airport names into the tokens used by the airport database. */
0016 class AirportNameTokenizer
0017 {
0018 public:
0019     explicit AirportNameTokenizer(QStringView text);
0020     ~AirportNameTokenizer();
0021 
0022     /** Returns @true if next() can be called one more time. */
0023     bool hasNext();
0024     /** Returns the next token and advances the tokenizer. */
0025     QStringView next();
0026 
0027     /** Returns a list containing all tokens. */
0028     QStringList toStringList();
0029 
0030 private:
0031     void advance();
0032 
0033     bool isSeparator(QChar c) const;
0034     static constexpr const int MIN_LENGTH = 3;
0035 
0036     QStringView m_text;
0037     int m_begin = 0;
0038     int m_end = 0;
0039 };
0040 
0041 }
0042 
0043 #endif // KITINERARY_AIRPORTNAMETOKENIZER_H