Merge pull request #1590 from ilya-lavrenov:cmd_parser_fix
This commit is contained in:
commit
19ceab13f2
@ -92,6 +92,22 @@ string del_space(string name)
|
|||||||
|
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
||||||
|
static bool keyIsNumber(const std::string & option, size_t start)
|
||||||
|
{
|
||||||
|
bool isNumber = true;
|
||||||
|
size_t end = option.find_first_of('=', start);
|
||||||
|
end = option.npos == end ? option.length() : end;
|
||||||
|
|
||||||
|
for ( ; start < end; ++start)
|
||||||
|
if (!isdigit(option[start]))
|
||||||
|
{
|
||||||
|
isNumber = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isNumber;
|
||||||
|
}
|
||||||
|
|
||||||
CommandLineParser::CommandLineParser(int argc, const char* const argv[], const char* keys)
|
CommandLineParser::CommandLineParser(int argc, const char* const argv[], const char* keys)
|
||||||
{
|
{
|
||||||
std::string keys_buffer;
|
std::string keys_buffer;
|
||||||
@ -144,13 +160,13 @@ CommandLineParser::CommandLineParser(int argc, const char* const argv[], const c
|
|||||||
if (!argv[i])
|
if (!argv[i])
|
||||||
break;
|
break;
|
||||||
curName = argv[i];
|
curName = argv[i];
|
||||||
if (curName.find('-') == 0 && ((curName[1] < '0') || (curName[1] > '9')))
|
|
||||||
{
|
size_t nondash = curName.find_first_not_of("-");
|
||||||
while (curName.find('-') == 0)
|
if (nondash == 0 || nondash == curName.npos || keyIsNumber(curName, nondash))
|
||||||
curName.erase(curName.begin(), (curName.begin() + 1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
withNoKey = true;
|
withNoKey = true;
|
||||||
|
else
|
||||||
|
curName.erase(0, nondash);
|
||||||
|
|
||||||
if (curName.find('=') != curName.npos)
|
if (curName.find('=') != curName.npos)
|
||||||
{
|
{
|
||||||
hasValueThroughEq = true;
|
hasValueThroughEq = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user