mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
@@ -1,6 +1,9 @@
|
||||
package models
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"encoding/csv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// IsQuoted returns true if the string starts and ends with a double quote.
|
||||
func IsQuoted(s string) bool {
|
||||
@@ -35,3 +38,14 @@ func ParseQuotedTxt(s string) []string {
|
||||
}
|
||||
return strings.Split(StripQuotes(s), `" "`)
|
||||
}
|
||||
|
||||
// ParseQuotedFields is like strings.Fields except individual fields
|
||||
// might be quoted using `"`.
|
||||
func ParseQuotedFields(s string) ([]string, error) {
|
||||
// Fields are space-separated but a field might be quoted. This is,
|
||||
// essentially, a CSV where spaces are the field separator (not
|
||||
// commas). Therefore, we use the CSV parser. See https://stackoverflow.com/a/47489846/71978
|
||||
r := csv.NewReader(strings.NewReader(s))
|
||||
r.Comma = ' ' // space
|
||||
return r.Read()
|
||||
}
|
||||
|
Reference in New Issue
Block a user