]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgo/go/encoding/json/indent.go
libgo: update to Go1.14beta1
[thirdparty/gcc.git] / libgo / go / encoding / json / indent.go
index fba19548c92721d2f2fb0c63dd3accaa8a3077d3..2924d3b49b944169569531c7702ccc96d028454a 100644 (file)
@@ -4,7 +4,9 @@
 
 package json
 
-import "bytes"
+import (
+       "bytes"
+)
 
 // Compact appends to dst the JSON-encoded src with
 // insignificant space characters elided.
@@ -14,8 +16,8 @@ func Compact(dst *bytes.Buffer, src []byte) error {
 
 func compact(dst *bytes.Buffer, src []byte, escape bool) error {
        origLen := dst.Len()
-       var scan scanner
-       scan.reset()
+       scan := newScanner()
+       defer freeScanner(scan)
        start := 0
        for i, c := range src {
                if escape && (c == '<' || c == '>' || c == '&') {
@@ -28,7 +30,7 @@ func compact(dst *bytes.Buffer, src []byte, escape bool) error {
                        start = i + 1
                }
                // Convert U+2028 and U+2029 (E2 80 A8 and E2 80 A9).
-               if c == 0xE2 && i+2 < len(src) && src[i+1] == 0x80 && src[i+2]&^1 == 0xA8 {
+               if escape && c == 0xE2 && i+2 < len(src) && src[i+1] == 0x80 && src[i+2]&^1 == 0xA8 {
                        if start < i {
                                dst.Write(src[start:i])
                        }
@@ -36,7 +38,7 @@ func compact(dst *bytes.Buffer, src []byte, escape bool) error {
                        dst.WriteByte(hex[src[i+2]&0xF])
                        start = i + 3
                }
-               v := scan.step(&scan, c)
+               v := scan.step(scan, c)
                if v >= scanSkipSpace {
                        if v == scanError {
                                break
@@ -78,13 +80,13 @@ func newline(dst *bytes.Buffer, prefix, indent string, depth int) {
 // if src ends in a trailing newline, so will dst.
 func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
        origLen := dst.Len()
-       var scan scanner
-       scan.reset()
+       scan := newScanner()
+       defer freeScanner(scan)
        needIndent := false
        depth := 0
        for _, c := range src {
                scan.bytes++
-               v := scan.step(&scan, c)
+               v := scan.step(scan, c)
                if v == scanSkipSpace {
                        continue
                }