OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
33 char *
strecat(
char *dst,
const char *src,
const char *last) NOACCESS(3);
34 char *
strecpy(
char *dst,
const char *src,
const char *last) NOACCESS(3);
35 char *
stredup(
const char *src,
const char *last =
nullptr) NOACCESS(2);
37 int CDECL
seprintf(
char *str, const
char *last, const
char *format, ...) WARN_FORMAT(3, 4) NOACCESS(2);
38 int CDECL
vseprintf(
char *str, const
char *last, const
char *format, va_list ap) WARN_FORMAT(3, 0) NOACCESS(2);
40 char *CDECL
str_fmt(const
char *str, ...) WARN_FORMAT(1, 2);
49 bool strtolower(std::
string &str, std::
string::size_type offs = 0);
51 bool StrValid(const
char *str, const
char *last) NOACCESS(2);
54 bool StrStartsWith(const std::string_view str, const std::string_view prefix);
55 bool StrEndsWith(const std::string_view str, const std::string_view suffix);
66 return s ==
nullptr || s[0] ==
'\0';
76 static inline size_t ttd_strnlen(
const char *str,
size_t maxlen)
79 for (t = str; (size_t)(t - str) < maxlen && *t !=
'\0'; t++) {}
83 char *
md5sumToString(
char *buf,
const char *last,
const uint8 md5sum[16]);
93 static inline WChar Utf8Consume(
const char **s)
100 template <
class Titr>
101 static inline WChar Utf8Consume(Titr &s)
115 if (c < 0x80)
return 1;
116 if (c < 0x800)
return 2;
117 if (c < 0x10000)
return 3;
118 if (c < 0x110000)
return 4;
134 if (
GB(c, 3, 5) == 0x1E)
return 4;
135 if (
GB(c, 4, 4) == 0x0E)
return 3;
136 if (
GB(c, 5, 3) == 0x06)
return 2;
137 if (
GB(c, 7, 1) == 0x00)
return 1;
145 static inline bool IsUtf8Part(
char c)
147 return GB(c, 6, 2) == 2;
160 while (IsUtf8Part(*--ret)) {}
167 while (IsUtf8Part(*--ret)) {}
181 return c >= 0xD800 && c <= 0xDBFF;
191 return c >= 0xDC00 && c <= 0xDFFF;
202 return 0x10000 + (((lead - 0xD800) << 10) | (trail - 0xDC00));
242 static inline bool IsPrintable(
WChar c)
244 if (c < 0x20)
return false;
245 if (c < 0xE000)
return true;
246 if (c < 0xE200)
return false;
259 return c == 0x0020 || c == 0x3000;
263 #if defined(__NetBSD__) || defined(__FreeBSD__)
264 #include <sys/param.h>
268 #if defined(_GNU_SOURCE) || (defined(__BSD_VISIBLE) && __BSD_VISIBLE) || (defined(__APPLE__) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))) || defined(_NETBSD_SOURCE)
269 # undef DEFINE_STRCASESTR
271 # define DEFINE_STRCASESTR
272 char *strcasestr(
const char *haystack,
const char *needle);
275 int strnatcmp(
const char *s1,
const char *s2,
bool ignore_garbage_at_front =
false);
char * strecat(char *dst, const char *src, const char *last) NOACCESS(3)
Appends characters from one string to another.
size_t Utf8Decode(WChar *c, const char *s)
Decode and consume the next UTF-8 encoded character.
char * stredup(const char *src, const char *last=nullptr) NOACCESS(2)
Create a duplicate of the given string.
char32_t WChar
Type for wide characters, i.e.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
void StrTrimInPlace(std::string &str)
Trim the spaces from given string in place, i.e.
static int8 Utf8CharLen(WChar c)
Return the length of a UTF-8 encoded character.
static const WChar CHAR_TD_LRO
Force the following characters to be treated as left-to-right characters.
size_t Utf8Encode(T buf, WChar c)
Encode a unicode character and place it in the buffer.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front=false)
Compares two strings using case insensitive natural sort.
static const WChar CHAR_TD_RLO
Force the following characters to be treated as right-to-left characters.
static WChar Utf16DecodeChar(const uint16 *c)
Decode an UTF-16 character.
char *CDECL 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).
bool StrValid(const char *str, const char *last) NOACCESS(2)
Checks whether the given string is valid, i.e.
bool StrStartsWith(const std::string_view str, const std::string_view prefix)
Check whether the given string starts with the given prefix.
size_t Utf8TrimString(char *s, size_t maxlen)
Properly terminate an UTF8 string to some maximum length.
bool StrEndsWith(const std::string_view str, const std::string_view suffix)
Check whether the given string ends with the given suffix.
bool IsValidChar(WChar key, CharSetFilter afilter)
Only allow certain keys.
bool strtolower(char *str)
Convert a given ASCII string to lowercase.
static const WChar CHAR_TD_RLE
The following text is embedded right-to-left.
static WChar Utf16DecodeSurrogate(uint lead, uint trail)
Convert an UTF-16 surrogate pair to the corresponding Unicode character.
static const WChar CHAR_TD_PDF
Restore the text-direction state to before the last LRE, RLE, LRO or RLO.
static const WChar CHAR_TD_LRE
The following text is embedded left-to-right.
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 th...
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
static bool Utf16IsLeadSurrogate(uint c)
Is the given character a lead surrogate code point?
static const WChar CHAR_TD_RLM
The next character acts like a right-to-left character.
static size_t ttd_strnlen(const char *str, size_t maxlen)
Get the length of a string, within a limited buffer.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
fluid_settings_t * settings
FluidSynth settings handle.
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
Safer implementation of vsnprintf; same as vsnprintf except:
void str_strip_colours(char *str)
Scans the string for colour codes and strips them.
StringValidationSettings
Settings for the string validation.
char * strecpy(char *dst, const char *src, const char *last) NOACCESS(3)
Copies characters from one buffer to another.
std::string StrMakeValid(const std::string &str, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Scans the string for invalid characters and replaces then with a question mark '?' (if not ignored).
char *CDECL str_fmt(const char *str,...)
Format, "printf", into a newly allocated string.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
static const WChar CHAR_TD_LRM
The next character acts like a left-to-right character.
static bool IsWhitespace(WChar c)
Check whether UNICODE character is whitespace or not, i.e.
void str_fix_scc_encoded(char *str, const char *last) NOACCESS(2)
Scan the string for old values of SCC_ENCODED and fix it to it's new, static value.
@ SVS_REPLACE_WITH_QUESTION_MARK
Replace the unknown/bad bits with question marks.
static bool Utf16IsTrailSurrogate(uint c)
Is the given character a lead surrogate code point?
CharSetFilter
Valid filter types for IsValidChar.
static bool IsTextDirectionChar(WChar c)
Is the given character a text direction character.
static char * Utf8PrevChar(char *s)
Retrieve the previous UNICODE character in an UTF-8 encoded string.
static int8 Utf8EncodedCharLen(char c)
Return the length of an UTF-8 encoded value based on a single char.