treat \ as escape only before a separator

This commit is contained in:
David Shiflet
2022-05-03 21:19:51 -04:00
committed by Alec Thomas
parent 5538b7f045
commit 29685e7da6
5 changed files with 86 additions and 20 deletions
+5 -2
View File
@@ -721,12 +721,15 @@ func SplitEscaped(s string, sep rune) (out []string) {
}
escaped := false
token := ""
for _, ch := range s {
for i, ch := range s {
switch {
case escaped:
if ch != sep {
token += `\`
}
token += string(ch)
escaped = false
case ch == '\\':
case ch == '\\' && i < len(s)-1:
escaped = true
case ch == sep && !escaped:
out = append(out, token)