2#ifndef __ASE_STRINGS_HH__
3#define __ASE_STRINGS_HH__
12#define ASE_STRING_SET_ASCII_ALNUM "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
13#define ASE_STRING_SET_LOWER_ALNUM "0123456789" "abcdefghijklmnopqrstuvwxyz"
16bool cstring_to_bool (
const char *
string,
bool fallback =
false);
17const char* strrstr (
const char *haystack,
const char *needle);
32bool string_is_ascii_alnum (
const String &str);
60 const String &delim =
" ");
65 const String &uuid_string2);
96StringS strings_version_sort (const
StringS &strings,
bool reverse = false);
97void strings_version_sort (
StringS *strings,
bool reverse = false);
112{
static_assert (!
sizeof (Type),
"string_to_type<>: unsupported Type"); __builtin_unreachable(); }
116{
static_assert (!
sizeof (Type),
"string_from_type<>: unsupported Type"); __builtin_unreachable(); }
121template<>
inline double string_to_type<double> (
const String &
string) {
return string_to_double (
string); }
123template<>
inline float string_to_type<float> (
const String &
string) {
return string_to_float (
string); }
125template<>
inline bool string_to_type<bool> (
const String &
string) {
return string_to_bool (
string); }
131template<>
inline int string_to_type<int> (
const String &
string) {
return string_to_int (
string); }
139template<>
inline String string_to_type<String> (
const String &
string) {
return string; }
140template<>
inline String string_from_type<String> (
String value) {
return value; }
153bool kvpairs_assign (
StringS &kvs,
const String &key_value_pair,
bool casesensitive =
true);
171 explicit Strings (
CS &s1,
CS &s2,
CS &s3,
CS &s4,
CS &s5,
CS &s6,
CS &s7,
CS &s8,
CS &s9,
CS &sA,
CS &sB);
172 explicit Strings (
CS &s1,
CS &s2,
CS &s3,
CS &s4,
CS &s5,
CS &s6,
CS &s7,
CS &s8,
CS &s9,
CS &sA,
CS &sB,
CS &sC);
178 const String &from_charset,
179 const String &input_string,
180 const String &fallback_charset =
"ISO-8859-15",
181 const String &output_mark =
"");
184const char*
strerror (
int errno_num);
188#define ASE_STRING_VECTOR_FROM_ARRAY(ConstCharArray) ({ \
190 const Ase::uint64 __l = ASE_ARRAY_SIZE (ConstCharArray); \
191 for (Ase::uint64 __ai = 0; __ai < __l; __ai++) \
192 __a.push_back (ConstCharArray[__ai]); \
194#define ASE_CQUOTE(str) (Ase::string_to_cquote (str).c_str())
Convenience Constructor for StringSeq or std::vector<std::string>
The Anklang C++ API namespace.
bool string_isupper(const String &str)
Check if all string characters are Unicode upper case characters.
String string_to_identifier(const String &input)
Force lower case, alphanumerics + underscore and non-digit start.
std::vector< double > string_to_double_vector(const String &string)
Parse a string into a list of doubles, expects ';' as delimiter.
int string_cmp(const String &s1, const String &s2)
Like strcmp(3) for UTF-8 strings.
String string_from_cquote(const String &input)
Parse a possibly quoted C string into regular string.
String string_from_errno(int errno_val)
Returns a String describing the passed in errno value, similar to strerror().
uint64_t uint64
A 64-bit unsigned integer, use PRI*64 in format strings.
String string_casefold(const String &src)
Yield UTF-8 string useful for case insensitive comparisons.
String string_join(const String &junctor, const StringS &strvec)
bool string_is_uuid(const String &uuid_string)
Returns whether uuid_string contains a properly formatted UUID string.
String string_totitle(const String &str)
Convert all string characters into Unicode title characters.
Type string_to_type(const String &string)
Convert a string to template argument type, such as bool, int, double.
String string_vprintf(const char *format, va_list vargs)
Formatted printing ala vprintf() into a String, using the POSIX/C locale.
StringS string_split(const String &string, const String &splitter, size_t maxn)
String string_hexdump(const void *addr, size_t length, size_t initial_offset)
bool string_is_canonified(const String &string, const String &valid_chars)
Check if string_canonify() would modify string.
int16_t int16
A 16-bit signed integer.
String string_from_long_double(long double value)
Convert a long double into a string, using the POSIX/C locale.
String string_to_hex(const String &input)
Convert bytes in string input to hexadecimal numbers.
String string_from_double(double value)
Convert a double into a string, using the POSIX/C locale.
String string_tolower(const String &str)
Convert all string characters into Unicode lower case characters.
bool string_match_identifier_tail(const String &ident, const String &tail)
Variant of string_match_identifier() that matches tail against ident at word boundary.
String string_lstrip(const String &input)
Strip whitespaces from the left of a string.
bool string_option_check(const String &optionlist, const String &feature)
Check if an option is set/unset in an options list string.
std::vector< String > StringS
Convenience alias for a std::vector<std::string>.
int64_t int64
A 64-bit unsigned integer, use PRI*64 in format strings.
String string_capitalize(const String &str, size_t maxn, bool rest_tolower)
Capitalize words, so the first letter is upper case, the rest lower case.
String string_vector_find_value(const StringS &svector, const String &prefix, const String &fallback)
String string_rstrip(const String &input)
Strip whitespaces from the right of a string.
String string_toupper(const String &str)
Convert all string characters into Unicode upper case characters.
String string_normalize_nfd(const String &src)
Yield normalized decomposed UTF-8 string.
int string_cmp_uuid(const String &uuid_string1, const String &uuid_string2)
Returns whether uuid_string1 compares smaller (-1), equal (0) or greater (+1) to uuid_string2.
int string_casecmp(const String &s1, const String &s2)
Like strcasecmp(3) for UTF-8 strings.
String string_from_int(int64 value)
Convert a 64bit signed integer into a string.
String string_from_uint(uint64 value)
Convert a 64bit unsigned integer into a string.
const char * string_find_word(const char *haystack, const char *word)
Find occurance of word in haystack.
String string_from_double_vector(const std::vector< double > &dvec, const String &delim)
Construct a string out of all double values passed in dvec, separated by delim.
void string_vector_erase_empty(StringS &svector)
Remove empty elements from a string vector.
long double posix_locale_strtold(const char *nptr, char **endptr)
Parse a double from a string ala strtod(), trying locale specific characters and POSIX/C formatting.
String string_from_pretty_function_name(const char *cxx_pretty_function)
double string_to_seconds(const String &string, double fallback)
Parse string into seconds.
StringS cstrings_to_vector(const char *s,...)
Construct a StringS from a NULL terminated list of string arguments.
const String & string_set_ascii_alnum()
Returns a string containing all of 0-9, A-Z and a-z.
long double string_to_long_double(const String &string)
Parse a long double from a string, trying locale specific characters and POSIX/C formatting.
int64 string_to_int(const String &string, size_t *consumed, uint base)
Parse a string into a 64bit integer, optionally specifying the expected number base.
String string_replace(const String &input, const String &marker, const String &replacement, size_t maxn)
Replace substring marker in input with replacement, at most maxn times.
StringS string_split_any(const String &string, const String &splitchars, size_t maxn)
String string_normalize_nfkc(const String &src)
Formatting stripped normalized composed UTF-8 string.
void string_vector_strip(StringS &svector)
Strip all elements of a string vector, see string_strip().
String string_url_decode(const String &urlstr, const bool form_url_encoded)
Decode URL %-sequences in a string, decode '+' if form_url_encoded.
String string_option_find(const String &optionlist, const String &feature, const String &fallback)
Retrieve the option value from an options list separated by ':' or ';' or fallback.
uint64 string_to_uint(const String &string, size_t *consumed, uint base)
Parse a string into a 64bit unsigned integer, optionally specifying the expected number base.
double string_to_double(const String &string)
Parse a double from a string, trying locale specific characters and POSIX/C formatting.
uint16_t uint16
A 16-bit unsigned integer.
const String & string_set_a2z()
Returns a string containing all of a-z.
bool string_has_int(const String &string)
Checks if a string contains a digit, optionally preceeded by whitespaces.
String string_normalize_nfkd(const String &src)
Formatting stripped normalized decomposed UTF-8 string.
String string_normalize_nfc(const String &src)
Yield normalized composed UTF-8 string.
std::string String
Convenience alias for std::string.
String string_vector_find(const StringS &svector, const String &prefix, const String &fallback)
bool string_to_bool(const String &string, bool fallback)
void string_vector_rstrip(StringS &svector)
Right-strip all elements of a string vector, see string_rstrip().
String string_multiply(const String &s, uint64 count)
Reproduce a string s for count times.
long double current_locale_strtold(const char *nptr, char **endptr)
Parse a double from a string ala strtod(), trying locale specific characters and POSIX/C formatting.
String string_canonify(const String &string, const String &valid_chars, const String &substitute)
String string_strip(const String &input)
Strip whitespaces from the left and right of a string.
const String & string_set_A2Z()
Returns a string containing all of A-Z.
String string_from_bool(bool value)
Convert a boolean value into a string.
uint32_t uint32
A 32-bit unsigned integer.
uint32_t uint
Provide 'uint' as convenience type.
String string_url_encode(const String &rawstr, const bool form_url_encoded)
Encode special characters to URL %-sequences, encode space as '+' if form_url_encoded.
bool string_endswith(const String &string, const String &fragment)
Returns whether string ends with fragment.
String string_substitute_char(const String &input, const char match, const char subst)
Replace all occouranes of match in input with subst.
bool string_islower(const String &str)
Check if all string characters are Unicode lower case characters.
bool string_match_identifier(const String &ident1, const String &ident2)
Check equality of strings canonicalized to "[0-9a-z_]+".
bool text_convert(const String &to_charset, String &output_string, const String &from_charset, const String &input_string, const String &fallback_charset, const String &output_mark)
String string_to_cquote(const String &str)
Returns a string as C string including double quotes.
std::string_view string_option_find_value(const char *string, const char *feature, const char *fallback, const char *denied, bool matchallnone)
Low level option search, avoids dynamic allocations.
String string_from_float(float value)
Convert a float into a string, using the POSIX/C locale.
String string_from_type(Type value)
Create a string from a templated argument value, such as bool, int, double.
void string_vector_lstrip(StringS &svector)
Left-strip all elements of a string vector, see string_lstrip().
void memset4(uint32 *mem, uint32 filler, uint length)
Fill a memory area with a 32-bit quantitiy.
String string_to_cescape(const String &str)
String string_locale_vprintf(const char *format, va_list vargs)
Formatted printing like string_vprintf using the current locale.
bool string_startswith(const String &string, const String &fragment)
Returns whether string starts with fragment.