WriteString writes the string into writer `str` may be wrapped in quotes and escaped according to RestoreFlags.
(str string)
| 310 | // WriteString writes the string into writer |
| 311 | // `str` may be wrapped in quotes and escaped according to RestoreFlags. |
| 312 | func (ctx *RestoreCtx) WriteString(str string) { |
| 313 | if ctx.Flags.HasStringEscapeBackslashFlag() { |
| 314 | str = strings.Replace(str, `\`, `\\`, -1) |
| 315 | } |
| 316 | quotes := "" |
| 317 | switch { |
| 318 | case ctx.Flags.HasStringSingleQuotesFlag(): |
| 319 | str = strings.Replace(str, `'`, `''`, -1) |
| 320 | quotes = `'` |
| 321 | case ctx.Flags.HasStringDoubleQuotesFlag(): |
| 322 | str = strings.Replace(str, `"`, `""`, -1) |
| 323 | quotes = `"` |
| 324 | } |
| 325 | fmt.Fprint(ctx.In, quotes, str, quotes) |
| 326 | } |
| 327 | |
| 328 | // WriteName writes the name into writer |
| 329 | // `name` maybe wrapped in quotes and escaped according to RestoreFlags. |