int cre2_match (const cre2_regexp_t *re , const char *text, int textlen, int startpos, int endpos, cre2_anchor_t anchor, cre2_string_t *match, int nmatch) { re2::StringPiece text_re2(text, textlen); re2::StringPiece match_re2[nmatch]; RE2::Anchor anchor_re2 = RE2::UNANCHORED; bool retval; // 0 for no match // 1 for successful matching switch (anchor) { case CRE2_ANCHOR_START: anchor_re2 = RE2::ANCHOR_START; break; case CRE2_ANCHOR_BOTH: anchor_re2 = RE2::ANCHOR_BOTH; break; case CRE2_UNANCHORED: break; } retval = TO_CONST_RE2(re)->Match(text_re2, startpos, endpos, anchor_re2, match_re2, nmatch); if (retval) { for (int i=0; i<nmatch; i++) { match[i].data = match_re2[i].data(); match[i].length = match_re2[i].length(); } } return (retval)? 1 : 0; }
int cre2_match (const cre2_regexp_t *re , const char *text, int textlen, int startpos, int endpos, cre2_anchor_t anchor, cre2_string_t *match, int nmatch) { re2::StringPiece text_re2(text, textlen); std::vector<re2::StringPiece> match_re2(nmatch); RE2::Anchor anchor_re2 = to_cre2_anchor(anchor); bool retval; // 0 for no match // 1 for successful matching retval = TO_CONST_RE2(re)->Match(text_re2, startpos, endpos, anchor_re2, match_re2.data(), nmatch); if (retval) { for (int i=0; i<nmatch; i++) { match[i].data = match_re2[i].data(); match[i].length = match_re2[i].length(); } } return (retval)? 1 : 0; }