mirror of https://github.com/golang/go.git
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
This commit is contained in:
parent
f19b24a182
commit
2f69a73591
|
|
@ -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])
|
||||
|
|
|
|||
Loading…
Reference in New Issue