diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-02-23 12:55:11 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-02-23 12:55:11 -0500 |
commit | 85ee489c766bfcdd063d703bd1b596f25d3a0efe (patch) | |
tree | f50c59b361d4ee9f4a3515aff5de1f38b2ba1cd9 | |
parent | 39dac54037dea20c8b4df2e71ffd5d83bfc880fb (diff) | |
download | bfs-85ee489c766bfcdd063d703bd1b596f25d3a0efe.tar.xz |
regex: Use onig_match() to implement BFS_REGEX_ANCHOR
-rw-r--r-- | regex.c | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -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, |