diff --git a/src/Arg.cpp b/src/Arg.cpp index 7acbcef..f0fca88 100644 --- a/src/Arg.cpp +++ b/src/Arg.cpp @@ -27,6 +27,10 @@ namespace TCLAP { // defaults bool Arg::_ignoreRest = false; char Arg::_delimiter = ' '; +const char Arg::blankChar = '*'; +const char Arg::flagStartChar = '-'; +const string Arg::flagStartString = "-"; +const string Arg::nameStartString = "--"; Arg::Arg( const string& flag, const string& name, @@ -89,7 +93,7 @@ string Arg::shortID( const string& valueId ) const { string id = ""; - id = "-" + _flag; + id = Arg::flagStartString + _flag; string delim = " "; delim[0] = Arg::_delimiter; // ugly!!! @@ -107,13 +111,13 @@ string Arg::longID( const string& valueId ) const { string id = ""; - id = "-" + _flag; + id = Arg::flagStartString + _flag; if ( _valueRequired ) id += " <" + valueId + ">"; - id += ", --" + _name; + id += ", " + Arg::nameStartString + _name; if ( _valueRequired ) id += " <" + valueId + ">"; @@ -162,8 +166,8 @@ bool Arg::isIgnoreable() const { return _ignoreable; } bool Arg::argMatches( const string& argFlag ) const { - if ( argFlag == "-" + _flag || - argFlag == "--" + _name ) + if ( argFlag == Arg::flagStartString + _flag || + argFlag == Arg::nameStartString + _name ) return true; else return false; @@ -171,7 +175,7 @@ bool Arg::argMatches( const string& argFlag ) const string Arg::toString() const { - string s = "-" + _flag + " (--" + _name + ")"; + string s = Arg::flagStartString + _flag + " (" + Arg::nameStartString + _name + ")"; return s; } @@ -202,4 +206,16 @@ void Arg::trimFlag(string& flag, string& value) const } +/** + * Implementation of _hasBlanks. + */ +bool Arg::_hasBlanks( const string& s ) const +{ + for ( int i = 1; i < s.length(); i++ ) + if ( s[i] == Arg::blankChar ) + return true; + + return false; +} + } diff --git a/src/CmdLine.cpp b/src/CmdLine.cpp index e6ae7b8..e9af286 100644 --- a/src/CmdLine.cpp +++ b/src/CmdLine.cpp @@ -43,7 +43,7 @@ CmdLine::CmdLine(const string& m, char delim, const string& v ) false, new VersionVisitor( this ) ); add( *vers ); - SwitchArg* ignore = new SwitchArg("-","ignore_rest", + SwitchArg* ignore = new SwitchArg(Arg::flagStartString,"ignore_rest", "Ignores the rest of the labeled arguments following this flag.", false, new IgnoreRestVisitor() ); add( *ignore ); @@ -118,6 +118,11 @@ void CmdLine::parse(int argc, char** argv) } } + // checks to see if the argument is an empty combined switch ... + // and if so, then we've actually matched it + if ( !matched && _emptyCombined( args[i] ) ) + matched = true; + if ( !matched && !Arg::ignoreRest() ) throw( ArgException("Couldn't find match for argument",args[i])); } @@ -137,4 +142,15 @@ void CmdLine::parse(int argc, char** argv) } } +bool CmdLine::_emptyCombined(const string& s) +{ + if ( s[0] != Arg::flagStartChar ) + return false; + + for ( int i = 1; (unsigned int)i < s.length(); i++ ) + if ( s[i] != Arg::blankChar ) + return false; + + return true; +} } diff --git a/src/SwitchArg.cpp b/src/SwitchArg.cpp index 820099a..092a4fa 100644 --- a/src/SwitchArg.cpp +++ b/src/SwitchArg.cpp @@ -58,7 +58,8 @@ bool SwitchArg::combinedSwitchesMatch(string& combinedSwitches ) // update the combined switches so this one is no longer present // this is necessary so that no unlabeled args are matched // later in the processing. - combinedSwitches.erase(i,1); + //combinedSwitches.erase(i,1); + combinedSwitches[i] = Arg::blankChar; return true; }