From 307c0a111c8f063032ba90b2a7ae07122e2a2b1a Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 21 Sep 2022 14:54:47 +0200 Subject: Recent macro renames: c_foreach_token() => c_fortoken() c_foreach_match() => c_formatch() Added: c_forfiltered() c_forpred() --- include/stc/ccommon.h | 8 ++++---- include/stc/cregex.h | 2 +- include/stc/csview.h | 15 +++++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index db273296..01af3111 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -164,13 +164,13 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle, #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=1} \ + 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_forfilter(...) c_MACRO_OVERLOAD(c_forfilter, __VA_ARGS__) -#define c_forfilter4(it, C, cnt, filter) \ +#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_forfilter5(it, C, cnt, filter, pred) \ +#define c_forfiltered5(it, C, cnt, filter, pred) \ c_forpred(it, C, cnt, pred) if (!((filter) && ++it.count)) ; else #define c_forpair(key, val, C, cnt) /* structured binding */ \ diff --git a/include/stc/cregex.h b/include/stc/cregex.h index 2222dc45..6c817f1c 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -77,7 +77,7 @@ typedef struct { csview match[cre_MAXCAPTURES]; } cregex_iter; -#define c_foreach_match(it, Re, Input) \ +#define c_formatch(it, Re, Input) \ for (cregex_iter it = {Re, Input}; \ cregex_find(it.re, it.input, it.match, cre_m_next) == cre_success;) diff --git a/include/stc/csview.h b/include/stc/csview.h index 5d30174f..f2ac1c42 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -31,7 +31,10 @@ #define csview_new(literal) c_sv(literal) #define csview_npos (SIZE_MAX >> 1) -STC_INLINE csview csview_init() { return csview_null; } +#define csview_init() csview_null +#define csview_drop(p) (p) +#define csview_clone(sv) (sv) + STC_INLINE csview csview_from(const char* str) { return c_make(csview){str, strlen(str)}; } STC_INLINE void csview_clear(csview* self) { *self = csview_null; } @@ -103,13 +106,13 @@ STC_API csview csview_substr_ex(csview sv, intptr_t pos, size_t n); STC_API csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2); STC_API csview csview_token(csview sv, csview sep, size_t* start); -#define c_foreach_token_sv(it, input, sep) \ - for (struct { csview _inp, _sep, token; size_t pos; } \ - it = {._inp=input, ._sep=sep, .token=it._inp, .pos=0} \ +#define c_fortoken_sv(it, input, sep) \ + for (struct { csview _inp, _sep, token, *ref; size_t pos; } \ + it = {._inp=input, ._sep=sep, .token=it._inp, .ref=&it.token, .pos=0} \ ; it.pos <= it._inp.size && (it.token = csview_token(it._inp, it._sep, &it.pos)).str ; ) -#define c_foreach_token(it, input, sep) \ - c_foreach_token_sv(it, csview_from(input), csview_from(sep)) +#define c_fortoken(it, input, sep) \ + c_fortoken_sv(it, csview_from(input), csview_from(sep)) /* csview interaction with cstr: */ #ifdef CSTR_H_INCLUDED -- cgit v1.2.3