summaryrefslogtreecommitdiff
path: root/misc.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-29 02:15:13 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-29 02:15:13 -0700
commit0b57145421e7e4f165f64e73ee7c5d8102945569 (patch)
tree25584309e42bb53469959a3725393bdbc8b225c7 /misc.go
parentffee5c8516f3f55f82ed5bb8f0a4f340d485fa92 (diff)
parent7e00adcf43b18a22ffbbadc79b8681a5d871f448 (diff)
Merge branch 'lukeshu/quality'
This branch works to improve code quality, without making any substantive changes.
Diffstat (limited to 'misc.go')
-rw-r--r--misc.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/misc.go b/misc.go
index 92757f4..fb96b4e 100644
--- a/misc.go
+++ b/misc.go
@@ -44,7 +44,7 @@ func writeRune(w io.Writer, c rune) (int, error) {
// JSON string encoding ////////////////////////////////////////////////////////
-// BackSlashEscapeMode identifies one of the three ways that a
+// BackslashEscapeMode identifies one of the three ways that a
// character may be represented in a JSON string:
//
// - literally (no backslash escaping)
@@ -65,6 +65,9 @@ const (
// JSON string. The `rune` argument is the character being
// considered, and the `BackslashEscapeMode` argument is how it was
// originally encoded in the input.
+//
+// The ReEncoder will panic if a BackslashEscaper returns an unknown
+// BackslashEscapeMode.
type BackslashEscaper = func(rune, BackslashEscapeMode) BackslashEscapeMode
// EscapePreserve is a BackslashEscaper that preserves the original
@@ -119,8 +122,8 @@ func EscapeDefault(c rune, wasEscaped BackslashEscapeMode) BackslashEscapeMode {
}
}
-// EscapeDefault is a BackslashEscaper that mimics the default
-// behavior of an encoding/json.Encoder that has had
+// EscapeDefaultNonHTMLSafe is a BackslashEscaper that mimics the
+// default behavior of an encoding/json.Encoder that has had
// SetEscapeHTML(false) called on it.
//
// It is like EscapeJSSafe, but also uses long Unicode `\uXXXX`
@@ -146,6 +149,7 @@ func writeStringUnicodeEscape(w io.Writer, c rune) (int, error) {
}
return w.Write(buf[:])
}
+
func writeStringShortEscape(w io.Writer, c rune) (int, error) {
var b byte
switch c {
@@ -167,6 +171,7 @@ func writeStringShortEscape(w io.Writer, c rune) (int, error) {
buf := [2]byte{'\\', b}
return w.Write(buf[:])
}
+
func writeStringChar(w io.Writer, c rune, wasEscaped BackslashEscapeMode, escaper BackslashEscaper) (int, error) {
if escaper == nil {
escaper = EscapeDefault