escapeBytesQuotes appends _binary'...' or '...' with single-quote escaping for bytes.
(buf, v []byte, binary bool)
| 689 | |
| 690 | // escapeBytesQuotes appends _binary'...' or '...' with single-quote escaping for bytes. |
| 691 | func escapeBytesQuotes(buf, v []byte, binary bool) []byte { |
| 692 | pos := len(buf) |
| 693 | if binary { |
| 694 | buf = reserveBuffer(buf, len(v)*2+9) |
| 695 | copy(buf[pos:], []byte("_binary'")) |
| 696 | pos += 8 |
| 697 | } else { |
| 698 | buf = reserveBuffer(buf, len(v)*2+2) |
| 699 | buf[pos] = '\'' |
| 700 | pos++ |
| 701 | } |
| 702 | for _, c := range v { |
| 703 | if c == '\'' { |
| 704 | buf[pos+1] = '\'' |
| 705 | buf[pos] = '\'' |
| 706 | pos += 2 |
| 707 | } else { |
| 708 | buf[pos] = c |
| 709 | pos++ |
| 710 | } |
| 711 | } |
| 712 | buf[pos] = '\'' |
| 713 | pos++ |
| 714 | return buf[:pos] |
| 715 | } |
| 716 | |
| 717 | // escapeStringQuotes is similar to escapeBytesQuotes but for string. |
| 718 | func escapeStringQuotes(buf []byte, v string) []byte { |