From bcd76fdeb1b7b5ac01ac9a204db74b537361c8b0 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Fri, 7 Jan 2022 14:33:29 +0100 Subject: Some renaming in cregex API. Added match function. Made utf8 operations branchless. --- examples/regex_match.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/regex_match.c b/examples/regex_match.c index dad28f84..20d331e2 100644 --- a/examples/regex_match.c +++ b/examples/regex_match.c @@ -15,22 +15,24 @@ int main() c_auto (cregex, re) { - re = cregex_compile("[+-]?([0-9]*\\.)?[0-9]+([Ee][-+]?[0-9]+)?"); - cregex_match_t m; - if (cregex_match(re, s, &m)) { + re = cregex_new("[+-]?([0-9]*\\.)?[0-9]+([Ee][-+]?[0-9]+)?"); + cregex_match m; + if (cregex_find(re, s, &m)) { printf("Found digits at position %u-%u\n", m.match_begin, m.match_end); } else { printf("Could not find any digits\n"); } - c_auto (cregex_res, matches) { - matches = cregex_match_all(re, s); + c_auto (cregex_result, matches) { + matches = cregex_find_all(re, s); csview sv = csview_from(s); - c_foreach (i, cregex_res, matches) { + c_foreach (i, cregex_result, matches) { csview r = csview_slice(sv, i.ref->match_begin, i.ref->match_end); printf(c_svfmt " / ", c_svarg(r)); } } + + puts(""); } } \ No newline at end of file -- cgit v1.2.3