OpenTTD Source 20261112-master-gbcbec5e63f
string_base.h
Go to the documentation of this file.
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
9
10#ifndef STRING_BASE_H
11#define STRING_BASE_H
12
14class StringIterator {
15public:
17 enum IterType : uint8_t {
20 };
21
23 static const size_t END = SIZE_MAX;
24
29 static std::unique_ptr<StringIterator> Create();
30
32 virtual ~StringIterator() = default;
33
39 virtual void SetString(std::string_view s) = 0;
40
47 virtual size_t SetCurPosition(size_t pos) = 0;
48
54 virtual size_t Next(IterType what = ITER_CHARACTER) = 0;
55
61 virtual size_t Prev(IterType what = ITER_CHARACTER) = 0;
62
63protected:
64 StringIterator() {}
65};
66
67#endif /* STRING_BASE_H */
static const size_t END
Sentinel to indicate end-of-iteration.
Definition string_base.h:23
virtual ~StringIterator()=default
Ensure the destructor of the sub classes are called as well.
virtual size_t Prev(IterType what=ITER_CHARACTER)=0
Move the cursor back by one iteration unit.
virtual size_t SetCurPosition(size_t pos)=0
Change the current string cursor.
virtual size_t Next(IterType what=ITER_CHARACTER)=0
Advance the cursor by one iteration unit.
static std::unique_ptr< StringIterator > Create()
Create a new iterator instance.
Definition string.cpp:746
IterType
Type of the iterator.
Definition string_base.h:17
@ ITER_WORD
Iterate over words.
Definition string_base.h:19
@ ITER_CHARACTER
Iterate over characters (or more exactly grapheme clusters).
Definition string_base.h:18
virtual void SetString(std::string_view s)=0
Set a new iteration string.