OpenTTD Source 20250529-master-g10c159a79f
string_type.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 <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef STRING_TYPE_H
11#define STRING_TYPE_H
12
13#include "core/enum_type.hpp"
14
16#define NBSP "\u00a0"
17
19#define LRM "\u200e"
20
32
33/* The following are directional formatting codes used to get the LTR and RTL strings right:
34 * http://www.unicode.org/unicode/reports/tr9/#Directional_Formatting_Codes */
35static const char32_t CHAR_TD_LRM = 0x200E;
36static const char32_t CHAR_TD_RLM = 0x200F;
37static const char32_t CHAR_TD_LRE = 0x202A;
38static const char32_t CHAR_TD_RLE = 0x202B;
39static const char32_t CHAR_TD_LRO = 0x202D;
40static const char32_t CHAR_TD_RLO = 0x202E;
41static const char32_t CHAR_TD_PDF = 0x202C;
42
55
57
58
60typedef std::vector<std::string> StringList;
61
63struct StringHash {
64 using hash_type = std::hash<std::string_view>;
65 using is_transparent = void;
66
67 std::size_t operator()(std::string_view str) const { return hash_type{}(str); }
68 std::size_t operator()(const std::string &str) const { return hash_type{}(str); }
69};
70
71#endif /* STRING_TYPE_H */
Enum-as-bit-set wrapper.
Type (helpers) for enums.
StringValidationSetting
Settings for the string validation.
Definition string_type.h:44
@ ReplaceWithQuestionMark
Replace the unknown/bad bits with question marks.
@ AllowControlCode
Allow the special control codes.
@ AllowNewline
Allow newlines; replaces '\r ' with ' ' during processing.
@ ReplaceTabCrNlWithSpace
Replace tabs ('\t'), carriage returns ('\r') and newlines (' ') with spaces.
static const char32_t CHAR_TD_RLE
The following text is embedded right-to-left.
Definition string_type.h:38
static const char32_t CHAR_TD_LRO
Force the following characters to be treated as left-to-right characters.
Definition string_type.h:39
static const char32_t CHAR_TD_LRM
The next character acts like a left-to-right character.
Definition string_type.h:35
CharSetFilter
Valid filter types for IsValidChar.
Definition string_type.h:24
@ CS_NUMERAL_SPACE
Only numbers and spaces.
Definition string_type.h:27
@ CS_HEXADECIMAL
Only hexadecimal characters.
Definition string_type.h:30
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition string_type.h:28
@ CS_ALPHA
Only alphabetic values.
Definition string_type.h:29
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition string_type.h:25
static const char32_t CHAR_TD_RLO
Force the following characters to be treated as right-to-left characters.
Definition string_type.h:40
static const char32_t CHAR_TD_LRE
The following text is embedded left-to-right.
Definition string_type.h:37
static const char32_t CHAR_TD_RLM
The next character acts like a right-to-left character.
Definition string_type.h:36
std::vector< std::string > StringList
Type for a list of strings.
Definition string_type.h:60
static const char32_t CHAR_TD_PDF
Restore the text-direction state to before the last LRE, RLE, LRO or RLO.
Definition string_type.h:41
Helper to provide transparent hashing for string types in e.g.
Definition string_type.h:63