diff options
| author | Tyge Lovset <[email protected]> | 2022-07-20 23:33:22 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-07-20 23:33:22 +0200 |
| commit | 6fcb91a18f3a97be0469211fffeafff533219715 (patch) | |
| tree | 497d3186a016994bc5daa6f41a55db90dba66489 | |
| parent | 3f89c290700618eae78eaa289bdb88d1cfb3514d (diff) | |
| download | STC-modified-6fcb91a18f3a97be0469211fffeafff533219715.tar.gz STC-modified-6fcb91a18f3a97be0469211fffeafff533219715.zip | |
Cleanups, and renamed cregex_replace_fn() => cregex_replace_ex().
| -rw-r--r-- | examples/regex_replace.c | 3 | ||||
| -rw-r--r-- | include/stc/cregex.h | 7 | ||||
| -rw-r--r-- | src/utf8code.c | 4 |
3 files changed, 5 insertions, 9 deletions
diff --git a/examples/regex_replace.c b/examples/regex_replace.c index 1216701f..2383a119 100644 --- a/examples/regex_replace.c +++ b/examples/regex_replace.c @@ -17,7 +17,6 @@ int main() const char* pattern = "\\b(\\d\\d\\d\\d)-(1[0-2]|0[1-9])-(3[01]|[12][0-9]|0[1-9])\\b"; const char* input = "start date: 2015-12-31, end date: 2022-02-28"; - c_auto (cregex, re) c_auto (cstr, str1, str2) { printf("input: %s\n", input); @@ -26,7 +25,7 @@ int main() printf("euros: %s\n", cstr_str(&str1)); /* US date format, and subtract 20 years: */ - str2 = cregex_replace_fn(input, pattern, "\\1/\\3/\\2", sub_20y, 0, 0); + str2 = cregex_replace_ex(input, pattern, "\\1/\\3/\\2", sub_20y, 0, 0); printf("us-20: %s\n", cstr_str(&str2)); } } diff --git a/include/stc/cregex.h b/include/stc/cregex.h index 11e21b06..a59a876c 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -84,17 +84,14 @@ int cregex_match(const cregex *self, const char* string, unsigned nmatch, csview match[], int mflags); /* replace regular expression */ -void cregex_build_replace(const char* repl, unsigned nmatch, const csview match[], - cstr (*mfun)(int i, csview match), cstr* out); - cstr cregex_replace_re(const char* input, const cregex* re, const char* repl, cstr (*mfun)(int i, csview match), int cflags, unsigned count); -cstr cregex_replace_fn(const char* input, const char* pattern, const char* replace, +cstr cregex_replace_ex(const char* input, const char* pattern, const char* replace, cstr (*mfun)(int i, csview match), int cflags, unsigned count); static inline cstr cregex_replace(const char* input, const char* pattern, const char* replace) - { return cregex_replace_fn(input, pattern, replace, NULL, 0, 0); } + { return cregex_replace_ex(input, pattern, replace, NULL, 0, 0); } /* destroy regex */ void cregex_drop(cregex* self); diff --git a/src/utf8code.c b/src/utf8code.c index 44120cee..e5a28bb6 100644 --- a/src/utf8code.c +++ b/src/utf8code.c @@ -283,12 +283,12 @@ cstr cregex_replace_re(const char* input, const cregex* re, const char* repl, } -cstr cregex_replace_fn(const char* input, const char* pattern, const char* repl, +cstr cregex_replace_ex(const char* input, const char* pattern, const char* repl, cstr (*mfun)(int i, csview match), int cflags, unsigned count) { cregex re = cregex_init(); int res = cregex_compile(&re, pattern, cflags); if (res < 0) - return cstr_new("[[cregex_replace_fn]]: invalid pattern"); + return cstr_new("[[cregex_replace_ex]]: invalid pattern"); cstr out = cregex_replace_re(input, &re, repl, mfun, cflags, count); cregex_drop(&re); return out; |
