aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2015-12-08 14:09:59 -0500
committerRuss Cox <rsc@golang.org>2015-12-08 19:26:26 +0000
commit1be2ddda9a372de052ba3428128085152b2e9044 (patch)
treed48f45f1ac5f8240f665cfcb13a3fc36c0c89601 /src/encoding
parentf740d717bd31e1a4b8281072b5cb3dfeb26f3273 (diff)
downloadgo-1be2ddda9a372de052ba3428128085152b2e9044.tar.xz
encoding/json: document Indent's preservation of trailing spaces
Fixes #13520. Change-Id: Ia70cc44be3912167b369d7f74d3436331975c300 Reviewed-on: https://go-review.googlesource.com/17561 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/json/indent.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/encoding/json/indent.go b/src/encoding/json/indent.go
index 153109fae6..7cd9f4db18 100644
--- a/src/encoding/json/indent.go
+++ b/src/encoding/json/indent.go
@@ -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