|
OpenTTD Source 15.0-beta2
|
Functions related to low-level strings. More...
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 | |
| void | strecpy (std::span< char > dst, std::string_view src) |
| Copies characters from one buffer to another. | |
| std::string | FormatArrayAsHex (std::span< const uint8_t > data) |
| Format a byte array into a continuous hex string. | |
| void | StrMakeValidInPlace (char *str, StringValidationSettings settings=StringValidationSetting::ReplaceWithQuestionMark) |
| Scans the string for invalid characters and replaces them with a question mark '?' (if not ignored). | |
| void | StrMakeValidInPlace (std::string &str, StringValidationSettings settings=StringValidationSetting::ReplaceWithQuestionMark) |
| Scans the string for invalid characters and replaces them with a question mark '?' (if not ignored). | |
| std::string | StrMakeValid (std::string_view str, StringValidationSettings settings=StringValidationSetting::ReplaceWithQuestionMark) |
Copies the valid (UTF-8) characters from str to the returned string. | |
| std::string | StrMakeValid (const char *str, StringValidationSettings settings=StringValidationSetting::ReplaceWithQuestionMark) |
| std::string | StrMakeValid (std::string &&str, StringValidationSettings settings=StringValidationSetting::ReplaceWithQuestionMark) |
| bool | strtolower (std::string &str, std::string::size_type offs=0) |
| bool | StrValid (std::span< const char > str) |
| Checks whether the given string is valid, i.e. | |
| void | StrTrimInPlace (std::string &str) |
| Trim the spaces from given string in place, i.e. | |
| std::string_view | StrTrimView (std::string_view str) |
| bool | StrStartsWithIgnoreCase (std::string_view str, const std::string_view prefix) |
| Check whether the given string starts with the given prefix, ignoring case. | |
| bool | StrEndsWithIgnoreCase (std::string_view str, const std::string_view suffix) |
| Check whether the given string ends with the given suffix, ignoring case. | |
| int | StrCompareIgnoreCase (const std::string_view str1, const std::string_view str2) |
| Compares two string( view)s, while ignoring the case of the characters. | |
| 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. | |
| bool | StrContainsIgnoreCase (const std::string_view str, const std::string_view value) |
| Checks if a string is contained in another string, while ignoring the case of the characters. | |
| int | StrNaturalCompare (std::string_view s1, std::string_view s2, bool ignore_garbage_at_front=false) |
| Compares two strings using case insensitive natural sort. | |
| 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. | |
| 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. | |
| 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. | |
| bool | StrEmpty (const char *s) |
| Check if a string buffer is empty. | |
| size_t | ttd_strnlen (const char *str, size_t maxlen) |
| Get the length of a string, within a limited buffer. | |
| bool | IsValidChar (char32_t key, CharSetFilter afilter) |
| Only allow certain keys. | |
| size_t | Utf8Decode (char32_t *c, const char *s) |
| Decode and consume the next UTF-8 encoded character. | |
| template<typename T > requires (!std::is_same_v<T, char *> && (std::is_same_v<std::string_view::iterator, T> || std::is_same_v<std::string::iterator, T>)) | |
| size_t | Utf8Decode (char32_t *c, T &s) |
| char32_t | Utf8Consume (const char **s) |
| template<class Titr > | |
| char32_t | Utf8Consume (Titr &s) |
| int8_t | Utf8EncodedCharLen (char c) |
| Return the length of an UTF-8 encoded value based on a single char. | |
| bool | IsUtf8Part (char c) |
| size_t | Utf8StringLength (std::string_view 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. | |
| bool | Utf16IsLeadSurrogate (uint c) |
| Is the given character a lead surrogate code point? | |
| bool | Utf16IsTrailSurrogate (uint c) |
| Is the given character a lead surrogate code point? | |
| char32_t | Utf16DecodeSurrogate (uint lead, uint trail) |
| Convert an UTF-16 surrogate pair to the corresponding Unicode character. | |
| char32_t | Utf16DecodeChar (const uint16_t *c) |
| Decode an UTF-16 character. | |
| bool | IsTextDirectionChar (char32_t c) |
| Is the given character a text direction character. | |
| bool | IsPrintable (char32_t c) |
| bool | IsWhitespace (char32_t c) |
| Check whether UNICODE character is whitespace or not, i.e. | |
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 659 of file string.cpp.
References ConvertHexNibbleToByte().
Referenced by X25519AuthorizedKeyClientHandler::GetValidSecretKeyAndUpdatePublicKey(), GRFLoadConfig(), PickerLoadConfig(), and ValidateSignature().
| std::string FormatArrayAsHex | ( | std::span< const uint8_t > | data | ) |
Format a byte array into a continuous hex string.
| data | Array to format |
Definition at line 78 of file string.cpp.
Referenced by AddGrfInfo(), CalculateHashV1(), GenerateUid(), X25519AuthenticationHandler::GetPeerPublicKey(), X25519AuthorizedKeyClientHandler::GetValidSecretKeyAndUpdatePublicKey(), HandleSavegameLoadCrash(), IsGoodGRFConfigList(), CommandHelperBase::LogCommandExecution(), NetworkContentListWindow::OpenExternalSearch(), OutputContentState(), ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(), and SurveyGrfs().
|
inline |
Definition at line 204 of file string_func.h.
|
inline |
Is the given character a text direction character.
| c | The character to test. |
Definition at line 187 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.
Referenced by MissingGlyphSearcher::FindMissingGlyphs(), GetLayouter(), and FallbackParagraphLayout::NextLine().
|
inline |
Definition at line 129 of file string_func.h.
| 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 418 of file string.cpp.
References CS_ALPHA, CS_ALPHANUMERAL, CS_HEXADECIMAL, CS_NUMERAL, CS_NUMERAL_SIGNED, and CS_NUMERAL_SPACE.
Referenced by IConsoleCmdExec(), Textbuf::InsertString(), OskWindow::OnClick(), VideoDriver_SDL_Base::PollEvent(), TranslateTTDPatchCodes(), and OskWindow::UpdateOskState().
|
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 219 of file string_func.h.
Referenced by IConsoleHistoryAdd(), IcuStringIterator::Next(), FallbackParagraphLayout::NextLine(), IcuStringIterator::Prev(), and StringFilter::SetFilterTerm().
| 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 355 of file string.cpp.
Referenced by MatchesExtension(), StrEqualsIgnoreCase(), and StrNaturalCompare().
| bool StrContainsIgnoreCase | ( | const std::string_view | str, |
| const std::string_view | value | ||
| ) |
Checks if a string is contained in another string, while ignoring the case of the characters.
| str | The string to search in. |
| value | The string to search for. |
Definition at line 381 of file string.cpp.
Referenced by StringFilter::AddLine(), and LoadWin32Font().
| void strecpy | ( | std::span< char > | dst, |
| std::string_view | src | ||
| ) |
Copies characters from one buffer to another.
Copies the source string to the destination buffer with respect of the terminating null-character and the size of the destination buffer.
| dst | The destination buffer |
| src | The buffer containing the string to copy |
Definition at line 57 of file string.cpp.
References Debug.
Referenced by FileStringReader::HandlePragma(), and StringReader::ParseFile().
|
inline |
Check if a string buffer is empty.
| s | The pointer to the first element of the buffer |
Definition at line 68 of file string_func.h.
Referenced by GetEnv(), Window::HandleEditBoxKey(), IConsoleCmdExec(), IConsoleHistoryAdd(), SavePresetWindow::OnClick(), openttd_main(), 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 342 of file string.cpp.
References StrEqualsIgnoreCase().
Referenced by TextfileWindow::AfterLoadText(), and TextfileWindow::NavigateToFile().
| 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 368 of file string.cpp.
References StrCompareIgnoreCase().
Referenced by ChangeWorkingDirectoryToExecutable(), DEF_CONSOLE_CMD(), AIScannerInfo::FindInfo(), GameScannerInfo::FindInfo(), FindKey(), FiosGetSavegameListCallback(), FiosGetScenarioListCallback(), FiosGetTownDataListCallback(), FiosMakeFilename(), FiosNumberedSaveName::FiosNumberedSaveName(), BlitterFactory::GetBlitterFactory(), GetFontByFaceName(), IsSameScript(), ParseCode(), ScriptScanner::RegisterScript(), DriverFactoryBase::SelectDriverImpl(), StrEndsWithIgnoreCase(), StringToContentType(), and StrStartsWithIgnoreCase().
|
inline |
Definition at line 28 of file string_func.h.
|
inline |
Definition at line 32 of file string_func.h.
| 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 226 of file string.cpp.
References settings, and StrMakeValid().
| void StrMakeValidInPlace | ( | char * | str, |
| StringValidationSettings | settings | ||
| ) |
Scans the string for invalid characters and replaces them with a question mark '?' (if not ignored).
| str | The string to validate. |
| settings | The settings for the string validation. |
Definition at line 194 of file string.cpp.
References settings, and StrMakeValid().
Referenced by StringSettingDesc::MakeValueValid(), SanitizeSingleStringHelper(), and SlStdString().
| void StrMakeValidInPlace | ( | std::string & | str, |
| StringValidationSettings | settings | ||
| ) |
Scans the string for invalid characters and replaces them with a question mark '?' (if not ignored).
| str | The string to validate. |
| settings | The settings for the string validation. |
Definition at line 208 of file string.cpp.
References settings, and StrMakeValid().
| 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 514 of file string.cpp.
References _current_collator, MacOSStringCompare(), SkipGarbage(), and StrCompareIgnoreCase().
Referenced by BuildGuiGroupList(), CargoSpecNameSorter(), EngineNameSorter(), GRFSorter(), IndustryDirectoryWindow::IndustryNameSorter(), IndustryTypeNameSorter(), NetworkContentListWindow::NameSorter(), NewGRFWindow::NameSorter(), DropDownString< TBase, TFs, TEnd >::NatSortFunc(), NetworkGameWindow::NGameNameSorter(), FiosItem::operator<(), SignList::SignNameSorter(), CompanyStationsWindow::StationNameSorter(), TownDirectoryWindow::TownNameSorter(), NetworkContentListWindow::TypeSorter(), and VehicleNameSorter().
| 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 585 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 612 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 302 of file string.cpp.
References StrEqualsIgnoreCase().
| bool strtolower | ( | std::string & | str, |
| std::string::size_type | offs = 0 |
||
| ) |
Definition at line 400 of file string.cpp.
| 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 281 of file string.cpp.
Referenced by TarScanner::AddFile(), CheckClientAndServerName(), NetworkValidateClientName(), and NetworkValidateServerName().
| std::string_view StrTrimView | ( | std::string_view | str | ) |
Definition at line 286 of file string.cpp.
| bool StrValid | ( | std::span< const char > | str | ) |
Checks whether the given string is valid, i.e.
contains only valid (printable) characters and is properly terminated.
| str | Span of chars to validate. |
Definition at line 248 of file string.cpp.
References Utf8Decode(), and Utf8EncodedCharLen().
Referenced by LanguagePackHeader::IsValid().
|
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 80 of file string_func.h.
Referenced by ByteReader::ReadString().
|
inline |
Decode an UTF-16 character.
| c | Pointer to one or two UTF-16 code points. |
Definition at line 172 of file string_func.h.
References Utf16DecodeSurrogate(), and Utf16IsLeadSurrogate().
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 162 of file string_func.h.
Referenced by HandleCharMsg(), and Utf16DecodeChar().
|
inline |
Is the given character a lead surrogate code point?
| c | The character to test. |
Definition at line 141 of file string_func.h.
Referenced by HandleCharMsg(), HandleIMEComposition(), and Utf16DecodeChar().
|
inline |
Is the given character a lead surrogate code point?
| c | The character to test. |
Definition at line 151 of file string_func.h.
Referenced by HandleCharMsg().
|
inline |
Definition at line 94 of file string_func.h.
|
inline |
Definition at line 102 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 441 of file string.cpp.
References GB(), and HasBit().
Referenced by DecodeEncodedString(), FixSCCEncoded(), HandleNewGRFStringControlCodes(), EncodedString::ReplaceParam(), StrMakeValid(), StrValid(), and TranslateTTDPatchCodes().
|
inline |
Definition at line 92 of file string_func.h.
|
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 116 of file string_func.h.
References GB().
Referenced by FixSCCEncoded(), StrMakeValid(), StrValid(), and TranslateTTDPatchCodes().
| size_t Utf8StringLength | ( | std::string_view | 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 394 of file string.cpp.
Referenced by CmdAlterGroup(), CmdFoundTown(), CmdPlaceSign(), CmdRenameCompany(), CmdRenameDepot(), CmdRenameEngine(), CmdRenamePresident(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), Textbuf::DeleteChar(), Textbuf::DeleteText(), GenerateCompanyName(), GeneratePresidentName(), Textbuf::UpdateSize(), and VerifyTownName().