diff --git a/src/ArgParser.cc b/src/ArgParser.cc index 81ff714..fcbe232 100644 --- a/src/ArgParser.cc +++ b/src/ArgParser.cc @@ -24,9 +24,16 @@ using std::unordered_map; using std::make_pair; using std::ostringstream; -void read_value(const char * arg, std::string * location) +bool read_value(const char * arg, char * location) +{ + *location = arg[0]; + return (arg[1] == 0); +} + +bool read_value(const char * arg, std::string * location) { *location = std::string(arg); + return true; } void dump_value(std::ostream & out, const std::string & v) diff --git a/src/include/ArgParser.h b/src/include/ArgParser.h index 3bfff92..ba8c908 100644 --- a/src/include/ArgParser.h +++ b/src/include/ArgParser.h @@ -22,16 +22,14 @@ namespace pdf2htmlEX { //helper template -void read_value(const char * arg, T * location) +bool read_value(const char * arg, T * location) { std::istringstream sin(arg); - if((sin >> (*location)) && (sin.eof())) - return; - - throw std::string("Invalid argument: ") + arg; + return ((sin >> (*location)) && (sin.eof())); } -extern void read_value(const char * arg, std::string * location); +extern bool read_value(const char * arg, char * location); +extern bool read_value(const char * arg, std::string * location); template void dump_value(std::ostream & out, const T & v) @@ -126,7 +124,8 @@ void ArgParser::ArgEntry::parse(const char * arg) const if(!arg) throw std::string("Missing argument of option: --") + name; - read_value(arg, location); + if(!read_value(arg, location)) + throw std::string("Invalid argument: ") + arg; } if(callback)