OpenTTD Source 20260109-master-g241b5fcdfe
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
10#ifndef STRING_BASE_H
11#define STRING_BASE_H
12
13#include "string_type.h"
14
17public:
19 enum IterType : uint8_t {
22 };
23
25 static const size_t END = SIZE_MAX;
26
31 static std::unique_ptr<StringIterator> Create();
32
33 virtual ~StringIterator() = default;
34
40 virtual void SetString(std::string_view s) = 0;
41
48 virtual size_t SetCurPosition(size_t pos) = 0;
49
54 virtual size_t Next(IterType what = ITER_CHARACTER) = 0;
55
60 virtual size_t Prev(IterType what = ITER_CHARACTER) = 0;
61
62protected:
64};
65
66#endif /* STRING_BASE_H */
Class for iterating over different kind of parts of a string.
Definition string_base.h:16
static const size_t END
Sentinel to indicate end-of-iteration.
Definition string_base.h:25
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:745
IterType
Type of the iterator.
Definition string_base.h:19
@ ITER_WORD
Iterate over words.
Definition string_base.h:21
@ ITER_CHARACTER
Iterate over characters (or more exactly grapheme clusters).
Definition string_base.h:20
virtual void SetString(std::string_view s)=0
Set a new iteration string.
Types for strings.