diff options
| author | Tyge Løvset <[email protected]> | 2022-12-19 09:04:23 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-12-19 09:04:23 +0100 |
| commit | 1d4ad83d6f3388982cb0aeadbc9815b4776df504 (patch) | |
| tree | 6d0d389219644b127eaa83c8a54ccd93deef96b7 | |
| parent | 26a75a218a115a10cee82534be568a606c83dbb2 (diff) | |
| download | STC-modified-1d4ad83d6f3388982cb0aeadbc9815b4776df504.tar.gz STC-modified-1d4ad83d6f3388982cb0aeadbc9815b4776df504.zip | |
Renames:
cstr_null => cstr_NULL
csview_null => csview_NULL
cstr_npos => c_NPOS
csview_npos => c_NPOS
c_ARGsv(sv) => c_ARGSV(sv)
c_init(x) => c_INIT(x)
36 files changed, 127 insertions, 131 deletions
diff --git a/docs/carc_api.md b/docs/carc_api.md index 18bf52c7..15e2c452 100644 --- a/docs/carc_api.md +++ b/docs/carc_api.md @@ -67,7 +67,7 @@ bool carc_X_value_eq(const i_val* x, const i_val* y); | Type name | Type definition | Used to represent... | |:------------------|:--------------------------------------------------|:-----------------------| -| `carc_null` | `{NULL, NULL}` | Init nullptr const | +| `carc_NULL` | `{NULL, NULL}` | Init nullptr const | | `carc_X` | `struct { carc_X_value* get; long* use_count; }` | The carc type | | `carc_X_value` | `i_val` | The carc element type | | `carc_X_raw` | `i_valraw` | Convertion type | diff --git a/docs/cbox_api.md b/docs/cbox_api.md index 710c82f7..b3314433 100644 --- a/docs/cbox_api.md +++ b/docs/cbox_api.md @@ -64,7 +64,7 @@ bool cbox_X_value_eq(const i_val* x, const i_val* y); | Type name | Type definition | Used to represent... | |:-------------------|:--------------------------------|:------------------------| -| `cbox_null` | `{NULL}` | Init nullptr const | +| `cbox_NULL` | `{NULL}` | Init nullptr const | | `cbox_X` | `struct { cbox_X_value* get; }` | The cbox type | | `cbox_X_value` | `i_val` | The cbox element type | diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 8a11042b..8f887626 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -84,7 +84,7 @@ cvec_str readFile(const char* name) cvec_str vec = cvec_str_init(); // returned c_with (FILE* fp = fopen(name, "r"), fclose(fp)) - c_with (cstr line = cstr_null, cstr_drop(&line)) + c_with (cstr line = cstr_NULL, cstr_drop(&line)) while (cstr_getline(&line, fp)) cvec_str_emplace_back(&vec, cstr_str(&line)); return vec; @@ -313,7 +313,7 @@ if (it.ref) cmap_str_erase_at(&map, it); c_erase_if(i, csmap_str, map, cstr_contains(i.ref, "hello")); ``` -### c_new, c_alloc, c_alloc_n, c_drop, c_init +### c_new, c_alloc, c_alloc_n, c_drop | Usage | Meaning | |:-------------------------------|:----------------------------------------| @@ -321,7 +321,6 @@ c_erase_if(i, csmap_str, map, cstr_contains(i.ref, "hello")); | `c_alloc (type)` | `(type *) c_malloc(sizeof(type))` | | `c_alloc_n (type, N)` | `(type *) c_malloc((N)*sizeof(type))` | | `c_drop (ctype, &c1, ..., &cN)` | `ctype_drop(&c1); ... ctype_drop(&cN)` | -| `c_init(type){value...}` | `(type){value...}` // c++ compatability | ```c struct Pnt { double x, y, z; }; diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 48aa7e0d..315d2062 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -277,7 +277,7 @@ typedef struct { cstr country; } Viking; -#define Viking_init() ((Viking){cstr_null, cstr_null}) +#define Viking_init() ((Viking){cstr_NULL, cstr_NULL}) static inline int Viking_cmp(const Viking* a, const Viking* b) { int c = cstr_cmp(&a->name, &b->name); diff --git a/docs/cregex_api.md b/docs/cregex_api.md index 9bed66fa..ce218721 100644 --- a/docs/cregex_api.md +++ b/docs/cregex_api.md @@ -107,7 +107,7 @@ int main() { // Lets find the first date in the string: csview match[4]; // full-match, year, month, date. if (cregex_find(&re, input, match, CREG_DEFAULT) == CREG_OK) - printf("Found date: %.*s\n", c_ARGsv(match[0])); + printf("Found date: %.*s\n", c_ARGSV(match[0])); else printf("Could not find any date\n"); @@ -123,7 +123,7 @@ int main() { For a single match you may use the all-in-one function: ```c if (cregex_find_pattern(pattern, input, match, CREG_DEFAULT)) - printf("Found date: %.*s\n", c_ARGsv(match[0])); + printf("Found date: %.*s\n", c_ARGSV(match[0])); ``` To compile, use: `gcc first_match.c src/cregex.c src/utf8code.c`. @@ -136,13 +136,13 @@ To iterate multiple matches in an input string, you may use csview match[5] = {0}; while (cregex_find(&re, input, match, CREG_M_NEXT) == CREG_OK) c_forrange (k, cregex_captures(&re)) - printf("submatch %lld: %.*s\n", k, c_ARGsv(match[k])); + printf("submatch %lld: %.*s\n", k, c_ARGSV(match[k])); ``` There is also a safe macro which simplifies this: ```c c_formatch (it, &re, input) c_forrange (k, cregex_captures(&re)) - printf("submatch %lld: %.*s\n", k, c_ARGsv(it.match[k])); + printf("submatch %lld: %.*s\n", k, c_ARGSV(it.match[k])); ``` ## Using cregex in a project diff --git a/docs/cstr_api.md b/docs/cstr_api.md index 5c7ba41c..1f80e8e4 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -18,7 +18,7 @@ All cstr definitions and prototypes are available by including a single header f ## Methods ```c -cstr cstr_init(void); // constructor; same as cstr_null. +cstr cstr_init(void); // constructor; same as cstr_NULL. cstr cstr_new(const char literal_only[]); // cstr from literal; no strlen() call. cstr cstr_from(const char* str); // constructor using strlen() cstr cstr_from_n(const char* str, size_t n); // constructor with n first bytes of str @@ -152,8 +152,8 @@ char* cstrnstrn(const char* str, const char* search, size_t slen, size_t | Name | Value | |:------------------|:------------------| -| `cstr_npos` | `INTPTR_MAX` | -| `cstr_null` | cstr null value | +| `c_NPOS` | `INTPTR_MAX` | +| `cstr_NULL` | cstr null value | ## Example ```c diff --git a/docs/csview_api.md b/docs/csview_api.md index 10325ceb..59ebf58d 100644 --- a/docs/csview_api.md +++ b/docs/csview_api.md @@ -86,7 +86,7 @@ csview cstr_slice_ex(const cstr* s, intptr_t p, intptr_t q); // nega To iterate tokens in an input string separated by a string: ```c c_fortoken (i, "hello, one, two, three", ", ") - printf("token: %.*s\n", c_ARGsv(i.token)); + printf("token: %.*s\n", c_ARGSV(i.token)); ``` #### Helper methods @@ -109,10 +109,8 @@ uint64_t csview_hash(const csview* x); | Name | Value | Usage | |:---------------|:---------------------|:---------------------------------------------| -| `csview_null` | same as `c_sv("")` | `sview = csview_null;` | -| `csview_npos` | same as `cstr_npos` | | -| `c_PRIsv` | `".*s"` | `printf("sv: %" c_PRIsv "\n", c_ARGsv(sv));` | -| `c_ARGsv(sv)` | printf argument | `printf("sv: %.*s\n", c_ARGsv(sv));` | +| `csview_NULL` | same as `c_sv("")` | `sview = csview_NULL;` | +| `c_ARGSV(sv)` | printf argument | `printf("sv: %.*s\n", c_ARGSV(sv));` | ## Example ```c @@ -129,7 +127,7 @@ int main () csview sv2 = cstr_substr(&str1, pos, 4); // get "live" csview sv3 = cstr_slice(&str1, -8, -1); // get "details" printf("%.*s %.*s %.*s\n", - c_ARGsv(sv1), c_ARGsv(sv2), c_ARGsv(sv3)); + c_ARGSV(sv1), c_ARGSV(sv2), c_ARGSV(sv3)); cstr s1 = cstr_new("Apples are red"); cstr s2 = cstr_from_sv(cstr_substr(&s1, -3, 3)); // "red" cstr s3 = cstr_from_sv(cstr_substr(&s1, 0, 6)); // "Apples" @@ -157,7 +155,7 @@ int main() printf("%s\n", cstr_str(&s1)); c_foreach (i, cstr, s1) - printf("%.*s,", c_ARGsv(i.u8.chr)); + printf("%.*s,", c_ARGSV(i.u8.chr)); } } ``` @@ -177,7 +175,7 @@ and does not depend on null-terminated strings. *string_split()* function return void print_split(csview input, const char* sep) { c_fortoken_sv (i, input, sep) - printf("[%.*s]\n", c_ARGsv(i.token)); + printf("[%.*s]\n", c_ARGSV(i.token)); } #include <stc/cstr.h> diff --git a/examples/cstr_match.c b/examples/cstr_match.c index 9324ce41..5ba09ed9 100644 --- a/examples/cstr_match.c +++ b/examples/cstr_match.c @@ -6,7 +6,7 @@ int main() { c_with (cstr ss = cstr_new("The quick brown fox jumps over the lazy dog.JPG"), cstr_drop(&ss)) { size_t pos = cstr_find_at(&ss, 0, "brown"); - printf("%" c_ZU " [%s]\n", pos, pos == cstr_npos ? "<NULL>" : cstr_str(&ss) + pos); + printf("%" c_ZU " [%s]\n", pos, pos == c_NPOS ? "<NULL>" : cstr_str(&ss) + pos); printf("equals: %d\n", cstr_equals(&ss, "The quick brown fox jumps over the lazy dog.JPG")); printf("contains: %d\n", cstr_contains(&ss, "umps ove")); printf("starts_with: %d\n", cstr_starts_with(&ss, "The quick brown")); @@ -17,7 +17,7 @@ int main() csview ch1 = cstr_u8_chr(&s1, 7); csview ch2 = cstr_u8_chr(&s1, 10); printf("%s\nsize: %" c_ZU ", %" c_ZU "\n", cstr_str(&s1), cstr_u8_size(&s1), cstr_size(&s1)); - printf("ch1: %.*s\n", c_ARGsv(ch1)); - printf("ch2: %.*s\n", c_ARGsv(ch2)); + printf("ch1: %.*s\n", c_ARGSV(ch1)); + printf("ch2: %.*s\n", c_ARGSV(ch2)); } } diff --git a/examples/forfilter.c b/examples/forfilter.c index bf486ea4..9eb1536e 100644 --- a/examples/forfilter.c +++ b/examples/forfilter.c @@ -99,7 +99,7 @@ void demo3(void) puts("demo3:"); c_foreach (w, SVec, words_containing_i) - printf(" %.*s", c_ARGsv(*w.ref)); + printf(" %.*s", c_ARGSV(*w.ref)); puts(""); } } diff --git a/examples/new_arr.c b/examples/new_arr.c index 79e7c7a6..871cfae0 100644 --- a/examples/new_arr.c +++ b/examples/new_arr.c @@ -46,7 +46,7 @@ int main() puts(""); } - c_with (carr2_str text2d = carr2_str_with_size(h, d, cstr_null), carr2_str_drop(&text2d)) + c_with (carr2_str text2d = carr2_str_with_size(h, d, cstr_NULL), carr2_str_drop(&text2d)) { cstr_assign(&text2d.data[2][1], "hello"); cstr_assign(&text2d.data[4][0], "world"); diff --git a/examples/read.c b/examples/read.c index 5a9a30d5..4efdcfeb 100644 --- a/examples/read.c +++ b/examples/read.c @@ -7,7 +7,7 @@ cvec_str read_file(const char* name) { cvec_str vec = cvec_str_init(); c_with (FILE* f = fopen(name, "r"), fclose(f)) - c_with (cstr line = cstr_null, cstr_drop(&line)) + c_with (cstr line = cstr_NULL, cstr_drop(&line)) while (cstr_getline(&line, f)) cvec_str_push(&vec, cstr_clone(line)); return vec; diff --git a/examples/regex2.c b/examples/regex2.c index 4f60cfc4..dbf6aae4 100644 --- a/examples/regex2.c +++ b/examples/regex2.c @@ -25,7 +25,7 @@ int main() c_formatch (j, &re, s[i].input) { c_forrange (k, cregex_captures(&re)) - printf(" submatch %lld: %.*s\n", k, c_ARGsv(j.match[k])); + printf(" submatch %lld: %.*s\n", k, c_ARGSV(j.match[k])); puts(""); } } diff --git a/examples/splitstr.c b/examples/splitstr.c index 39db1a54..a3c12a3a 100644 --- a/examples/splitstr.c +++ b/examples/splitstr.c @@ -8,12 +8,12 @@ int main() puts("Split with c_fortoken (csview):"); c_fortoken (i, "Hello World C99!", " ") - printf("'%.*s'\n", c_ARGsv(i.token)); + printf("'%.*s'\n", c_ARGSV(i.token)); puts("\nSplit with c_formatch (regex):"); c_with (cregex re = cregex_from("[^ ]+", CREG_DEFAULT), cregex_drop(&re)) c_formatch (i, &re, " Hello World C99! ") - printf("'%.*s'\n", c_ARGsv(i.match[0])); + printf("'%.*s'\n", c_ARGSV(i.match[0])); } diff --git a/examples/sso_substr.c b/examples/sso_substr.c index 0c8e9b22..ea10c411 100644 --- a/examples/sso_substr.c +++ b/examples/sso_substr.c @@ -9,7 +9,7 @@ int main () size_t pos = cstr_find(&str, "live"); // position of "live" csview sv2 = cstr_substr_ex(&str, pos, 4); // "live" csview sv3 = cstr_slice_ex(&str, -8, -1); // "details" - printf("%.*s, %.*s, %.*s\n", c_ARGsv(sv1), c_ARGsv(sv2), c_ARGsv(sv3)); + printf("%.*s, %.*s, %.*s\n", c_ARGSV(sv1), c_ARGSV(sv2), c_ARGSV(sv3)); cstr_assign(&str, "apples are green or red"); cstr s2 = cstr_from_sv(cstr_substr_ex(&str, -3, 3)); // "red" diff --git a/examples/sview_split.c b/examples/sview_split.c index 634fdc38..81d93276 100644 --- a/examples/sview_split.c +++ b/examples/sview_split.c @@ -11,7 +11,7 @@ int main() const csview month = csview_token(date, "/", &pos); const csview day = csview_token(date, "/", &pos); - printf("%.*s, %.*s, %.*s\n", c_ARGsv(year), c_ARGsv(month), c_ARGsv(day)); + printf("%.*s, %.*s, %.*s\n", c_ARGSV(year), c_ARGSV(month), c_ARGSV(day)); c_auto (cstr, y, m, d) { y = cstr_from_sv(year), m = cstr_from_sv(month), d = cstr_from_sv(day); diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c index be77d615..c2b3c0cf 100644 --- a/examples/utf8replace_c.c +++ b/examples/utf8replace_c.c @@ -17,7 +17,7 @@ int main() { upper = cstr_toupper_sv(cstr_sv(&hello)); c_foreach (c, cstr, hello) - printf("%.*s,", c_ARGsv(c.u8.chr)); + printf("%.*s,", c_ARGSV(c.u8.chr)); puts(""); } } diff --git a/examples/vikings.c b/examples/vikings.c index a1099d28..26a74757 100644 --- a/examples/vikings.c +++ b/examples/vikings.c @@ -23,11 +23,11 @@ static inline int RViking_cmp(const RViking* rx, const RViking* ry) { } static inline Viking Viking_from(RViking raw) { // note: parameter is by value - return c_init(Viking){cstr_from(raw.name), cstr_from(raw.country)}; + return c_INIT(Viking){cstr_from(raw.name), cstr_from(raw.country)}; } static inline RViking Viking_toraw(const Viking* vp) { - return c_init(RViking){cstr_str(&vp->name), cstr_str(&vp->country)}; + return c_INIT(RViking){cstr_str(&vp->name), cstr_str(&vp->country)}; } // With this in place, we define the Viking => int hash map type: diff --git a/include/stc/alt/csmap.h b/include/stc/alt/csmap.h index c1ceb756..65a9f80b 100644 --- a/include/stc/alt/csmap.h +++ b/include/stc/alt/csmap.h @@ -130,7 +130,7 @@ _cx_memb(_clear)(_cx_self* self) STC_INLINE _cx_raw _cx_memb(_value_toraw)(_cx_value* val) { return _i_SET_ONLY( i_keyto(val) ) - _i_MAP_ONLY( c_init(_cx_raw){i_keyto((&val->first)), + _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} ); } @@ -471,7 +471,7 @@ _cx_memb(_clone_r_)(_cx_node *tn) { STC_DEF _cx_self _cx_memb(_clone)(_cx_self cx) { - return c_init(_cx_self){_cx_memb(_clone_r_)(cx.root), cx.size}; + return c_INIT(_cx_self){_cx_memb(_clone_r_)(cx.root), cx.size}; } #endif // !i_no_clone diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index ba0eb0bb..4496fb35 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -31,16 +31,18 @@ #include <stdio.h> /* vsnprintf */ #include <ctype.h> +#define c_unchecked_container_of(ptr, type, member) \ + ((type*)((char*)(ptr) - offsetof(type, member))) + typedef char cstr_value; typedef struct { cstr_value* str; } cstr; -#define cstr_npos (SIZE_MAX >> 1) typedef struct { size_t size, cap; char chr[1]; } cstr_priv; #define _cstr_p(self) c_unchecked_container_of((self)->str, cstr_priv, chr) #ifdef i_static static cstr_priv _cstr_nullrep = {0, 0, {0}}; - static const cstr cstr_null = {_cstr_nullrep.chr}; + static const cstr cstr_NULL = {_cstr_nullrep.chr}; #else - extern const cstr cstr_null; + extern const cstr cstr_NULL; #endif /* optimal memory: based on malloc_usable_size() sequence: 24, 40, 56, ... */ #define _cstr_opt_mem(cap) ((((offsetof(cstr_priv, chr) + (cap) + 8)>>4)<<4) + 8) @@ -61,11 +63,11 @@ STC_API size_t cstr_find(const cstr* self, const char* needle); STC_API size_t cstr_find_at(const cstr* self, size_t pos, const char* needle); STC_API bool cstr_getdelim(cstr *self, int delim, FILE *stream); -STC_INLINE cstr cstr_init() { return cstr_null; } +STC_INLINE cstr cstr_init() { return cstr_NULL; } STC_INLINE const char* cstr_str(const cstr* self) { return self->str; } #define cstr_toraw(self) (self)->str STC_INLINE csview cstr_sv(const cstr* self) - { return c_init(csview){self->str, _cstr_p(self)->size}; } + { return c_INIT(csview){self->str, _cstr_p(self)->size}; } #define cstr_new(literal) \ cstr_from_n(literal, c_strlen_lit(literal)) STC_INLINE cstr cstr_from(const char* str) @@ -116,17 +118,17 @@ STC_INLINE bool cstr_getline(cstr *self, FILE *stream) STC_INLINE cstr_buf cstr_buffer(cstr* s) { cstr_priv* p = _cstr_p(s); - return c_init(cstr_buf){s->str, p->size, p->cap}; + return c_INIT(cstr_buf){s->str, p->size, p->cap}; } STC_INLINE cstr cstr_with_capacity(const size_t cap) { - cstr s = cstr_null; + cstr s = cstr_NULL; cstr_reserve(&s, cap); return s; } STC_INLINE cstr cstr_with_size(const size_t len, const char fill) { - cstr s = cstr_null; + cstr s = cstr_NULL; cstr_resize(&s, len, fill); return s; } @@ -147,7 +149,7 @@ STC_INLINE cstr* cstr_take(cstr* self, cstr s) { STC_INLINE cstr cstr_move(cstr* self) { cstr tmp = *self; - *self = cstr_null; + *self = cstr_NULL; return tmp; } @@ -192,7 +194,7 @@ cstr_replace(cstr* self, const char* find, const char* repl, unsigned count) { #ifndef i_static static cstr_priv _cstr_nullrep = {0, 0, {0}}; -const cstr cstr_null = {_cstr_nullrep.chr}; +const cstr cstr_NULL = {_cstr_nullrep.chr}; #endif STC_DEF char* @@ -219,7 +221,7 @@ cstr_resize(cstr* self, const size_t len, const char fill) { STC_DEF cstr cstr_from_n(const char* str, const size_t n) { - if (n == 0) return cstr_null; + if (n == 0) return cstr_NULL; cstr_priv* prv = (cstr_priv*) c_malloc(_cstr_opt_mem(n)); cstr s = {(char *) memcpy(prv->chr, str, n)}; s.str[prv->size = n] = '\0'; @@ -254,7 +256,7 @@ cstr_vfmt(cstr* self, const char* fmt, va_list args) { STC_DEF cstr cstr_from_fmt(const char* fmt, ...) { - cstr ret = cstr_null; + cstr ret = cstr_NULL; va_list args; va_start(args, fmt); cstr_vfmt(&ret, fmt, args); va_end(args); @@ -263,7 +265,7 @@ cstr_from_fmt(const char* fmt, ...) { STC_DEF int cstr_printf(cstr* self, const char* fmt, ...) { - cstr ret = cstr_null; + cstr ret = cstr_NULL; va_list args; va_start(args, fmt); int n = cstr_vfmt(&ret, fmt, args); @@ -320,7 +322,7 @@ cstr_replace_at_sv(cstr* self, const size_t pos, size_t len, csview repl) { STC_DEF cstr cstr_replace_sv(csview str, csview find, csview repl, unsigned count) { - cstr out = cstr_null; + cstr out = cstr_NULL; size_t from = 0; char* res; if (count == 0) count = ~0; if (find.size) @@ -368,14 +370,14 @@ cstr_getdelim(cstr *self, const int delim, FILE *fp) { STC_DEF size_t cstr_find(const cstr* self, const char* needle) { char* res = strstr(self->str, needle); - return res ? res - self->str : cstr_npos; + return res ? res - self->str : c_NPOS; } STC_DEF size_t cstr_find_at(const cstr* self, const size_t pos, const char* needle) { - if (pos > _cstr_p(self)->size) return cstr_npos; + if (pos > _cstr_p(self)->size) return c_NPOS; char* res = strstr(self->str + pos, needle); - return res ? res - self->str : cstr_npos; + return res ? res - self->str : c_NPOS; } #endif diff --git a/include/stc/carc.h b/include/stc/carc.h index 78887073..509bc595 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -71,7 +71,7 @@ int main() { #define c_atomic_dec_and_test(v) (atomic_fetch_sub(v, 1) == 1) #endif -#define carc_null {NULL, NULL} +#define carc_NULL {NULL, NULL} #define _cx_carc_rep struct _cx_memb(_rep_) #endif // CARC_H_INCLUDED @@ -94,7 +94,7 @@ _cx_deftypes(_c_carc_types, _cx_self, i_key); _cx_carc_rep { catomic_long counter; i_key value; }; STC_INLINE _cx_self _cx_memb(_init)(void) - { return c_init(_cx_self){NULL, NULL}; } + { return c_INIT(_cx_self){NULL, NULL}; } STC_INLINE long _cx_memb(_use_count)(const _cx_self* self) { return self->use_count ? *self->use_count : 0; } diff --git a/include/stc/carr2.h b/include/stc/carr2.h index 2574a933..4a12c2e3 100644 --- a/include/stc/carr2.h +++ b/include/stc/carr2.h @@ -91,11 +91,11 @@ STC_INLINE size_t _cx_memb(_idx)(const _cx_self* self, size_t x, size_t y) { STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { size_t n = self->xdim*self->ydim; - return c_init(_cx_iter){n ? *self->data : NULL, *self->data + n}; + return c_INIT(_cx_iter){n ? *self->data : NULL, *self->data + n}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_init(_cx_iter){NULL, *self->data + self->xdim*self->ydim}; } + { return c_INIT(_cx_iter){NULL, *self->data + self->xdim*self->ydim}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } diff --git a/include/stc/carr3.h b/include/stc/carr3.h index 0197e4f5..c22536cb 100644 --- a/include/stc/carr3.h +++ b/include/stc/carr3.h @@ -94,11 +94,11 @@ STC_INLINE size_t _cx_memb(_idx)(const _cx_self* self, size_t x, size_t y, size_ STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { size_t n = _cx_memb(_size)(self); - return c_init(_cx_iter){n ? **self->data : NULL, **self->data + n}; + return c_INIT(_cx_iter){n ? **self->data : NULL, **self->data + n}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_init(_cx_iter){NULL, **self->data + _cx_memb(_size)(self)}; } + { return c_INIT(_cx_iter){NULL, **self->data + _cx_memb(_size)(self)}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 031ef80c..8c0db10f 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -123,7 +123,7 @@ STC_INLINE bool _cbits_disjoint(const uint64_t* set, const uint64_t* other, cons struct { uint64_t *data64; size_t _size; } typedef i_type; -STC_INLINE cbits cbits_init(void) { return c_init(cbits){NULL}; } +STC_INLINE cbits cbits_init(void) { return c_INIT(cbits){NULL}; } STC_INLINE void cbits_create(cbits* self) { self->data64 = NULL; self->_size = 0; } STC_INLINE void cbits_drop(cbits* self) { c_free(self->data64); } STC_INLINE size_t cbits_size(const cbits* self) { return self->_size; } @@ -195,7 +195,7 @@ STC_INLINE cbits cbits_with_pattern(const size_t size, const uint64_t pattern) { struct { uint64_t data64[(i_capacity - 1)/64 + 1]; } typedef i_type; -STC_INLINE i_type _i_memb(_init)(void) { return c_init(i_type){0}; } +STC_INLINE i_type _i_memb(_init)(void) { return c_INIT(i_type){0}; } STC_INLINE void _i_memb(_create)(i_type* self) {} STC_INLINE void _i_memb(_drop)(i_type* self) {} STC_INLINE size_t _i_memb(_size)(const i_type* self) { return i_capacity; } diff --git a/include/stc/cbox.h b/include/stc/cbox.h index a5e01519..4cbd5f84 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -64,7 +64,7 @@ int main() { #include <stdlib.h> #include <string.h> -#define cbox_null {NULL} +#define cbox_NULL {NULL} #endif // CBOX_H_INCLUDED #ifndef _i_prefix @@ -79,13 +79,13 @@ _cx_deftypes(_c_cbox_types, _cx_self, i_key); // constructors (takes ownsership) STC_INLINE _cx_self _cx_memb(_init)(void) - { return c_init(_cx_self){NULL}; } + { return c_INIT(_cx_self){NULL}; } STC_INLINE long _cx_memb(_use_count)(const _cx_self* self) { return (long)(self->get != NULL); } STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p) - { return c_init(_cx_self){p}; } + { return c_INIT(_cx_self){p}; } // c++: std::make_unique<i_key>(val) STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) { diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 0777d0ce..c33f5f59 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -32,8 +32,10 @@ #if SIZE_MAX == UINT32_MAX #define c_ZU PRIu32 + #define c_NPOS INT32_MAX #elif SIZE_MAX == UINT64_MAX #define c_ZU PRIu64 + #define c_NPOS INT64_MAX #endif #if defined(_MSC_VER) @@ -61,22 +63,20 @@ #define c_static_assert(cond) \ typedef char c_paste(_static_assert_line_, __LINE__)[(cond) ? 1 : -1] -#define c_unchecked_container_of(ptr, type, member) \ - ((type*)((char*)(ptr) - offsetof(type, member))) #define c_container_of(p, T, m) \ ((T*)((char*)(p) + 0*sizeof((p) == &((T*)0)->m) - offsetof(T, m))) #ifndef __cplusplus #define c_alloc(T) c_malloc(sizeof(T)) #define c_alloc_n(T, n) c_malloc(sizeof(T)*(n)) - #define c_init(T) (T) #define c_new(T, ...) ((T*)memcpy(c_alloc(T), (T[]){__VA_ARGS__}, sizeof(T))) + #define c_INIT(T) (T) #else #include <new> #define c_alloc(T) static_cast<T*>(c_malloc(sizeof(T))) #define c_alloc_n(T, n) static_cast<T*>(c_malloc(sizeof(T)*(n))) - #define c_init(T) T #define c_new(T, ...) new (c_alloc(T)) T(__VA_ARGS__) + #define c_INIT(T) T #endif #ifndef c_malloc #define c_malloc(sz) malloc(sz) @@ -116,12 +116,12 @@ typedef const char* crawstr; #define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp)) #define crawstr_hash(p) cstrhash(*(p)) -#define c_strlen_lit(literal) (sizeof "" literal - 1U) +#define c_strlen_lit(literal) (sizeof("" literal) - 1U) #define c_sv(...) c_MACRO_OVERLOAD(c_sv, __VA_ARGS__) -#define c_sv1(lit) (c_init(csview){lit, c_strlen_lit(lit)}) -#define c_sv2(str, n) (c_init(csview){str, n}) -#define c_PRIsv ".*s" -#define c_ARGsv(sv) (int)(sv).size, (sv).str +#define c_sv1(lit) c_sv2(lit, c_strlen_lit(lit)) +#define c_sv2(str, n) (c_INIT(csview){str, n}) +#define c_ARGsv(sv) c_ARGSV(sv) /* [deprecated] */ +#define c_ARGSV(sv) (int)(sv).size, (sv).str /* use with "%.*s" */ #define c_PAIR(ref) (ref)->first, (ref)->second #define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k))) diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 11bc82d2..a8a704b4 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -99,11 +99,11 @@ STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) // == _pop() when _ STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { size_t n = self->_len; - return c_init(_cx_iter){n ? self->data : NULL, self->data + n}; + return c_INIT(_cx_iter){n ? self->data : NULL, self->data + n}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_init(_cx_iter){NULL, self->data + self->_len}; } + { return c_INIT(_cx_iter){NULL, self->data + self->_len}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } @@ -343,7 +343,7 @@ _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) { self->_len += n; pos = self->data + idx; } - return c_init(_cx_iter){pos, self->data + self->_len}; + return c_INIT(_cx_iter){pos, self->data + self->_len}; } STC_DEF _cx_value* @@ -375,7 +375,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { { i_keydrop(p); } memmove(p1, p2, (size_t)(end - p2)*sizeof *p1); self->_len -= (size_t)len; - return c_init(_cx_iter){p2 == end ? NULL : p1, end - len}; + return c_INIT(_cx_iter){p2 == end ? NULL : p1, end - len}; } #if !defined i_no_clone diff --git a/include/stc/clist.h b/include/stc/clist.h index cb692eae..8b96eabf 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -133,7 +133,7 @@ STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw) { return _cx_memb(_push_back)(self, i_keyfrom(raw)); } #endif // !i_no_emplace -STC_INLINE _cx_self _cx_memb(_init)(void) { return c_init(_cx_self){NULL}; } +STC_INLINE _cx_self _cx_memb(_init)(void) { return c_INIT(_cx_self){NULL}; } STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) { return true; } STC_INLINE bool _cx_memb(_empty)(const _cx_self* self) { return self->last == NULL; } STC_INLINE void _cx_memb(_clear)(_cx_self* self) { _cx_memb(_drop)(self); } @@ -157,12 +157,12 @@ _cx_memb(_count)(const _cx_self* self) { STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { _cx_value* head = self->last ? &self->last->next->value : NULL; - return c_init(_cx_iter){head, &self->last, self->last}; + return c_INIT(_cx_iter){head, &self->last, self->last}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_init(_cx_iter){NULL}; } + { return c_INIT(_cx_iter){NULL}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { diff --git a/include/stc/cmap.h b/include/stc/cmap.h index ff7c7840..dabb1138 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -107,7 +107,7 @@ STC_API chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawke STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey); STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* val); -STC_INLINE _cx_self _cx_memb(_init)(void) { return c_init(_cx_self){0}; } +STC_INLINE _cx_self _cx_memb(_init)(void) { return c_INIT(_cx_self){0}; } STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) { _cx_memb(_reserve)(self, self->size); } STC_INLINE float _cx_memb(_max_load_factor)(const _cx_self* self) { return (float)(i_max_load_factor); } STC_INLINE bool _cx_memb(_empty)(const _cx_self* map) { return !map->size; } @@ -167,7 +167,7 @@ _cx_memb(_emplace)(_cx_self* self, _cx_rawkey rkey _i_MAP_ONLY(, i_valraw rmappe STC_INLINE _cx_raw _cx_memb(_value_toraw)(const _cx_value* val) { return _i_SET_ONLY( i_keyto(val) ) - _i_MAP_ONLY( c_init(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} ); + _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} ); } STC_INLINE void @@ -208,7 +208,7 @@ _cx_memb(_begin)(const _cx_self* self) { STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_init(_cx_iter){NULL}; } + { return c_INIT(_cx_iter){NULL}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { @@ -226,7 +226,7 @@ STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) { size_t idx; if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx]) - return c_init(_cx_iter){self->table + idx, + return c_INIT(_cx_iter){self->table + idx, self->table + self->bucket_count, self->_hashx + idx}; return _cx_memb(_end)(self); diff --git a/include/stc/cpque.h b/include/stc/cpque.h index 996e1a22..9cf4b167 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -45,7 +45,7 @@ STC_API void _cx_memb(_erase_at)(_cx_self* self, size_t idx); STC_API void _cx_memb(_push)(_cx_self* self, _cx_value value); STC_INLINE _cx_self _cx_memb(_init)(void) - { return c_init(_cx_self){NULL}; } + { return c_INIT(_cx_self){NULL}; } STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, const size_t cap) { if (cap != self->_len && cap <= self->_cap) return true; diff --git a/include/stc/crandom.h b/include/stc/crandom.h index 6c41be83..6f65c84c 100644 --- a/include/stc/crandom.h +++ b/include/stc/crandom.h @@ -100,12 +100,12 @@ STC_INLINE double stc64_uniformf(stc64_t* rng, stc64_uniformf_t* dist) { /* Init uniform distributed float64 RNG, range [low, high). */ STC_INLINE stc64_uniformf_t stc64_uniformf_new(double low, double high) { - return c_init(stc64_uniformf_t){low, high - low}; + return c_INIT(stc64_uniformf_t){low, high - low}; } /* Marsaglia polar method for gaussian/normal distribution, float64. */ STC_INLINE stc64_normalf_t stc64_normalf_new(double mean, double stddev) { - return c_init(stc64_normalf_t){mean, stddev, 0.0, 0}; + return c_INIT(stc64_normalf_t){mean, stddev, 0.0, 0}; } /* -------------------------- IMPLEMENTATION ------------------------- */ diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 68b69831..5c73294e 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -144,7 +144,7 @@ _cx_memb(_clear)(_cx_self* self) STC_INLINE _cx_raw _cx_memb(_value_toraw)(const _cx_value* val) { return _i_SET_ONLY( i_keyto(val) ) - _i_MAP_ONLY( c_init(_cx_raw){i_keyto((&val->first)), + _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} ); } @@ -232,7 +232,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t cap) { _cx_node* nodes = (_cx_node*)c_realloc(self->nodes, (cap + 1)*sizeof(_cx_node)); if (!nodes) return false; - nodes[0] = c_init(_cx_node){{0, 0}, 0}; + nodes[0] = c_INIT(_cx_node){{0, 0}, 0}; self->nodes = nodes; self->cap = (i_size)cap; return true; diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 7aacb076..23778e3c 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -170,12 +170,12 @@ STC_INLINE i_keyraw _cx_memb(_value_toraw)(const _cx_value* val) #endif // !i_no_clone STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { - return c_init(_cx_iter){self->_len ? (_cx_value*)self->data : NULL, + return c_INIT(_cx_iter){self->_len ? (_cx_value*)self->data : NULL, (_cx_value*)self->data + self->_len}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_init(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; } + { return c_INIT(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 29a2e4a4..b60a072e 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -71,8 +71,7 @@ STC_API char* _cstr_internal_move(cstr* self, size_t pos1, size_t pos2); /**************************** PUBLIC API **********************************/ #define cstr_new(literal) cstr_from_n(literal, c_strlen_lit(literal)) -#define cstr_npos (SIZE_MAX >> 1) -#define cstr_null (c_init(cstr){{{0}, 0}}) +#define cstr_NULL (c_INIT(cstr){{{0}, 0}}) #define cstr_toraw(self) cstr_str(self) STC_API char* cstr_reserve(cstr* self, size_t cap); @@ -92,16 +91,16 @@ STC_API cstr cstr_replace_sv(csview sv, csview search, csview repl, unsigned STC_INLINE cstr_buf cstr_buffer(cstr* s) { return cstr_is_long(s) - ? c_init(cstr_buf){s->lon.data, cstr_l_size(s), cstr_l_cap(s)} - : c_init(cstr_buf){s->sml.data, cstr_s_size(s), cstr_s_cap}; + ? c_INIT(cstr_buf){s->lon.data, cstr_l_size(s), cstr_l_cap(s)} + : c_INIT(cstr_buf){s->sml.data, cstr_s_size(s), cstr_s_cap}; } STC_INLINE csview cstr_sv(const cstr* s) { - return cstr_is_long(s) ? c_init(csview){s->lon.data, cstr_l_size(s)} - : c_init(csview){s->sml.data, cstr_s_size(s)}; + return cstr_is_long(s) ? c_INIT(csview){s->lon.data, cstr_l_size(s)} + : c_INIT(csview){s->sml.data, cstr_s_size(s)}; } STC_INLINE cstr cstr_init(void) - { return cstr_null; } + { return cstr_NULL; } STC_INLINE cstr cstr_from_n(const char* str, const size_t len) { cstr s; @@ -136,7 +135,7 @@ STC_INLINE cstr* cstr_take(cstr* self, const cstr s) { STC_INLINE cstr cstr_move(cstr* self) { cstr tmp = *self; - *self = cstr_null; + *self = cstr_NULL; return tmp; } @@ -224,11 +223,11 @@ STC_INLINE csview cstr_u8_chr(const cstr* self, size_t u8idx) { STC_INLINE cstr_iter cstr_begin(const cstr* self) { csview sv = cstr_sv(self); - if (!sv.size) return c_init(cstr_iter){NULL}; - return c_init(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}}}; + if (!sv.size) return c_INIT(cstr_iter){NULL}; + return c_INIT(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}}}; } STC_INLINE cstr_iter cstr_end(const cstr* self) { - (void)self; return c_init(cstr_iter){NULL}; + (void)self; return c_INIT(cstr_iter){NULL}; } STC_INLINE void cstr_next(cstr_iter* it) { it->ref += it->u8.chr.size; @@ -283,7 +282,7 @@ STC_INLINE bool cstr_iequals(const cstr* self, const char* str) STC_INLINE size_t cstr_find(const cstr* self, const char* search) { const char *str = cstr_str(self), *res = strstr((char*)str, search); - return res ? (size_t)(res - str) : cstr_npos; + return res ? (size_t)(res - str) : c_NPOS; } STC_API size_t cstr_find_sv(const cstr* self, csview search); @@ -296,7 +295,7 @@ STC_INLINE bool cstr_contains(const cstr* self, const char* search) { return strstr((char*)cstr_str(self), search) != NULL; } STC_INLINE bool cstr_contains_sv(const cstr* self, csview search) - { return cstr_find_sv(self, search) != cstr_npos; } + { return cstr_find_sv(self, search) != c_NPOS; } STC_INLINE bool cstr_contains_s(const cstr* self, cstr search) { return strstr((char*)cstr_str(self), cstr_str(&search)) != NULL; } @@ -450,7 +449,7 @@ STC_DEF uint64_t cstr_hash(const cstr *self) { STC_DEF size_t cstr_find_sv(const cstr* self, csview search) { csview sv = cstr_sv(self); char* res = cstrnstrn(sv.str, search.str, sv.size, search.size); - return res ? (size_t)(res - sv.str) : cstr_npos; + return res ? (size_t)(res - sv.str) : c_NPOS; } STC_DEF char* _cstr_internal_move(cstr* self, const size_t pos1, const size_t pos2) { @@ -522,9 +521,9 @@ STC_DEF void cstr_resize(cstr* self, const size_t size, const char value) { STC_DEF size_t cstr_find_at(const cstr* self, const size_t pos, const char* search) { csview sv = cstr_sv(self); - if (pos > sv.size) return cstr_npos; + if (pos > sv.size) return c_NPOS; const char* res = strstr((char*)sv.str + pos, search); - return res ? (size_t)(res - sv.str) : cstr_npos; + return res ? (size_t)(res - sv.str) : c_NPOS; } STC_DEF char* cstr_assign_n(cstr* self, const char* str, const size_t len) { @@ -568,7 +567,7 @@ STC_DEF bool cstr_getdelim(cstr *self, const int delim, FILE *fp) { STC_DEF cstr cstr_replace_sv(csview in, csview search, csview repl, unsigned count) { - cstr out = cstr_null; + cstr out = cstr_NULL; size_t from = 0; char* res; if (!count) count = ~0U; if (search.size) @@ -627,7 +626,7 @@ STC_DEF size_t cstr_vfmt(cstr* self, size_t start, const char* fmt, va_list args #endif STC_DEF cstr cstr_from_fmt(const char* fmt, ...) { - cstr s = cstr_null; + cstr s = cstr_NULL; va_list args; va_start(args, fmt); cstr_vfmt(&s, 0, fmt, args); diff --git a/include/stc/csview.h b/include/stc/csview.h index 4bd37173..e0f2ad0e 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -27,19 +27,17 @@ #include "forward.h" #include "utf8.h" -#define csview_null c_sv("") -#define csview_npos (SIZE_MAX >> 1) - -#define csview_init() csview_null -#define csview_drop c_default_drop -#define csview_clone c_default_clone -#define csview_from_n c_sv +#define csview_NULL c_sv1("") +#define csview_init() csview_NULL +#define csview_drop(p) c_default_drop(p) +#define csview_clone(sv) c_default_clone(sv) +#define csview_from_n(str, n) c_sv2(str, n) STC_API size_t csview_find_sv(csview sv, csview search); STC_INLINE csview csview_from(const char* str) - { return c_init(csview){str, strlen(str)}; } -STC_INLINE void csview_clear(csview* self) { *self = csview_null; } + { return c_INIT(csview){str, strlen(str)}; } +STC_INLINE void csview_clear(csview* self) { *self = csview_NULL; } STC_INLINE size_t csview_size(csview sv) { return sv.size; } STC_INLINE bool csview_empty(csview sv) { return sv.size == 0; } @@ -51,7 +49,7 @@ STC_INLINE size_t csview_find(csview sv, const char* str) { return csview_find_sv(sv, c_sv(str, strlen(str))); } STC_INLINE bool csview_contains(csview sv, const char* str) - { return csview_find(sv, str) != csview_npos; } + { return csview_find(sv, str) != c_NPOS; } STC_INLINE bool csview_starts_with(csview sv, const char* str) { size_t n = strlen(str); @@ -77,12 +75,12 @@ STC_INLINE csview csview_slice(csview sv, size_t p1, size_t p2) { /* utf8 iterator */ STC_INLINE csview_iter csview_begin(const csview* self) { - if (!self->size) return c_init(csview_iter){NULL}; - return c_init(csview_iter){.u8 = {{self->str, utf8_chr_size(self->str)}, + if (!self->size) return c_INIT(csview_iter){NULL}; + return c_INIT(csview_iter){.u8 = {{self->str, utf8_chr_size(self->str)}, self->str + self->size}}; } STC_INLINE csview_iter csview_end(const csview* self) { - return c_init(csview_iter){.u8 = {{NULL}, self->str + self->size}}; + return c_INIT(csview_iter){.u8 = {{NULL}, self->str + self->size}}; } STC_INLINE void csview_next(csview_iter* it) { it->ref += it->u8.chr.size; @@ -164,7 +162,7 @@ STC_API uint64_t csview_hash(const csview *self); STC_DEF size_t csview_find_sv(csview sv, csview search) { char* res = cstrnstrn(sv.str, search.str, sv.size, search.size); - return res ? (size_t)(res - sv.str) : csview_npos; + return res ? (size_t)(res - sv.str) : c_NPOS; } STC_DEF uint64_t csview_hash(const csview *self) diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 7a674228..ae6e452c 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -196,11 +196,11 @@ _cx_memb(_at_mut)(_cx_self* self, const size_t idx) { STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { size_t n = self->_len; - return c_init(_cx_iter){n ? self->data : NULL, self->data + n}; + return c_INIT(_cx_iter){n ? self->data : NULL, self->data + n}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_init(_cx_iter){NULL, self->data + self->_len}; } + { return c_INIT(_cx_iter){NULL, self->data + self->_len}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } @@ -325,7 +325,7 @@ _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) { memmove(pos + n, pos, (self->_len - idx)*sizeof *pos); self->_len += n; } - return c_init(_cx_iter){pos, self->data + self->_len}; + return c_INIT(_cx_iter){pos, self->data + self->_len}; } STC_DEF _cx_iter @@ -345,7 +345,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { { i_keydrop(p); } memmove(p1, p2, (size_t)(end - p2)*sizeof *p1); self->_len -= len; - return c_init(_cx_iter){p2 == end ? NULL : p1, end - len}; + return c_INIT(_cx_iter){p2 == end ? NULL : p1, end - len}; } #if !defined i_no_clone diff --git a/src/cregex.c b/src/cregex.c index acbf53fa..94e591a4 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -1174,7 +1174,7 @@ _build_subst(const char* replace, unsigned nmatch, const csview match[], cstr_buf buf = cstr_buffer(subst); size_t len = 0, cap = buf.cap; char* dst = buf.data; - cstr mstr = cstr_null; + cstr mstr = cstr_NULL; while (*replace != '\0') { if (*replace == '$') { @@ -1248,8 +1248,8 @@ cregex_find_pattern(const char* pattern, const char* input, cstr cregex_replace_sv(const cregex* re, csview input, const char* replace, unsigned count, bool (*mfun)(int, csview, cstr*), int rflags) { - cstr out = cstr_null; - cstr subst = cstr_null; + cstr out = cstr_NULL; + cstr subst = cstr_NULL; csview match[CREG_MAX_CAPTURES]; unsigned nmatch = cregex_captures(re); if (!count) count = ~0U; |
