20void strecpy(std::span<char> dst, std::string_view src);
28bool strtolower(std::string &str, std::string::size_type offs = 0);
30[[nodiscard]]
bool StrValid(std::span<const char> str);
32std::string_view StrTrimView(std::string_view str);
38[[nodiscard]]
bool StrEqualsIgnoreCase(
const std::string_view str1,
const std::string_view str2);
39[[nodiscard]]
int StrNaturalCompare(std::string_view s1, std::string_view s2,
bool ignore_garbage_at_front =
false);
40[[nodiscard]]
bool StrNaturalContains(
const std::string_view str,
const std::string_view value);
47 bool operator()(
const std::string_view s1,
const std::string_view s2)
const {
return StrCompareIgnoreCase(s1, s2) < 0; }
59 return s ==
nullptr || s[0] ==
'\0';
72 for (t = str;
static_cast<size_t>(t - str) < maxlen && *t !=
'\0'; t++) {}
80size_t Utf8Encode(std::ostreambuf_iterator<char> &buf,
char32_t c);
81size_t Utf8Encode(std::back_insert_iterator<std::string> &buf,
char32_t c);
85inline char32_t Utf8Consume(
const char **s)
93inline char32_t Utf8Consume(Titr &s)
107 if (c < 0x80)
return 1;
108 if (c < 0x800)
return 2;
109 if (c < 0x10000)
return 3;
110 if (c < 0x110000)
return 4;
126 if (
GB(c, 3, 5) == 0x1E)
return 4;
127 if (
GB(c, 4, 4) == 0x0E)
return 3;
128 if (
GB(c, 5, 3) == 0x06)
return 2;
129 if (
GB(c, 7, 1) == 0x00)
return 1;
137inline bool IsUtf8Part(
char c)
139 return GB(c, 6, 2) == 2;
152 while (IsUtf8Part(*--ret)) {}
159 while (IsUtf8Part(*--ret)) {}
173 return c >= 0xD800 && c <= 0xDBFF;
183 return c >= 0xDC00 && c <= 0xDFFF;
194 return 0x10000 + (((lead - 0xD800) << 10) | (trail - 0xDC00));
234inline bool IsPrintable(
char32_t c)
236 if (c < 0x20)
return false;
237 if (c < 0xE000)
return true;
238 if (c < 0xE200)
return false;
251 return c == 0x0020 || c == 0x3000;
255#if defined(__NetBSD__) || defined(__FreeBSD__)
256#include <sys/param.h>
260#if defined(_GNU_SOURCE) || (defined(__BSD_VISIBLE) && __BSD_VISIBLE) || (defined(__APPLE__) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))) || defined(_NETBSD_SOURCE)
261# undef DEFINE_STRCASESTR
263# define DEFINE_STRCASESTR
264char *strcasestr(
const char *haystack,
const char *needle);
Functions related to bit mathematics.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
fluid_settings_t * settings
FluidSynth settings handle.
size_t Utf8Encode(T buf, char32_t c)
Encode a unicode character and place it in the buffer.
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.
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 StrEmpty(const char *s)
Check if a string buffer is empty.
bool Utf16IsLeadSurrogate(uint c)
Is the given character a lead surrogate code point?
bool IsValidChar(char32_t key, CharSetFilter afilter)
Only allow certain keys.
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 IsWhitespace(char32_t c)
Check whether UNICODE character is whitespace or not, i.e.
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 sensiti...
int8_t Utf8EncodedCharLen(char c)
Return the length of an UTF-8 encoded value based on a single char.
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.
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...
bool StrStartsWithIgnoreCase(std::string_view str, const std::string_view prefix)
Check whether the given string starts with the given prefix, ignoring case.
bool StrValid(std::span< const char > str)
Checks whether the given string is valid, i.e.
size_t Utf8Decode(char32_t *c, const char *s)
Decode and consume the next UTF-8 encoded character.
std::string StrMakeValid(std::string_view str, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Copies the valid (UTF-8) characters from str to the returned string.
int8_t Utf8CharLen(char32_t c)
Return the length of a UTF-8 encoded character.
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 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 insensi...
bool Utf16IsTrailSurrogate(uint c)
Is the given character a lead surrogate code point?
int StrCompareIgnoreCase(const std::string_view str1, const std::string_view str2)
Compares two string( view)s, while ignoring the case of the characters.
char * Utf8PrevChar(char *s)
Retrieve the previous UNICODE character in an UTF-8 encoded string.
bool IsTextDirectionChar(char32_t c)
Is the given character a text direction character.
bool StrEndsWithIgnoreCase(std::string_view str, const std::string_view suffix)
Check whether the given string ends with the given suffix, ignoring case.
size_t Utf8TrimString(char *s, size_t maxlen)
Properly terminate an UTF8 string to some maximum length.
void StrTrimInPlace(std::string &str)
Trim the spaces from given string in place, i.e.
size_t ttd_strnlen(const char *str, size_t maxlen)
Get the length of a string, within a limited buffer.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front=false)
Compares two strings using case insensitive natural sort.
CharSetFilter
Valid filter types for IsValidChar.
static const char32_t CHAR_TD_RLE
The following text is embedded right-to-left.
static const char32_t CHAR_TD_LRO
Force the following characters to be treated as left-to-right characters.
StringValidationSettings
Settings for the string validation.
@ SVS_REPLACE_WITH_QUESTION_MARK
Replace the unknown/bad bits with question marks.
static const char32_t CHAR_TD_LRM
The next character acts like a left-to-right character.
static const char32_t CHAR_TD_RLO
Force the following characters to be treated as right-to-left characters.
static const char32_t CHAR_TD_LRE
The following text is embedded left-to-right.
static const char32_t CHAR_TD_RLM
The next character acts like a right-to-left character.
static const char32_t CHAR_TD_PDF
Restore the text-direction state to before the last LRE, RLE, LRO or RLO.
Case insensitive comparator for strings, for example for use in std::map.