escapedString converts a string into an escaped string for exports.
(str string)
| 116 | |
| 117 | // escapedString converts a string into an escaped string for exports. |
| 118 | func escapedString(str string) string { |
| 119 | // We use the Marshal function in the JSON package for all export formats |
| 120 | // because it properly escapes strings. |
| 121 | byt, err := json.Marshal(str) |
| 122 | if err != nil { |
| 123 | // All valid stings should be able to be escaped to a JSON string so |
| 124 | // it's safe to panic here. Marshal has to return an error because it |
| 125 | // accepts an interface. |
| 126 | x.Panic(errors.New("Could not marshal string to JSON string")) |
| 127 | } |
| 128 | return string(byt) |
| 129 | } |
| 130 | |
| 131 | func (e *exporter) toJSON() (*bpb.KVList, error) { |
| 132 | bp := new(bytes.Buffer) |