From b05b98df7544d02387f583ca5434f33f3e9cb471 Mon Sep 17 00:00:00 2001 From: Alexander Ried Date: Tue, 18 Oct 2016 20:21:21 +0200 Subject: replace own regex class with std::regex --- src/libexpr/primops.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/libexpr/primops.cc') diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 377fb8c75eb4..4bf3f5a02707 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -18,6 +18,7 @@ #include #include +#include #include @@ -1618,25 +1619,23 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args, ‘null’ or a list containing substring matches. */ static void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v) { - Regex regex(state.forceStringNoCtx(*args[0], pos), true); + std::regex regex(state.forceStringNoCtx(*args[0], pos), std::regex::extended); PathSet context; - string s = state.forceString(*args[1], context, pos); + const std::string str = state.forceString(*args[1], context, pos); + - Regex::Subs subs; - if (!regex.matches(s, subs)) { + std::smatch match; + if (!std::regex_match(str, match, regex)) { mkNull(v); return; } - unsigned int len = subs.empty() ? 0 : subs.rbegin()->first + 1; + // the first match is the whole string + const size_t len = match.size() - 1; state.mkList(v, len); - for (unsigned int n = 0; n < len; ++n) { - auto i = subs.find(n); - if (i == subs.end()) - mkNull(*(v.listElems()[n] = state.allocValue())); - else - mkString(*(v.listElems()[n] = state.allocValue()), i->second); + for (size_t i = 0; i < len; ++i) { + mkString(*(v.listElems()[i] = state.allocValue()), match[i + 1].str().c_str()); } } -- cgit 1.4.1