Skip to main content

Module go

Module go 

Source
Expand description

go literal encoders.

encodes untrusted strings for safe embedding in go source literals.

§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 \xHH per byte (byte string)

the encoders differ in which quote is escaped and how non-ASCII is handled:

encoderquote escapenon-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 input for safe embedding in a go string literal used in a byte-explicit context ([]byte("...")).
for_go_char
encodes input for safe embedding in a go rune literal ('...').
for_go_string
encodes input for safe embedding in a go interpreted string literal ("...").
write_go_byte_string
writes the go-byte-string-encoded form of input to out.
write_go_char
writes the go-char-encoded form of input to out.
write_go_string
writes the go-string-encoded form of input to out.