OpenTTD Source: src/string_base.h Source File

OpenTTD Source 14.0-RC3

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 <http://www.gnu.org/licenses/>.
6 */
7
8 #ifndef STRING_BASE_H
9 #define STRING_BASE_H
10
11 #include "string_type.h"
12
14 class StringIterator {
15 public:
17 enum IterType {
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(const char *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
60 protected:
61 StringIterator() {}
62 };
63
64 #endif /* STRING_BASE_H */
StringIterator::Prev
virtual size_t Prev(IterType what=ITER_CHARACTER)=0
Move the cursor back by one iteration unit.
StringIterator::IterType
IterType
Type of the iterator.
Definition: string_base.h:17
StringIterator::END
static const size_t END
Sentinel to indicate end-of-iteration.
Definition: string_base.h:23
StringIterator::Next
virtual size_t Next(IterType what=ITER_CHARACTER)=0
Advance the cursor by one iteration unit.
StringIterator::SetString
virtual void SetString(const char *s)=0
Set a new iteration string.
StringIterator::ITER_CHARACTER
@ ITER_CHARACTER
Iterate over characters (or more exactly grapheme clusters).
Definition: string_base.h:18
StringIterator
Class for iterating over different kind of parts of a string.
Definition: string_base.h:14
StringIterator::SetCurPosition
virtual size_t SetCurPosition(size_t pos)=0
Change the current string cursor.
StringIterator::Create
static std::unique_ptr< StringIterator > Create()
Create a new iterator instance.
Definition: string.cpp:913
StringIterator::ITER_WORD
@ ITER_WORD
Iterate over words.
Definition: string_base.h:19
string_type.h