summaryrefslogtreecommitdiffhomepage
path: root/include/stc
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-09-06 18:20:23 +0200
committerTyge Løvset <[email protected]>2022-09-06 18:20:23 +0200
commit90311ff7eb34e5fc4fc1c2c38b8d0433642e9659 (patch)
tree11352fe3b7530ed1c6b49fa1914ccef7142c92b4 /include/stc
parent2857a84df612d2e1ae4389e3a747a39d933c0400 (diff)
downloadSTC-modified-90311ff7eb34e5fc4fc1c2c38b8d0433642e9659.tar.gz
STC-modified-90311ff7eb34e5fc4fc1c2c38b8d0433642e9659.zip
- 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.
Diffstat (limited to 'include/stc')
-rw-r--r--include/stc/cregex.h4
-rw-r--r--include/stc/csview.h5
2 files changed, 7 insertions, 2 deletions
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