From 4b9289cfb260f4bcecaf23a810584ef6ef8e8501 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 30 Mar 2011 22:33:41 +0000 Subject: Ok, string stuff is working much, much better, a load of new unit tests have been added, and I deleted a whole slew of stupid old tests that I don't need. --- src/optparser.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'src/optparser.cpp') diff --git a/src/optparser.cpp b/src/optparser.cpp index bab93d0..74aba3e 100644 --- a/src/optparser.cpp +++ b/src/optparser.cpp @@ -167,6 +167,68 @@ void Bu::OptParser::parse( int argc, char **argv ) } } +void Bu::OptParser::parse( const Bu::String &sLine ) +{ + Bu::String sCmd = sLine.clone(); + int iParams = 0; + bool bInGap = true; + bool bInQuote = false; + for( Bu::String::iterator i = sCmd.begin(); i; i++ ) + { + if( bInQuote == false && (*i == ' ' || *i == '\t') ) + { + if( bInGap == false ) + { + bInGap = true; + } + } + else if( *i == '"' ) + { + bInQuote = !bInQuote; + } + else + { + if( bInGap ) + { + iParams++; + bInGap = false; + } + } + } + + bInQuote = false; + bInGap = true; + char **asParam = new char*[iParams]; + iParams = 0; + for( char *i = sCmd.getStr(); *i; i++ ) + { + if( bInQuote == false && (*i == ' ' || *i == '\t') ) + { + if( bInGap == false ) + { + bInGap = true; + *i = '\0'; + } + } + else if( *i == '"' ) + { + bInQuote = !bInQuote; + } + else + { + if( bInGap ) + { + asParam[iParams++] = i; + bInGap = false; + } + } + } + + parse( iParams, asParam ); + + delete[] asParam; +} + void Bu::OptParser::addOption( const Option &opt ) { lOption.append( opt ); -- cgit v1.2.3