summaryrefslogtreecommitdiff
path: root/libgo/go/encoding/json/indent.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/encoding/json/indent.go')
-rw-r--r--libgo/go/encoding/json/indent.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/libgo/go/encoding/json/indent.go b/libgo/go/encoding/json/indent.go
index 5ba19b07ac6..e8dfa4ec436 100644
--- a/libgo/go/encoding/json/indent.go
+++ b/libgo/go/encoding/json/indent.go
@@ -9,11 +9,24 @@ import "bytes"
// Compact appends to dst the JSON-encoded src with
// insignificant space characters elided.
func Compact(dst *bytes.Buffer, src []byte) error {
+ return compact(dst, src, false)
+}
+
+func compact(dst *bytes.Buffer, src []byte, escape bool) error {
origLen := dst.Len()
var scan scanner
scan.reset()
start := 0
for i, c := range src {
+ if escape && (c == '<' || c == '>' || c == '&') {
+ if start < i {
+ dst.Write(src[start:i])
+ }
+ dst.WriteString(`\u00`)
+ dst.WriteByte(hex[c>>4])
+ dst.WriteByte(hex[c&0xF])
+ start = i + 1
+ }
v := scan.step(&scan, int(c))
if v >= scanSkipSpace {
if v == scanError {