2022-06-02 15:53:09 +03:00
|
|
|
/* This software is licensed by the MIT License, see LICENSE file */
|
|
|
|
/* Copyright © 2022 Gregory Lirent */
|
|
|
|
|
|
|
|
#include "../string.h"
|
|
|
|
|
|
|
|
#ifndef LIBCDSB_EXTRA_STRING_H
|
|
|
|
#define LIBCDSB_EXTRA_STRING_H
|
|
|
|
|
2022-06-03 18:34:57 +03:00
|
|
|
/*#####################################################################################################################*/
|
|
|
|
|
2022-08-17 22:20:04 +03:00
|
|
|
#define string_split(s, sep, maxn) _LIBCDSB_GenericS(libcdsb_string, split, sep)(s, sep, maxn)
|
2022-06-02 15:53:09 +03:00
|
|
|
#define string_case_compare string_compare_case_insensitive
|
|
|
|
|
2022-06-03 18:34:57 +03:00
|
|
|
#define string_replace_r(x, src, dest, maxn) _LIBCDSB_GenericS2(libcdsb_string, replace_r, src, dest)(x, src, dest, maxn)
|
|
|
|
|
2022-06-04 15:43:30 +03:00
|
|
|
#define string_trim(x, arg) _LIBCDSB_GenericS(libcdsb_string, trim, arg)(x, arg, 0)
|
|
|
|
#define string_ltrim(x, arg) _LIBCDSB_GenericS(libcdsb_string, trim, arg)(x, arg, -1)
|
|
|
|
#define string_rtrim(x, arg) _LIBCDSB_GenericS(libcdsb_string, trim, arg)(x, arg, 1)
|
|
|
|
|
2022-08-16 01:36:37 +03:00
|
|
|
extern size_t string_to_lower (vtype_string* x) Nonnull__(1);
|
|
|
|
extern size_t string_to_upper (vtype_string* x) Nonnull__(1);
|
|
|
|
extern size_t string_capitalize(vtype_string* x) Nonnull__(1);
|
2022-06-02 15:53:09 +03:00
|
|
|
|
2022-08-16 01:36:37 +03:00
|
|
|
extern size_t string_reverse (vtype_string* x) Nonnull__(1);
|
2022-06-04 00:33:29 +03:00
|
|
|
|
2022-08-16 01:36:37 +03:00
|
|
|
extern size_t string_align_center(vtype_string* x, size_t padsize, int padchr) Nonnull__(1);
|
|
|
|
extern size_t string_align_right (vtype_string* x, size_t padsize, int padchr) Nonnull__(1);
|
|
|
|
extern size_t string_align_left (vtype_string* x, size_t padsize, int padchr) Nonnull__(1);
|
2022-06-04 00:33:29 +03:00
|
|
|
|
2022-08-16 01:36:37 +03:00
|
|
|
extern void libcdsb_string_replace(vtype_string* x, char* dest, size_t dest_nmemb, const char* src, size_t nmemb) Nonnull__(1,2);
|
2022-06-06 11:21:32 +03:00
|
|
|
|
2022-06-03 18:34:57 +03:00
|
|
|
/*#####################################################################################################################*/
|
|
|
|
|
2022-08-17 22:20:04 +03:00
|
|
|
extern int string_compare_case_insensitive(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2);
|
|
|
|
|
|
|
|
inline vtype_array libcdsb_string_split_string (const vtype_string* s, const vtype_string* sep, size_t maxn) Nonnull__(1) Always_inline__;
|
|
|
|
extern vtype_array libcdsb_string_split_cstring(const vtype_string* s, const char* sep, size_t maxn) Nonnull__(1);
|
|
|
|
extern vtype_array libcdsb_string_split_char (const vtype_string* s, int chr, size_t maxn) Nonnull__(1);
|
2022-08-16 01:36:37 +03:00
|
|
|
|
|
|
|
inline void libcdsb_string_trim_string (vtype_string* x, const vtype_string* s, int direction) Nonnull__(1) Always_inline__;
|
|
|
|
extern void libcdsb_string_trim_cstring(vtype_string* x, const char* s, int direction) Nonnull__(1);
|
|
|
|
extern void libcdsb_string_trim_char (vtype_string* x, int sc, int direction) Nonnull__(1);
|
|
|
|
|
|
|
|
inline size_t libcdsb_string_replace_r_string_string (vtype_string*restrict x, const vtype_string*restrict src, const vtype_string*restrict dest, size_t maxn) Nonnull__(1) Always_inline__;
|
|
|
|
inline size_t libcdsb_string_replace_r_string_cstring (vtype_string*restrict x, const vtype_string*restrict src, const char*restrict dest, size_t maxn) Nonnull__(1) Always_inline__;
|
|
|
|
inline size_t libcdsb_string_replace_r_string_char (vtype_string*restrict x, const vtype_string*restrict src, int dest, size_t maxn) Nonnull__(1) Always_inline__;
|
|
|
|
inline size_t libcdsb_string_replace_r_cstring_string (vtype_string*restrict x, const char*restrict src, const vtype_string*restrict dest, size_t maxn) Nonnull__(1) Always_inline__;
|
|
|
|
extern size_t libcdsb_string_replace_r_cstring_cstring(vtype_string*restrict x, const char*restrict src, const char*restrict dest, size_t maxn) Nonnull__(1);
|
|
|
|
extern size_t libcdsb_string_replace_r_cstring_char (vtype_string*restrict x, const char*restrict src, int dest, size_t maxn) Nonnull__(1);
|
|
|
|
inline size_t libcdsb_string_replace_r_char_string (vtype_string*restrict x, int src, const vtype_string*restrict dest, size_t maxn) Nonnull__(1) Always_inline__;
|
|
|
|
extern size_t libcdsb_string_replace_r_char_cstring (vtype_string*restrict x, int src, const char*restrict dest, size_t maxn) Nonnull__(1);
|
2022-06-03 19:12:26 +03:00
|
|
|
#define libcdsb_string_replace_r_char_char libcdsb_string_replace_char_char
|
2022-06-03 18:34:57 +03:00
|
|
|
|
|
|
|
/*#####################################################################################################################*/
|
|
|
|
|
2022-06-02 15:53:09 +03:00
|
|
|
inline vtype_array libcdsb_string_split_string(const vtype_string* x, const vtype_string* sep, size_t maxn) {
|
|
|
|
return string_split(x, sep->buffer, maxn);
|
|
|
|
}
|
|
|
|
|
2022-06-04 15:43:30 +03:00
|
|
|
inline void libcdsb_string_trim_string(vtype_string* x, const vtype_string* s, int direction) {
|
|
|
|
return libcdsb_string_trim_cstring (x, s->buffer, direction);
|
|
|
|
}
|
|
|
|
|
2022-06-03 18:34:57 +03:00
|
|
|
inline size_t libcdsb_string_replace_r_string_string (vtype_string*restrict x, const vtype_string*restrict src, const vtype_string*restrict dest, size_t maxn) {
|
|
|
|
return string_replace_r(x, src->buffer, dest->buffer, maxn);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t libcdsb_string_replace_r_string_cstring(vtype_string*restrict x, const vtype_string*restrict src, const char*restrict dest, size_t maxn) {
|
|
|
|
return string_replace_r(x, src->buffer, dest, maxn);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t libcdsb_string_replace_r_cstring_string(vtype_string*restrict x, const char*restrict src, const vtype_string*restrict dest, size_t maxn) {
|
|
|
|
return string_replace_r(x, src, dest->buffer, maxn);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t libcdsb_string_replace_r_string_char (vtype_string*restrict x, const vtype_string*restrict src, int dest, size_t maxn) {
|
|
|
|
return string_replace_r(x, src->buffer, dest, maxn);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t libcdsb_string_replace_r_char_string (vtype_string*restrict x, int src, const vtype_string*restrict dest, size_t maxn) {
|
|
|
|
return string_replace_r(x, src, dest->buffer, maxn);
|
|
|
|
}
|
|
|
|
|
2022-06-02 15:53:09 +03:00
|
|
|
#endif /* LIBCDSB_EXTRA_STRING_H */
|