github.com/avicd/go-utilx@v0.1.0/tokx/quota.go (about) 1 package tokx 2 3 import "strings" 4 5 func DoubleQuota(text string) string { 6 buf := text 7 str := &strings.Builder{} 8 var left string 9 for { 10 var si int 11 if left == "" { 12 si = strings.IndexFunc(buf, func(r rune) bool { 13 return r == '"' || r == '\'' 14 }) 15 } else { 16 si = strings.Index(buf, left) 17 } 18 if si > -1 { 19 if left == "" { 20 left = buf[si : si+1] 21 } else { 22 left = "" 23 } 24 str.WriteString(buf[:si]) 25 str.WriteString("\"") 26 buf = buf[si+1:] 27 } else { 28 str.WriteString(buf) 29 break 30 } 31 } 32 return str.String() 33 }