find and execute special commands in code, remove them from returned string
(ir *interp.Interp, outerr OutErr, code string)
| 697 | |
| 698 | // find and execute special commands in code, remove them from returned string |
| 699 | func evalSpecialCommands(ir *interp.Interp, outerr OutErr, code string) string { |
| 700 | lines := strings.Split(code, "\n") |
| 701 | stop := false |
| 702 | for i, line := range lines { |
| 703 | line = strings.TrimSpace(line) |
| 704 | if len(line) != 0 { |
| 705 | switch line[0] { |
| 706 | case '%': |
| 707 | evalSpecialCommand(ir, outerr, line) |
| 708 | lines[i] = "" |
| 709 | case '$': |
| 710 | evalShellCommand(ir, outerr, line) |
| 711 | lines[i] = "" |
| 712 | default: |
| 713 | // if a line is NOT a special command, |
| 714 | // stop processing special commands |
| 715 | stop = true |
| 716 | } |
| 717 | } |
| 718 | if stop { |
| 719 | break |
| 720 | } |
| 721 | } |
| 722 | return strings.Join(lines, "\n") |
| 723 | } |
| 724 | |
| 725 | // execute special command. line must start with '%' |
| 726 | func evalSpecialCommand(ir *interp.Interp, outerr OutErr, line string) { |
no test coverage detected