Skip to content

Commit

Permalink
fix static regEX
Browse files Browse the repository at this point in the history
  • Loading branch information
solaslin authored Aug 9, 2023
1 parent c11aacf commit 7520fc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 12 additions & 4 deletions library/src/include/option_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
#include <vector>

// Regular expression for token delimiters (whitespace and commas)
static const std::regex program_options_regex{"[, \\f\\n\\r\\t\\v]+",
std::regex_constants::optimize};

static const std::regex vector_delim{",", std::regex_constants::optimize};
#define PROGRAM_OPTIONS_REGEX "[, \\f\\n\\r\\t\\v]+"
#define VECTOR_DELIM ","

// variables_map is a set of seen options
using variables_map = std::set<std::string>;
Expand Down Expand Up @@ -264,6 +262,9 @@ class options_description
// Parse an option at the current (argc, argv) position
void parse_option(int& argc, char**& argv, variables_map& vm, bool ignoreUnknown = false) const
{
static const std::regex program_options_regex{PROGRAM_OPTIONS_REGEX,
std::regex_constants::optimize};

// Iterate across all options
for(const auto& opt : m_optlist)
{
Expand Down Expand Up @@ -312,6 +313,9 @@ class options_description
// Formatted output of command-line arguments description
friend std::ostream& operator<<(std::ostream& os, const options_description& d)
{
static const std::regex program_options_regex{PROGRAM_OPTIONS_REGEX,
std::regex_constants::optimize};

// Iterate across all options
for(const auto& opt : d.m_optlist)
{
Expand Down Expand Up @@ -404,6 +408,8 @@ inline void notify(const variables_map&) {}

void parse_arg_ints(std::string const& inStr, std::vector<size_t>& outVector)
{
static const std::regex vector_delim{VECTOR_DELIM, std::regex_constants::optimize};

// std::cout << inStr << std::endl;
for(std::sregex_token_iterator tok{inStr.begin(), inStr.end(), vector_delim, -1};
tok != std::sregex_token_iterator();
Expand All @@ -415,6 +421,8 @@ void parse_arg_ints(std::string const& inStr, std::vector<size_t>& outVector)

void parse_arg_strings(std::string const& inStr, std::vector<std::string>& outVector)
{
static const std::regex vector_delim{VECTOR_DELIM, std::regex_constants::optimize};

// std::cout << inStr << std::endl;
for(std::sregex_token_iterator tok{inStr.begin(), inStr.end(), vector_delim, -1};
tok != std::sregex_token_iterator();
Expand Down
6 changes: 5 additions & 1 deletion library/src/solution_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace fs = std::filesystem;

static std::regex regEx("[^:;,\"\\{\\}\\[\\s]+", std::regex_constants::optimize);
#define REGEX "[^:;,\"\\{\\}\\[\\s]+"

static const char* def_solution_map_path = "rocfft_solution_map.dat";

Expand Down Expand Up @@ -477,6 +477,8 @@ size_t solution_map::add_solution(const ProblemKey& probKey,
// parse the format version of the input file, call by converter
bool solution_map::get_solution_map_version(const fs::path& sol_map_in_path)
{
static std::regex regEx(REGEX, std::regex_constants::optimize);

if(LOG_TRACE_ENABLED())
(*LogSingleton::GetInstance().GetTraceOS())
<< "reading solution map data from: " << sol_map_in_path.c_str() << std::endl;
Expand Down Expand Up @@ -505,6 +507,8 @@ bool solution_map::get_solution_map_version(const fs::path& sol_map_in_path)
// read the map from input stream
bool solution_map::read_solution_map_data(const fs::path& sol_map_in_path, bool primary_map)
{
static std::regex regEx(REGEX, std::regex_constants::optimize);

if(LOG_TRACE_ENABLED())
(*LogSingleton::GetInstance().GetTraceOS())
<< "reading solution map data from: " << sol_map_in_path.c_str() << std::endl;
Expand Down

0 comments on commit 7520fc6

Please sign in to comment.