(command string, stripQuotes bool)
| 50 | var envNameRe = regexp.MustCompile(`^[A-Za-z_]\w*$`) |
| 51 | |
| 52 | func Tokenize(command string, stripQuotes bool) []string { |
| 53 | var tokens []string |
| 54 | var current []rune |
| 55 | inSingle := false |
| 56 | inDouble := false |
| 57 | i := 0 |
| 58 | runes := []rune(command) |
| 59 | n := len(runes) |
| 60 | |
| 61 | for i < n { |
| 62 | ch := runes[i] |
| 63 | if ch == '\\' && i+1 < n { |
| 64 | nextCh := runes[i+1] |
| 65 | if nextCh == ' ' || nextCh == '\t' || nextCh == '\\' || nextCh == '\'' || nextCh == '"' { |
| 66 | current = append(current, nextCh) |
| 67 | i += 2 |
| 68 | continue |
| 69 | } |
| 70 | i += 1 |
| 71 | current = append(current, ch) |
| 72 | continue |
| 73 | } else if ch == '\'' && !inDouble { |
| 74 | inSingle = !inSingle |
| 75 | if !stripQuotes { |
| 76 | current = append(current, ch) |
| 77 | } |
| 78 | } else if ch == '"' && !inSingle { |
| 79 | inDouble = !inDouble |
| 80 | if !stripQuotes { |
| 81 | current = append(current, ch) |
| 82 | } |
| 83 | } else if (ch == ' ' || ch == '\t') && !inSingle && !inDouble { |
| 84 | if current != nil && len(current) > 0 { |
| 85 | tokens = append(tokens, string(current)) |
| 86 | current = []rune{} |
| 87 | } |
| 88 | } else { |
| 89 | current = append(current, ch) |
| 90 | } |
| 91 | i += 1 |
| 92 | } |
| 93 | if current != nil && len(current) > 0 { |
| 94 | tokens = append(tokens, string(current)) |
| 95 | } |
| 96 | return tokens |
| 97 | } |
| 98 | |
| 99 | func SplitPipeline(command string) []string { |
| 100 | var segments []string |
no outgoing calls