diff options
Diffstat (limited to 'libgo/go/encoding/json/indent.go')
-rw-r--r-- | libgo/go/encoding/json/indent.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libgo/go/encoding/json/indent.go b/libgo/go/encoding/json/indent.go index e1bacafd6b8..7cd9f4db184 100644 --- a/libgo/go/encoding/json/indent.go +++ b/libgo/go/encoding/json/indent.go @@ -36,7 +36,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, int(c)) + v := scan.step(&scan, c) if v >= scanSkipSpace { if v == scanError { break @@ -70,8 +70,12 @@ func newline(dst *bytes.Buffer, prefix, indent string, depth int) { // indented line beginning with prefix followed by one or more // copies of indent according to the indentation nesting. // The data appended to dst does not begin with the prefix nor -// any indentation, and has no trailing newline, to make it -// easier to embed inside other formatted JSON data. +// any indentation, to make it easier to embed inside other formatted JSON data. +// Although leading space characters (space, tab, carriage return, newline) +// at the beginning of src are dropped, trailing space characters +// at the end of src are preserved and copied to dst. +// For example, if src has no trailing spaces, neither will dst; +// 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 @@ -80,7 +84,7 @@ func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error { depth := 0 for _, c := range src { scan.bytes++ - v := scan.step(&scan, int(c)) + v := scan.step(&scan, c) if v == scanSkipSpace { continue } |