From bee68e519a11f2b1710de8026b7aa17090acb83c Mon Sep 17 00:00:00 2001 From: Andrey Morozov Date: Mon, 3 Oct 2011 11:44:31 +0000 Subject: [PATCH] fixed several bugs in CommandLineParser --- modules/core/src/cmdparser.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/core/src/cmdparser.cpp b/modules/core/src/cmdparser.cpp index 795734437a..5c0425e035 100644 --- a/modules/core/src/cmdparser.cpp +++ b/modules/core/src/cmdparser.cpp @@ -208,8 +208,6 @@ CommandLineParser::CommandLineParser(int argc, const char* const argv[], const c withNoKey = false; hasValueThroughEq = false; - if(!isFound) - printf("The current parameter is not defined: %s\n", curName.c_str()); isFound = false; } } @@ -273,6 +271,7 @@ template for (size_t i = 0; i < keysVector.size(); i++) keysVector[i] = del_space(keysVector[i]); cout << " "; + buf = ""; if (keysVector[0] != "") { buf = "-" + keysVector[0]; @@ -294,13 +293,19 @@ template while (true) { - bool tr = (buf.length() >= col_d-2) ? true: false; + bool tr = (buf.length() > col_d-2) ? true: false; int pos; if (tr) { pos = buf.find_first_of(' '); - while (buf.find_first_of(' ', pos + 1 ) > 0 && pos < col_d-2) pos = buf.find_first_of(' ', pos + 1); + while (true) + { + if (buf.find_first_of(' ', pos + 1 ) < col_d-2 && buf.find_first_of(' ', pos + 1 ) != std::string::npos) + pos = buf.find_first_of(' ', pos + 1); + else + break; + } pos++; cout << setw(col_d-2) << left << buf.substr(0, pos) << endl; }