aboutsummaryrefslogtreecommitdiff
path: root/src/pkg
diff options
context:
space:
mode:
authorEvan Martin <evan.martin@gmail.com>2011-07-11 07:31:08 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2011-07-11 07:31:08 -0700
commit2f69a7359159171c0fe2ddede22a1328f71bc4ef (patch)
treee0c8b22343dc159811f24690ca6aeeb3d3c98ebe /src/pkg
parentf19b24a182c445ceb3d998b2ebc20f1d8718df9b (diff)
downloadgo-2f69a7359159171c0fe2ddede22a1328f71bc4ef.tar.xz
json: encode \r and \n in strings as e.g. "\n", not "\u000A"
This is allowed by the JSON spec and is shorter/easier to read. R=golang-dev, bradfitz, rsc CC=golang-dev https://golang.org/cl/4678046
Diffstat (limited to 'src/pkg')
-rw-r--r--src/pkg/json/encode.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/pkg/json/encode.go b/src/pkg/json/encode.go
index adc0f0f371..3e4532cee4 100644
--- a/src/pkg/json/encode.go
+++ b/src/pkg/json/encode.go
@@ -344,10 +344,17 @@ func (e *encodeState) string(s string) {
if start < i {
e.WriteString(s[start:i])
}
- if b == '\\' || b == '"' {
+ switch b {
+ case '\\', '"':
e.WriteByte('\\')
e.WriteByte(b)
- } else {
+ case '\n':
+ e.WriteByte('\\')
+ e.WriteByte('n')
+ case '\r':
+ e.WriteByte('\\')
+ e.WriteByte('r')
+ default:
e.WriteString(`\u00`)
e.WriteByte(hex[b>>4])
e.WriteByte(hex[b&0xF])