push
github
174 of 179 branches covered (97.21%)
Branch coverage included in aggregate %.
291 of 294 relevant lines covered (98.98%)
134.9 hits per line
| 1 |
export function parse (command: string) { |
6✔ |
| 2 |
const args: string[] = [] |
1,038✔ |
| 3 |
let lastQuote: string | false = false |
1,038✔ |
| 4 |
let escaped = false
|
1,038✔ |
| 5 |
let part = ''
|
1,038✔ |
| 6 |
for (let i = 0; i < command.length; ++i) { |
1,038✔ |
| 7 |
const char = command.charAt(i) |
15,690✔ |
| 8 |
if (char === '\\') { |
|
| 9 |
part += char
|
18✔ |
| 10 |
escaped = true
|
18✔ |
| 11 |
} else {
|
|
| 12 |
if (char === ' ' && !lastQuote) { |
|
| 13 |
args.push(part) |
1,209✔ |
| 14 |
part = ''
|
1,209✔ |
| 15 |
} else if (!escaped && (char === '"' || char === "'")) { |
|
| 16 |
part += char
|
132✔ |
| 17 |
if (char === lastQuote) { |
|
| 18 |
lastQuote = false
|
63✔ |
| 19 |
} else if (!lastQuote) { |
|
| 20 |
lastQuote = char
|
63✔ |
| 21 |
} |
|
| 22 |
} else {
|
|
| 23 |
part += char
|
14,331✔ |
| 24 |
} |
|
| 25 |
escaped = false
|
15,672✔ |
| 26 |
} |
|
| 27 |
} |
|
| 28 |
args.push(part) |
1,038✔ |
| 29 |
return args
|
1,038✔ |
| 30 |
} |