----------------------------------------------------------------------------- Parse a string containing program options, such as a command line -----------------------------------------------------------------------------
| 404 | // Parse a string containing program options, such as a command line |
| 405 | //----------------------------------------------------------------------------- |
| 406 | bool Options::ParseOptionsString |
| 407 | ( |
| 408 | string const& _commandLine |
| 409 | ) |
| 410 | { |
| 411 | bool res = true; |
| 412 | |
| 413 | size_t pos = 0; |
| 414 | size_t start = 0; |
| 415 | while( 1 ) |
| 416 | { |
| 417 | // find start of first option name |
| 418 | pos = _commandLine.find_first_of( "--", start ); |
| 419 | if( string::npos == pos ) |
| 420 | { |
| 421 | break; |
| 422 | } |
| 423 | start = pos + 2; |
| 424 | |
| 425 | // found an option. Get the name. |
| 426 | string optionName; |
| 427 | pos = _commandLine.find( " ", start ); |
| 428 | if( string::npos == pos ) |
| 429 | { |
| 430 | optionName = _commandLine.substr( start ); |
| 431 | start = pos; |
| 432 | } |
| 433 | else |
| 434 | { |
| 435 | optionName = _commandLine.substr( start, pos-start ); |
| 436 | start = pos + 1; |
| 437 | } |
| 438 | |
| 439 | // Find the matching option object |
| 440 | Option* option = Find( optionName ); |
| 441 | if( option ) |
| 442 | { |
| 443 | // Read the values |
| 444 | int numValues = 0; |
| 445 | bool parsing = true; |
| 446 | while( parsing ) |
| 447 | { |
| 448 | string value; |
| 449 | size_t back = start; |
| 450 | pos = _commandLine.find( " ", start ); |
| 451 | if( string::npos == pos ) |
| 452 | { |
| 453 | // Last value in string |
| 454 | value = _commandLine.substr( start ); |
| 455 | parsing = false; |
| 456 | start = pos; |
| 457 | } |
| 458 | else |
| 459 | { |
| 460 | value = _commandLine.substr( start, pos-start ); |
| 461 | start = pos+1; |
| 462 | } |
| 463 |
nothing calls this directly
no test coverage detected