Skip to content
Snippets Groups Projects
Commit 9664a336 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

replace regex in ParseUtil

parent cfd45272
No related branches found
No related tags found
1 merge request!1860replace regex in Device/IO/ParseUtils, which caused numerous tests to fail in debug mode
Pipeline #108645 passed
...@@ -18,10 +18,8 @@ ...@@ -18,10 +18,8 @@
#include "Base/Util/StringUtil.h" #include "Base/Util/StringUtil.h"
#include "Device/Data/Datafield.h" #include "Device/Data/Datafield.h"
#include <cmath> // ignoreDenormalized #include <cmath> // ignoreDenormalized
#include <functional>
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
#include <regex>
namespace { namespace {
...@@ -64,13 +62,29 @@ Scale* Util::Parse::parseScale(std::istream& input_stream) ...@@ -64,13 +62,29 @@ Scale* Util::Parse::parseScale(std::istream& input_stream)
{ {
std::string line; std::string line;
std::getline(input_stream, line); std::getline(input_stream, line);
std::smatch matched;
std::regex_match(line, matched, std::regex("(\\w+)\\(\"(.*?)\",\\s*(.+?)\\)")); size_t j = line.find_first_of('(');
if (matched.size() != 4) if (j == std::string::npos)
throw std::runtime_error("Cannot read axis from input"); throw std::runtime_error("Scale constructor has no '('");
const std::string type = matched[1]; std::string type = line.substr(0, j);
const std::string name = matched[2];
const std::string body = matched[3]; line = line.substr(j + 1);
if (line.back() != ')')
throw std::runtime_error("Scale constructor call not ending with ')'");
line = line.substr(0, line.size() - 1);
if (line[0] != '"')
throw std::runtime_error("Scale constructor arg 1 does not start with \"");
j = 1 + line.substr(1).find_first_of('"');
if (j == std::string::npos)
throw std::runtime_error("Scale constructor arg 1 has no closing \"");
std::string name = line.substr(1, j - 1);
if (line[j + 1] != ',')
throw std::runtime_error("Scale constructor arg 1 not followed by comma");
std::string body = line.substr(j + 2);
body = Base::String::trimFront(body, " ");
if (type == "EquiDivision" || type == "FixedBinAxis" /* for compatibility with pre-21 */) { if (type == "EquiDivision" || type == "FixedBinAxis" /* for compatibility with pre-21 */) {
std::vector<std::string> arr = Base::String::split(body, ","); std::vector<std::string> arr = Base::String::split(body, ",");
int nbins; int nbins;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment