OpenTTD Source
1.11.0-beta2
|
Go to the source code of this file.
Functions | |
char * | strecat (char *dst, const char *src, const char *last) |
Appends characters from one string to another. More... | |
char * | strecpy (char *dst, const char *src, const char *last) |
Copies characters from one buffer to another. More... | |
char * | stredup (const char *src, const char *last=nullptr) |
Create a duplicate of the given string. More... | |
int CDECL | seprintf (char *str, const char *last, const char *format,...) WARN_FORMAT(3 |
int CDECL int CDECL | vseprintf (char *str, const char *last, const char *format, va_list ap) WARN_FORMAT(3 |
int CDECL int CDECL char *CDECL | str_fmt (const char *str,...) WARN_FORMAT(1 |
int CDECL int CDECL char *CDECL void | str_validate (char *str, const char *last, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK) |
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mark '?' (if not ignored) More... | |
std::string | str_validate (const std::string &str, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK) |
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mark '?' (if not ignored) More... | |
void | ValidateString (const char *str) |
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mark '?'. More... | |
void | str_fix_scc_encoded (char *str, const char *last) |
Scan the string for old values of SCC_ENCODED and fix it to it's new, static value. More... | |
void | str_strip_colours (char *str) |
Scans the string for colour codes and strips them. | |
bool | strtolower (char *str) |
Convert a given ASCII string to lowercase. More... | |
bool | strtolower (std::string &str, std::string::size_type offs=0) |
bool | StrValid (const char *str, const char *last) |
Checks whether the given string is valid, i.e. More... | |
static bool | StrEmpty (const char *s) |
Check if a string buffer is empty. More... | |
static size_t | ttd_strnlen (const char *str, size_t maxlen) |
Get the length of a string, within a limited buffer. More... | |
char * | md5sumToString (char *buf, const char *last, const uint8 md5sum[16]) |
Convert the md5sum to a hexadecimal string representation. More... | |
bool | IsValidChar (WChar key, CharSetFilter afilter) |
Only allow certain keys. More... | |
size_t | Utf8Decode (WChar *c, const char *s) |
Decode and consume the next UTF-8 encoded character. More... | |
size_t | Utf8Encode (char *buf, WChar c) |
size_t | Utf8Encode (std::ostreambuf_iterator< char > &buf, WChar c) |
size_t | Utf8TrimString (char *s, size_t maxlen) |
Properly terminate an UTF8 string to some maximum length. More... | |
static WChar | Utf8Consume (const char **s) |
template<class Titr > | |
static WChar | Utf8Consume (Titr &s) |
static int8 | Utf8CharLen (WChar c) |
Return the length of a UTF-8 encoded character. More... | |
static int8 | Utf8EncodedCharLen (char c) |
Return the length of an UTF-8 encoded value based on a single char. More... | |
static bool | IsUtf8Part (char c) |
static char * | Utf8PrevChar (char *s) |
Retrieve the previous UNICODE character in an UTF-8 encoded string. More... | |
static 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... | |
static bool | Utf16IsLeadSurrogate (uint c) |
Is the given character a lead surrogate code point? More... | |
static bool | Utf16IsTrailSurrogate (uint c) |
Is the given character a lead surrogate code point? More... | |
static WChar | Utf16DecodeSurrogate (uint lead, uint trail) |
Convert an UTF-16 surrogate pair to the corresponding Unicode character. More... | |
static WChar | Utf16DecodeChar (const uint16 *c) |
Decode an UTF-16 character. More... | |
static bool | IsTextDirectionChar (WChar c) |
Is the given character a text direction character. More... | |
static bool | IsPrintable (WChar c) |
static bool | IsWhitespace (WChar c) |
Check whether UNICODE character is whitespace or not, i.e. More... | |
int | strnatcmp (const char *s1, const char *s2, bool ignore_garbage_at_front=false) |
Compares two strings using case insensitive natural sort. More... | |
Functions related to low-level strings.
Definition in file string_func.h.
|
inlinestatic |
Is the given character a text direction character.
c | The character to test. |
Definition at line 220 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 | ( | WChar | 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 383 of file string.cpp.
References CS_ALPHANUMERAL.
Referenced by IConsoleCmdExec().
|
inlinestatic |
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 252 of file string_func.h.
Referenced by IConsoleHistoryAdd(), IcuStringIterator::Next(), FallbackParagraphLayout::NextLine(), and IcuStringIterator::Prev().
char* md5sumToString | ( | char * | buf, |
const char * | last, | ||
const uint8 | md5sum[16] | ||
) |
Convert the md5sum to a hexadecimal string representation.
buf | buffer to put the md5sum into |
last | last character of buffer (usually lastof(buf)) |
md5sum | the md5sum itself |
Definition at line 460 of file string.cpp.
References seprintf().
Referenced by HandleSavegameLoadCrash(), IsGoodGRFConfigList(), OutputContentState(), PrintGrfInfo(), and ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS().
void str_fix_scc_encoded | ( | char * | str, |
const char * | last | ||
) |
Scan the string for old values of SCC_ENCODED and fix it to it's new, static value.
str | the string to scan |
last | the last valid character of str |
Definition at line 169 of file string.cpp.
References Utf8Decode(), and Utf8EncodedCharLen().
int CDECL int CDECL char* CDECL void str_validate | ( | char * | str, |
const char * | last, | ||
StringValidationSettings | settings | ||
) |
Scans the string for valid characters and if it finds invalid ones, replaces them 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 237 of file string.cpp.
References settings, and str_validate().
Referenced by str_validate(), and ValidateString().
std::string str_validate | ( | const std::string & | str, |
StringValidationSettings | settings | ||
) |
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mark '?' (if not ignored)
str | the string to validate |
settings | the settings for the string validation. |
Definition at line 250 of file string.cpp.
References settings, and str_validate().
char* strecat | ( | char * | dst, |
const char * | src, | ||
const char * | last | ||
) |
Appends characters from one string to another.
Appends the source string to the destination string with respect of the terminating null-character and 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 buffer containing the target string |
src | The buffer containing the string to append |
last | The pointer to the last element of the destination buffer |
Definition at line 84 of file string.cpp.
References strecpy().
Referenced by KeycodeToString(), Squirrel::PrintFunc(), ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE(), SaveKeycodes(), ServerNetworkGameSocketHandler::SendCompanyInfo(), and ScriptConfig::SettingsToString().
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 112 of file string.cpp.
References DEBUG, and error().
Referenced by ScenarioScanner::AddFile(), Textbuf::Assign(), DoNetworkUDPQueryServer(), DriverFactoryBase::DriverFactoryBase(), GameScannerInfo::FindInfo(), AIScannerInfo::FindInfo(), GamelogRevision(), GenerateTownNameString(), NetworkAddress::GetAddressAsString(), ServerNetworkGameSocketHandler::GetClientName(), GetClipboardContents(), GRFBuildParamList(), FileStringReader::HandlePragma(), IConsoleAliasExec(), MakeCatalanTownName(), MakeCzechTownName(), MakeFinnishTownName(), MakeFrenchTownName(), MakeHungarianTownName(), MakeItalianTownName(), MakeNorwegianTownName(), MakeRomanianTownName(), MakeSillyTownName(), MakeSlovakTownName(), MakeSpanishTownName(), MakeSwissTownName(), MakeTurkishTownName(), mkpath(), NetworkAddChatMessage(), NetworkAddress::NetworkAddress(), NetworkFindBroadcastIPsInternal(), NetworkFindName(), NetworkGameListHandleDelayedInsert(), NetworkSendCommand(), NetworkServerSetCompanyPassword(), BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(), NetworkGameWindow::OnEditboxChanged(), NetworkStartServerWindow::OnEditboxChanged(), AIDebugWindow::OnEditboxChanged(), NetworkStartServerWindow::OnQueryTextFinished(), MusicDriver_ExtMidi::PlaySong(), StringListReader::ReadLine(), ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(), ClientNetworkContentSocketHandler::Receive_SERVER_INFO(), NetworkAddress::Resolve(), ServerNetworkGameSocketHandler::SendCompanyInfo(), SetFallbackFont(), TextfileWindow::SetFontNames(), LanguagePackGlyphSearcher::SetFontNames(), FileToSaveLoad::SetTitle(), ShowMissingContentWindow(), strecat(), and DriverFactoryBase::~DriverFactoryBase().
char* stredup | ( | const char * | s, |
const char * | last | ||
) |
Create a duplicate of the given string.
s | The string to duplicate. |
last | The last character that is safe to duplicate. If nullptr, the whole string is duplicated. |
Definition at line 137 of file string.cpp.
References ttd_strnlen().
Referenced by ScriptInfo::AddLabels(), ScriptInfo::AddSetting(), ScriptConfig::Change(), NetworkChatWindow::ChatTabCompletion(), CmdSetGoalProgress(), CmdSetGoalText(), CmdSetStoryPageTitle(), AIInfo::Constructor(), ErrorMessageData::ErrorMessageData(), FileWriter::FileWriter(), GamelogSetting(), GetFontByFaceName(), GetNetworkRevisionString(), GRFConfig::GRFConfig(), GRFFile::GRFFile(), IConsoleAliasRegister(), IConsolePrint(), IsGoodGRFConfigList(), ScriptScanner::RegisterScript(), ScriptConfig::ScriptConfig(), ErrorMessageData::SetDParamStr(), AIConfig::SetSetting(), ScriptConfig::SetSetting(), SlError(), MusicDriver_ExtMidi::Start(), ScriptConfig::StringToSettings(), UpdateElement(), and UpdateOSKOriginalText().
|
inlinestatic |
Check if a string buffer is empty.
s | The pointer to the first element of the buffer |
Definition at line 60 of file string_func.h.
Referenced by ServerNetworkAdminSocketHandler::AllowConnection(), CStrA::AppendStr(), CmdAlterGroup(), CmdIndustryCtrl(), CmdPlaceSign(), CmdRenameCompany(), CmdRenameDepot(), CmdRenameEngine(), CmdRenamePresident(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdSetGoalProgress(), CmdSetGoalText(), CmdSetStoryPageTitle(), CmdTownSetText(), NetworkStartServerWindow::DrawWidget(), GenerateCompanyPasswordHash(), ServerNetworkGameSocketHandler::GetClientName(), NetworkAddress::GetHostname(), GetKeyboardLayout(), GRFConfig::GetName(), GetSavegameFormat(), GRFLoadConfig(), IConsoleCmdExec(), IConsoleHistoryAdd(), NetworkAddress::Listen(), MakeScreenshotName(), NetworkAddress::NetworkAddress(), NetworkAutoCleanCompanies(), NetworkGameListAddItem(), NetworkGameListHandleDelayedInsert(), NetworkServerSetCompanyPassword(), NetworkStartUp(), NetworkGameWindow::NGameAllowedSorter(), SavePresetWindow::OnClick(), NetworkGameWindow::OnEditboxChanged(), NetworkContentListWindow::OnInvalidateData(), CheatWindow::OnQueryTextFinished(), NewGRFParametersWindow::OnQueryTextFinished(), AISettingsWindow::OnQueryTextFinished(), NewGRFInspectWindow::OnQueryTextFinished(), TimetableWindow::OnQueryTextFinished(), GenerateLandscapeWindow::OnQueryTextFinished(), NetworkGameWindow::OnQueryTextFinished(), SpriteAlignerWindow::OnQueryTextFinished(), CreateScenarioWindow::OnQueryTextFinished(), IndustryViewWindow::OnQueryTextFinished(), OrdersWindow::OnQueryTextFinished(), SelectCompanyManagerFaceWindow::OnQueryTextFinished(), NetworkJoinStatusWindow::OnQueryTextFinished(), GameSettingsWindow::OnQueryTextFinished(), ScenarioEditorToolbarWindow::OnQueryTextFinished(), FileStringReader::ParseFile(), ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(), ClientNetworkContentSocketHandler::Receive_SERVER_INFO(), ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD(), ClientNetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD(), ClientNetworkUDPSocketHandler::Receive_SERVER_NEWGRFS(), RenameSign(), NetworkAddress::Resolve(), SendChat(), ServerNetworkGameSocketHandler::SendCompanyInfo(), MusicDriver_ExtMidi::Start(), LandInfoWindow::UpdateWidgetSize(), and VerifyElementContentParameters().
int strnatcmp | ( | const char * | s1, |
const char * | 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 625 of file string.cpp.
References _current_collator, and SkipGarbage().
Referenced by GRFSorter(), IndustryDirectoryWindow::IndustryNameSorter(), NetworkContentListWindow::NameSorter(), NewGRFWindow::NameSorter(), NetworkGameWindow::NGameNameSorter(), SignList::SignNameSorter(), CompanyStationsWindow::StationNameSorter(), TownDirectoryWindow::TownNameSorter(), and NetworkContentListWindow::TypeSorter().
bool strtolower | ( | char * | str | ) |
Convert a given ASCII string to lowercase.
NOTE: only support ASCII characters, no UTF8 fancy. As currently the function is only used to lowercase data-filenames if they are not found, this is sufficient. If more, or general functionality is needed, look to r7271 where it was removed because it was broken when using certain locales: eg in Turkish the uppercase 'I' was converted to '?', so just revert to the old functionality
str | string to convert |
Definition at line 354 of file string.cpp.
Referenced by GameScannerInfo::FindInfo(), AIScannerInfo::FindInfo(), GameScannerLibrary::FindLibrary(), AIScannerLibrary::FindLibrary(), ScriptScanner::RegisterScript(), and SimplifyFileName().
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 281 of file string.cpp.
References Utf8Decode(), and Utf8EncodedCharLen().
|
inlinestatic |
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 72 of file string_func.h.
Referenced by stredup().
|
inlinestatic |
Decode an UTF-16 character.
c | Pointer to one or two UTF-16 code points. |
Definition at line 205 of file string_func.h.
References Utf16DecodeSurrogate(), and Utf16IsLeadSurrogate().
Referenced by IcuStringIterator::Next(), and IcuStringIterator::Prev().
|
inlinestatic |
Convert an UTF-16 surrogate pair to the corresponding Unicode character.
lead | Lead surrogate code point. |
trail | Trail surrogate code point. |
Definition at line 195 of file string_func.h.
Referenced by HandleCharMsg(), and Utf16DecodeChar().
|
inlinestatic |
Is the given character a lead surrogate code point?
c | The character to test. |
Definition at line 174 of file string_func.h.
Referenced by HandleCharMsg(), HandleIMEComposition(), and Utf16DecodeChar().
|
inlinestatic |
Is the given character a lead surrogate code point?
c | The character to test. |
Definition at line 184 of file string_func.h.
Referenced by HandleCharMsg().
|
inlinestatic |
Return the length of a UTF-8 encoded character.
c | Unicode character. |
Definition at line 109 of file string_func.h.
size_t Utf8Decode | ( | WChar * | 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 481 of file string.cpp.
References GB(), and HasBit().
Referenced by Layouter::GetCharPosition(), Layouter::Layouter(), str_fix_scc_encoded(), str_strip_colours(), StrValid(), and TranslateTTDPatchCodes().
|
inlinestatic |
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 128 of file string_func.h.
References GB().
Referenced by str_fix_scc_encoded(), StrValid(), TranslateTTDPatchCodes(), and Utf8TrimString().
|
inlinestatic |
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 153 of file string_func.h.
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 334 of file string.cpp.
Referenced by CmdAlterGroup(), CmdPlaceSign(), CmdRenameCompany(), CmdRenameDepot(), CmdRenameEngine(), CmdRenamePresident(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), and VerifyTownName().
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 567 of file string.cpp.
References Utf8EncodedCharLen().
Referenced by NetworkAddChatMessage().
void ValidateString | ( | const char * | str | ) |
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mark '?'.
str | the string to validate |
Definition at line 267 of file string.cpp.
References str_validate().
Referenced by ScriptInfo::AddLabels(), and ScriptInfo::AddSetting().