about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorAlexander Ried <ried@mytum.de>2016-10-18T18·21+0200
committerAlexander Ried <ried@mytum.de>2016-10-18T18·22+0200
commitb05b98df7544d02387f583ca5434f33f3e9cb471 (patch)
tree4f2c923dc552faed3bf2ea1330d4bf68eda80471 /src/libexpr
parentae8884b94975673e6a3338d2c5173c006b4c8d4b (diff)
replace own regex class with std::regex
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/names.cc4
-rw-r--r--src/libexpr/names.hh4
-rw-r--r--src/libexpr/primops.cc21
3 files changed, 14 insertions, 15 deletions
diff --git a/src/libexpr/names.cc b/src/libexpr/names.cc
index 7bca9b6550be..6d78d2116121 100644
--- a/src/libexpr/names.cc
+++ b/src/libexpr/names.cc
@@ -33,8 +33,8 @@ DrvName::DrvName(const string & s) : hits(0)
 bool DrvName::matches(DrvName & n)
 {
     if (name != "*") {
-        if (!regex) regex = std::shared_ptr<Regex>(new Regex(name));
-        if (!regex->matches(n.name)) return false;
+        if (!regex) regex = std::unique_ptr<std::regex>(new std::regex(name, std::regex::extended));
+        if (!std::regex_match(n.name, *regex)) return false;
     }
     if (version != "" && version != n.version) return false;
     return true;
diff --git a/src/libexpr/names.hh b/src/libexpr/names.hh
index 4b3dcddf70d7..9667fc96fd0f 100644
--- a/src/libexpr/names.hh
+++ b/src/libexpr/names.hh
@@ -3,7 +3,7 @@
 #include <memory>
 
 #include "types.hh"
-#include "regex.hh"
+#include <regex>
 
 namespace nix {
 
@@ -19,7 +19,7 @@ struct DrvName
     bool matches(DrvName & n);
 
 private:
-    std::shared_ptr<Regex> regex;
+    std::unique_ptr<std::regex> regex;
 };
 
 typedef list<DrvName> DrvNames;
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 <algorithm>
 #include <cstring>
+#include <regex>
 #include <dlfcn.h>
 
 
@@ -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());
     }
 }