diff options
| author | Tyge Løvset <[email protected]> | 2022-09-21 19:28:23 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-09-21 19:28:23 +0200 |
| commit | c3cefd740a90378a53698df639d7889c6baffcb8 (patch) | |
| tree | 06abef793b8f9eabed59000596c4fe78601c3edc /include | |
| parent | 307c0a111c8f063032ba90b2a7ae07122e2a2b1a (diff) | |
| download | STC-modified-c3cefd740a90378a53698df639d7889c6baffcb8.tar.gz STC-modified-c3cefd740a90378a53698df639d7889c6baffcb8.zip | |
Added cstr_push(), cstr_pop() - push/pop one utf8 char.
Renamed c_forpred() to c_forloop() - used by c_forfiltered().
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/ccommon.h | 16 | ||||
| -rw-r--r-- | include/stc/csmap.h | 3 | ||||
| -rw-r--r-- | include/stc/cstr.h | 10 | ||||
| -rw-r--r-- | include/stc/csview.h | 4 |
4 files changed, 22 insertions, 11 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 01af3111..64c39da0 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -162,16 +162,16 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle, for (C##_iter it = start, *_endref = (C##_iter*)(finish).ref \ ; it.ref != (C##_value*)_endref; C##_next(&it)) -#define c_forpred(i, C, cnt, pred) \ - for (struct {C##_iter it; const C##_value *ref; size_t idx, count;} \ - i = {.it=C##_begin(&cnt), .ref=i.it.ref, .idx=0, .count=0} \ - ; i.ref && (pred); C##_next(&i.it), i.ref = i.it.ref, ++i.idx) - #define c_forfiltered(...) c_MACRO_OVERLOAD(c_forfiltered, __VA_ARGS__) #define c_forfiltered4(it, C, cnt, filter) \ - c_forpred(it, C, cnt, true) if (!(filter)) ; else -#define c_forfiltered5(it, C, cnt, filter, pred) \ - c_forpred(it, C, cnt, pred) if (!((filter) && ++it.count)) ; else + c_forloop(it, C, cnt, true) if (!(filter)) ; else +#define c_forfiltered5(it, C, cnt, filter, cond) \ + c_forloop(it, C, cnt, cond) if (!((filter) && ++it.count)) ; else + +#define c_forloop(i, C, cnt, cond) \ + for (struct {C##_iter it; const C##_value *ref; size_t idx, count;} \ + i = {.it=C##_begin(&cnt), .ref=i.it.ref, .idx=0, .count=0} \ + ; i.ref && (cond); C##_next(&i.it), i.ref = i.it.ref, ++i.idx) #define c_forpair(key, val, C, cnt) /* structured binding */ \ for (struct {C##_iter _it; const C##_key* key; C##_mapped* val;} _ = {C##_begin(&cnt)} \ diff --git a/include/stc/csmap.h b/include/stc/csmap.h index c773e70f..bcb85a6b 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -150,7 +150,8 @@ _cx_memb(_value_toraw)(const _cx_value* val) { STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { - const _cx_rawkey rx = i_keyto(_i_keyref(x)), ry = i_keyto(_i_keyref(y)); + const _cx_rawkey rx = i_keyto(_i_keyref(x)); + const _cx_rawkey ry = i_keyto(_i_keyref(y)); return i_cmp((&rx), (&ry)); } diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 983c3d4b..1e7a351f 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -349,6 +349,16 @@ STC_INLINE char* cstr_copy(cstr* self, cstr s) { } +STC_INLINE char* cstr_push(cstr* self, const char* chr) + { return cstr_append_n(self, chr, utf8_chr_size(chr)); } + +STC_INLINE void cstr_pop(cstr* self) { + csview sv = cstr_sv(self); + const char* s = sv.str + sv.size; + while ((*--s & 0xC0) == 0x80) ; + _cstr_set_size(self, s - sv.str); +} + STC_INLINE char* cstr_append(cstr* self, const char* str) { return cstr_append_n(self, str, strlen(str)); } diff --git a/include/stc/csview.h b/include/stc/csview.h index f2ac1c42..54a4c4cc 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -32,8 +32,8 @@ #define csview_npos (SIZE_MAX >> 1) #define csview_init() csview_null -#define csview_drop(p) (p) -#define csview_clone(sv) (sv) +#define csview_drop c_default_drop +#define csview_clone c_default_clone STC_INLINE csview csview_from(const char* str) { return c_make(csview){str, strlen(str)}; } |
