diff --git a/components/tactility-core/src/core.h b/components/tactility-core/src/core.h index c7da5bfc..1bc7b294 100644 --- a/components/tactility-core/src/core.h +++ b/components/tactility-core/src/core.h @@ -14,7 +14,6 @@ #include "string.h" #include "thread.h" #include "timer.h" -#include "tt_string.h" #ifdef __cplusplus extern "C" { diff --git a/components/tactility-core/src/tt_string.c b/components/tactility-core/src/tt_string.c deleted file mode 100644 index 9370d817..00000000 --- a/components/tactility-core/src/tt_string.c +++ /dev/null @@ -1,305 +0,0 @@ -#include "tt_string.h" -#include - -struct TtString { - string_t string; - // TODO store optional hash for quick string comparison -}; - -#undef tt_string_alloc_set -#undef tt_string_set -#undef tt_string_cmp -#undef tt_string_cmpi -#undef tt_string_search -#undef tt_string_search_str -#undef tt_string_equal -#undef tt_string_replace -#undef tt_string_replace_str -#undef tt_string_replace_all -#undef tt_string_start_with -#undef tt_string_end_with -#undef tt_string_search_char -#undef tt_string_search_rchar -#undef tt_string_trim -#undef tt_string_cat - -TtString* tt_string_alloc() { - TtString* string = malloc(sizeof(TtString)); - string_init(string->string); - return string; -} - -TtString* tt_string_alloc_set(const TtString* s) { - TtString* string = malloc(sizeof(TtString)); //-V799 - string_init_set(string->string, s->string); - return string; -} //-V773 - -TtString* tt_string_alloc_set_str(const char cstr[]) { - TtString* string = malloc(sizeof(TtString)); //-V799 - string_init_set(string->string, cstr); - return string; -} //-V773 - -TtString* tt_string_alloc_printf(const char format[], ...) { - va_list args; - va_start(args, format); - TtString* string = tt_string_alloc_vprintf(format, args); - va_end(args); - return string; -} - -TtString* tt_string_alloc_vprintf(const char format[], va_list args) { - TtString* string = malloc(sizeof(TtString)); - string_init_vprintf(string->string, format, args); - return string; -} - -TtString* tt_string_alloc_move(TtString* s) { - TtString* string = malloc(sizeof(TtString)); - string_init_move(string->string, s->string); - free(s); - return string; -} - -void tt_string_free(TtString* s) { - string_clear(s->string); - free(s); -} - -void tt_string_reserve(TtString* s, size_t alloc) { - string_reserve(s->string, alloc); -} - -void tt_string_reset(TtString* s) { - string_reset(s->string); -} - -void tt_string_swap(TtString* v1, TtString* v2) { - string_swap(v1->string, v2->string); -} - -void tt_string_move(TtString* v1, TtString* v2) { - string_clear(v1->string); - string_init_move(v1->string, v2->string); - free(v2); -} - -size_t tt_string_hash(const TtString* v) { - return string_hash(v->string); -} - -char tt_string_get_char(const TtString* v, size_t index) { - return string_get_char(v->string, index); -} - -const char* tt_string_get_cstr(const TtString* s) { - return string_get_cstr(s->string); -} - -void tt_string_set(TtString* s, TtString* source) { - string_set(s->string, source->string); -} - -void tt_string_set_str(TtString* s, const char cstr[]) { - string_set(s->string, cstr); -} - -void tt_string_set_strn(TtString* s, const char str[], size_t n) { - string_set_strn(s->string, str, n); -} - -void tt_string_set_char(TtString* s, size_t index, const char c) { - string_set_char(s->string, index, c); -} - -int tt_string_cmp(const TtString* s1, const TtString* s2) { - return string_cmp(s1->string, s2->string); -} - -int tt_string_cmp_str(const TtString* s1, const char str[]) { - return string_cmp(s1->string, str); -} - -int tt_string_cmpi(const TtString* v1, const TtString* v2) { - return string_cmpi(v1->string, v2->string); -} - -int tt_string_cmpi_str(const TtString* v1, const char p2[]) { - return string_cmpi_str(v1->string, p2); -} - -size_t tt_string_search(const TtString* v, const TtString* needle, size_t start) { - return string_search(v->string, needle->string, start); -} - -size_t tt_string_search_str(const TtString* v, const char needle[], size_t start) { - return string_search(v->string, needle, start); -} - -bool tt_string_equal(const TtString* v1, const TtString* v2) { - return string_equal_p(v1->string, v2->string); -} - -bool tt_string_equal_str(const TtString* v1, const char v2[]) { - return string_equal_p(v1->string, v2); -} - -void tt_string_push_back(TtString* v, char c) { - string_push_back(v->string, c); -} - -size_t tt_string_size(const TtString* s) { - return string_size(s->string); -} - -int tt_string_printf(TtString* v, const char format[], ...) { - va_list args; - va_start(args, format); - int result = tt_string_vprintf(v, format, args); - va_end(args); - return result; -} - -int tt_string_vprintf(TtString* v, const char format[], va_list args) { - return string_vprintf(v->string, format, args); -} - -int tt_string_cat_printf(TtString* v, const char format[], ...) { - va_list args; - va_start(args, format); - int result = tt_string_cat_vprintf(v, format, args); - va_end(args); - return result; -} - -int tt_string_cat_vprintf(TtString* v, const char format[], va_list args) { - TtString* string = tt_string_alloc(); - int ret = tt_string_vprintf(string, format, args); - tt_string_cat(v, string); - tt_string_free(string); - return ret; -} - -bool tt_string_empty(const TtString* v) { - return string_empty_p(v->string); -} - -void tt_string_replace_at(TtString* v, size_t pos, size_t len, const char str2[]) { - string_replace_at(v->string, pos, len, str2); -} - -size_t -tt_string_replace(TtString* string, TtString* needle, TtString* replace, size_t start) { - return string_replace(string->string, needle->string, replace->string, start); -} - -size_t tt_string_replace_str(TtString* v, const char str1[], const char str2[], size_t start) { - return string_replace_str(v->string, str1, str2, start); -} - -void tt_string_replace_all_str(TtString* v, const char str1[], const char str2[]) { - string_replace_all_str(v->string, str1, str2); -} - -void tt_string_replace_all(TtString* v, const TtString* str1, const TtString* str2) { - string_replace_all(v->string, str1->string, str2->string); -} - -bool tt_string_start_with(const TtString* v, const TtString* v2) { - return string_start_with_string_p(v->string, v2->string); -} - -bool tt_string_start_with_str(const TtString* v, const char str[]) { - return string_start_with_str_p(v->string, str); -} - -bool tt_string_end_with(const TtString* v, const TtString* v2) { - return string_end_with_string_p(v->string, v2->string); -} - -bool tt_string_end_with_str(const TtString* v, const char str[]) { - return string_end_with_str_p(v->string, str); -} - -size_t tt_string_search_char(const TtString* v, char c, size_t start) { - return string_search_char(v->string, c, start); -} - -size_t tt_string_search_rchar(const TtString* v, char c, size_t start) { - return string_search_rchar(v->string, c, start); -} - -void tt_string_left(TtString* v, size_t index) { - string_left(v->string, index); -} - -void tt_string_right(TtString* v, size_t index) { - string_right(v->string, index); -} - -void tt_string_mid(TtString* v, size_t index, size_t size) { - string_mid(v->string, index, size); -} - -void tt_string_trim(TtString* v, const char charac[]) { - string_strim(v->string, charac); -} - -void tt_string_cat(TtString* v, const TtString* v2) { - string_cat(v->string, v2->string); -} - -void tt_string_cat_str(TtString* v, const char str[]) { - string_cat(v->string, str); -} - -void tt_string_set_n(TtString* v, const TtString* ref, size_t offset, size_t length) { - string_set_n(v->string, ref->string, offset, length); -} - -size_t tt_string_utf8_length(TtString* str) { - return string_length_u(str->string); -} - -void tt_string_utf8_push(TtString* str, TtStringUnicodeValue u) { - string_push_u(str->string, u); -} - -static m_str1ng_utf8_state_e tt_state_to_state(TtStringUTF8State state) { - switch (state) { - case TtStringUTF8StateStarting: - return M_STR1NG_UTF8_STARTING; - case TtStringUTF8StateDecoding1: - return M_STR1NG_UTF8_DECODING_1; - case TtStringUTF8StateDecoding2: - return M_STR1NG_UTF8_DECODING_2; - case TtStringUTF8StateDecoding3: - return M_STR1NG_UTF8_DECODING_3; - default: - return M_STR1NG_UTF8_ERROR; - } -} - -static TtStringUTF8State state_to_tt_state(m_str1ng_utf8_state_e state) { - switch (state) { - case M_STR1NG_UTF8_STARTING: - return TtStringUTF8StateStarting; - case M_STR1NG_UTF8_DECODING_1: - return TtStringUTF8StateDecoding1; - case M_STR1NG_UTF8_DECODING_2: - return TtStringUTF8StateDecoding2; - case M_STR1NG_UTF8_DECODING_3: - return TtStringUTF8StateDecoding3; - default: - return TtStringUTF8StateError; - } -} - -void tt_string_utf8_decode(char c, TtStringUTF8State* state, TtStringUnicodeValue* unicode) { - string_unicode_t m_u = *unicode; - m_str1ng_utf8_state_e m_state = tt_state_to_state(*state); - m_str1ng_utf8_decode(c, &m_state, &m_u); - *state = state_to_tt_state(m_state); - *unicode = m_u; -} diff --git a/components/tactility-core/src/tt_string.h b/components/tactility-core/src/tt_string.h deleted file mode 100644 index 1cf1b0a2..00000000 --- a/components/tactility-core/src/tt_string.h +++ /dev/null @@ -1,738 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief String failure constant. - */ -#define TT_STRING_FAILURE ((size_t)-1) - -/** - * @brief Tactility string primitive. - */ -typedef struct TtString TtString; - -//--------------------------------------------------------------------------- -// Constructors -//--------------------------------------------------------------------------- - -/** - * @brief Allocate new TtString. - * @return TtString* - */ -TtString* tt_string_alloc(); - -/** - * @brief Allocate new TtString and set it to string. - * Allocate & Set the string a to the string. - * @param source - * @return TtString* - */ -TtString* tt_string_alloc_set(const TtString* source); - -/** - * @brief Allocate new TtString and set it to C string. - * Allocate & Set the string a to the C string. - * @param cstr_source - * @return TtString* - */ -TtString* tt_string_alloc_set_str(const char cstr_source[]); - -/** - * @brief Allocate new TtString and printf to it. - * Initialize and set a string to the given formatted value. - * @param format - * @param ... - * @return TtString* - */ -TtString* tt_string_alloc_printf(const char format[], ...) - _ATTRIBUTE((__format__(__printf__, 1, 2))); - -/** - * @brief Allocate new TtString and printf to it. - * Initialize and set a string to the given formatted value. - * @param format - * @param args - * @return TtString* - */ -TtString* tt_string_alloc_vprintf(const char format[], va_list args); - -/** - * @brief Allocate new TtString and move source string content to it. - * Allocate the string, set it to the other one, and destroy the other one. - * @param source - * @return TtString* - */ -TtString* tt_string_alloc_move(TtString* source); - -//--------------------------------------------------------------------------- -// Destructors -//--------------------------------------------------------------------------- - -/** - * @brief Free TtString. - * @param string - */ -void tt_string_free(TtString* string); - -//--------------------------------------------------------------------------- -// String memory management -//--------------------------------------------------------------------------- - -/** - * @brief Reserve memory for string. - * Modify the string capacity to be able to handle at least 'alloc' characters (including final null char). - * @param string - * @param size - */ -void tt_string_reserve(TtString* string, size_t size); - -/** - * @brief Reset string. - * Make the string empty. - * @param s - */ -void tt_string_reset(TtString* string); - -/** - * @brief Swap two strings. - * Swap the two strings string_1 and string_2. - * @param string_1 - * @param string_2 - */ -void tt_string_swap(TtString* string_1, TtString* string_2); - -/** - * @brief Move string_2 content to string_1. - * Set the string to the other one, and destroy the other one. - * @param string_1 - * @param string_2 - */ -void tt_string_move(TtString* string_1, TtString* string_2); - -/** - * @brief Compute a hash for the string. - * @param string - * @return size_t - */ -size_t tt_string_hash(const TtString* string); - -/** - * @brief Get string size (usually length, but not for UTF-8) - * @param string - * @return size_t - */ -size_t tt_string_size(const TtString* string); - -/** - * @brief Check that string is empty or not - * @param string - * @return bool - */ -bool tt_string_empty(const TtString* string); - -//--------------------------------------------------------------------------- -// Getters -//--------------------------------------------------------------------------- - -/** - * @brief Get the character at the given index. - * Return the selected character of the string. - * @param string - * @param index - * @return char - */ -char tt_string_get_char(const TtString* string, size_t index); - -/** - * @brief Return the string view a classic C string. - * @param string - * @return const char* - */ -const char* tt_string_get_cstr(const TtString* string); - -//--------------------------------------------------------------------------- -// Setters -//--------------------------------------------------------------------------- - -/** - * @brief Set the string to the other string. - * Set the string to the source string. - * @param string - * @param source - */ -void tt_string_set(TtString* string, TtString* source); - -/** - * @brief Set the string to the other C string. - * Set the string to the source C string. - * @param string - * @param source - */ -void tt_string_set_str(TtString* string, const char source[]); - -/** - * @brief Set the string to the n first characters of the C string. - * @param string - * @param source - * @param length - */ -void tt_string_set_strn(TtString* string, const char source[], size_t length); - -/** - * @brief Set the character at the given index. - * @param string - * @param index - * @param c - */ -void tt_string_set_char(TtString* string, size_t index, const char c); - -/** - * @brief Set the string to the n first characters of other one. - * @param string - * @param source - * @param offset - * @param length - */ -void tt_string_set_n(TtString* string, const TtString* source, size_t offset, size_t length); - -/** - * @brief Format in the string the given printf format - * @param string - * @param format - * @param ... - * @return int - */ -int tt_string_printf(TtString* string, const char format[], ...) - _ATTRIBUTE((__format__(__printf__, 2, 3))); - -/** - * @brief Format in the string the given printf format - * @param string - * @param format - * @param args - * @return int - */ -int tt_string_vprintf(TtString* string, const char format[], va_list args); - -//--------------------------------------------------------------------------- -// Appending -//--------------------------------------------------------------------------- - -/** - * @brief Append a character to the string. - * @param string - * @param c - */ -void tt_string_push_back(TtString* string, char c); - -/** - * @brief Append a string to the string. - * Concatenate the string with the other string. - * @param string_1 - * @param string_2 - */ -void tt_string_cat(TtString* string_1, const TtString* string_2); - -/** - * @brief Append a C string to the string. - * Concatenate the string with the C string. - * @param string_1 - * @param cstring_2 - */ -void tt_string_cat_str(TtString* string_1, const char cstring_2[]); - -/** - * @brief Append to the string the formatted string of the given printf format. - * @param string - * @param format - * @param ... - * @return int - */ -int tt_string_cat_printf(TtString* string, const char format[], ...) - _ATTRIBUTE((__format__(__printf__, 2, 3))); - -/** - * @brief Append to the string the formatted string of the given printf format. - * @param string - * @param format - * @param args - * @return int - */ -int tt_string_cat_vprintf(TtString* string, const char format[], va_list args); - -//--------------------------------------------------------------------------- -// Comparators -//--------------------------------------------------------------------------- - -/** - * @brief Compare two strings and return the sort order. - * @param string_1 - * @param string_2 - * @return int - */ -int tt_string_cmp(const TtString* string_1, const TtString* string_2); - -/** - * @brief Compare string with C string and return the sort order. - * @param string_1 - * @param cstring_2 - * @return int - */ -int tt_string_cmp_str(const TtString* string_1, const char cstring_2[]); - -/** - * @brief Compare two strings (case insensitive according to the current locale) and return the sort order. - * Note: doesn't work with UTF-8 strings. - * @param string_1 - * @param string_2 - * @return int - */ -int tt_string_cmpi(const TtString* string_1, const TtString* string_2); - -/** - * @brief Compare string with C string (case insensitive according to the current locale) and return the sort order. - * Note: doesn't work with UTF-8 strings. - * @param string_1 - * @param cstring_2 - * @return int - */ -int tt_string_cmpi_str(const TtString* string_1, const char cstring_2[]); - -//--------------------------------------------------------------------------- -// Search -//--------------------------------------------------------------------------- - -/** - * @brief Search the first occurrence of the needle in the string from the position start. - * Return STRING_FAILURE if not found. - * By default, start is zero. - * @param string - * @param needle - * @param start - * @return size_t - */ -size_t tt_string_search(const TtString* string, const TtString* needle, size_t start); - -/** - * @brief Search the first occurrence of the needle in the string from the position start. - * Return STRING_FAILURE if not found. - * @param string - * @param needle - * @param start - * @return size_t - */ -size_t tt_string_search_str(const TtString* string, const char needle[], size_t start); - -/** - * @brief Search for the position of the character c from the position start (include) in the string. - * Return STRING_FAILURE if not found. - * By default, start is zero. - * @param string - * @param c - * @param start - * @return size_t - */ -size_t tt_string_search_char(const TtString* string, char c, size_t start); - -/** - * @brief Reverse search for the position of the character c from the position start (include) in the string. - * Return STRING_FAILURE if not found. - * By default, start is zero. - * @param string - * @param c - * @param start - * @return size_t - */ -size_t tt_string_search_rchar(const TtString* string, char c, size_t start); - -//--------------------------------------------------------------------------- -// Equality -//--------------------------------------------------------------------------- - -/** - * @brief Test if two strings are equal. - * @param string_1 - * @param string_2 - * @return bool - */ -bool tt_string_equal(const TtString* string_1, const TtString* string_2); - -/** - * @brief Test if the string is equal to the C string. - * @param string_1 - * @param cstring_2 - * @return bool - */ -bool tt_string_equal_str(const TtString* string_1, const char cstring_2[]); - -//--------------------------------------------------------------------------- -// Replace -//--------------------------------------------------------------------------- - -/** - * @brief Replace in the string the sub-string at position 'pos' for 'len' bytes into the C string 'replace'. - * @param string - * @param pos - * @param len - * @param replace - */ -void tt_string_replace_at(TtString* string, size_t pos, size_t len, const char replace[]); - -/** - * @brief Replace a string 'needle' to string 'replace' in a string from 'start' position. - * By default, start is zero. - * Return STRING_FAILURE if 'needle' not found or replace position. - * @param string - * @param needle - * @param replace - * @param start - * @return size_t - */ -size_t -tt_string_replace(TtString* string, TtString* needle, TtString* replace, size_t start); - -/** - * @brief Replace a C string 'needle' to C string 'replace' in a string from 'start' position. - * By default, start is zero. - * Return STRING_FAILURE if 'needle' not found or replace position. - * @param string - * @param needle - * @param replace - * @param start - * @return size_t - */ -size_t tt_string_replace_str( - TtString* string, - const char needle[], - const char replace[], - size_t start -); - -/** - * @brief Replace all occurrences of 'needle' string into 'replace' string. - * @param string - * @param needle - * @param replace - */ -void tt_string_replace_all( - TtString* string, - const TtString* needle, - const TtString* replace -); - -/** - * @brief Replace all occurrences of 'needle' C string into 'replace' C string. - * @param string - * @param needle - * @param replace - */ -void tt_string_replace_all_str(TtString* string, const char needle[], const char replace[]); - -//--------------------------------------------------------------------------- -// Start / End tests -//--------------------------------------------------------------------------- - -/** - * @brief Test if the string starts with the given string. - * @param string - * @param start - * @return bool - */ -bool tt_string_start_with(const TtString* string, const TtString* start); - -/** - * @brief Test if the string starts with the given C string. - * @param string - * @param start - * @return bool - */ -bool tt_string_start_with_str(const TtString* string, const char start[]); - -/** - * @brief Test if the string ends with the given string. - * @param string - * @param end - * @return bool - */ -bool tt_string_end_with(const TtString* string, const TtString* end); - -/** - * @brief Test if the string ends with the given C string. - * @param string - * @param end - * @return bool - */ -bool tt_string_end_with_str(const TtString* string, const char end[]); - -//--------------------------------------------------------------------------- -// Trim -//--------------------------------------------------------------------------- - -/** - * @brief Trim the string left to the first 'index' bytes. - * @param string - * @param index - */ -void tt_string_left(TtString* string, size_t index); - -/** - * @brief Trim the string right from the 'index' position to the last position. - * @param string - * @param index - */ -void tt_string_right(TtString* string, size_t index); - -/** - * @brief Trim the string from position index to size bytes. - * See also tt_string_set_n. - * @param string - * @param index - * @param size - */ -void tt_string_mid(TtString* string, size_t index, size_t size); - -/** - * @brief Trim a string from the given set of characters (default is " \n\r\t"). - * @param string - * @param chars - */ -void tt_string_trim(TtString* string, const char chars[]); - -//--------------------------------------------------------------------------- -// UTF8 -//--------------------------------------------------------------------------- - -/** - * @brief An unicode value. - */ -typedef unsigned int TtStringUnicodeValue; - -/** - * @brief Compute the length in UTF8 characters in the string. - * @param string - * @return size_t - */ -size_t tt_string_utf8_length(TtString* string); - -/** - * @brief Push unicode into string, encoding it in UTF8. - * @param string - * @param unicode - */ -void tt_string_utf8_push(TtString* string, TtStringUnicodeValue unicode); - -/** - * @brief State of the UTF8 decoding machine state. - */ -typedef enum { - TtStringUTF8StateStarting, - TtStringUTF8StateDecoding1, - TtStringUTF8StateDecoding2, - TtStringUTF8StateDecoding3, - TtStringUTF8StateError -} TtStringUTF8State; - -/** - * @brief Main generic UTF8 decoder. - * It takes a character, and the previous state and the previous value of the unicode value. - * It updates the state and the decoded unicode value. - * A decoded unicode encoded value is valid only when the state is TtStringUTF8StateStarting. - * @param c - * @param state - * @param unicode - */ -void tt_string_utf8_decode(char c, TtStringUTF8State* state, TtStringUnicodeValue* unicode); - -//--------------------------------------------------------------------------- -// Lasciate ogne speranza, voi ch’entrate -//--------------------------------------------------------------------------- - -/** - * - * Select either the string function or the str function depending on - * the b operand to the function. - * func1 is the string function / func2 is the str function. - */ - -/** - * @brief Select for 1 argument - */ -#define TT_STRING_SELECT1(func1, func2, a) \ - _Generic((a), char*: func2, const char*: func2, TtString*: func1, const TtString*: func1)(a) - -/** - * @brief Select for 2 arguments - */ -#define TT_STRING_SELECT2(func1, func2, a, b) \ - _Generic((b), char*: func2, const char*: func2, TtString*: func1, const TtString*: func1)(a, b) - -/** - * @brief Select for 3 arguments - */ -#define TT_STRING_SELECT3(func1, func2, a, b, c) \ - _Generic((b), char*: func2, const char*: func2, TtString*: func1, const TtString*: func1)(a, b, c) - -/** - * @brief Select for 4 arguments - */ -#define TT_STRING_SELECT4(func1, func2, a, b, c, d) \ - _Generic((b), char*: func2, const char*: func2, TtString*: func1, const TtString*: func1)(a, b, c, d) - -/** - * @brief Allocate new TtString and set it content to string (or C string). - * ([c]string) - */ -#define tt_string_alloc_set(a) \ - TT_STRING_SELECT1(tt_string_alloc_set, tt_string_alloc_set_str, a) - -/** - * @brief Set the string content to string (or C string). - * (string, [c]string) - */ -#define tt_string_set(a, b) TT_STRING_SELECT2(tt_string_set, tt_string_set_str, a, b) - -/** - * @brief Compare string with string (or C string) and return the sort order. - * Note: doesn't work with UTF-8 strings. - * (string, [c]string) - */ -#define tt_string_cmp(a, b) TT_STRING_SELECT2(tt_string_cmp, tt_string_cmp_str, a, b) - -/** - * @brief Compare string with string (or C string) (case insensitive according to the current locale) and return the sort order. - * Note: doesn't work with UTF-8 strings. - * (string, [c]string) - */ -#define tt_string_cmpi(a, b) TT_STRING_SELECT2(tt_string_cmpi, tt_string_cmpi_str, a, b) - -/** - * @brief Test if the string is equal to the string (or C string). - * (string, [c]string) - */ -#define tt_string_equal(a, b) TT_STRING_SELECT2(tt_string_equal, tt_string_equal_str, a, b) - -/** - * @brief Replace all occurrences of string into string (or C string to another C string) in a string. - * (string, [c]string, [c]string) - */ -#define tt_string_replace_all(a, b, c) \ - TT_STRING_SELECT3(tt_string_replace_all, tt_string_replace_all_str, a, b, c) - -/** - * @brief Search for a string (or C string) in a string - * (string, [c]string[, start=0]) - */ -#define tt_string_search(...) \ - M_APPLY( \ - TT_STRING_SELECT3, \ - tt_string_search, \ - tt_string_search_str, \ - M_DEFAULT_ARGS(3, (0), __VA_ARGS__) \ - ) -/** - * @brief Search for a C string in a string - * (string, cstring[, start=0]) - */ -#define tt_string_search_str(...) tt_string_search_str(M_DEFAULT_ARGS(3, (0), __VA_ARGS__)) - -/** - * @brief Test if the string starts with the given string (or C string). - * (string, [c]string) - */ -#define tt_string_start_with(a, b) \ - TT_STRING_SELECT2(tt_string_start_with, tt_string_start_with_str, a, b) - -/** - * @brief Test if the string ends with the given string (or C string). - * (string, [c]string) - */ -#define tt_string_end_with(a, b) \ - TT_STRING_SELECT2(tt_string_end_with, tt_string_end_with_str, a, b) - -/** - * @brief Append a string (or C string) to the string. - * (string, [c]string) - */ -#define tt_string_cat(a, b) TT_STRING_SELECT2(tt_string_cat, tt_string_cat_str, a, b) - -/** - * @brief Trim a string from the given set of characters (default is " \n\r\t"). - * (string[, set=" \n\r\t"]) - */ -#define tt_string_trim(...) tt_string_trim(M_DEFAULT_ARGS(2, (" \n\r\t"), __VA_ARGS__)) - -/** - * @brief Search for a character in a string. - * (string, character[, start=0]) - */ -#define tt_string_search_char(...) tt_string_search_char(M_DEFAULT_ARGS(3, (0), __VA_ARGS__)) - -/** - * @brief Reverse Search for a character in a string. - * (string, character[, start=0]) - */ -#define tt_string_search_rchar(...) tt_string_search_rchar(M_DEFAULT_ARGS(3, (0), __VA_ARGS__)) - -/** - * @brief Replace a string to another string (or C string to another C string) in a string. - * (string, [c]string, [c]string[, start=0]) - */ -#define tt_string_replace(...) \ - M_APPLY( \ - TT_STRING_SELECT4, \ - tt_string_replace, \ - tt_string_replace_str, \ - M_DEFAULT_ARGS(4, (0), __VA_ARGS__) \ - ) - -/** - * @brief Replace a C string to another C string in a string. - * (string, cstring, cstring[, start=0]) - */ -#define tt_string_replace_str(...) tt_string_replace_str(M_DEFAULT_ARGS(4, (0), __VA_ARGS__)) - -/** - * @brief INIT OPLIST for TtString. - */ -#define F_STR_INIT(a) ((a) = tt_string_alloc()) - -/** - * @brief INIT SET OPLIST for TtString. - */ -#define F_STR_INIT_SET(a, b) ((a) = tt_string_alloc_set(b)) - -/** - * @brief INIT MOVE OPLIST for TtString. - */ -#define F_STR_INIT_MOVE(a, b) ((a) = tt_string_alloc_move(b)) - -/** - * @brief OPLIST for TtString. - */ -#define TT_STRING_OPLIST \ - (INIT(F_STR_INIT), \ - INIT_SET(F_STR_INIT_SET), \ - SET(tt_string_set), \ - INIT_MOVE(F_STR_INIT_MOVE), \ - MOVE(tt_string_move), \ - SWAP(tt_string_swap), \ - RESET(tt_string_reset), \ - EMPTY_P(tt_string_empty), \ - CLEAR(tt_string_free), \ - HASH(tt_string_hash), \ - EQUAL(tt_string_equal), \ - CMP(tt_string_cmp), \ - TYPE(TtString*)) - -#ifdef __cplusplus -} -#endif diff --git a/components/tactility/src/services/loader/loader.h b/components/tactility/src/services/loader/loader.h index 433acee7..07312b74 100644 --- a/components/tactility/src/services/loader/loader.h +++ b/components/tactility/src/services/loader/loader.h @@ -5,7 +5,6 @@ #include "pubsub.h" #include "service_manifest.h" #include "tactility_core.h" -#include "tt_string.h" #ifdef __cplusplus extern "C" {