37 lines
540 B
Go
37 lines
540 B
Go
package utils
|
|
|
|
func QuotedStringToArray(text string) []string {
|
|
var escape, quoted bool
|
|
out := make([]string, 0)
|
|
var a string
|
|
|
|
runeArr := []rune(text)
|
|
for _, char := range runeArr {
|
|
if escape {
|
|
a += string(char)
|
|
escape = false
|
|
continue
|
|
}
|
|
switch char {
|
|
case ' ':
|
|
if quoted {
|
|
a += " "
|
|
} else if a != "" {
|
|
out = append(out, a)
|
|
a = ""
|
|
}
|
|
case '\\':
|
|
escape = true
|
|
case '"':
|
|
quoted = !quoted
|
|
default:
|
|
a += string(char)
|
|
}
|
|
}
|
|
if a != "" {
|
|
out = append(out, a)
|
|
a = ""
|
|
}
|
|
return out
|
|
}
|