Use std::regex

This commit is contained in:
Eelco Dolstra 2016-10-21 18:06:26 +02:00
parent 5d8fbc6ca1
commit a3efdcdfd9

View file

@ -1,9 +1,10 @@
#include "build-result.hh" #include "build-result.hh"
#include "store-api.hh" #include "store-api.hh"
#include "util.hh" #include "util.hh"
#include "regex.hh"
#include "fs-accessor.hh" #include "fs-accessor.hh"
#include <regex>
using namespace nix; using namespace nix;
@ -28,14 +29,14 @@ BuildOutput getBuildOutput(nix::ref<Store> store,
/* Get build products. */ /* Get build products. */
bool explicitProducts = false; bool explicitProducts = false;
Regex regex( std::regex regex(
"(([a-zA-Z0-9_-]+)" // type (e.g. "doc") "([a-zA-Z0-9_-]+)" // type (e.g. "doc")
"[[:space:]]+" "[[:space:]]+"
"([a-zA-Z0-9_-]+)" // subtype (e.g. "readme") "([a-zA-Z0-9_-]+)" // subtype (e.g. "readme")
"[[:space:]]+" "[[:space:]]+"
"(\"[^\"]+\"|[^[:space:]\"]+))" // path (may be quoted) "(\"[^\"]+\"|[^[:space:]\"]+)" // path (may be quoted)
"([[:space:]]+([^[:space:]]+))?" // entry point "([[:space:]]+([^[:space:]]+))?" // entry point
, true); , std::regex::extended);
for (auto & output : outputs) { for (auto & output : outputs) {
Path failedFile = output + "/nix-support/failed"; Path failedFile = output + "/nix-support/failed";
@ -51,13 +52,14 @@ BuildOutput getBuildOutput(nix::ref<Store> store,
for (auto & line : tokenizeString<Strings>(accessor->readFile(productsFile), "\n")) { for (auto & line : tokenizeString<Strings>(accessor->readFile(productsFile), "\n")) {
BuildProduct product; BuildProduct product;
Regex::Subs subs; std::smatch match;
if (!regex.matches(line, subs)) continue; if (!std::regex_match(line, match, regex)) continue;
product.type = subs[1]; product.type = match[1];
product.subtype = subs[2]; product.subtype = match[2];
product.path = subs[3][0] == '"' ? string(subs[3], 1, subs[3].size() - 2) : subs[3]; std::string s(match[3]);
product.defaultPath = subs[5]; product.path = s[0] == '"' ? string(s, 1, s.size() - 2) : s;
product.defaultPath = match[5];
/* Ensure that the path exists and points into the Nix /* Ensure that the path exists and points into the Nix
store. */ store. */