(txt string)
| 397 | } |
| 398 | |
| 399 | func escapeString(txt string) string { |
| 400 | var ( |
| 401 | esc string |
| 402 | buf bytes.Buffer |
| 403 | ) |
| 404 | last := 0 |
| 405 | for ii, bb := range txt { |
| 406 | switch bb { |
| 407 | case 0: |
| 408 | esc = `\0` |
| 409 | case '\n': |
| 410 | esc = `\n` |
| 411 | case '\r': |
| 412 | esc = `\r` |
| 413 | case '\\': |
| 414 | esc = `\\` |
| 415 | case '\'': |
| 416 | esc = `\'` |
| 417 | case '"': |
| 418 | esc = `\"` |
| 419 | case '\032': |
| 420 | esc = `\Z` |
| 421 | default: |
| 422 | continue |
| 423 | } |
| 424 | io.WriteString(&buf, txt[last:ii]) |
| 425 | io.WriteString(&buf, esc) |
| 426 | last = ii + 1 |
| 427 | } |
| 428 | io.WriteString(&buf, txt[last:]) |
| 429 | return buf.String() |
| 430 | } |
| 431 | |
| 432 | func escapeQuotes(txt string) string { |
| 433 | var buf bytes.Buffer |
no test coverage detected