|
OpenTTD Source
14.0-beta1
|
Go to the source code of this file.
Data Structures | |
| struct | CaseInsensitiveComparator |
| Case insensitive comparator for strings, for example for use in std::map. More... | |
Functions | |
| char * | strecpy (char *dst, const char *src, const char *last) NOACCESS(3) |
| Copies characters from one buffer to another. More... | |
| std::string | FormatArrayAsHex (std::span< const byte > data) |
| Format a byte array into a continuous hex string. More... | |
| void | StrMakeValidInPlace (char *str, const char *last, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK) NOACCESS(2) |
| Scans the string for invalid characters and replaces then with a question mark '?' (if not ignored). More... | |
| std::string | StrMakeValid (std::string_view str, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK) |
Copies the valid (UTF-8) characters from str to the returned string. More... | |
| void | StrMakeValidInPlace (char *str, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK) |
| Scans the string for invalid characters and replaces then with a question mark '?' (if not ignored). More... | |
| bool | strtolower (std::string &str, std::string::size_type offs=0) |
| bool | StrValid (const char *str, const char *last) NOACCESS(2) |
| Checks whether the given string is valid, i.e. More... | |
| void | StrTrimInPlace (std::string &str) |
| Trim the spaces from given string in place, i.e. More... | |
| bool | StrStartsWithIgnoreCase (std::string_view str, const std::string_view prefix) |
| Check whether the given string starts with the given prefix, ignoring case. More... | |
| bool | StrEndsWithIgnoreCase (std::string_view str, const std::string_view suffix) |
| Check whether the given string ends with the given suffix, ignoring case. More... | |
| int | StrCompareIgnoreCase (const std::string_view str1, const std::string_view str2) |
| Compares two string( view)s, while ignoring the case of the characters. More... | |
| bool | StrEqualsIgnoreCase (const std::string_view str1, const std::string_view str2) |
| Compares two string( view)s for equality, while ignoring the case of the characters. More... | |
| int | StrNaturalCompare (std::string_view s1, std::string_view s2, bool ignore_garbage_at_front=false) |
| Compares two strings using case insensitive natural sort. More... | |
| bool | StrNaturalContains (const std::string_view str, const std::string_view value) |
| Checks if a string is contained in another string with a locale-aware comparison that is case sensitive. More... | |
| bool | StrNaturalContainsIgnoreCase (const std::string_view str, const std::string_view value) |
| Checks if a string is contained in another string with a locale-aware comparison that is case insensitive. More... | |
| bool | ConvertHexToBytes (std::string_view hex, std::span< uint8_t > bytes) |
| Convert a hex-string to a byte-array, while validating it was actually hex. More... | |
| bool | StrEmpty (const char *s) |
| Check if a string buffer is empty. More... | |
| size_t | ttd_strnlen (const char *str, size_t maxlen) |
| Get the length of a string, within a limited buffer. More... | |
| bool | IsValidChar (char32_t key, CharSetFilter afilter) |
| Only allow certain keys. More... | |
| size_t | Utf8Decode (char32_t *c, const char *s) |
| Decode and consume the next UTF-8 encoded character. More... | |
| size_t | Utf8Encode (char *buf, char32_t c) |
| size_t | Utf8Encode (std::ostreambuf_iterator< char > &buf, char32_t c) |
| size_t | Utf8Encode (std::back_insert_iterator< std::string > &buf, char32_t c) |
| size_t | Utf8TrimString (char *s, size_t maxlen) |
| Properly terminate an UTF8 string to some maximum length. More... | |
| char32_t | Utf8Consume (const char **s) |
| template<class Titr > | |
| char32_t | Utf8Consume (Titr &s) |
| int8_t | Utf8CharLen (char32_t c) |
| Return the length of a UTF-8 encoded character. More... | |
| int8_t | Utf8EncodedCharLen (char c) |
| Return the length of an UTF-8 encoded value based on a single char. More... | |
| bool | IsUtf8Part (char c) |
| char * | Utf8PrevChar (char *s) |
| Retrieve the previous UNICODE character in an UTF-8 encoded string. More... | |
| const char * | Utf8PrevChar (const char *s) |
| size_t | Utf8StringLength (const char *s) |
| Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes that the encoded string contains. More... | |
| size_t | Utf8StringLength (const std::string &str) |
| Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes that the encoded string contains. More... | |
| bool | Utf16IsLeadSurrogate (uint c) |
| Is the given character a lead surrogate code point? More... | |
| bool | Utf16IsTrailSurrogate (uint c) |
| Is the given character a lead surrogate code point? More... | |
| char32_t | Utf16DecodeSurrogate (uint lead, uint trail) |
| Convert an UTF-16 surrogate pair to the corresponding Unicode character. More... | |
| char32_t | Utf16DecodeChar (const uint16_t *c) |
| Decode an UTF-16 character. More... | |
| bool | IsTextDirectionChar (char32_t c) |
| Is the given character a text direction character. More... | |
| bool | IsPrintable (char32_t c) |
| bool | IsWhitespace (char32_t c) |
| Check whether UNICODE character is whitespace or not, i.e. More... | |
Functions related to low-level strings.
Definition in file string_func.h.
| bool ConvertHexToBytes | ( | std::string_view | hex, |
| std::span< uint8_t > | bytes | ||
| ) |
Convert a hex-string to a byte-array, while validating it was actually hex.
| hex | The hex-string to convert. |
| bytes | The byte-array to write the result to. |
Definition at line 730 of file string.cpp.
References ConvertHexNibbleToByte().
Referenced by GRFLoadConfig(), and ValidateSignature().
| std::string FormatArrayAsHex | ( | std::span< const byte > | data | ) |
Format a byte array into a continuous hex string.
| data | Array to format |
Definition at line 88 of file string.cpp.
Referenced by AddGrfInfo(), CalculateHashV1(), GenerateCompanyPasswordHash(), GenerateUid(), HandleSavegameLoadCrash(), IsGoodGRFConfigList(), CommandHelperBase::LogCommandExecution(), NetworkContentListWindow::OpenExternalSearch(), OutputContentState(), ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(), and SurveyGrfs().
|
inline |
Is the given character a text direction character.
| c | The character to test. |
Definition at line 216 of file string_func.h.
References CHAR_TD_LRE, CHAR_TD_LRM, CHAR_TD_LRO, CHAR_TD_PDF, CHAR_TD_RLE, CHAR_TD_RLM, and CHAR_TD_RLO.
| bool IsValidChar | ( | char32_t | key, |
| CharSetFilter | afilter | ||
| ) |
Only allow certain keys.
You can define the filter to be used. This makes sure no invalid keys can get into an editbox, like BELL.
| key | character to be checked |
| afilter | the filter to use |
Definition at line 415 of file string.cpp.
References CS_ALPHANUMERAL.
Referenced by IConsoleCmdExec().
|
inline |
Check whether UNICODE character is whitespace or not, i.e.
whether this is a potential line-break character.
| c | UNICODE character to check |
Definition at line 248 of file string_func.h.
Referenced by IConsoleHistoryAdd(), IcuStringIterator::Next(), FallbackParagraphLayout::NextLine(), and IcuStringIterator::Prev().
| int StrCompareIgnoreCase | ( | const std::string_view | str1, |
| const std::string_view | str2 | ||
| ) |
Compares two string( view)s, while ignoring the case of the characters.
| str1 | The first string. |
| str2 | The second string. |
Definition at line 353 of file string.cpp.
Referenced by StrEqualsIgnoreCase().
| char* strecpy | ( | char * | dst, |
| const char * | src, | ||
| const char * | last | ||
| ) |
Copies characters from one buffer to another.
Copies the source string to the destination buffer with respect of the terminating null-character and the last pointer to the last element in the destination buffer. If the last pointer is set to nullptr no boundary check is performed.
| dst | The destination buffer |
| src | The buffer containing the string to copy |
| last | The pointer to the last element of the destination buffer |
Definition at line 65 of file string.cpp.
Referenced by Textbuf::Assign(), and FileStringReader::HandlePragma().
|
inline |
Check if a string buffer is empty.
| s | The pointer to the first element of the buffer |
Definition at line 56 of file string_func.h.
Referenced by FormatBytes(), FormatNumber(), GetEnv(), GRFConfig::GetName(), IConsoleCmdExec(), IConsoleHistoryAdd(), FileStringReader::ParseFile(), RenameSign(), and MusicDriver_ExtMidi::Start().
| bool StrEndsWithIgnoreCase | ( | std::string_view | str, |
| const std::string_view | suffix | ||
| ) |
Check whether the given string ends with the given suffix, ignoring case.
| str | The string to look at. |
| suffix | The suffix to look for. |
Definition at line 340 of file string.cpp.
References StrEqualsIgnoreCase().
Referenced by TextfileWindow::AfterLoadText().
| bool StrEqualsIgnoreCase | ( | const std::string_view | str1, |
| const std::string_view | str2 | ||
| ) |
Compares two string( view)s for equality, while ignoring the case of the characters.
| str1 | The first string. |
| str2 | The second string. |
Definition at line 366 of file string.cpp.
References StrCompareIgnoreCase().
Referenced by ChangeWorkingDirectoryToExecutable(), DEF_CONSOLE_CMD(), GameScannerInfo::FindInfo(), AIScannerInfo::FindInfo(), FiosGetSavegameListCallback(), FiosGetScenarioListCallback(), BlitterFactory::GetBlitterFactory(), MatchesExtension(), ScriptScanner::RegisterScript(), StrEndsWithIgnoreCase(), StringToContentType(), and StrStartsWithIgnoreCase().
| std::string StrMakeValid | ( | std::string_view | str, |
| StringValidationSettings | settings | ||
| ) |
Copies the valid (UTF-8) characters from str to the returned string.
Depending on the settings invalid characters can be replaced with a question mark, as well as determining what characters are deemed invalid.
| str | The string to validate. |
| settings | The settings for the string validation. |
Definition at line 212 of file string.cpp.
References settings, and StrMakeValid().
| void StrMakeValidInPlace | ( | char * | str, |
| const char * | last, | ||
| StringValidationSettings | settings | ||
| ) |
Scans the string for invalid characters and replaces then with a question mark '?' (if not ignored).
| str | The string to validate. |
| last | The last valid character of str. |
| settings | The settings for the string validation. |
Definition at line 185 of file string.cpp.
References settings, and StrMakeValid().
Referenced by Textbuf::Assign(), and StrMakeValidInPlace().
| void StrMakeValidInPlace | ( | char * | str, |
| StringValidationSettings | settings | ||
| ) |
Scans the string for invalid characters and replaces then with a question mark '?' (if not ignored).
Only use this function when you are sure the string ends with a '\0'; otherwise use StrMakeValidInPlace(str, last, settings) variant.
| str | The string (of which you are sure ends with '\0') to validate. |
Definition at line 199 of file string.cpp.
References settings, and StrMakeValidInPlace().
| int StrNaturalCompare | ( | std::string_view | s1, |
| std::string_view | s2, | ||
| bool | ignore_garbage_at_front | ||
| ) |
Compares two strings using case insensitive natural sort.
| s1 | First string to compare. |
| s2 | Second string to compare. |
| ignore_garbage_at_front | Skip punctuation characters in the front |
Definition at line 585 of file string.cpp.
References _current_collator, and SkipGarbage().
Referenced by VehicleGroupWindow::BuildGroupList(), CargoSpecNameSorter(), GRFSorter(), IndustryDirectoryWindow::IndustryNameSorter(), IndustryTypeNameSorter(), NetworkContentListWindow::NameSorter(), NewGRFWindow::NameSorter(), DropDownString< DropDownListItem >::NatSortFunc(), NetworkGameWindow::NGameNameSorter(), SignList::SignNameSorter(), CompanyStationsWindow::StationNameSorter(), TownDirectoryWindow::TownNameSorter(), and NetworkContentListWindow::TypeSorter().
| bool StrNaturalContains | ( | const std::string_view | str, |
| const std::string_view | value | ||
| ) |
Checks if a string is contained in another string with a locale-aware comparison that is case sensitive.
| str | The string to search in. |
| value | The string to search for. |
Definition at line 656 of file string.cpp.
References ICUStringContains(), MacOSStringContains(), and Win32StringContains().
Referenced by StringFilter::AddLine().
| bool StrNaturalContainsIgnoreCase | ( | const std::string_view | str, |
| const std::string_view | value | ||
| ) |
Checks if a string is contained in another string with a locale-aware comparison that is case insensitive.
| str | The string to search in. |
| value | The string to search for. |
Definition at line 683 of file string.cpp.
References ICUStringContains(), MacOSStringContains(), and Win32StringContains().
Referenced by StringFilter::AddLine().
| bool StrStartsWithIgnoreCase | ( | std::string_view | str, |
| const std::string_view | prefix | ||
| ) |
Check whether the given string starts with the given prefix, ignoring case.
| str | The string to look at. |
| prefix | The prefix to look for. |
Definition at line 300 of file string.cpp.
References StrEqualsIgnoreCase().
| void StrTrimInPlace | ( | std::string & | str | ) |
Trim the spaces from given string in place, i.e.
the string buffer that is passed will be modified whenever spaces exist in the given string. When there are spaces at the begin, the whole string is moved forward and when there are spaces at the back the '\0' termination is moved.
| str | The string to perform the in place trimming on. |
Definition at line 288 of file string.cpp.
References StrLeftTrimInPlace(), and StrRightTrimInPlace().
Referenced by CheckClientAndServerName(), NetworkValidateClientName(), and NetworkValidateServerName().
| bool StrValid | ( | const char * | str, |
| const char * | last | ||
| ) |
Checks whether the given string is valid, i.e.
contains only valid (printable) characters and is properly terminated.
| str | The string to validate. |
| last | The last character of the string, i.e. the string must be terminated here or earlier. |
Definition at line 233 of file string.cpp.
References Utf8Decode(), and Utf8EncodedCharLen().
|
inline |
Get the length of a string, within a limited buffer.
| str | The pointer to the first element of the buffer |
| maxlen | The maximum size of the buffer |
Definition at line 68 of file string_func.h.
|
inline |
Decode an UTF-16 character.
| c | Pointer to one or two UTF-16 code points. |
Definition at line 201 of file string_func.h.
Referenced by IcuStringIterator::Next(), and IcuStringIterator::Prev().
|
inline |
Convert an UTF-16 surrogate pair to the corresponding Unicode character.
| lead | Lead surrogate code point. |
| trail | Trail surrogate code point. |
Definition at line 191 of file string_func.h.
Referenced by HandleCharMsg().
|
inline |
Is the given character a lead surrogate code point?
| c | The character to test. |
Definition at line 170 of file string_func.h.
Referenced by HandleCharMsg().
|
inline |
Is the given character a lead surrogate code point?
| c | The character to test. |
Definition at line 180 of file string_func.h.
Referenced by HandleCharMsg().
|
inline |
Return the length of a UTF-8 encoded character.
| c | Unicode character. |
Definition at line 104 of file string_func.h.
| size_t Utf8Decode | ( | char32_t * | c, |
| const char * | s | ||
| ) |
Decode and consume the next UTF-8 encoded character.
| c | Buffer to place decoded character. |
| s | Character stream to retrieve character from. |
Definition at line 438 of file string.cpp.
References GB(), and HasBit().
Referenced by FixSCCEncoded(), StrValid(), and TranslateTTDPatchCodes().
|
inline |
Return the length of an UTF-8 encoded value based on a single char.
This char should be the first byte of the UTF-8 encoding. If not, or encoding is invalid, return value is 0
| c | char to query length of |
Definition at line 123 of file string_func.h.
References GB().
Referenced by FixSCCEncoded(), StrValid(), TranslateTTDPatchCodes(), and Utf8TrimString().
|
inline |
Retrieve the previous UNICODE character in an UTF-8 encoded string.
| s | char pointer pointing to (the first char of) the next character |
Definition at line 148 of file string_func.h.
Referenced by Textbuf::Assign().
| size_t Utf8StringLength | ( | const char * | s | ) |
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes that the encoded string contains.
| s | The string to get the length for. |
Definition at line 378 of file string.cpp.
Referenced by Textbuf::Assign(), CmdAlterGroup(), CmdPlaceSign(), CmdRenameCompany(), CmdRenameDepot(), CmdRenameEngine(), CmdRenamePresident(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), Utf8StringLength(), and VerifyTownName().
| size_t Utf8StringLength | ( | const std::string & | str | ) |
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes that the encoded string contains.
| s | The string to get the length for. |
Definition at line 392 of file string.cpp.
References Utf8StringLength().
| size_t Utf8TrimString | ( | char * | s, |
| size_t | maxlen | ||
| ) |
Properly terminate an UTF8 string to some maximum length.
| s | string to check if it needs additional trimming |
| maxlen | the maximum length the buffer can have. |
Definition at line 527 of file string.cpp.
References Utf8EncodedCharLen().