diff --git a/examples/Makefile.am b/examples/Makefile.am index 381fdb7..fe7df3b 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,6 +1,6 @@ noinst_PROGRAMS = test1 test2 test3 test4 test5 test6 test7 test8 test9 \ - test10 test11 test12 + test10 test11 test12 test13 test1_SOURCES = test1.cpp test2_SOURCES = test2.cpp @@ -14,6 +14,7 @@ test9_SOURCES = test9.cpp test10_SOURCES = test10.cpp test11_SOURCES = test11.cpp test12_SOURCES = test12.cpp +test13_SOURCES = test13.cpp INCLUDES = -I$(top_srcdir)/include diff --git a/examples/test13.cpp b/examples/test13.cpp new file mode 100644 index 0000000..0a42d62 --- /dev/null +++ b/examples/test13.cpp @@ -0,0 +1,55 @@ +#include +#include + +#include + +using namespace TCLAP; + +// +// This file tests that we can parse args from a vector +// of strings rather than argv. This also tests a bug +// where a single element in the vector contains both +// the flag and value AND the value contains the flag +// from another switch arg. This would fool the parser +// into thinking that the string was a combined switches +// string rather than a flag value combo. +// +// This should not print an error +// +int main(int argc, char ** argv) +{ + + try + { + CmdLine cmd("Test", ' ', "not versioned",true); + + MultiArg Arg("X","fli","fli module",false,"string"); + cmd.add(Arg); + MultiSwitchArg ArgMultiSwitch("d","long_d","example"); + cmd.add(ArgMultiSwitch); + + std::vector in; + in.push_back("prog name"); + in.push_back("-X module"); + cmd.parse(in); + + std::vector s = Arg.getValue(); + for(unsigned int i = 0 ; i < s.size() ; i++) + { + std::cout << s[i] << "\n"; + } + std::cout << "MultiSwtichArg was found " << ArgMultiSwitch.getValue() << " times.\n"; + + } + catch (ArgException &e) // catch any exceptions + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } + + std::cout << "done...\n"; + + return 0; +} + + + diff --git a/include/tclap/SwitchArg.h b/include/tclap/SwitchArg.h index da04feb..878ed43 100644 --- a/include/tclap/SwitchArg.h +++ b/include/tclap/SwitchArg.h @@ -147,6 +147,10 @@ inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches ) Arg::nameStartString() ) return false; + // make sure the delimiter isn't in the string + if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos ) + return false; + // ok, we're not specifying a ValueArg, so we know that we have // a combined switch list. for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) diff --git a/tests/Makefile.am b/tests/Makefile.am index 7268bf5..31d3ae0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -61,7 +61,13 @@ TESTS = test1.sh \ test59.sh \ test60.sh \ test61.sh \ - test62.sh + test62.sh \ + test63.sh \ + test64.sh \ + test65.sh \ + test66.sh \ + test67.sh \ + test68.sh EXTRA_DIST = $(TESTS) \ test1.out \ @@ -125,6 +131,12 @@ EXTRA_DIST = $(TESTS) \ test59.out \ test60.out \ test61.out \ - test62.out + test62.out \ + test63.out \ + test64.out \ + test65.out \ + test66.out \ + test67.out \ + test68.out CLEANFILES = tmp.out diff --git a/tests/test68.out b/tests/test68.out new file mode 100644 index 0000000..912bb3b --- /dev/null +++ b/tests/test68.out @@ -0,0 +1,3 @@ +module +MultiSwtichArg was found 0 times. +done... diff --git a/tests/test68.sh b/tests/test68.sh new file mode 100755 index 0000000..c8f19d7 --- /dev/null +++ b/tests/test68.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# this tests whether we can parse args from +# a vector of strings and that combined switch +# handling doesn't get fooled if the delimiter +# is in the string +# success +../examples/test13 > tmp.out 2>&1 + +if cmp -s tmp.out $srcdir/test68.out; then + exit 0 +else + exit 1 +fi +