| 579 | } |
| 580 | |
| 581 | FString SubstituteAliasParams (FString &command, FCommandLine &args) |
| 582 | { |
| 583 | // Do substitution by replacing %x with the argument x. |
| 584 | // If there is no argument x, then %x is simply removed. |
| 585 | |
| 586 | // For some reason, strtoul's stop parameter is non-const. |
| 587 | char *p = command.LockBuffer(), *start = p; |
| 588 | unsigned long argnum; |
| 589 | FString buf; |
| 590 | bool inquote = false; |
| 591 | |
| 592 | while (*p != '\0') |
| 593 | { |
| 594 | if (p[0] == '%' && ((p[1] >= '0' && p[1] <= '9') || p[1] == '{')) |
| 595 | { |
| 596 | // Do a substitution. Output what came before this. |
| 597 | buf.AppendCStrPart (start, p - start); |
| 598 | |
| 599 | // Extract the argument number and substitute the corresponding argument. |
| 600 | argnum = strtoul (p + 1 + (p[1] == '{'), &start, 10); |
| 601 | if ((p[1] != '{' || *start == '}') && argnum < (unsigned long)args.argc()) |
| 602 | { |
| 603 | buf += args[argnum]; |
| 604 | } |
| 605 | p = (start += (p[1] == '{' && *start == '}')); |
| 606 | } |
| 607 | else if (p[0] == '%' && p[1] == '%') |
| 608 | { |
| 609 | // Do not substitute. Just collapse to a single %. |
| 610 | buf.AppendCStrPart (start, p - start + 1); |
| 611 | start = p = p + 2; |
| 612 | continue; |
| 613 | } |
| 614 | else if (p[0] == '%' && p[1] == '"') |
| 615 | { |
| 616 | // Collapse %" to " and remember that we're in a quote so when we |
| 617 | // see a " character again, we don't start skipping below. |
| 618 | if (!inquote) |
| 619 | { |
| 620 | inquote = true; |
| 621 | buf.AppendCStrPart(start, p - start); |
| 622 | start = p + 1; |
| 623 | } |
| 624 | else |
| 625 | { |
| 626 | inquote = false; |
| 627 | } |
| 628 | p += 2; |
| 629 | } |
| 630 | else if (p[0] == '\\' && p[1] == '"') |
| 631 | { |
| 632 | p += 2; |
| 633 | } |
| 634 | else if (p[0] == '"') |
| 635 | { |
| 636 | // Don't substitute inside quoted strings if it didn't start |
| 637 | // with a %" |
| 638 | if (!inquote) |
no test coverage detected