summaryrefslogtreecommitdiffstats
path: root/regex.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-02-23 12:55:11 -0500
committerTavian Barnes <tavianator@tavianator.com>2022-02-23 12:55:11 -0500
commit85ee489c766bfcdd063d703bd1b596f25d3a0efe (patch)
treef50c59b361d4ee9f4a3515aff5de1f38b2ba1cd9 /regex.c
parent39dac54037dea20c8b4df2e71ffd5d83bfc880fb (diff)
downloadbfs-85ee489c766bfcdd063d703bd1b596f25d3a0efe.tar.xz
regex: Use onig_match() to implement BFS_REGEX_ANCHOR
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/regex.c b/regex.c
index a06d172..fee25ad 100644
--- a/regex.c
+++ b/regex.c
@@ -123,20 +123,19 @@ bool bfs_regexec(struct bfs_regex *regex, const char *str, enum bfs_regexec_flag
const unsigned char *ustr = (const unsigned char *)str;
const unsigned char *end = ustr + len;
- OnigRegion *region = onig_region_new();
- if (!region) {
- *err = ONIGERR_MEMORY;
- return false;
+ int ret;
+ if (flags & BFS_REGEX_ANCHOR) {
+ ret = onig_match(regex->impl, ustr, end, ustr, NULL, ONIG_OPTION_DEFAULT);
+ } else {
+ ret = onig_search(regex->impl, ustr, end, ustr, end, NULL, ONIG_OPTION_DEFAULT);
}
- bool match = false;
- int ret = onig_search(regex->impl, ustr, end, ustr, end, region, ONIG_OPTION_DEFAULT);
if (ret >= 0) {
*err = 0;
if (flags & BFS_REGEX_ANCHOR) {
- match = region->beg[0] == 0 && (size_t)region->end[0] == len;
+ return (size_t)ret == len;
} else {
- match = true;
+ return true;
}
} else if (ret == ONIG_MISMATCH) {
*err = 0;
@@ -144,8 +143,7 @@ bool bfs_regexec(struct bfs_regex *regex, const char *str, enum bfs_regexec_flag
*err = ret;
}
- onig_region_free(region, 1);
- return match;
+ return false;
#else
regmatch_t match = {
.rm_so = 0,