mirror of
https://github.com/turbot/steampipe.git
synced 2026-02-14 19:00:10 -05:00
22 lines
514 B
Go
22 lines
514 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/csv"
|
|
"strings"
|
|
)
|
|
|
|
// SplitByRune uses the CSV decoder to parse out the tokens - even if they are quoted and/or escaped
|
|
func SplitByRune(str string, r rune) []string {
|
|
csvDecoder := csv.NewReader(strings.NewReader(str))
|
|
csvDecoder.Comma = r
|
|
csvDecoder.LazyQuotes = true
|
|
csvDecoder.TrimLeadingSpace = true
|
|
split, _ := csvDecoder.Read()
|
|
return split
|
|
}
|
|
|
|
// SplitByWhitespace splits by the ' ' rune
|
|
func SplitByWhitespace(str string) []string {
|
|
return SplitByRune(str, ' ')
|
|
}
|