OpenTTD Source: src/string_type.h Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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
24 enum CharSetFilter : uint8_t {
25 CS_ALPHANUMERAL,
26 CS_NUMERAL,
27 CS_NUMERAL_SPACE,
28 CS_NUMERAL_SIGNED,
29 CS_ALPHA,
30 CS_HEXADECIMAL,
31};
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 */
35 static const char32_t CHAR_TD_LRM = 0x200E;
36 static const char32_t CHAR_TD_RLM = 0x200F;
37 static const char32_t CHAR_TD_LRE = 0x202A;
38 static const char32_t CHAR_TD_RLE = 0x202B;
39 static const char32_t CHAR_TD_LRO = 0x202D;
40 static const char32_t CHAR_TD_RLO = 0x202E;
41 static const char32_t CHAR_TD_PDF = 0x202C;
42
44 enum class StringValidationSetting : uint8_t {
45 ReplaceWithQuestionMark,
46 AllowNewline,
47 AllowControlCode,
53 ReplaceTabCrNlWithSpace,
54};
55
56using StringValidationSettings = EnumBitSet<StringValidationSetting, uint8_t>;
57
58
60 typedef std::vector<std::string> StringList;
61
63 struct 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 */
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
enum_type.hpp
Type (helpers) for enums.
StringValidationSetting
StringValidationSetting
Settings for the string validation.
Definition string_type.h:44
StringValidationSetting::ReplaceWithQuestionMark
@ ReplaceWithQuestionMark
Replace the unknown/bad bits with question marks.
StringValidationSetting::AllowControlCode
@ AllowControlCode
Allow the special control codes.
StringValidationSetting::AllowNewline
@ AllowNewline
Allow newlines; replaces '\r ' with ' ' during processing.
StringValidationSetting::ReplaceTabCrNlWithSpace
@ ReplaceTabCrNlWithSpace
Replace tabs ('\t'), carriage returns ('\r') and newlines (' ') with spaces.
CHAR_TD_RLE
static const char32_t CHAR_TD_RLE
The following text is embedded right-to-left.
Definition string_type.h:38
CHAR_TD_LRO
static const char32_t CHAR_TD_LRO
Force the following characters to be treated as left-to-right characters.
Definition string_type.h:39
CHAR_TD_LRM
static const char32_t CHAR_TD_LRM
The next character acts like a left-to-right character.
Definition string_type.h:35
CharSetFilter
CharSetFilter
Valid filter types for IsValidChar.
Definition string_type.h:24
CS_NUMERAL_SPACE
@ CS_NUMERAL_SPACE
Only numbers and spaces.
Definition string_type.h:27
CS_HEXADECIMAL
@ CS_HEXADECIMAL
Only hexadecimal characters.
Definition string_type.h:30
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
CS_NUMERAL_SIGNED
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition string_type.h:28
CS_ALPHA
@ CS_ALPHA
Only alphabetic values.
Definition string_type.h:29
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition string_type.h:25
CHAR_TD_RLO
static const char32_t CHAR_TD_RLO
Force the following characters to be treated as right-to-left characters.
Definition string_type.h:40
CHAR_TD_LRE
static const char32_t CHAR_TD_LRE
The following text is embedded left-to-right.
Definition string_type.h:37
CHAR_TD_RLM
static const char32_t CHAR_TD_RLM
The next character acts like a right-to-left character.
Definition string_type.h:36
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition string_type.h:60
CHAR_TD_PDF
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
StringHash
Helper to provide transparent hashing for string types in e.g.
Definition string_type.h:63