summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-08-02 09:32:22 +0200
committerTyge Løvset <[email protected]>2022-08-02 09:32:22 +0200
commita0b56360cc65f9add1ab169beeb063a3cbd1322f (patch)
treee0c73d0a9c19cd05eaa3f0c1d4f680b528c13b05
parent23ed40d55f3ff2b30f3b3fe01edfb51e418292b4 (diff)
downloadSTC-modified-a0b56360cc65f9add1ab169beeb063a3cbd1322f.tar.gz
STC-modified-a0b56360cc65f9add1ab169beeb063a3cbd1322f.zip
Changed c_foreach_match (m, re, input) to take pointer: cregex* re.
-rw-r--r--examples/regex2.c19
-rw-r--r--include/stc/cregex.h2
2 files changed, 12 insertions, 9 deletions
diff --git a/examples/regex2.c b/examples/regex2.c
index c3f1e6d6..257cdc1e 100644
--- a/examples/regex2.c
+++ b/examples/regex2.c
@@ -5,23 +5,26 @@
int main()
{
- const char* inputs[] = {"date: 2024-02-29 leapyear day, christmas eve is on 2022-12-24.", "https://en.cppreference.com/w/cpp/regex/regex_search", "!123abcabc!"};
- const char* patterns[] = {"(\\d\\d\\d\\d)[-_](1[0-2]|0[1-9])[-_](3[01]|[12][0-9]|0[1-9])",
- "(https?://|ftp://|www\\.)([0-9A-Za-z@:%_+~#=-]+\\.)+([a-z][a-z][a-z]?)(/[/0-9A-Za-z\\.@:%_+~#=\\?&-]*)?",
- "!((abc|123)+)!",
+ struct { const char *pattern, *input; } s[] = {
+ {"(\\d\\d\\d\\d)[-_](1[0-2]|0[1-9])[-_](3[01]|[12][0-9]|0[1-9])",
+ "date: 2024-02-29 leapyear day, christmas eve is on 2022-12-24."},
+ {"(https?://|ftp://|www\\.)([0-9A-Za-z@:%_+~#=-]+\\.)+([a-z][a-z][a-z]?)(/[/0-9A-Za-z\\.@:%_+~#=\\?&-]*)?",
+ "https://en.cppreference.com/w/cpp/regex/regex_search"},
+ {"!((abc|123)+)!", "!123abcabc!"}
};
- c_forrange (i, c_arraylen(inputs))
+
+ c_forrange (i, c_arraylen(s))
{
c_auto (cregex, re)
{
- int res = cregex_compile(&re, patterns[i], 0);
+ int res = cregex_compile(&re, s[i].pattern, 0);
if (res < 0) {
printf("error in regex pattern: %d\n", res);
continue;
}
- printf("input: %s\n", inputs[i]);
+ printf("input: %s\n", s[i].input);
- c_foreach_match (m, re, inputs[i]) {
+ c_foreach_match (m, &re, s[i].input) {
c_forrange (int, j, cregex_captures(&re))
printf(" submatch %d: %.*s\n", j, c_ARGsv(m[j]));
puts("");
diff --git a/include/stc/cregex.h b/include/stc/cregex.h
index e828e944..fbf5b931 100644
--- a/include/stc/cregex.h
+++ b/include/stc/cregex.h
@@ -72,7 +72,7 @@ typedef struct {
#define c_foreach_match(m, re, input) \
for (csview m[cre_MAXCAPTURES] = {{0}}, _c_in = csview_from(input); \
- cregex_find(_c_in.str, &(re), m, cre_m_next) == cre_success; )
+ cregex_find(_c_in.str, re, m, cre_m_next) == cre_success; )
//typedef csview cregmatch;