/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include "__generics.h" #include "vtype.h" #include #ifndef LIBCDSB_STRING_H #define LIBCDSB_STRING_H /*#####################################################################################################################*/ extern void string_init(vtype_string* x, const char* value) LIBCDSB_nt__ LIBCDSB_nn1__; extern char* string_at(const vtype_string* s, ssize_t index) LIBCDSB_nt__ LIBCDSB_nn1__; extern _Bool string_slice(vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn12__; #define string_indexof(s, arg) _LIBCDSB_GenericS(libcdsb_string, indexof, arg)(s, arg) #define string_count(s, arg) _LIBCDSB_GenericS(libcdsb_string, count, arg)(s, arg) #define string_concat(s, value) _LIBCDSB_GenericS(libcdsb_string, concat, value)(s, value) #define string_trim(x, arg) _LIBCDSB_GenericS(libcdsb_string, trim, arg)(x, arg) #define string_ltrim(x, arg) _LIBCDSB_GenericS(libcdsb_string, ltrim, arg)(x, arg) #define string_rtrim(x, arg) _LIBCDSB_GenericS(libcdsb_string, rtrim, arg)(x, arg) #define string_replace(x, src, dest, maxn) _LIBCDSB_GenericS2(libcdsb_string, replace, src, dest)(x, src, dest, maxn) /*#####################################################################################################################*/ inline ssize_t libcdsb_string_indexof_string (const vtype_string* s, const vtype_string* arg) __attribute__((always_inline)); extern ssize_t libcdsb_string_indexof_cstring(const vtype_string* s, const char* arg) LIBCDSB_pure__ LIBCDSB_nn1__; extern ssize_t libcdsb_string_indexof_char (const vtype_string* s, int arg) LIBCDSB_pure__ LIBCDSB_nn1__; inline size_t libcdsb_string_count_string (const vtype_string* s, const vtype_string* arg) __attribute__((always_inline)); extern size_t libcdsb_string_count_cstring(const vtype_string* s, const char* arg) LIBCDSB_pure__ LIBCDSB_nn1__; extern size_t libcdsb_string_count_char (const vtype_string* s, int arg) LIBCDSB_pure__ LIBCDSB_nn1__; inline _Bool libcdsb_string_concat_string (vtype_string* x, const vtype_string* value) __attribute__((always_inline)); extern _Bool libcdsb_string_concat_cstring(vtype_string* x, const char* value) LIBCDSB_nt__ LIBCDSB_nn1__; extern _Bool libcdsb_string_concat_char (vtype_string* x, int value) LIBCDSB_nt__ LIBCDSB_nn1__; inline void libcdsb_string_trim_string (vtype_string* x, const vtype_string* arg) __attribute__((always_inline)); extern void libcdsb_string_trim_cstring (vtype_string* x, const char* arg) LIBCDSB_nt__ LIBCDSB_nn1__; extern void libcdsb_string_trim_char (vtype_string* x, int arg) LIBCDSB_nt__ LIBCDSB_nn1__; inline void libcdsb_string_ltrim_string (vtype_string* x, const vtype_string* arg) __attribute__((always_inline)); extern void libcdsb_string_ltrim_cstring(vtype_string* x, const char* arg) LIBCDSB_nt__ LIBCDSB_nn1__; extern void libcdsb_string_ltrim_char (vtype_string* x, int arg) LIBCDSB_nt__ LIBCDSB_nn1__; inline void libcdsb_string_rtrim_string (vtype_string* x, const vtype_string* arg) __attribute__((always_inline)); extern void libcdsb_string_rtrim_cstring(vtype_string* x, const char* arg) LIBCDSB_nt__ LIBCDSB_nn1__; extern void libcdsb_string_rtrim_char (vtype_string* x, int arg) LIBCDSB_nt__ LIBCDSB_nn1__; inline size_t libcdsb_string_replace_string_string (vtype_string* x, const vtype_string* src, const vtype_string* dest, size_t maxn) __attribute__((always_inline)); inline size_t libcdsb_string_replace_string_cstring (vtype_string* x, const vtype_string* src, const char* dest, size_t maxn) __attribute__((always_inline)); inline size_t libcdsb_string_replace_string_char (vtype_string* x, const vtype_string* src, int dest, size_t maxn) __attribute__((always_inline)); inline size_t libcdsb_string_replace_cstring_string (vtype_string* x, const char* src, const vtype_string* dest, size_t maxn) __attribute__((always_inline)); extern size_t libcdsb_string_replace_cstring_cstring(vtype_string* x, const char* src, const char* dest, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__; extern size_t libcdsb_string_replace_cstring_char (vtype_string* x, const char* src, int dest, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__; inline size_t libcdsb_string_replace_char_string (vtype_string* x, int src, const vtype_string* dest, size_t maxn) __attribute__((always_inline)); extern size_t libcdsb_string_replace_char_cstring (vtype_string* x, int src, const char* dest, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__; extern size_t libcdsb_string_replace_char_char (vtype_string* x, int src, int dest, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__; /*#####################################################################################################################*/ inline ssize_t libcdsb_string_indexof_string(const vtype_string* s, const vtype_string* arg) { return string_indexof(s, arg->buffer); } inline size_t libcdsb_string_count_string(const vtype_string* s, const vtype_string* arg) { return string_count(s, arg->buffer); } inline _Bool libcdsb_string_concat_string(vtype_string* x, const vtype_string* s) { return string_concat(x, s->buffer); } inline void libcdsb_string_trim_string (vtype_string* x, const vtype_string* s) { return string_trim (x, s->buffer); } inline void libcdsb_string_ltrim_string (vtype_string* x, const vtype_string* s) { return string_ltrim(x, s->buffer); } inline void libcdsb_string_rtrim_string (vtype_string* x, const vtype_string* s) { return string_rtrim(x, s->buffer); } inline size_t libcdsb_string_replace_string_string (vtype_string* x, const vtype_string* src, const vtype_string* dest, size_t maxn) { return string_replace(x, src->buffer, dest->buffer, maxn); } inline size_t libcdsb_string_replace_string_cstring(vtype_string* x, const vtype_string* src, const char* dest, size_t maxn) { return string_replace(x, src->buffer, dest, maxn); } inline size_t libcdsb_string_replace_cstring_string(vtype_string* x, const char* src, const vtype_string* dest, size_t maxn) { return string_replace(x, src, dest->buffer, maxn); } inline size_t libcdsb_string_replace_string_char (vtype_string* x, const vtype_string* src, int dest, size_t maxn) { return string_replace(x, src->buffer, dest, maxn); } inline size_t libcdsb_string_replace_char_string (vtype_string* x, int src, const vtype_string* dest, size_t maxn) { return string_replace(x, src, dest->buffer, maxn); } #endif /* LIBCDSB_BASE_STRING_H */