Commit 3ca5e6e0 authored by novatig's avatar novatig

intel gave me trouble, can we avoid regex? is there an alternative to the line I commented out?

parent 17362acb
......@@ -3,7 +3,9 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <regex> // C++11
#include <sstream>
#include <limits>
//#include <regex> // C++11
#include "Cubism/ArgumentParser.h"
......@@ -117,7 +119,9 @@ CommandlineParser::CommandlineParser(const int argc, char **argv)
// if the current value is numeric and (possibly) negative,
// do not interpret it as a key
const bool leadingDash = (argv[j][0] == '-');
const bool isNumeric = std::regex_match(argv[j], std::regex("(\\+|-)?[0-9]*(\\.[0-9]*)?((e|E)(\\+|-)?[0-9]*)?"));
const char c = argv[j][1];
const bool isNumeric = ((c>='0' && c<='9') || c==0)? true:false;
// const bool isNumeric = std::regex_match(argv[j], std::regex("(\\+|-)?[0-9]*(\\.[0-9]*)?((e|E)(\\+|-)?[0-9]*)?"));
if (leadingDash && !isNumeric)
break;
else
......
  • Here's a simple way to test if a string is a floating point number. A modified version of the stackoverflow answer:

    #include <cmath>
    #include <cstdlib>
    // https://stackoverflow.com/questions/29169153/how-do-i-verify-a-string-is-valid-double-even-if-it-has-a-point-in-it
    bool is_float(const char *s) {
        char *end = 0;
        double val = strtod(s, &end);
        return end != s && *end == '\0' && val != HUGE_VAL;
    }

    This one will also treat e.g. "-inf" and "-nan" as valid floating point values.

  • What Intel compiler did you use? I can compile on panda with 2018.1.

    Nevertheless, I will check what Ivica suggested and if it works as expected, I will remove the regex

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment