diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-03-30 22:33:41 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-03-30 22:33:41 +0000 |
commit | 4b9289cfb260f4bcecaf23a810584ef6ef8e8501 (patch) | |
tree | 79136af08c7e42ba3322f0d73e9779e4354b318a /src/optparser.cpp | |
parent | c7636dc954eddfe58f7959392602fbc9072d77e7 (diff) | |
download | libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.gz libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.bz2 libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.xz libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.zip |
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.
Diffstat (limited to 'src/optparser.cpp')
-rw-r--r-- | src/optparser.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
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 ) | |||
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | void Bu::OptParser::parse( const Bu::String &sLine ) | ||
171 | { | ||
172 | Bu::String sCmd = sLine.clone(); | ||
173 | int iParams = 0; | ||
174 | bool bInGap = true; | ||
175 | bool bInQuote = false; | ||
176 | for( Bu::String::iterator i = sCmd.begin(); i; i++ ) | ||
177 | { | ||
178 | if( bInQuote == false && (*i == ' ' || *i == '\t') ) | ||
179 | { | ||
180 | if( bInGap == false ) | ||
181 | { | ||
182 | bInGap = true; | ||
183 | } | ||
184 | } | ||
185 | else if( *i == '"' ) | ||
186 | { | ||
187 | bInQuote = !bInQuote; | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | if( bInGap ) | ||
192 | { | ||
193 | iParams++; | ||
194 | bInGap = false; | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | |||
199 | bInQuote = false; | ||
200 | bInGap = true; | ||
201 | char **asParam = new char*[iParams]; | ||
202 | iParams = 0; | ||
203 | for( char *i = sCmd.getStr(); *i; i++ ) | ||
204 | { | ||
205 | if( bInQuote == false && (*i == ' ' || *i == '\t') ) | ||
206 | { | ||
207 | if( bInGap == false ) | ||
208 | { | ||
209 | bInGap = true; | ||
210 | *i = '\0'; | ||
211 | } | ||
212 | } | ||
213 | else if( *i == '"' ) | ||
214 | { | ||
215 | bInQuote = !bInQuote; | ||
216 | } | ||
217 | else | ||
218 | { | ||
219 | if( bInGap ) | ||
220 | { | ||
221 | asParam[iParams++] = i; | ||
222 | bInGap = false; | ||
223 | } | ||
224 | } | ||
225 | } | ||
226 | |||
227 | parse( iParams, asParam ); | ||
228 | |||
229 | delete[] asParam; | ||
230 | } | ||
231 | |||
170 | void Bu::OptParser::addOption( const Option &opt ) | 232 | void Bu::OptParser::addOption( const Option &opt ) |
171 | { | 233 | { |
172 | lOption.append( opt ); | 234 | lOption.append( opt ); |