diff options
| author | Tyge Løvset <[email protected]> | 2022-08-02 17:09:13 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-08-02 17:09:13 +0200 |
| commit | 9a9b6b2b7b7931bf9ad301ba34aa53c341ec2505 (patch) | |
| tree | efe47167a4ce65159204728c6223e970f586e0a3 /include | |
| parent | a0b56360cc65f9add1ab169beeb063a3cbd1322f (diff) | |
| download | STC-modified-9a9b6b2b7b7931bf9ad301ba34aa53c341ec2505.tar.gz STC-modified-9a9b6b2b7b7931bf9ad301ba34aa53c341ec2505.zip | |
Improved the cregex_iter type and c_foreach_match() macro.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/cregex.h | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/include/stc/cregex.h b/include/stc/cregex.h index fbf5b931..653b0b07 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -70,16 +70,19 @@ typedef struct { int error; } cregex; -#define c_foreach_match(m, re, input) \ - for (csview m[cre_MAXCAPTURES] = {{0}}, _c_in = csview_from(input); \ - cregex_find(_c_in.str, re, m, cre_m_next) == cre_success; ) - -//typedef csview cregmatch; +typedef struct { + const cregex* re; + const char* input; + csview ref[cre_MAXCAPTURES]; +} cregex_iter; + +#define c_foreach_match(i, _re, _input) \ + for (cregex_iter i = {_re, _input}; cregex_find(i.input, i.re, i.ref, cre_m_next) == cre_success;) static inline cregex cregex_init(void) { - cregex rx = {0}; - return rx; + cregex re = {0}; + return re; } /* return 1 on success, or negative error code on failure. */ @@ -87,9 +90,9 @@ int cregex_compile(cregex *self, const char* pattern, int cflags); static inline cregex cregex_from(const char* pattern, int cflags) { - cregex rx = {0}; - cregex_compile(&rx, pattern, cflags); - return rx; + cregex re = {0}; + cregex_compile(&re, pattern, cflags); + return re; } /* number of capture groups in a regex pattern, 0 if regex is invalid */ |
