package parse
import (
)
func ( string) string {
, _ = QuoteAs(, Bareword)
return
}
func ( string) string {
if == "" {
return "''"
}
:= true
for , := range {
if !unicode.IsPrint() {
return quoteDouble()
}
if !allowedInVariableName() {
= false
break
}
}
if {
return
}
return quoteSingle()
}
func ( string, PrimaryType) (string, PrimaryType) {
if == DoubleQuoted {
return quoteDouble(), DoubleQuoted
}
if == "" {
return "''", SingleQuoted
}
:= [0] != '~'
for , := range {
if !unicode.IsPrint() {
return quoteDouble(), DoubleQuoted
}
if !allowedInBareword(, strictExpr) {
= false
}
}
if == Bareword && {
return , Bareword
}
return quoteSingle(), SingleQuoted
}
func ( string) string {
var bytes.Buffer
.WriteByte('\'')
for , := range {
.WriteRune()
if == '\'' {
.WriteByte('\'')
}
}
.WriteByte('\'')
return .String()
}
func ( rune, int) []byte {
:= make([]byte, )
for := - 1; >= 0; -- {
:= byte( % 16)
/= 16
if <= 9 {
[] = '0' +
} else {
[] = 'a' + - 10
}
}
return
}
func ( string) string {
var bytes.Buffer
.WriteByte('"')
for , := range {
if , := doubleUnescape[]; {
.WriteByte('\\')
.WriteRune()
} else if !unicode.IsPrint() {
.WriteByte('\\')
if <= 0xff {
.WriteByte('x')
.Write(rtohex(, 2))
} else if <= 0xffff {
.WriteByte('u')
.Write(rtohex(, 4))
} else {
.WriteByte('U')
.Write(rtohex(, 8))
}
} else {
.WriteRune()
}
}
.WriteByte('"')
return .String()
}