Parse string containing parameters separated with spaces. Support quote marks. Param can be NULL to return the pointer to next parameter, which can be used to estimate the buffer size for Param.
| 397 | // Support quote marks. Param can be NULL to return the pointer to next |
| 398 | // parameter, which can be used to estimate the buffer size for Param. |
| 399 | const wchar* GetCmdParam(const wchar *CmdLine,wchar *Param,size_t MaxSize) |
| 400 | { |
| 401 | while (IsSpace(*CmdLine)) |
| 402 | CmdLine++; |
| 403 | if (*CmdLine==0) |
| 404 | return NULL; |
| 405 | |
| 406 | size_t ParamSize=0; |
| 407 | bool Quote=false; |
| 408 | while (*CmdLine!=0 && (Quote || !IsSpace(*CmdLine))) |
| 409 | { |
| 410 | if (*CmdLine=='\"') |
| 411 | { |
| 412 | if (CmdLine[1]=='\"') |
| 413 | { |
| 414 | // Insert the quote character instead of two adjoining quote characters. |
| 415 | if (Param!=NULL && ParamSize<MaxSize-1) |
| 416 | Param[ParamSize++]='\"'; |
| 417 | CmdLine++; |
| 418 | } |
| 419 | else |
| 420 | Quote=!Quote; |
| 421 | } |
| 422 | else |
| 423 | if (Param!=NULL && ParamSize<MaxSize-1) |
| 424 | Param[ParamSize++]=*CmdLine; |
| 425 | CmdLine++; |
| 426 | } |
| 427 | if (Param!=NULL) |
| 428 | Param[ParamSize]=0; |
| 429 | return CmdLine; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | #ifndef RARDLL |
no test coverage detected