1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-04 17:18:40 +00:00

fix argparse for char

This commit is contained in:
Lu Wang 2012-09-11 22:30:12 +08:00
parent 4a908db655
commit 8205cd5bc7
2 changed files with 14 additions and 8 deletions

View File

@ -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)

View File

@ -22,16 +22,14 @@ namespace pdf2htmlEX {
//helper
template<class T>
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<class T>
void dump_value(std::ostream & out, const T & v)
@ -126,7 +124,8 @@ void ArgParser::ArgEntry<T, Tv>::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)