diff options
| author | Tyge Løvset <[email protected]> | 2022-09-11 18:30:00 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-09-11 21:47:10 +0200 |
| commit | c319568654c54243cb8fdb54f4ff53f0300a09a8 (patch) | |
| tree | 8ec9558df96896d4d3f23fe2479988e86858a407 /include/stc/cregex.h | |
| parent | 7eaeb7bb2c7cad9b0a437df71a396424b0c6933e (diff) | |
| download | STC-modified-c319568654c54243cb8fdb54f4ff53f0300a09a8.tar.gz STC-modified-c319568654c54243cb8fdb54f4ff53f0300a09a8.zip | |
Changed cregex API:
1) Renamed:
cregex_find_pt() -> cregex_find_pattern()
cregex_replace_pe() -> cregex_replace_pattern()
cregex_replace_ex() -> cregex_replace_sv()
2) Removed: cregex_replace_pt()
3) Moved cregex* (or pattern) to be first parameter.
Diffstat (limited to 'include/stc/cregex.h')
| -rw-r--r-- | include/stc/cregex.h | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/include/stc/cregex.h b/include/stc/cregex.h index f0dd13aa..17c3ec61 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -78,7 +78,7 @@ typedef struct { #define c_foreach_match(it, Re, Input) \ for (cregex_iter it = {Re, Input}; \ - cregex_find(it.input, it.re, it.match, cre_m_next) == cre_success;) + cregex_find(it.re, it.input, it.match, cre_m_next) == cre_success;) static inline cregex cregex_init(void) { @@ -100,36 +100,35 @@ cregex cregex_from(const char* pattern, int cflags) { int cregex_captures(const cregex* self); /* return 1 on match, 0 on nomatch, and -1 on failure. */ -int cregex_find(const char* input, const cregex* re, +int cregex_find(const cregex* re, const char* input, csview match[], int mflags); static inline -int cregex_find_sv(csview input, const cregex* re, csview match[]) { +int cregex_find_sv(const cregex* re, csview input, csview match[]) { match[0] = input; - return cregex_find(input.str, re, match, cre_m_startend); + return cregex_find(re, input.str, match, cre_m_startend); } /* match + compile RE pattern */ -int cregex_find_pt(const char* input, const char* pattern, - csview match[], int cmflags); +int cregex_find_pattern(const char* pattern, const char* input, + csview match[], int cmflags); static inline -bool cregex_is_match(const char* input, const cregex* re) - { return cregex_find(input, re, NULL, 0) == cre_success; } +bool cregex_is_match(const cregex* re, const char* input) + { return cregex_find(re, input, NULL, 0) == cre_success; } /* replace regular expression */ -cstr cregex_replace_ex(const char* input, const cregex* re, const char* replace, unsigned count, +cstr cregex_replace_sv(const cregex* re, csview input, const char* replace, unsigned count, int rflags, bool (*mfun)(int i, csview match, cstr* mstr)); -static inline -cstr cregex_replace(const char* input, const cregex* re, const char* replace, unsigned count) - { return cregex_replace_ex(input, re, replace, count, 0, NULL); } -/* replace + compile RE pattern, and extra arguments */ -cstr cregex_replace_pe(const char* input, const char* pattern, const char* replace, unsigned count, - int crflags, bool (*mfun)(int i, csview match, cstr* mstr)); static inline -cstr cregex_replace_pt(const char* input, const char* pattern, const char* replace, unsigned count) - { return cregex_replace_pe(input, pattern, replace, count, 0, NULL); } +cstr cregex_replace(const cregex* re, const char* input, const char* replace, unsigned count) { + csview sv = {input, strlen(input)}; + return cregex_replace_sv(re, sv, replace, count, 0, NULL); +} +/* replace + compile RE pattern, and extra arguments */ +cstr cregex_replace_pattern(const char* pattern, const char* input, const char* replace, unsigned count, + int crflags, bool (*mfun)(int i, csview match, cstr* mstr)); /* destroy regex */ void cregex_drop(cregex* self); |
