mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 09:57:51 +08:00
928949077b
This fixes #985.
25 lines
358 B
Go
25 lines
358 B
Go
package buildinfo
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
)
|
|
|
|
func quoteJSON(s string) string {
|
|
var b bytes.Buffer
|
|
b.WriteRune('"')
|
|
for _, r := range s {
|
|
if r == '\\' {
|
|
b.WriteString(`\\`)
|
|
} else if r == '"' {
|
|
b.WriteString(`\"`)
|
|
} else if r < 0x20 {
|
|
fmt.Fprintf(&b, `\u%04x`, r)
|
|
} else {
|
|
b.WriteRune(r)
|
|
}
|
|
}
|
|
b.WriteRune('"')
|
|
return b.String()
|
|
}
|