libcdsb/include/string.h
2022-08-22 12:13:20 +03:00

49 lines
3.6 KiB
C

/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "bits/__generics.h"
#include "vtype.h"
#ifndef LIBCDSB_STRING_H
#define LIBCDSB_STRING_H
/*#####################################################################################################################*/
extern size_t string_slice (vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, bool cut) Nonnull__(1,2);
extern size_t string_reverse (vtype_string* x) Nonnull__(1);
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);
extern char* at_string (const vtype_string* s, ssize_t index) Nonnull__(1);
/*#####################################################################################################################*/
#define string_init(x, s) libcdsb_string_init (x, _LIBCDSB_to_cstring(s), 0)
#define string_indexof(x, s) libcdsb_string_indexof(x, _LIBCDSB_to_cstring(s))
#define string_count(x, s) libcdsb_string_count (x, _LIBCDSB_to_cstring(s), 0)
#define string_concat(x, s) libcdsb_string_concat (x, _LIBCDSB_to_cstring(s), 0)
#define string_align(x, n, c) libcdsb_string_align (x, n, c, 0)
#define string_lalign(x, n, c) libcdsb_string_align (x, n, c, -1)
#define string_ralign(x, n, c) libcdsb_string_align (x, n, c, 1)
#define string_split(x, s) libcdsb_string_split (x, _LIBCDSB_to_cstring(s), 0, -1)
#define string_trim(x, s) libcdsb_string_trim (x, _LIBCDSB_to_cstring(s), 0)
#define string_ltrim(x, s) libcdsb_string_trim (x, _LIBCDSB_to_cstring(s), -1)
#define string_rtrim(x, s) libcdsb_string_trim (x, _LIBCDSB_to_cstring(s), 1)
#define string_replace(x, s, d) libcdsb_string_replace(x, _LIBCDSB_to_cstring(s), 0, _LIBCDSB_to_cstring(d), 0, -1)
/*#####################################################################################################################*/
inline void libcdsb_string_init (vtype_string* x, const char* s, size_t nmemb) Always_inline__ Nonnull__(1);
extern bool libcdsb_string_concat (vtype_string* x, const char* s, size_t nmemb) Nonnull__(1);
extern void libcdsb_string_trim (vtype_string* x, const char* s, int direction) Nonnull__(1);
extern size_t libcdsb_string_align (vtype_string* x, size_t padsize, int padchr, int direction) Nonnull__(1);
extern ssize_t libcdsb_string_indexof(const vtype_string* x, const char* s) Pure__ Warn_unused_result__ Nonnull__(1);
extern size_t libcdsb_string_count (const vtype_string* x, const char* s, size_t nmemb) Pure__ Warn_unused_result__ Nonnull__(1);
extern vtype_array libcdsb_string_split (const vtype_string* x, const char* s, size_t nmemb, size_t maxn) Nonnull__(1);
extern size_t libcdsb_string_replace(vtype_string* x, const char* s, size_t snmemb, const char* d, size_t dnmemb, size_t maxn) Nonnull__(1,2);
inline void libcdsb_string_init (vtype_string* x, const char* s, size_t nmemb) { x->buffer = ((nmemb) ? libcdsb_strndup(s, nmemb) : libcdsb_strdup(s)); }
#endif /* LIBCDSB_STRING_H */