summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-09-11 18:30:00 +0200
committerTyge Løvset <[email protected]>2022-09-11 21:47:10 +0200
commitc319568654c54243cb8fdb54f4ff53f0300a09a8 (patch)
tree8ec9558df96896d4d3f23fe2479988e86858a407 /examples
parent7eaeb7bb2c7cad9b0a437df71a396424b0c6933e (diff)
downloadSTC-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 'examples')
-rw-r--r--examples/regex1.c2
-rw-r--r--examples/regex_match.c3
-rw-r--r--examples/regex_replace.c13
3 files changed, 10 insertions, 8 deletions
diff --git a/examples/regex1.c b/examples/regex1.c
index c8b3a4f5..56ba8f1d 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_is_match(cstr_str(&input), &float_expr))
+ if (cregex_is_match(&float_expr, cstr_str(&input)))
printf("Input is a float\n");
else
printf("Invalid input : Not a float\n");
diff --git a/examples/regex_match.c b/examples/regex_match.c
index 1e463104..78af5c77 100644
--- a/examples/regex_match.c
+++ b/examples/regex_match.c
@@ -1,5 +1,6 @@
#define i_implement
#include <stc/cstr.h>
+#include <stc/csview.h>
#include <stc/cregex.h>
#define i_val float
#include <stc/cstack.h>
@@ -28,7 +29,7 @@ int main()
printf(" %g\n", *i.ref);
// extracts the numbers only to a comma separated string.
- nums = cregex_replace_ex(str, &re, " $0,", 0, cre_r_strip, NULL);
+ nums = cregex_replace_sv(&re, csview_from(str), " $0,", 0, cre_r_strip, NULL);
printf("\n%s\n", cstr_str(&nums));
}
}
diff --git a/examples/regex_replace.c b/examples/regex_replace.c
index 8640ced1..6464198c 100644
--- a/examples/regex_replace.c
+++ b/examples/regex_replace.c
@@ -1,5 +1,6 @@
#define i_implement
#include <stc/cstr.h>
+#include <stc/csview.h>
#include <stc/cregex.h>
bool add_10_years(int i, csview m, cstr* mstr) {
@@ -22,15 +23,15 @@ int main()
printf("INPUT: %s\n", input);
/* replace with a fixed string, extended all-in-one call: */
- cstr_take(&str, cregex_replace_pt(input, pattern, "YYYY-MM-DD", 0));
+ cstr_take(&str, cregex_replace_pattern(pattern, input, "YYYY-MM-DD", 0, 0, NULL));
printf("fixed: %s\n", cstr_str(&str));
/* US date format, and add 10 years to dates: */
- cstr_take(&str, cregex_replace_pe(input, pattern, "$1/$3/$2", 0, 0, add_10_years));
+ cstr_take(&str, cregex_replace_pattern(pattern, input, "$1/$3/$2", 0, 0, add_10_years));
printf("us+10: %s\n", cstr_str(&str));
/* Wrap first date inside []: */
- cstr_take(&str, cregex_replace_pt(input, pattern, "[$0]", 1));
+ cstr_take(&str, cregex_replace_pattern(pattern, input, "[$0]", 1, 0, NULL));
printf("brack: %s\n", cstr_str(&str));
/* Shows how to compile RE separately */
@@ -38,16 +39,16 @@ int main()
if (cregex_captures(&re) == 0)
continue; // break c_with
/* European date format. */
- cstr_take(&str, cregex_replace(input, &re, "$3.$2.$1", 0));
+ cstr_take(&str, cregex_replace(&re, input, "$3.$2.$1", 0));
printf("euros: %s\n", cstr_str(&str));
/* Strip out everything but the matches */
- cstr_take(&str, cregex_replace_ex(input, &re, "$3.$2.$1;", 0, cre_r_strip, NULL));
+ cstr_take(&str, cregex_replace_sv(&re, csview_from(input), "$3.$2.$1;", 0, cre_r_strip, NULL));
printf("strip: %s\n", cstr_str(&str));
}
/* Wrap all words in ${} */
- cstr_take(&str, cregex_replace_pt("[52] apples and [31] mangoes", "[a-z]+", "$${$0}", 0));
+ cstr_take(&str, cregex_replace_pattern("[a-z]+", "52 apples and 31 mangoes", "$${$0}", 0, 0, NULL));
printf("curly: %s\n", cstr_str(&str));
}
}