2022-06-02 15:53:09 +03:00
|
|
|
/* This software is licensed by the MIT License, see LICENSE file */
|
|
|
|
/* Copyright © 2022 Gregory Lirent */
|
|
|
|
|
|
|
|
#include "__generics.h"
|
|
|
|
#include "vtype.h"
|
|
|
|
#include <uchar.h>
|
|
|
|
|
|
|
|
#ifndef LIBCDSB_STRING_H
|
|
|
|
#define LIBCDSB_STRING_H
|
|
|
|
|
2022-06-03 18:34:57 +03:00
|
|
|
/*#####################################################################################################################*/
|
|
|
|
|
2022-06-02 15:53:09 +03:00
|
|
|
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)
|
|
|
|
|
2022-06-04 15:43:30 +03:00
|
|
|
#define string_trim_spaces(x) libcdsb_string_trim_spaces(x, 0)
|
|
|
|
#define string_ltrim_spaces(x) libcdsb_string_trim_spaces(x, -1)
|
|
|
|
#define string_rtrim_spaces(x) libcdsb_string_trim_spaces(x, 1)
|
2022-06-02 15:53:09 +03:00
|
|
|
|
|
|
|
#define string_replace(x, src, dest, maxn) _LIBCDSB_GenericS2(libcdsb_string, replace, src, dest)(x, src, dest, maxn)
|
|
|
|
|
2022-06-03 18:34:57 +03:00
|
|
|
/*#####################################################################################################################*/
|
2022-06-02 15:53:09 +03:00
|
|
|
|
|
|
|
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__;
|
|
|
|
|
2022-06-04 15:43:30 +03:00
|
|
|
extern void libcdsb_string_trim_spaces(vtype_string* x, int direction) LIBCDSB_nt__ LIBCDSB_nn1__;
|
2022-06-02 15:53:09 +03:00
|
|
|
|
|
|
|
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));
|
2022-06-03 18:34:57 +03:00
|
|
|
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__;
|
2022-06-02 15:53:09 +03:00
|
|
|
|
2022-06-03 18:34:57 +03:00
|
|
|
/*#####################################################################################################################*/
|
2022-06-02 15:53:09 +03:00
|
|
|
|
|
|
|
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 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 */
|