34 char *
strecat(
char *dst,
const char *src,
const char *last);
35 char *
strecpy(
char *dst,
const char *src,
const char *last);
36 char *
stredup(
const char *src,
const char *last = NULL);
38 int CDECL
seprintf(
char *str,
const char *last,
const char *format, ...) WARN_FORMAT(3, 4);
39 int CDECL
vseprintf(
char *str, const
char *last, const
char *format, va_list ap);
41 char *CDECL
str_fmt(const
char *str, ...) WARN_FORMAT(1, 2);
50 bool StrValid(const
char *str, const
char *last);
61 return s == NULL || s[0] ==
'\0';
71 static inline size_t ttd_strnlen(
const char *str,
size_t maxlen)
74 for (t = str; (size_t)(t - str) < maxlen && *t !=
'\0'; t++) {}
78 char *
md5sumToString(
char *buf,
const char *last,
const uint8 md5sum[16]);
87 static inline WChar Utf8Consume(
const char **s)
101 if (c < 0x80)
return 1;
102 if (c < 0x800)
return 2;
103 if (c < 0x10000)
return 3;
104 if (c < 0x110000)
return 4;
120 if (
GB(c, 3, 5) == 0x1E)
return 4;
121 if (
GB(c, 4, 4) == 0x0E)
return 3;
122 if (
GB(c, 5, 3) == 0x06)
return 2;
123 if (
GB(c, 7, 1) == 0x00)
return 1;
131 static inline bool IsUtf8Part(
char c)
133 return GB(c, 6, 2) == 2;
146 while (IsUtf8Part(*--ret)) {}
153 while (IsUtf8Part(*--ret)) {}
166 return c >= 0xD800 && c <= 0xDBFF;
176 return c >= 0xDC00 && c <= 0xDFFF;
187 return 0x10000 + (((lead - 0xD800) << 10) | (trail - 0xDC00));
227 static inline bool IsPrintable(
WChar c)
229 if (c < 0x20)
return false;
230 if (c < 0xE000)
return true;
231 if (c < 0xE200)
return false;
244 return c == 0x0020 || c == 0x3000;
248 #if defined(__NetBSD__) || defined(__FreeBSD__) 249 #include <sys/param.h> 253 #if defined(_GNU_SOURCE) || (defined(__BSD_VISIBLE) && __BSD_VISIBLE) || (defined(__APPLE__) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))) || defined(_NETBSD_SOURCE) 254 # undef DEFINE_STRCASESTR 256 # define DEFINE_STRCASESTR 257 char *strcasestr(
const char *haystack,
const char *needle);
260 int strnatcmp(
const char *s1,
const char *s2,
bool ignore_garbage_at_front =
false);
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 *CDECL str_fmt(const char *str,...)
Format, "printf", into a newly allocated string.
static const WChar CHAR_TD_LRM
The next character acts like a left-to-right character.
bool IsValidChar(WChar key, CharSetFilter afilter)
Only allow certain keys.
static const WChar CHAR_TD_LRE
The following text is embedded left-to-right.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
static bool IsWhitespace(WChar c)
Check whether UNICODE character is whitespace or not, i.e.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static bool IsTextDirectionChar(WChar c)
Is the given character a text direction character.
char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
Functions related to bit mathematics.
StringValidationSettings
Settings for the string validation.
static int8 Utf8EncodedCharLen(char c)
Return the length of an UTF-8 encoded value based on a single char.
size_t Utf8Decode(WChar *c, const char *s)
Decode and consume the next UTF-8 encoded character.
static WChar Utf16DecodeChar(const uint16 *c)
Decode an UTF-16 character.
void ValidateString(const char *str)
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mar...
size_t Utf8TrimString(char *s, size_t maxlen)
Properly terminate an UTF8 string to some maximum length.
bool strtolower(char *str)
Convert a given ASCII string to lowercase.
static int8 Utf8CharLen(WChar c)
Return the length of a UTF-8 encoded character.
int CDECL int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
Safer implementation of vsnprintf; same as vsnprintf except:
static const WChar CHAR_TD_RLE
The following text is embedded right-to-left.
CharSetFilter
Valid filter types for IsValidChar.
static WChar Utf16DecodeSurrogate(uint lead, uint trail)
Convert an UTF-16 surrogate pair to the corresponding Unicode character.
size_t Utf8Encode(char *buf, WChar c)
Encode a unicode character and place it in the buffer.
static const WChar CHAR_TD_PDF
Restore the text-direction state to before the last LRE, RLE, LRO or RLO.
char * stredup(const char *src, const char *last=NULL)
Create a duplicate of the given string.
static bool Utf16IsTrailSurrogate(uint c)
Is the given character a lead surrogate code point?
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 mar...
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.
void str_strip_colours(char *str)
Scans the string for colour codes and strips them.
Replace the unknown/bad bits with question marks.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static const WChar CHAR_TD_RLM
The next character acts like a right-to-left character.
static char * Utf8PrevChar(char *s)
Retrieve the previous UNICODE character in an UTF-8 encoded string.
bool StrValid(const char *str, const char *last)
Checks whether the given string is valid, i.e.
static bool Utf16IsLeadSurrogate(uint c)
Is the given character a lead surrogate code point?
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.
uint32 WChar
Type for wide characters, i.e.
static const WChar CHAR_TD_LRO
Force the following characters to be treated as left-to-right characters.
static const WChar CHAR_TD_RLO
Force the following characters to be treated as right-to-left characters.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front=false)
Compares two strings using case insensitive natural sort.