Split on whitespace, but leave quoted strings in tact
(s string)
| 140 | |
| 141 | // Split on whitespace, but leave quoted strings in tact |
| 142 | func safeSplit(s string) []string { |
| 143 | split := strings.Split(s, " ") |
| 144 | |
| 145 | var result []string |
| 146 | var inquote string |
| 147 | var block string |
| 148 | for _, i := range split { |
| 149 | if inquote == "" { |
| 150 | if strings.HasPrefix(i, "'") || strings.HasPrefix(i, "\"") { |
| 151 | inquote = string(i[0]) |
| 152 | block = strings.TrimPrefix(i, inquote) + " " |
| 153 | } else { |
| 154 | result = append(result, i) |
| 155 | } |
| 156 | } else { |
| 157 | if !strings.HasSuffix(i, inquote) { |
| 158 | block += i + " " |
| 159 | } else { |
| 160 | block += strings.TrimSuffix(i, inquote) |
| 161 | inquote = "" |
| 162 | result = append(result, block) |
| 163 | block = "" |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | return result |
| 169 | } |
| 170 | |
| 171 | func domain(s string) string { |
| 172 | domain := World["$domain"].(string) |