options: added possibility to ignore negative numbers as options

This commit is contained in:
zawz 2019-10-04 02:47:42 +02:00
parent 03bf9107e4
commit ec2c2c8c37
2 changed files with 49 additions and 40 deletions

View file

@ -136,12 +136,12 @@ namespace ztd
@param arguments vector of string containing arguments and options @param arguments vector of string containing arguments and options
@return Leftover arguments that are not options\n @return Leftover arguments that are not options\n
*/ */
std::vector<std::string> process(std::vector<std::string> arguments); std::vector<std::string> process(std::vector<std::string> arguments, bool ignore_numbers=false);
//! @brief Process arguments through the option set //! @brief Process arguments through the option set
/*! /*!
calls process(std::vector<std::string> arguments) calls process(std::vector<std::string> arguments)
*/ */
inline std::vector<std::string> process(int argc, char** argv) { return this->process(ztd::argVector(argc, argv)); } inline std::vector<std::string> process(int argc, char** argv, bool ignore_numbers=false) { return this->process(ztd::argVector(argc, argv), ignore_numbers); }
//! @brief Options in the set //! @brief Options in the set
std::vector<option> option_vec; std::vector<option> option_vec;

View file

@ -159,7 +159,7 @@ ztd::option* ztd::option_set::find(std::string const& str)
return nullptr; return nullptr;
} }
std::vector<std::string> ztd::option_set::process(std::vector<std::string> arguments) std::vector<std::string> ztd::option_set::process(std::vector<std::string> arguments, bool ignore_numbers)
{ {
std::vector<std::string> out; std::vector<std::string> out;
unsigned int i=0; unsigned int i=0;
@ -213,6 +213,14 @@ std::vector<std::string> ztd::option_set::process(std::vector<std::string> argum
else else
{ {
i=1; i=1;
if( ignore_numbers && (*it)[i] >= '0' && (*it)[i] <= '9')
{
while(it!=arguments.end() && (*it).size()>i)
i++;
out.push_back(*it);
}
else
{
ztd::option* popt=nullptr; ztd::option* popt=nullptr;
bool tstop=false; bool tstop=false;
while( !tstop && it!=arguments.end() && (*it).size()>i ) while( !tstop && it!=arguments.end() && (*it).size()>i )
@ -252,7 +260,8 @@ std::vector<std::string> ztd::option_set::process(std::vector<std::string> argum
option_sequence.push_back(*popt); option_sequence.push_back(*popt);
} }
i++; i++;
} } //while
} // if not number
} }
} }
else else