Skip to content
Snippets Groups Projects
Commit 773a47db authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

BUG : negative real number were considered as arguments

parent eaab69c9
No related branches found
No related tags found
No related merge requests found
......@@ -302,9 +302,18 @@ bool CommandLineArgumentParser::TryParseCommandLine(int argc, char *argv[],
if (argv[i + 1] != NULL)
{
std::string strArgv = std::string(argv[i + 1]);
if (strArgv[0] == '-')
if (strArgv[0] == '-' )
{
goOnFlag = false;
// Test if the string is an argument or a real
if(!this->IsNumber(strArgv))
{
goOnFlag = false;
}
else // If not an argument add it to the option list
{
outResult->AddParameter(m_OptionList[index].CommonName, strArgv);
++i;
}
}
else
{
......@@ -337,6 +346,28 @@ bool CommandLineArgumentParser::TryParseCommandLine(int argc, char *argv[],
return true;
}
bool CommandLineArgumentParser::IsNumber(std::string text)
{
if(text.empty())
return false;
// Don't test the sign (-)
unsigned int i = 1;
while (text[i])
{
if( text[i] != '.' && text[i] != ',')
{
if(!isdigit(text[i]))
{
return false;
}
}
i++;
}
return true;
}
bool CommandLineArgumentParser::FindOption(const std::string& option, int& index)
{
//Look through the option list
......
......@@ -263,6 +263,7 @@ private:
void PrintUsage(std::ostream& os) const;
void PrintVersion(std::ostream& os) const;
bool FindOption(const std::string&, int& index);
bool IsNumber(std::string text);
/** Try processing a command line. Returns false if something breaks */
bool TryParseCommandLine(int argc, char *argv[],
......
......@@ -83,7 +83,7 @@ ADD_TEST(coTuCmdLineArgParser_EmptyList ${COMMON_TESTS1}
ADD_TEST(coTuCmdLineArgParser_List1Arg ${COMMON_TESTS1}
otbTestCommandLineArgumentParserList
-image image.png -entier 150 -double 12.25 -deuxentiers 78 56 -doubles 1.0)
-image image.png -entier 150 -double 12.25 -deuxentiers 78 56 -doubles 1.0 2.5)
ADD_TEST(coTuCmdLineArgParser_List2Arg ${COMMON_TESTS1}
otbTestCommandLineArgumentParserList
......@@ -93,6 +93,11 @@ ADD_TEST(coTuCmdLineArgParser_List2ArgBis ${COMMON_TESTS1}
otbTestCommandLineArgumentParserList
-image image.png -entier 150 -double 12.25 -doubles 1.0 2.0 -deuxentiers 78 56 )
ADD_TEST(coTuCmdLineArgParser_List3ArgWithError ${COMMON_TESTS1}
otbTestCommandLineArgumentParserList
-image image.png -entier 150 -double 12.25 -deuxentiers 78 56 -doubles 1.0 2.5 -3.5)
#ADD_TEST(coTuCmdLineArgParserGUIDeuxEntiers_ExactNumberArg ${COMMON_TESTS1}
# otbTestCommandLineArgumentParserGUI
# -image image.png -entier 150 -double 12.25 -deuxentiers 78 56 )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment