changed: simplify seqnumFromSeparateFilename by using a regex
This commit is contained in:
parent
7876f530a1
commit
0f31f83483
@ -23,6 +23,7 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <regex>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -33,23 +34,19 @@
|
|||||||
namespace {
|
namespace {
|
||||||
int seqnumFromSeparateFilename(const std::string& filename)
|
int seqnumFromSeparateFilename(const std::string& filename)
|
||||||
{
|
{
|
||||||
int p=0;
|
const auto re = std::regex {
|
||||||
|
R"~(\.[FX]([0-9]{4})$)~"
|
||||||
|
};
|
||||||
|
|
||||||
std::string errMessage="Unable to Determine Report Step Sequence Number From Restart Filename \"" + filename + '"';
|
auto match = std::smatch{};
|
||||||
|
if (std::regex_search(filename, match, re)) {
|
||||||
if (filename.find(".F") != std::string::npos) {
|
return std::stoi(match[1]);
|
||||||
p = filename.find_last_of(".F");
|
|
||||||
} else if (filename.find(".X") != std::string::npos) {
|
|
||||||
p = filename.find_last_of(".X");
|
|
||||||
} else {
|
|
||||||
OPM_THROW(std::invalid_argument, errMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return std::stoi(filename.substr(p+1,filename.size() - p-1));
|
|
||||||
} catch (...) {
|
|
||||||
OPM_THROW(std::invalid_argument, errMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw std::invalid_argument {
|
||||||
|
"Unable to Determine Report Step Sequence Number "
|
||||||
|
"From Restart Filename \"" + filename + '"'
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user