From 698e70e7d3e7dcdf6b6e7b03689dabc184d34bf6 Mon Sep 17 00:00:00 2001 From: Tyge Lovset Date: Fri, 22 Jul 2022 00:34:19 +0200 Subject: Changed / improved cregex API again (as promised). Possible final API. --- examples/regex1.c | 2 +- examples/regex2.c | 2 +- examples/regex_match.c | 8 ++++---- examples/regex_replace.c | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/regex1.c b/examples/regex1.c index d5c14509..98fc644d 100644 --- a/examples/regex1.c +++ b/examples/regex1.c @@ -22,7 +22,7 @@ int main(int argc, char* argv[]) if (cstr_equals(input, "q")) break; - if (cregex_match_re(cstr_str(&input), &float_expr, 0, NULL, 0) > 0) + if (cregex_match(cstr_str(&input), &float_expr, NULL, 0) == 1) printf("Input is a float\n"); else printf("Invalid input : Not a float\n"); diff --git a/examples/regex2.c b/examples/regex2.c index 0d10205a..7c17e663 100644 --- a/examples/regex2.c +++ b/examples/regex2.c @@ -20,7 +20,7 @@ int main() } cregmatch m[20]; printf("input: %s\n", inputs[i]); - if (cregex_match_re(inputs[i], &re, 20, m, 0) > 0) + if (cregex_match(inputs[i], &re, m, 0) == 1) { c_forrange (j, cregex_captures(&re)) { diff --git a/examples/regex_match.c b/examples/regex_match.c index 5f1075ff..646f2318 100644 --- a/examples/regex_match.c +++ b/examples/regex_match.c @@ -13,21 +13,21 @@ int main() { int res = cregex_compile(&re, "[+-]?([0-9]*\\.)?\\d+([Ee][+-]?\\d+)?", 0); printf("%d\n", res); - csview m[10]; - if (cregex_match_re(s, &re, 10, m, 0) > 0) { + csview m[5]; + if (cregex_match(s, &re, m, 0) == 1) { printf("Found digits at position %" PRIuMAX "-%" PRIuMAX "\n", m[0].str - s, m[0].str - s + m[0].size); } else { printf("Could not find any digits\n"); } - while (cregex_match_re(s, &re, 10, m, cre_NEXT) > 0) { + while (cregex_match(s, &re, m, cre_NEXT) == 1) { printf("%" c_PRIsv " ; ", c_ARGsv(m[0])); } puts(""); res = cregex_compile(&re, "(.+)\\b(.+)", 0); printf("groups: %d\n", res); - if ((res = cregex_match_re("hello@wørld", &re, 10, m, 0)) > 0) { + if ((res = cregex_match("hello@wørld", &re, m, 0)) == 1) { c_forrange (i, res) printf("match: [%" c_PRIsv "]\n", c_ARGsv(m[i])); } else diff --git a/examples/regex_replace.c b/examples/regex_replace.c index ff4b4a6a..d57dede8 100644 --- a/examples/regex_replace.c +++ b/examples/regex_replace.c @@ -21,23 +21,23 @@ int main() { printf("input: %s\n", input); /* European date format */ - cstr_take(&str, cregex_replace(input, pattern, "\\3.\\2.\\1")); + cstr_take(&str, cregex_replace_pat(input, pattern, "\\3.\\2.\\1")); printf("euros: %s\n", cstr_str(&str)); /* US date format, and subtract 20 years: */ - cstr_take(&str, cregex_replace_ex(input, pattern, "\\1/\\3/\\2", sub_20y, 0, 0)); + cstr_take(&str, cregex_replace_patx(input, pattern, "\\1/\\3/\\2", sub_20y, 0, 0)); printf("us-20: %s\n", cstr_str(&str)); /* replace with a fixed string: */ - cstr_take(&str, cregex_replace(input, pattern, "YYYY-MM-DD")); + cstr_take(&str, cregex_replace_pat(input, pattern, "YYYY-MM-DD")); printf("fixed: %s\n", cstr_str(&str)); /* Wrap first date inside []: */ - cstr_take(&str, cregex_replace_ex(input, pattern, "[\\0]", NULL, 0, 1)); + cstr_take(&str, cregex_replace_patx(input, pattern, "[\\0]", NULL, 1, 0)); printf("brack: %s\n", cstr_str(&str)); /* Wrap all words in {} */ - cstr_take(&str, cregex_replace("[52] apples and [31] mangoes", "[a-z]+", "{\\0}")); + cstr_take(&str, cregex_replace_pat("[52] apples and [31] mangoes", "[a-z]+", "{\\0}")); printf("curly: %s\n", cstr_str(&str)); } } -- cgit v1.2.3