mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-08-05 18:56:54 -04:00
fixed some combined switch stuff
This commit is contained in:
parent
f1df55e8dc
commit
3bf7558a30
28
src/Arg.cpp
28
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user