diff options
| author | Tyge Løvset <[email protected]> | 2022-12-11 10:52:32 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-12-11 10:52:32 +0100 |
| commit | 0db528ed0062920e9bd5b2c7fcdc7506bd41abad (patch) | |
| tree | 217b0c6b36964b84bac423bfc6a6c3333c0cd83d /examples | |
| parent | f500cd5301433015e7860ea4446e81db29c9369e (diff) | |
| parent | 3b616b5260f2f477563508b6eec5370506565da9 (diff) | |
| download | STC-modified-0db528ed0062920e9bd5b2c7fcdc7506bd41abad.tar.gz STC-modified-0db528ed0062920e9bd5b2c7fcdc7506bd41abad.zip | |
Merge branch 'master' of github.com:tylov/STC
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/regex_replace.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/examples/regex_replace.c b/examples/regex_replace.c index e88c559f..808ac086 100644 --- a/examples/regex_replace.c +++ b/examples/regex_replace.c @@ -2,11 +2,11 @@ #include <stc/cregex.h> #include <stc/csview.h> -bool add_10_years(int i, csview m, cstr* mstr) { +bool add_10_years(int i, csview match, cstr* out) { if (i == 1) { // group 1 matches year int year; - sscanf(m.str, "%4d", &year); - cstr_printf(mstr, "%04d", year + 10); + sscanf(match.str, "%4d", &year); // scan 4 chars only + cstr_printf(out, "%04d", year + 10); return true; } return false; @@ -22,23 +22,23 @@ int main() printf("INPUT: %s\n", input); /* replace with a fixed string, extended all-in-one call: */ - cstr_take(&str, cregex_replace_pattern(pattern, input, "YYYY-MM-DD", 0, NULL, cre_default)); + cstr_take(&str, cregex_replace_pattern(pattern, input, "YYYY-MM-DD")); printf("fixed: %s\n", cstr_str(&str)); /* US date format, and add 10 years to dates: */ - cstr_take(&str, cregex_replace_pattern(pattern, input, "$1/$3/$2", 0, add_10_years, cre_default)); + cstr_take(&str, cregex_replace_pattern_n(pattern, input, "$1/$3/$2", 0, add_10_years, cre_default)); printf("us+10: %s\n", cstr_str(&str)); /* Wrap first date inside []: */ - cstr_take(&str, cregex_replace_pattern(pattern, input, "[$0]", 1, NULL, cre_default)); + cstr_take(&str, cregex_replace_pattern_n(pattern, input, "[$0]", 1, NULL, cre_default)); printf("brack: %s\n", cstr_str(&str)); /* Shows how to compile RE separately */ c_with (cregex re = cregex_from(pattern, cre_default), cregex_drop(&re)) { if (cregex_captures(&re) == 0) - continue; // break c_with + continue; /* break c_with */ /* European date format. */ - cstr_take(&str, cregex_replace(&re, input, "$3.$2.$1", 0)); + cstr_take(&str, cregex_replace(&re, input, "$3.$2.$1")); printf("euros: %s\n", cstr_str(&str)); /* Strip out everything but the matches */ @@ -47,7 +47,7 @@ int main() } /* Wrap all words in ${} */ - cstr_take(&str, cregex_replace_pattern("[a-z]+", "52 apples and 31 mangoes", "$${$0}", 0, NULL, cre_default)); + cstr_take(&str, cregex_replace_pattern("[a-z]+", "52 apples and 31 mangoes", "$${$0}")); printf("curly: %s\n", cstr_str(&str)); } } |
