OpenTTD Source: src/string_base.h Source File

OpenTTD Source 15.0-RC2

string_base.h
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
8#ifndef STRING_BASE_H
9#define STRING_BASE_H
10
11#include "string_type.h"
12
14 class StringIterator {
15public:
17 enum IterType : uint8_t {
18 ITER_CHARACTER,
19 ITER_WORD,
20 };
21
23 static const size_t END = SIZE_MAX;
24
29 static std::unique_ptr<StringIterator> Create();
30
31 virtual ~StringIterator() = default;
32
38 virtual void SetString(std::string_view s) = 0;
39
46 virtual size_t SetCurPosition(size_t pos) = 0;
47
52 virtual size_t Next(IterType what = ITER_CHARACTER) = 0;
53
58 virtual size_t Prev(IterType what = ITER_CHARACTER) = 0;
59
60protected:
61 StringIterator() {}
62};
63
64#endif /* STRING_BASE_H */
StringIterator
Class for iterating over different kind of parts of a string.
Definition string_base.h:14
StringIterator::END
static const size_t END
Sentinel to indicate end-of-iteration.
Definition string_base.h:23
StringIterator::Prev
virtual size_t Prev(IterType what=ITER_CHARACTER)=0
Move the cursor back by one iteration unit.
StringIterator::SetCurPosition
virtual size_t SetCurPosition(size_t pos)=0
Change the current string cursor.
StringIterator::Next
virtual size_t Next(IterType what=ITER_CHARACTER)=0
Advance the cursor by one iteration unit.
StringIterator::Create
static std::unique_ptr< StringIterator > Create()
Create a new iterator instance.
Definition string.cpp:745
StringIterator::IterType
IterType
Type of the iterator.
Definition string_base.h:17
StringIterator::ITER_WORD
@ ITER_WORD
Iterate over words.
Definition string_base.h:19
StringIterator::ITER_CHARACTER
@ ITER_CHARACTER
Iterate over characters (or more exactly grapheme clusters).
Definition string_base.h:18
StringIterator::SetString
virtual void SetString(std::string_view s)=0
Set a new iteration string.
string_type.h
Types for strings.