** Interpret zArg as an integer value, possibly with suffixes. */
| 621 | ** Interpret zArg as an integer value, possibly with suffixes. |
| 622 | */ |
| 623 | int64_t ShellState::StringToInt(const string &arg) { |
| 624 | int64_t v = 0; |
| 625 | static const struct { |
| 626 | const char *zSuffix; |
| 627 | int iMult; |
| 628 | } aMult[] = { |
| 629 | {"KiB", 1024}, {"MiB", 1024 * 1024}, {"GiB", 1024 * 1024 * 1024}, |
| 630 | {"KB", 1000}, {"MB", 1000000}, {"GB", 1000000000}, |
| 631 | {"K", 1000}, {"M", 1000000}, {"G", 1000000000}, |
| 632 | }; |
| 633 | int i; |
| 634 | int isNeg = 0; |
| 635 | auto zArg = arg.c_str(); |
| 636 | if (zArg[0] == '-') { |
| 637 | isNeg = 1; |
| 638 | zArg++; |
| 639 | } else if (zArg[0] == '+') { |
| 640 | zArg++; |
| 641 | } |
| 642 | if (zArg[0] == '0' && zArg[1] == 'x') { |
| 643 | int x; |
| 644 | zArg += 2; |
| 645 | while ((x = hexDigitValue(zArg[0])) >= 0) { |
| 646 | v = (v << 4) + x; |
| 647 | zArg++; |
| 648 | } |
| 649 | } else { |
| 650 | while (IsDigit(zArg[0])) { |
| 651 | v = v * 10 + zArg[0] - '0'; |
| 652 | zArg++; |
| 653 | } |
| 654 | } |
| 655 | for (i = 0; i < ArraySize(aMult); i++) { |
| 656 | if (StringUtil::CIEquals(aMult[i].zSuffix, zArg)) { |
| 657 | v *= aMult[i].iMult; |
| 658 | break; |
| 659 | } |
| 660 | } |
| 661 | return isNeg ? -v : v; |
| 662 | } |
| 663 | |
| 664 | string ShellState::ModeToString(RenderMode mode) { |
| 665 | switch (mode) { |
no test coverage detected