89 lines
5.4 KiB
C
89 lines
5.4 KiB
C
/* 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
|
|
|
|
/*#####################################################################################################################*/
|
|
|
|
extern void string_init(vtype_string* x, const char* value) Nonnull__(1);
|
|
|
|
extern char* string_at(const vtype_string* s, ssize_t index) Nonnull__(1);
|
|
extern size_t string_slice(vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, bool cut) Nonnull__(1,2);
|
|
|
|
#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(x, value) _LIBCDSB_GenericS(libcdsb_string, concat, value)(x, value)
|
|
|
|
#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)
|
|
|
|
#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) Pure__ Warn_unused_result__ Nonnull__(1) Always_inline__;
|
|
extern ssize_t libcdsb_string_indexof_cstring(const vtype_string* s, const char* arg) Pure__ Warn_unused_result__ Nonnull__(1);
|
|
extern ssize_t libcdsb_string_indexof_char (const vtype_string* s, int arg) Pure__ Warn_unused_result__ Nonnull__(1);
|
|
|
|
inline size_t libcdsb_string_count_string (const vtype_string* s, const vtype_string* arg) Pure__ Warn_unused_result__ Nonnull__(1) Always_inline__;
|
|
extern size_t libcdsb_string_count_cstring(const vtype_string* s, const char* arg) Pure__ Warn_unused_result__ Nonnull__(1);
|
|
extern size_t libcdsb_string_count_char (const vtype_string* s, int arg) Pure__ Warn_unused_result__ Nonnull__(1);
|
|
|
|
inline bool libcdsb_string_concat_string (vtype_string* x, const vtype_string* value) Nonnull__(1) Always_inline__;
|
|
extern bool libcdsb_string_concat_cstring(vtype_string* x, const char* value) Nonnull__(1);
|
|
extern bool libcdsb_string_concat_char (vtype_string* x, int value) Nonnull__(1);
|
|
|
|
extern void libcdsb_string_trim_spaces(vtype_string* x, int direction) Nonnull__(1);
|
|
|
|
inline size_t libcdsb_string_replace_string_string (vtype_string* x, const vtype_string* src, const vtype_string* dest, size_t maxn) Nonnull__(1) Always_inline__;
|
|
inline size_t libcdsb_string_replace_string_cstring (vtype_string* x, const vtype_string* src, const char* dest, size_t maxn) Nonnull__(1) Always_inline__;
|
|
inline size_t libcdsb_string_replace_string_char (vtype_string* x, const vtype_string* src, int dest, size_t maxn) Nonnull__(1) Always_inline__;
|
|
inline size_t libcdsb_string_replace_cstring_string (vtype_string* x, const char* src, const vtype_string* dest, size_t maxn) Nonnull__(1) Always_inline__;
|
|
extern size_t libcdsb_string_replace_cstring_cstring(vtype_string* x, const char* src, const char* dest, size_t maxn) Nonnull__(1);
|
|
extern size_t libcdsb_string_replace_cstring_char (vtype_string* x, const char* src, int dest, size_t maxn) Nonnull__(1);
|
|
inline size_t libcdsb_string_replace_char_string (vtype_string* x, int src, const vtype_string* dest, size_t maxn) Nonnull__(1) Always_inline__;
|
|
extern size_t libcdsb_string_replace_char_cstring (vtype_string* x, int src, const char* dest, size_t maxn) Nonnull__(1);
|
|
extern size_t libcdsb_string_replace_char_char (vtype_string* x, int src, int dest, size_t maxn) Nonnull__(1);
|
|
|
|
/*#####################################################################################################################*/
|
|
|
|
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 */
|