utils/string.h file

String utilities.

Contents

Functions

auto string_is_ascii(const char* string) -> int
Returns if the string is ASCII.
auto string_array_contains_substr(char** str_array, int num_str, const char* substr) -> char*
Returns the matched string if the string array contains the given substring.
auto string_contains_substr(const char* str, const char* substr) -> bool
Returns if the given string contains the given substring.
void string_to_upper(const char* in, char* out)
Converts the given string to uppercase in out.
void string_to_lower(const char* in, char* out)
Converts the given string to lowercase in out.
auto string_is_equal_ignore_case(const char* str1, const char* str2) -> bool
Returns if the two strings are equal ignoring case.
auto string_convert_to_filename(const char* str) -> char*
Returns a newly allocated string that is a filename version of the given string.
auto string_get_substr_before_suffix(const char* str, const char* suffix) -> MALLOC NONNULL char*
Removes the suffix starting from suffix from full_str and returns a newly allocated string.
auto string_remove_until_after_first_match(const char* str, const char* match) -> char*
Removes everything up to and including the first match of match from the start of the string and returns a newly allocated string.
void string_replace_regex(char** str, const char* regex, const char* replace_str)
Replaces src_str with replace_str in all instances matched by regex.
auto string_get_regex_group(const char* str, const char* regex, int group) -> char*
Gets the string in the given regex group.
auto string_get_regex_group_as_int(const char* str, const char* regex, int group, int def) -> int
Gets the string in the given regex group as an integer.
auto string_get_int_after_last_space(const char* str, char* str_without_num) -> int
Returns the integer found at the end of a string like "My String 3" -> 3, or -1 if no number is found.
auto string_array_sort_and_remove_duplicates(char** str_arr) -> char**
TODO Sorts the given string array and removes duplicates.
void string_copy_w_realloc(char** dest, const char* src)
Copies the string src to the buffer in dest after reallocating the buffer in dest to the length of src.
auto string_symbolify(const char* in) -> char*
Returns a new string with only ASCII alphanumeric characters and replaces the rest with underscore.
auto string_is_empty(const char* str) -> PURE bool
Returns whether the string is NULL or empty.
auto string_utf8_strcasecmp(const char* s1, const char* s2) -> int
Compares two UTF-8 strings using approximate case-insensitive ordering.

Defines

#define string_is_equal(str1, str2)
Returns if the two strings are exactly equal.