Expand description
go literal encoders.
encodes untrusted strings for safe embedding in go source literals.
for_go_string— safe for go interpreted string literals ("...")for_go_char— safe for go rune literals ('...')for_go_byte_string— safe for go byte-explicit string literals ([]byte("..."))
§encoding rules
all three encoders use go’s native escape syntax:
- named escapes:
\a,\b,\t,\n,\v,\f,\r,\\ - other C0 controls and DEL →
\xHH - unicode non-characters → space (string/char) or
\xHHper byte (byte string)
the encoders differ in which quote is escaped and how non-ASCII is handled:
| encoder | quote escape | non-ASCII |
|---|---|---|
for_go_string | " → \" | passes through |
for_go_char | ' → \' | passes through |
for_go_byte_string | " → \" | each UTF-8 byte → \xHH |
Functions§
- for_
go_ byte_ string - encodes
inputfor safe embedding in a go string literal used in a byte-explicit context ([]byte("...")). - for_
go_ char - encodes
inputfor safe embedding in a go rune literal ('...'). - for_
go_ string - encodes
inputfor safe embedding in a go interpreted string literal ("..."). - write_
go_ byte_ string - writes the go-byte-string-encoded form of
inputtoout. - write_
go_ char - writes the go-char-encoded form of
inputtoout. - write_
go_ string - writes the go-string-encoded form of
inputtoout.