Skip to content

Instantly share code, notes, and snippets.

@subuk
Created October 12, 2016 12:45
Show Gist options
  • Save subuk/dcf6e38166ba516fdfad355966028870 to your computer and use it in GitHub Desktop.
Save subuk/dcf6e38166ba516fdfad355966028870 to your computer and use it in GitHub Desktop.
func QuotedSplit(input string) []string {
runedParts := [12][]rune{}
runedPartsEl := 0
quoteActive := false
for _, r := range input {
if r == '"' && !quoteActive {
quoteActive = true
continue
}
if r == '"' && quoteActive {
quoteActive = false
continue
}
if r == ' ' && !quoteActive {
runedPartsEl++
continue
}
runedParts[runedPartsEl] = append(runedParts[runedPartsEl], r)
}
output := []string{}
for _, part := range runedParts {
output = append(output, string(part))
}
return output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment