mirror of https://github.com/tidwall/tile38.git
18 lines
323 B
Go
18 lines
323 B
Go
package controller
|
|
|
|
import "encoding/json"
|
|
|
|
func jsonString(s string) string {
|
|
for i := 0; i < len(s); i++ {
|
|
if s[i] < ' ' || s[i] == '\\' || s[i] == '"' || s[i] > 126 {
|
|
d, _ := json.Marshal(s)
|
|
return string(d)
|
|
}
|
|
}
|
|
b := make([]byte, len(s)+2)
|
|
b[0] = '"'
|
|
copy(b[1:], s)
|
|
b[len(b)-1] = '"'
|
|
return string(b)
|
|
}
|