Match regex against target and produce string_views out of matches.
| 30 | |
| 31 | /// Match regex against target and produce string_views out of matches. |
| 32 | inline bool RegexMatch(const std::regex& regex, std::string_view target, |
| 33 | std::initializer_list<std::string_view*> out_matches) { |
| 34 | assert(regex.mark_count() == out_matches.size()); |
| 35 | |
| 36 | std::match_results<decltype(target.begin())> match; |
| 37 | if (!std::regex_match(target.begin(), target.end(), match, regex)) { |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | // Match #0 is the whole matched sequence |
| 42 | assert(regex.mark_count() + 1 == match.size()); |
| 43 | auto out_it = out_matches.begin(); |
| 44 | for (size_t i = 1; i < match.size(); ++i) { |
| 45 | **out_it++ = target.substr(match.position(i), match.length(i)); |
| 46 | } |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | } // namespace internal |
| 51 | } // namespace arrow |