diff options
Diffstat (limited to 'encode_string.go')
-rw-r--r-- | encode_string.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/encode_string.go b/encode_string.go index c5cb442..831a038 100644 --- a/encode_string.go +++ b/encode_string.go @@ -45,7 +45,7 @@ func writeStringShortEscape(w io.Writer, c rune) (int, error) { return w.Write(buf[:]) } -func writeStringChar(w io.Writer, c rune, wasEscaped BackslashEscapeMode, escaper BackslashEscaper) (int, error) { +func writeStringChar(w internal.AllWriter, c rune, wasEscaped BackslashEscapeMode, escaper BackslashEscaper) (int, error) { if escaper == nil { escaper = EscapeDefault } @@ -62,19 +62,19 @@ func writeStringChar(w io.Writer, c rune, wasEscaped BackslashEscapeMode, escape case c == '"' || c == '\\': // override, gotta escape these return writeStringShortEscape(w, c) default: // obey - return writeRune(w, c) + return w.WriteRune(c) } case BackslashEscapeShort: switch c { case '"', '\\', '/', '\b', '\f', '\n', '\r', '\t': // obey return writeStringShortEscape(w, c) default: // override, can't short-escape these - return writeRune(w, c) + return w.WriteRune(c) } case BackslashEscapeUnicode: switch { case c > 0xFFFF: // override, can't escape these (TODO: unless we use UTF-16 surrogates?) - return writeRune(w, c) + return w.WriteRune(c) default: // obey return writeStringUnicodeEscape(w, c) } @@ -83,7 +83,7 @@ func writeStringChar(w io.Writer, c rune, wasEscaped BackslashEscapeMode, escape } } -func encodeStringFromString(w io.Writer, escaper BackslashEscaper, str string) { +func encodeStringFromString(w internal.AllWriter, escaper BackslashEscaper, str string) { encodeWriteByte(w, '"') for _, c := range str { if _, err := writeStringChar(w, c, BackslashEscapeNone, escaper); err != nil { @@ -93,7 +93,7 @@ func encodeStringFromString(w io.Writer, escaper BackslashEscaper, str string) { encodeWriteByte(w, '"') } -func encodeStringFromBytes(w io.Writer, escaper BackslashEscaper, str []byte) { +func encodeStringFromBytes(w internal.AllWriter, escaper BackslashEscaper, str []byte) { encodeWriteByte(w, '"') for i := 0; i < len(str); { c, size := utf8.DecodeRune(str[i:]) @@ -106,6 +106,6 @@ func encodeStringFromBytes(w io.Writer, escaper BackslashEscaper, str []byte) { } func init() { - internal.EncodeStringFromString = func(w io.Writer, s string) { encodeStringFromString(w, nil, s) } - internal.EncodeStringFromBytes = func(w io.Writer, s []byte) { encodeStringFromBytes(w, nil, s) } + internal.EncodeStringFromString = func(w io.Writer, s string) { encodeStringFromString(internal.NewAllWriter(w), nil, s) } + internal.EncodeStringFromBytes = func(w io.Writer, s []byte) { encodeStringFromBytes(internal.NewAllWriter(w), nil, s) } } |