|
|
@ -16,12 +16,17 @@ function escapedSplit(str) { |
|
|
|
max = str.length, |
|
|
|
ch, |
|
|
|
escapes = 0, |
|
|
|
lastPos = 0; |
|
|
|
lastPos = 0, |
|
|
|
backTicked = false, |
|
|
|
lastBackTick = 0; |
|
|
|
|
|
|
|
ch = str.charCodeAt(pos); |
|
|
|
|
|
|
|
while (pos < max) { |
|
|
|
if (ch === 0x7c/* | */ && (escapes % 2 === 0)) { |
|
|
|
if (ch === 0x60/* ` */ && (escapes % 2 === 0)) { |
|
|
|
backTicked = !backTicked; |
|
|
|
lastBackTick = pos; |
|
|
|
} else if (ch === 0x7c/* | */ && (escapes % 2 === 0) && !backTicked) { |
|
|
|
result.push(str.substring(lastPos, pos)); |
|
|
|
lastPos = pos + 1; |
|
|
|
} else if (ch === 0x5c/* \ */) { |
|
|
@ -30,7 +35,16 @@ function escapedSplit(str) { |
|
|
|
escapes = 0; |
|
|
|
} |
|
|
|
|
|
|
|
ch = str.charCodeAt(++pos); |
|
|
|
pos++; |
|
|
|
|
|
|
|
// If there was an un-closed backtick, go back to just after
|
|
|
|
// the last backtick, but as if it was a normal character
|
|
|
|
if (pos === max && backTicked) { |
|
|
|
backTicked = false; |
|
|
|
pos = lastBackTick + 1; |
|
|
|
} |
|
|
|
|
|
|
|
ch = str.charCodeAt(pos); |
|
|
|
} |
|
|
|
|
|
|
|
result.push(str.substring(lastPos)); |
|
|
|