diff --git a/src/regex.hh b/src/regex.hh index 58f71270..4c7b8ecb 100644 --- a/src/regex.hh +++ b/src/regex.hh @@ -95,6 +95,8 @@ struct MatchResults m_values.swap(other.m_values); } + Vector& values() { return m_values; } + private: Vector m_values; }; @@ -116,10 +118,8 @@ bool regex_match(It begin, It end, const Regex& re) template bool regex_match(It begin, It end, MatchResults& res, const Regex& re) { - Vector captures; - const bool matched = regex_match(begin, end, captures, *re.impl()); - res = matched ? MatchResults{std::move(captures)} : MatchResults{}; - return matched; + res.values().clear(); + return regex_match(begin, end, res.values(), *re.impl()); } template @@ -133,10 +133,8 @@ template bool regex_search(It begin, It end, MatchResults& res, const Regex& re, RegexExecFlags flags = RegexExecFlags::None) { - Vector captures; - const bool matched = regex_search(begin, end, captures, *re.impl(), flags); - res = matched ? MatchResults{std::move(captures)} : MatchResults{}; - return matched; + res.values().clear(); + return regex_search(begin, end, res.values(), *re.impl(), flags); } String option_to_string(const Regex& re);