#include "core/bitmath_func.hpp"
#include "string_type.h"
Go to the source code of this file.
Functions | |
void | ttd_strlcat (char *dst, const char *src, size_t size) |
Appends characters from one string to another. | |
void | ttd_strlcpy (char *dst, const char *src, size_t size) |
Copies characters from one buffer to another. | |
char * | strecat (char *dst, const char *src, const char *last) |
Appends characters from one string to another. | |
char * | strecpy (char *dst, const char *src, const char *last) |
Copies characters from one buffer to another. | |
int CDECL | seprintf (char *str, const char *last, const char *format,...) |
Safer implementation of snprintf; same as snprintf except:
| |
char *CDECL | str_fmt (const char *str,...) |
void | str_validate (char *str, const char *last, bool allow_newlines=false, bool ignore=false) |
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mark '?' (if not ignored). | |
void | str_strip_colours (char *str) |
Scans the string for colour codes and strips them. | |
void | strtolower (char *str) |
Convert the given string to lowercase, only works with ASCII! | |
static bool | StrEmpty (const char *s) |
Check if a string buffer is empty. | |
static size_t | ttd_strnlen (const char *str, size_t maxlen) |
Get the length of a string, within a limited buffer. | |
char * | md5sumToString (char *buf, const char *last, const uint8 md5sum[16]) |
Convert the md5sum number to a 'hexadecimal' string, return next pos in buffer. | |
bool | IsValidChar (WChar key, CharSetFilter afilter) |
Only allow certain keys. | |
size_t | Utf8Decode (WChar *c, const char *s) |
size_t | Utf8Encode (char *buf, WChar c) |
size_t | Utf8TrimString (char *s, size_t maxlen) |
Properly terminate an UTF8 string to some maximum length. | |
static WChar | Utf8Consume (const char **s) |
static int8 | Utf8CharLen (WChar c) |
Return the length of a UTF-8 encoded character. | |
static int8 | Utf8EncodedCharLen (char c) |
Return the length of an UTF-8 encoded value based on a single char. | |
static bool | IsUtf8Part (char c) |
static char * | Utf8PrevChar (const char *s) |
Retrieve the previous UNICODE character in an UTF-8 encoded string. | |
static bool | IsPrintable (WChar c) |
static bool | IsWhitespace (WChar c) |
Check whether UNICODE character is whitespace or not, i.e. | |
char * | strndup (const char *s, size_t len) |
const char * | strcasestr (const char *haystack, const char *needle) |
Definition in file string_func.h.
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 187 of file string.cpp.
References CS_ALPHA, CS_ALPHANUMERAL, and CS_NUMERAL.
Referenced by IConsoleCmdExec().
static bool IsWhitespace | ( | WChar | c | ) | [inline, static] |
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 234 of file string_func.h.
Referenced by FormatStringLinebreaks().
char* md5sumToString | ( | char * | buf, | |
const char * | last, | |||
const uint8 | md5sum[16] | |||
) |
Convert the md5sum number to a 'hexadecimal' string, return next pos in buffer.
Convert the md5sum number to a 'hexadecimal' string, return next pos in buffer.
buf | buffer to put the md5sum into | |
last | last character of buffer (usually lastof(buf)) | |
md5sum | the md5sum itself |
Definition at line 255 of file string.cpp.
References seprintf().
Referenced by HandleSavegameLoadCrash(), IsGoodGRFConfigList(), and PrintGrfInfo().
int CDECL seprintf | ( | char * | str, | |
const char * | last, | |||
const char * | format, | |||
... | ||||
) |
Safer implementation of snprintf; same as snprintf except:
replace sizeof with lastof.
str | buffer to write to up to last | |
last | last character we may write to | |
format | the formatting (see snprintf) |
Definition at line 239 of file string.cpp.
References vseprintf().
Referenced by CheckExternalFiles(), CloneVehicleName(), FormatBytes(), GetGraphicsSetsList(), HandleSavegameLoadCrash(), ini_save_settings(), make_intlist(), make_manyofmany(), make_oneofmany(), md5sumToString(), and ShowHelp().
void str_validate | ( | char * | str, | |
const char * | last, | |||
bool | allow_newlines = false , |
|||
bool | ignore = false | |||
) |
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 | |
allow_newlines | whether newlines should be allowed or ignored | |
ignore | whether to ignore or replace with a question mark |
Definition at line 100 of file string.cpp.
References Utf8EncodedCharLen().
Referenced by FiosFileScanner::AddFile(), FiosGetFileList(), GetFileTitle(), IConsolePrint(), and SlString().
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 NULL no boundary check is performed.
lastof() applies only to fixed size arrays
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 55 of file string.cpp.
References strecpy().
Referenced by CloneVehicleName(), DoAutosave(), GetDebugString(), and GetFileTitle().
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 NULL no boundary check is performed.
lastof() applies only to fixed size arrays
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 67 of file string.cpp.
References error.
Referenced by FiosFileScanner::AddFile(), CloneVehicleName(), DoDrawString(), DoDrawStringCentered(), DoDrawStringTruncated(), DrawStringMultiCenter(), FiosGetFileList(), GamelogRevision(), GetFileTitle(), GetKeyboardLayout(), IConsoleCopyInParams(), InsertTextBufferClipboard(), FileScanner::Scan(), ShowHelp(), ShowRefitOptionsList(), and strecat().
static bool StrEmpty | ( | const char * | s | ) | [inline, static] |
Check if a string buffer is empty.
s | The pointer to the firste element of the buffer |
Definition at line 119 of file string_func.h.
Referenced by FiosFileScanner::AddFile(), AISign::BuildSign(), CmdCompanyCtrl(), CmdPlaceSign(), CmdRenameCompany(), CmdRenameEngine(), CmdRenameGroup(), CmdRenamePresident(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), GetKeyboardLayout(), NewGRFWindow::OnPaint(), NewGRFAddWindow::OnPaint(), AISettingsWindow::OnQueryTextFinished(), RenameSign(), SaveToHighScore(), BlitterFactoryBase::SelectBlitter(), SetGraphicsSet(), AIWaypoint::SetName(), AIVehicle::SetName(), AIStation::SetName(), AISign::SetName(), AIGroup::SetName(), AICompany::SetName(), and AICompany::SetPresidentName().
void strtolower | ( | char * | str | ) |
Convert the given string to lowercase, only works with ASCII!
Convert the given string to lowercase, only works with ASCII!
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 175 of file string.cpp.
Referenced by FioFOpenFile(), and SimplifyFileName().
void ttd_strlcat | ( | char * | dst, | |
const char * | src, | |||
size_t | size | |||
) |
Appends characters from one string to another.
Appends the source string to the destination string with respect of the terminating null-character and the maximum size of the destination buffer.
lengthof() applies only to fixed size arrays
dst | The buffer containing the target string | |
src | The buffer containing the string to append | |
size | The maximum size of the destination buffer |
Definition at line 33 of file string.cpp.
References ttd_strlcpy().
Referenced by BuildWithFullPath().
void ttd_strlcpy | ( | char * | dst, | |
const char * | src, | |||
size_t | size | |||
) |
Copies characters from one buffer to another.
Copies the source string to the destination buffer with respect of the terminating null-character and the maximum size of the destination buffer.
lengthof() applies only to fixed size arrays
dst | The destination buffer | |
src | The buffer containing the string to copy | |
size | The maximum size of the destination buffer |
Definition at line 45 of file string.cpp.
Referenced by BuildWithFullPath(), FioCreateDirectory(), IConsoleHistoryNavigate(), IConsoleVarSetStringvalue(), ini_load_settings(), AIController::LoadedLibrary(), mkpath(), NewGRFWindow::OnClick(), SetSettingValue(), and ttd_strlcat().
static size_t ttd_strnlen | ( | const char * | str, | |
size_t | maxlen | |||
) | [inline, static] |
Get the length of a string, within a limited buffer.
str | The pointer to the firste element of the buffer | |
maxlen | The maximum size of the buffer |
Definition at line 131 of file string_func.h.
static int8 Utf8CharLen | ( | WChar | c | ) | [inline, static] |
Return the length of a UTF-8 encoded character.
c | Unicode character. |
Definition at line 167 of file string_func.h.
Referenced by CopyFromOldName(), FS2OTTD(), InsertTextBufferChar(), InsertTextBufferClipboard(), and UpdateTextBufferSize().
static int8 Utf8EncodedCharLen | ( | char | c | ) | [inline, static] |
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 186 of file string_func.h.
References GB().
Referenced by str_validate(), and Utf8TrimString().
static char* Utf8PrevChar | ( | const char * | s | ) | [inline, static] |
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 211 of file string_func.h.
Referenced by FormatStringLinebreaks(), and MoveTextBufferPos().
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 348 of file string.cpp.
References Utf8EncodedCharLen().