From 347075d9bb7cd91c2d98a52ae03f4e0ce194bbcc Mon Sep 17 00:00:00 2001 From: Jose Date: Mon, 13 Aug 2018 19:09:02 +0200 Subject: IceUtil Options incorrectly paring multiple short options Fixes #168 --- cpp/src/IceUtil/Options.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'cpp/src') diff --git a/cpp/src/IceUtil/Options.cpp b/cpp/src/IceUtil/Options.cpp index c93154496a4..25379394aaf 100644 --- a/cpp/src/IceUtil/Options.cpp +++ b/cpp/src/IceUtil/Options.cpp @@ -646,13 +646,20 @@ IceUtilInternal::Options::parse(const StringVector& args) if(p != string::npos) { - if(pos->second->arg == NoArg && p != args[i].size() - 1) + if(pos->second->arg == NoArg) { string err = "`"; - err += args[i]; + err += opt; err += "': option does not take an argument"; throw BadOptException(__FILE__, __LINE__, err); } + else if(pos->second->arg == NeedArg && p == args[i].size() - 1) + { + string err = "`"; + err += opt; + err += "': option requires an argument"; + throw BadOptException(__FILE__, __LINE__, err); + } setOpt(opt, "", args[i].substr(p + 1), pos->second->repeat); argDone = true; } @@ -685,12 +692,20 @@ IceUtilInternal::Options::parse(const StringVector& args) } } - if(pos->second->arg == NeedArg && p != args[i].size() - 1) + if(pos->second->arg == NeedArg) + { + if(p != args[i].size() - 1) + { + string optArg = args[i].substr(p + 1); + setOpt(opt, "", optArg, pos->second->repeat); + argDone = true; + break; + } + } + else { - string optArg = args[i].substr(p + 1); - setOpt(opt, "", optArg, pos->second->repeat); + setOpt(opt, "", "1", pos->second->repeat); argDone = true; - break; } } } -- cgit v1.2.3