Update of /cvsroot/pclasses/pclasses2/src/Util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16410/src/Util
Modified Files:
SimpleArgvParser.cpp
Log Message:
Added API docs.
Fixed (argc,argv) ctor to actually use it's args.
Values may now be quoted strings.
Index: SimpleArgvParser.cpp
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/src/Util/SimpleArgvParser.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- SimpleArgvParser.cpp 31 Dec 2004 02:19:37 -0000 1.2
+++ SimpleArgvParser.cpp 31 Dec 2004 02:45:09 -0000 1.3
@@ -1,7 +1,9 @@
#include <vector>
#include <list>
#include <pclasses/Util/SimpleArgvParser.h>
+#include <pclasses/Util/StringTool.h>
#include <pclasses/Phoenix.h>
+
namespace P { namespace Util {
SimpleArgvParser::SimpleArgvParser()
@@ -9,13 +11,17 @@
}
SimpleArgvParser::SimpleArgvParser( int argc, char ** argv )
{
-
+ this->parse( argc, argv );
}
SimpleArgvParser::~SimpleArgvParser()
{
}
+ /**
+ Internal helper function to change a char** into an STL
+ container of strings.
+ */
template <typename ListT>
size_t toList( ListT & tgt, int argc, char ** argv )
{
@@ -25,7 +31,7 @@
}
}
- std::string strip_dashes( const std::string & s )
+ std::string internal_strip_leading_dashes( const std::string & s )
{
if( 0 != s.find( "-" ) ) return s;
std::string::size_type first = s.find_first_not_of( "-" );
@@ -52,12 +58,13 @@
k = alist[at];
if( IS_ARG(k) )
{
- k = strip_dashes( k );
+ k = internal_strip_leading_dashes( k );
if( std::string::npos != (eqat = k.find( '=' )) )
{
++ret;
nextarg = k.substr( eqat+1 );
+ ::P::StringTool::normalizeString( nextarg ); // remove leading/trailing quotes
k = k.substr( 0, eqat );
this->set( k, nextarg );
continue;
@@ -78,11 +85,16 @@
else
{
++ret;
+ ::P::StringTool::normalizeString( nextarg ); // remove leading/trailing quotes
this->set( k, nextarg );
skipnext = true;
continue;
}
}
+ else
+ {
+ // do nothing - we're not interesting in non-dashed args.
+ }
}
return ret;
#undef IS_ARG
@@ -99,9 +111,15 @@
return s;
}
+ //! Internal marker class
+ struct SimpleArgvParserSharingContext {};
+
SimpleArgvParser & SimpleArgvParser::args()
{
- return ArgvPhoenix::instance();
+ return ::P::Phoenix<
+ SimpleArgvParser,
+ SimpleArgvParserSharingContext
+ >::instance();
}
|