diff options
author | Brad King <brad.king@kitware.com> | 2021-03-29 13:29:30 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-03-29 13:29:40 (GMT) |
commit | c4f800545443d0816a3d87cc7161c1d8dc7b529f (patch) | |
tree | 85f4fc3dbfc30f1044d1cf72760bd9dcdb06dafa /Source/cmCommandLineArgument.h | |
parent | d5ab6a53edef5f259f9b9446943dcc5113898b51 (diff) | |
parent | 79d7bcaf4029ce7b78abfcbcaf8cd1a09a172437 (diff) | |
download | CMake-c4f800545443d0816a3d87cc7161c1d8dc7b529f.zip CMake-c4f800545443d0816a3d87cc7161c1d8dc7b529f.tar.gz CMake-c4f800545443d0816a3d87cc7161c1d8dc7b529f.tar.bz2 |
Merge topic 'correct_arg_parsing'
79d7bcaf40 cmCommandLineArgument: correctly compute next parse index
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5936
Diffstat (limited to 'Source/cmCommandLineArgument.h')
-rw-r--r-- | Source/cmCommandLineArgument.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Source/cmCommandLineArgument.h b/Source/cmCommandLineArgument.h index 6b75da0..b14cfc2 100644 --- a/Source/cmCommandLineArgument.h +++ b/Source/cmCommandLineArgument.h @@ -76,8 +76,9 @@ struct cmCommandLineArgument } else if (this->Type == Values::One || this->Type == Values::ZeroOrOne) { if (input.size() == this->Name.size()) { - ++index; - if (index >= allArgs.size() || allArgs[index][0] == '-') { + auto nextValueIndex = index + 1; + if (nextValueIndex >= allArgs.size() || + allArgs[nextValueIndex][0] == '-') { if (this->Type == Values::ZeroOrOne) { parseState = this->StoreCall(std::string{}, std::forward<CallState>(state)...) @@ -87,10 +88,11 @@ struct cmCommandLineArgument parseState = ParseMode::ValueError; } } else { - parseState = - this->StoreCall(allArgs[index], std::forward<CallState>(state)...) + parseState = this->StoreCall(allArgs[nextValueIndex], + std::forward<CallState>(state)...) ? ParseMode::Valid : ParseMode::Invalid; + index = nextValueIndex; } } else { // parse the string to get the value @@ -137,7 +139,8 @@ struct cmCommandLineArgument } else if (this->Type == Values::OneOrMore) { if (input.size() == this->Name.size()) { auto nextValueIndex = index + 1; - if (nextValueIndex >= allArgs.size() || allArgs[index + 1][0] == '-') { + if (nextValueIndex >= allArgs.size() || + allArgs[nextValueIndex][0] == '-') { parseState = ParseMode::ValueError; } else { std::string buffer = allArgs[nextValueIndex++]; @@ -149,6 +152,7 @@ struct cmCommandLineArgument this->StoreCall(buffer, std::forward<CallState>(state)...) ? ParseMode::Valid : ParseMode::Invalid; + index = (nextValueIndex - 1); } } } |