diff options
| author | Tyge Løvset <[email protected]> | 2022-07-28 00:24:13 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-07-28 12:39:34 +0200 |
| commit | 281a4148d9143260c614c92e81d3484103479761 (patch) | |
| tree | 6661f8f41c416c0120d677fbaffb07f9b3eabbc9 /include/stc/cregex.h | |
| parent | 18392a1f49bb742fce3e28bb8196b2a64ea07219 (diff) | |
| download | STC-modified-281a4148d9143260c614c92e81d3484103479761.tar.gz STC-modified-281a4148d9143260c614c92e81d3484103479761.zip | |
VERSION 3.8 RC. Added cregex with "final" API + docs. README.md updated with links to cregex, coption.
crandom.h: fixed "stc64_with_seq doesn't use seq argument #31" thanks to funny-falcon. Removed deprecated funcs.
Added tags for v3.6 and v3.7.
Diffstat (limited to 'include/stc/cregex.h')
| -rw-r--r-- | include/stc/cregex.h | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/include/stc/cregex.h b/include/stc/cregex.h index c920ae7b..4247197c 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -1,6 +1,5 @@ /* This is a Unix port of the Plan 9 regular expression library, by Rob Pike. -Please send comments about the packaging to Russ Cox <[email protected]>. Copyright © 2021 Plan 9 Foundation Copyright © 2022 Tyge Løvset, for additions made in 2022. @@ -31,6 +30,7 @@ THE SOFTWARE. * This is a extended version of regexp9, supporting UTF8 input, common * shorthand character classes, ++. */ +#include <stdbool.h> #include "forward.h" // csview typedef enum { @@ -52,12 +52,14 @@ typedef enum { enum { /* compile-flags */ - cre_c_dotall = 1<<0, - cre_c_caseless = 1<<1, + cre_c_dotall = 1<<0, /* dot matches newline too */ + cre_c_caseless = 1<<1, /* ignore case */ /* match-flags */ - cre_m_fullmatch = 1<<2, - cre_m_next = 1<<3, - cre_m_startend = 1<<4, + cre_m_fullmatch = 1<<2, /* like start-, end-of-line anchors were in pattern: "^ ... $" */ + cre_m_next = 1<<3, /* use end of previous match[0] as start of input */ + cre_m_startend = 1<<4, /* use match[0] as start+end of input */ + /* replace-flags */ + cre_r_strip = 1<<5, /* only keep the matched strings, strip rest */ /* limits */ cre_MAXCLASSES = 16, cre_MAXCAPTURES = 32, @@ -103,14 +105,14 @@ bool cregex_is_match(const char* input, const cregex* re, int mflags) /* replace regular expression */ cstr cregex_replace_re(const char* input, const cregex* re, const char* replace, - bool (*mfun)(int i, csview match, cstr* mstr), unsigned count); + bool (*mfun)(int i, csview match, cstr* mstr), unsigned count, int rflags); static inline cstr cregex_replace(const char* input, const cregex* re, const char* replace) - { return cregex_replace_re(input, re, replace, NULL, 0); } + { return cregex_replace_re(input, re, replace, NULL, 0, 0); } /* replace + compile RE pattern, and extra arguments */ cstr cregex_replace_pe(const char* input, const char* pattern, const char* replace, - bool (*mfun)(int i, csview match, cstr* mstr), unsigned count, int cflags); + bool (*mfun)(int i, csview match, cstr* mstr), unsigned count, int crflags); static inline cstr cregex_replace_p(const char* input, const char* pattern, const char* replace) { return cregex_replace_pe(input, pattern, replace, NULL, 0, 0); } |
