Refactor string symbols

This commit is contained in:
Gregory Lirent 2022-06-06 11:21:32 +03:00
parent 4d50d639cc
commit 51c1fbf52d
9 changed files with 51 additions and 83 deletions

View File

@ -27,9 +27,10 @@ extern size_t string_align_center(vtype_string* x, size_t padsize, int padchr) L
extern size_t string_align_right (vtype_string* x, size_t padsize, int padchr) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t string_align_left (vtype_string* x, size_t padsize, int padchr) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int string_compare_case_insensitive(const vtype_string* s0, const vtype_string* s1) LIBCDSB_cmpattr__;
extern void libcdsb_string_replace(vtype_string* x, char* dest, size_t dest_nmemb, const char* src, size_t nmemb);
/*#####################################################################################################################*/
inline vtype_array libcdsb_string_split_string (const vtype_string* x, const vtype_string* sep, size_t maxn) __attribute__((always_inline));

View File

@ -60,7 +60,7 @@ int string_compare(const str_t* s0, const str_t* s1) {
/*#####################################################################################################################*/
_Bool string_concat_cstring(str_t* x, const char* s) {
_Bool libcdsb_string_concat_cstring(str_t* x, const char* s) {
size_t n;
size_t xn;
@ -77,7 +77,7 @@ _Bool string_concat_cstring(str_t* x, const char* s) {
}
_Bool string_concat_char(str_t* x, int chr) {
_Bool libcdsb_string_concat_char(str_t* x, int chr) {
size_t xn;
size_t n;
char *e;

View File

@ -3,7 +3,7 @@
#include "include.h"
arr_t string_split_cstring(const str_t* s, const char* a, size_t maxn) {
arr_t libcdsb_string_split_cstring(const str_t* s, const char* a, size_t maxn) {
arr_t x = { .mem = 0, .size = 0, .type = VTYPE_STRING };
size_t n;
@ -46,7 +46,7 @@ arr_t string_split_cstring(const str_t* s, const char* a, size_t maxn) {
}
arr_t string_split_char(const str_t* s, int ac, size_t maxn) {
arr_t libcdsb_string_split_char(const str_t* s, int ac, size_t maxn) {
arr_t x = { .mem = 0, .size = 0, .type = VTYPE_STRING };
char a[5] = { 0 };

View File

@ -4,7 +4,7 @@
#include <ctype.h>
#include "include.h"
int string_case_compare(const str_t* s0, const str_t* s1) {
int string_compare_case_insensitive(const str_t* s0, const str_t* s1) {
const char *p0, *p1, *t0, *t1;
ssize_t n0, n1;
u32_t uc0, uc1;
@ -76,7 +76,7 @@ size_t string_to_lower(str_t* x) {
es = tochar_unicode(ps, uc1);
if (!is_null(es)) {
string_replace(x, p, e-p, ps, es-ps);
libcdsb_string_replace(x, p, e-p, ps, es-ps);
++n;
}
}
@ -112,7 +112,7 @@ size_t string_to_upper(str_t* x) {
es = tochar_unicode(ps, uc1);
if (!is_null(es)) {
string_replace(x, p, e-p, ps, es-ps);
libcdsb_string_replace(x, p, e-p, ps, es-ps);
++n;
}
}
@ -146,7 +146,7 @@ size_t string_capitalize(str_t* x) {
es = tochar_unicode(ps, uc1);
if (!is_null(es)) {
string_replace(x, p, e-p, ps, es-ps);
libcdsb_string_replace(x, p, e-p, ps, es-ps);
++n;
}
}
@ -164,7 +164,7 @@ size_t string_capitalize(str_t* x) {
es = tochar_unicode(ps, uc1);
if (!is_null(es)) {
string_replace(x, p, e-p, ps, es-ps);
libcdsb_string_replace(x, p, e-p, ps, es-ps);
++n;
}
}
@ -207,3 +207,22 @@ size_t string_reverse(str_t* x) {
return n;
}
/*#####################################################################################################################*/
void libcdsb_string_replace(str_t* x, char* p, size_t n, const char* v, size_t vn) {
if (n != vn) {
size_t l = strlen(x->buffer);
if (n < vn) {
char* t = x->buffer;
x->buffer = realloc(x->buffer, l + (vn - n) + 1);
p = x->buffer + (p - t);
}
memmove(p+vn, p+n, l - (p+n - x->buffer) + 1);
}
memcpy(p, v, vn);
}

View File

@ -63,7 +63,7 @@ _Bool string_slice(str_t* x, str_t* s, ssize_t i, size_t c, _Bool cut) {
/*#####################################################################################################################*/
ssize_t string_indexof_cstring(const str_t* s, const char* a) {
ssize_t libcdsb_string_indexof_cstring(const str_t* s, const char* a) {
char *e, *p;
size_t n;
@ -92,7 +92,7 @@ ssize_t string_indexof_cstring(const str_t* s, const char* a) {
}
ssize_t string_indexof_char(const str_t* s, int ac) {
ssize_t libcdsb_string_indexof_char(const str_t* s, int ac) {
size_t n;
char* e;
@ -127,7 +127,7 @@ ssize_t string_indexof_char(const str_t* s, int ac) {
/*#####################################################################################################################*/
size_t string_count_cstring(const str_t* s, const char* a) {
size_t libcdsb_string_count_cstring(const str_t* s, const char* a) {
char* p;
size_t n, c;
@ -148,7 +148,7 @@ size_t string_count_cstring(const str_t* s, const char* a) {
}
size_t string_count_char(const str_t* s, int ac) {
size_t libcdsb_string_count_char(const str_t* s, int ac) {
size_t n, c;
char a[5] = {0};

View File

@ -29,35 +29,4 @@ ainline(char* prev_char(char* s)) {
return s;
}
extern void libcdsb_string_replace(str_t* x, char* p, size_t n, const char* v, size_t vn);
#ifdef string_replace
#undef string_replace
#endif
#ifdef string_trim_spaces
#undef string_trim_spaces
#endif
#define string_replace libcdsb_string_replace
#define string_indexof_cstring libcdsb_string_indexof_cstring
#define string_indexof_char libcdsb_string_indexof_char
#define string_count_cstring libcdsb_string_count_cstring
#define string_count_char libcdsb_string_count_char
#define string_concat_cstring libcdsb_string_concat_cstring
#define string_concat_char libcdsb_string_concat_char
#define string_trim_spaces libcdsb_string_trim_spaces
#define string_trim_cstring libcdsb_string_trim_cstring
#define string_trim_char libcdsb_string_trim_char
#define string_replace_cstring_cstring libcdsb_string_replace_cstring_cstring
#define string_replace_cstring_char libcdsb_string_replace_cstring_char
#define string_replace_char_cstring libcdsb_string_replace_char_cstring
#define string_replace_char_char libcdsb_string_replace_char_char
#define string_split_string libcdsb_string_split_string
#define string_split_cstring libcdsb_string_split_cstring
#define string_split_char libcdsb_string_split_char
#define string_replace_cstring_cstring_r libcdsb_string_replace_r_cstring_cstring
#define string_replace_cstring_char_r libcdsb_string_replace_r_cstring_char
#define string_replace_char_cstring_r libcdsb_string_replace_r_char_cstring
#endif /* LIBCDSB_SRC_STRING_INCLUDE_H */

View File

@ -1,21 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "include.h"
void string_replace(str_t* x, char* p, size_t n, const char* v, size_t vn) {
if (n != vn) {
size_t l = strlen(x->buffer);
if (n < vn) {
char* t = x->buffer;
x->buffer = realloc(x->buffer, l + (vn - n) + 1);
p = x->buffer + (p - t);
}
memmove(p+vn, p+n, l - (p+n - x->buffer) + 1);
}
memcpy(p, v, vn);
}

View File

@ -3,7 +3,7 @@
#include "include.h"
size_t string_replace_cstring_cstring(str_t* x, const char* a, const char* d, size_t maxn) {
size_t libcdsb_string_replace_cstring_cstring(str_t* x, const char* a, const char* d, size_t maxn) {
char *p, *t, *r;
size_t c, n, an, dn;
@ -38,7 +38,7 @@ size_t string_replace_cstring_cstring(str_t* x, const char* a, const char* d, si
}
while (maxn-- && !is_null(p = strstr(p, a))) {
string_replace(x, p, an, d, dn);
libcdsb_string_replace(x, p, an, d, dn);
p += an;
++c;
}
@ -49,7 +49,7 @@ size_t string_replace_cstring_cstring(str_t* x, const char* a, const char* d, si
}
size_t string_replace_cstring_char(str_t* x, const char* a, int dc, size_t maxn) {
size_t libcdsb_string_replace_cstring_char(str_t* x, const char* a, int dc, size_t maxn) {
char *p, *t;
char d[4];
size_t c, n, an, dn;
@ -77,7 +77,7 @@ size_t string_replace_cstring_char(str_t* x, const char* a, int dc, size_t maxn)
}
while (maxn-- && !is_null(p = strstr(p, a))) {
string_replace(x, p, an, d, dn);
libcdsb_string_replace(x, p, an, d, dn);
p += an;
++c;
}
@ -87,7 +87,7 @@ size_t string_replace_cstring_char(str_t* x, const char* a, int dc, size_t maxn)
}
size_t string_replace_char_cstring(str_t* x, int ac, const char* d, size_t maxn) {
size_t libcdsb_string_replace_char_cstring(str_t* x, int ac, const char* d, size_t maxn) {
char *p, *t;
char a[4];
size_t c, n, an, dn;
@ -110,7 +110,7 @@ size_t string_replace_char_cstring(str_t* x, int ac, const char* d, size_t maxn)
}
while (maxn-- && !is_null(p = strstr(p, a))) {
string_replace(x, p, an, d, dn);
libcdsb_string_replace(x, p, an, d, dn);
p += an;
++c;
}
@ -120,7 +120,7 @@ size_t string_replace_char_cstring(str_t* x, int ac, const char* d, size_t maxn)
}
size_t string_replace_char_char(str_t* x, int ac, int dc, size_t maxn) {
size_t libcdsb_string_replace_char_char(str_t* x, int ac, int dc, size_t maxn) {
char* p;
char a[4];
char d[4];
@ -139,7 +139,7 @@ size_t string_replace_char_char(str_t* x, int ac, int dc, size_t maxn) {
c = 0;
while (maxn-- && !is_null(p = strstr(p, a))) {
string_replace(x, p, an, d, dn);
libcdsb_string_replace(x, p, an, d, dn);
p += an;
++c;
}
@ -149,7 +149,7 @@ size_t string_replace_char_char(str_t* x, int ac, int dc, size_t maxn) {
size_t string_replace_cstring_cstring_r(str_t* x, const char*restrict a, const char*restrict d, size_t maxn) {
size_t libcdsb_string_replace_r_cstring_cstring(str_t* x, const char*restrict a, const char*restrict d, size_t maxn) {
char *restrict p;
size_t c, an, dn;
@ -163,7 +163,7 @@ size_t string_replace_cstring_cstring_r(str_t* x, const char*restrict a, const c
c = 0;
while (maxn-- && !is_null(p = strstr(p, a))) {
string_replace(x, p, an, d, dn);
libcdsb_string_replace(x, p, an, d, dn);
p += an;
++c;
}
@ -172,7 +172,7 @@ size_t string_replace_cstring_cstring_r(str_t* x, const char*restrict a, const c
}
size_t string_replace_cstring_char_r(str_t* x, const char*restrict a, int dc, size_t maxn) {
size_t libcdsb_string_replace_r_cstring_char(str_t* x, const char*restrict a, int dc, size_t maxn) {
char *restrict p;
char d[4];
size_t c, an, dn;
@ -188,7 +188,7 @@ size_t string_replace_cstring_char_r(str_t* x, const char*restrict a, int dc, si
c = 0;
while (maxn-- && !is_null(p = strstr(p, a))) {
string_replace(x, p, an, d, dn);
libcdsb_string_replace(x, p, an, d, dn);
p += an;
++c;
}
@ -197,7 +197,7 @@ size_t string_replace_cstring_char_r(str_t* x, const char*restrict a, int dc, si
}
size_t string_replace_char_cstring_r(str_t* x, int ac, const char*restrict d, size_t maxn) {
size_t libcdsb_string_replace_r_char_cstring(str_t* x, int ac, const char*restrict d, size_t maxn) {
char *restrict p;
char a[4];
size_t c, an, dn;
@ -214,7 +214,7 @@ size_t string_replace_char_cstring_r(str_t* x, int ac, const char*restrict d, si
c = 0;
while (maxn-- && !is_null(p = strstr(p, a))) {
string_replace(x, p, an, d, dn);
libcdsb_string_replace(x, p, an, d, dn);
p += an;
++c;
}

View File

@ -7,7 +7,7 @@
/*#####################################################################################################################*/
void string_trim_spaces(str_t* x, int direction) {
void libcdsb_string_trim_spaces(str_t* x, int direction) {
static size_t m[32/(sizeof(size_t))] = {0};
u8_t* l;
@ -51,7 +51,7 @@ void string_trim_spaces(str_t* x, int direction) {
/*#####################################################################################################################*/
void string_trim_cstring(str_t* x, const char* s, int direction) {
void libcdsb_string_trim_cstring(str_t* x, const char* s, int direction) {
u8_t* l;
u8_t* r;
@ -122,7 +122,7 @@ void string_trim_cstring(str_t* x, const char* s, int direction) {
}
void string_trim_char(str_t* x, int sc, int direction) {
void libcdsb_string_trim_char(str_t* x, int sc, int direction) {
u8_t* l;
u8_t* r;