From 90311ff7eb34e5fc4fc1c2c38b8d0433642e9659 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 6 Sep 2022 18:20:23 +0200 Subject: - Added c_foreach_token(it, ...) macro in csview.h. - Changed c_foreach_match(it, ...): to access matches, use it.match[j] - splitstr.c now shows usages of both the above. --- include/stc/cregex.h | 4 ++-- include/stc/csview.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/stc/cregex.h b/include/stc/cregex.h index 4812bff2..f0dd13aa 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -73,12 +73,12 @@ typedef struct { typedef struct { const cregex* re; const char* input; - csview ref[cre_MAXCAPTURES]; + csview match[cre_MAXCAPTURES]; } cregex_iter; #define c_foreach_match(it, Re, Input) \ for (cregex_iter it = {Re, Input}; \ - cregex_find(it.input, it.re, it.ref, cre_m_next) == cre_success;) + cregex_find(it.input, it.re, it.match, cre_m_next) == cre_success;) static inline cregex cregex_init(void) { diff --git a/include/stc/csview.h b/include/stc/csview.h index 555dd538..bfbf1c61 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -103,6 +103,11 @@ 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(it, input, sep) \ + for (struct { csview token, _sep, _inp; size_t start; } \ + it = {.token=csview_from(input), ._sep=csview_from(sep), ._inp=it.token, .start=0} \ + ; it.start <= it._inp.size && (it.token = csview_token(it._inp, it._sep, &it.start)).str ; ) + /* csview interaction with cstr: */ #ifdef CSTR_H_INCLUDED -- cgit v1.2.3