summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-10-21 10:57:05 +0200
committerTyge Løvset <[email protected]>2022-10-21 10:57:05 +0200
commit3b0e849ca26bceab8c6a7b19e6a27bb4aa4d123a (patch)
tree0aef18c4f50d336ae7bb2164913d21ec97d3641b /examples
parent3eb08b0372dd669af535a368e8a8cdb8a9c793c5 (diff)
downloadSTC-modified-3b0e849ca26bceab8c6a7b19e6a27bb4aa4d123a.tar.gz
STC-modified-3b0e849ca26bceab8c6a7b19e6a27bb4aa4d123a.zip
Swapped two last params in cregex_replace_pattern() and cregex_replace_sv() to always have flags at last (sorry for inconveniences).
Fixed a small bug in cregex_find_sv(), and added cre_default flag for readability.
Diffstat (limited to 'examples')
-rw-r--r--examples/regex1.c2
-rw-r--r--examples/regex2.c2
-rw-r--r--examples/regex_match.c4
-rw-r--r--examples/regex_replace.c12
-rw-r--r--examples/splitstr.c2
5 files changed, 11 insertions, 11 deletions
diff --git a/examples/regex1.c b/examples/regex1.c
index 56ba8f1d..d1f061fb 100644
--- a/examples/regex1.c
+++ b/examples/regex1.c
@@ -11,7 +11,7 @@ int main(int argc, char* argv[])
c_auto (cstr, input)
c_auto (cregex, float_expr)
{
- int res = cregex_compile(&float_expr, "^[+-]?[0-9]+((\\.[0-9]*)?|\\.[0-9]+)$", 0);
+ int res = cregex_compile(&float_expr, "^[+-]?[0-9]+((\\.[0-9]*)?|\\.[0-9]+)$", cre_default);
// Until "q" is given, ask for another number
if (res > 0) while (true)
{
diff --git a/examples/regex2.c b/examples/regex2.c
index 013fa557..1f656265 100644
--- a/examples/regex2.c
+++ b/examples/regex2.c
@@ -17,7 +17,7 @@ int main()
c_with (cregex re = cregex_init(), cregex_drop(&re))
c_forrange (i, c_arraylen(s))
{
- int res = cregex_compile(&re, s[i].pattern, 0);
+ int res = cregex_compile(&re, s[i].pattern, cre_default);
if (res < 0) {
printf("error in regex pattern: %d\n", res);
continue;
diff --git a/examples/regex_match.c b/examples/regex_match.c
index 50fdba9a..da23b3a2 100644
--- a/examples/regex_match.c
+++ b/examples/regex_match.c
@@ -18,7 +18,7 @@ int main()
c_auto (cstr, nums)
{
const char* pattern = "[+-]?([0-9]*\\.)?\\d+([Ee][+-]?\\d+)?";
- int res = cregex_compile(&re, pattern, 0);
+ int res = cregex_compile(&re, pattern, cre_default);
printf("%d: %s\n", res, pattern);
// extract and convert all numbers in str to floats
@@ -29,7 +29,7 @@ int main()
printf(" %g\n", *i.ref);
// extracts the numbers only to a comma separated string.
- nums = cregex_replace_sv(&re, csview_from(str), " $0,", 0, cre_r_strip, NULL);
+ nums = cregex_replace_sv(&re, csview_from(str), " $0,", 0, NULL, cre_r_strip);
printf("\n%s\n", cstr_str(&nums));
}
}
diff --git a/examples/regex_replace.c b/examples/regex_replace.c
index 6464198c..e6054d9f 100644
--- a/examples/regex_replace.c
+++ b/examples/regex_replace.c
@@ -23,19 +23,19 @@ 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, 0, NULL));
+ cstr_take(&str, cregex_replace_pattern(pattern, input, "YYYY-MM-DD", 0, NULL, cre_default));
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, 0, add_10_years));
+ cstr_take(&str, cregex_replace_pattern(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, 0, NULL));
+ cstr_take(&str, cregex_replace_pattern(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, 0), cregex_drop(&re)) {
+ c_with (cregex re = cregex_from(pattern, cre_default), cregex_drop(&re)) {
if (cregex_captures(&re) == 0)
continue; // break c_with
/* European date format. */
@@ -43,12 +43,12 @@ int main()
printf("euros: %s\n", cstr_str(&str));
/* Strip out everything but the matches */
- cstr_take(&str, cregex_replace_sv(&re, csview_from(input), "$3.$2.$1;", 0, cre_r_strip, NULL));
+ cstr_take(&str, cregex_replace_sv(&re, csview_from(input), "$3.$2.$1;", 0, NULL, cre_r_strip));
printf("strip: %s\n", cstr_str(&str));
}
/* Wrap all words in ${} */
- cstr_take(&str, cregex_replace_pattern("[a-z]+", "52 apples and 31 mangoes", "$${$0}", 0, 0, NULL));
+ cstr_take(&str, cregex_replace_pattern("[a-z]+", "52 apples and 31 mangoes", "$${$0}", 0, NULL, cre_default));
printf("curly: %s\n", cstr_str(&str));
}
}
diff --git a/examples/splitstr.c b/examples/splitstr.c
index 8e976892..27dd308c 100644
--- a/examples/splitstr.c
+++ b/examples/splitstr.c
@@ -14,7 +14,7 @@ int main()
puts("\nSplit with c_formatch (regex):");
- c_with (cregex re = cregex_from("[^ ]+", 0), cregex_drop(&re))
+ c_with (cregex re = cregex_from("[^ ]+", cre_default), cregex_drop(&re))
c_formatch (i, &re, " Hello World C99! ")
printf("'%.*s'\n", c_ARGsv(i.match[0]));
}