| 647 | } |
| 648 | |
| 649 | static std::string PutCommandString(std::string_view str) |
| 650 | { |
| 651 | std::string result; |
| 652 | StringBuilder builder(result); |
| 653 | StringConsumer consumer(str); |
| 654 | _cur_argidx = 0; |
| 655 | |
| 656 | for (;;) { |
| 657 | /* Process characters as they are until we encounter a { */ |
| 658 | builder.Put(consumer.ReadUntilChar('{', StringConsumer::KEEP_SEPARATOR)); |
| 659 | if (!consumer.AnyBytesLeft()) break; |
| 660 | |
| 661 | auto cs = ParseCommandString(consumer); |
| 662 | auto *cmd = cs.cmd; |
| 663 | if (cmd == nullptr) break; |
| 664 | |
| 665 | if (cs.casei.has_value()) { |
| 666 | builder.PutUtf8(SCC_SET_CASE); // {SET_CASE} |
| 667 | builder.PutUint8(*cs.casei); |
| 668 | } |
| 669 | |
| 670 | /* For params that consume values, we need to handle the argindex properly */ |
| 671 | if (cmd->consumes > 0) { |
| 672 | /* Check if we need to output a move-param command */ |
| 673 | if (cs.argno.has_value() && *cs.argno != _cur_argidx) { |
| 674 | _cur_argidx = *cs.argno; |
| 675 | PutArgidxCommand(builder); |
| 676 | } |
| 677 | |
| 678 | /* Output the one from the master string... it's always accurate. */ |
| 679 | cmd = _cur_pcs.consuming_commands[_cur_argidx++]; |
| 680 | if (cmd == nullptr) { |
| 681 | StrgenFatal("{}: No argument exists at position {}", _cur_ident, _cur_argidx - 1); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | cmd->proc(builder, cs.param, cmd->value); |
| 686 | } |
| 687 | return result; |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Write the length as a simple gamma. |
no test coverage detected