github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/util/vtabutil/arg.go (about) 1 // Package ioutil implements virtual table utility functions. 2 package vtabutil 3 4 import "strings" 5 6 // NamedArg splits an named arg into a key and value, 7 // around an equals sign. 8 // Spaces are trimmed around both key and value. 9 func NamedArg(arg string) (key, val string) { 10 key, val, _ = strings.Cut(arg, "=") 11 key = strings.TrimSpace(key) 12 val = strings.TrimSpace(val) 13 return 14 } 15 16 // Unquote unquotes a string. 17 func Unquote(val string) string { 18 if len(val) < 2 { 19 return val 20 } 21 if val[0] != val[len(val)-1] { 22 return val 23 } 24 var old, new string 25 switch val[0] { 26 default: 27 return val 28 case '"': 29 old, new = `""`, `"` 30 case '\'': 31 old, new = `''`, `'` 32 } 33 return strings.ReplaceAll(val[1:len(val)-1], old, new) 34 }