MCPcopy
hub / github.com/go-sql-driver/mysql / escapeBytesBackslash

Function escapeBytesBackslash

utils.go:664–688  ·  view source on GitHub ↗

escapeBytesBackslash appends _binary'...' or '...' with backslash escaping for bytes.

(buf, v []byte, binary bool)

Source from the content-addressed store, hash-verified

662
663// escapeBytesBackslash appends _binary'...' or '...' with backslash escaping for bytes.
664func escapeBytesBackslash(buf, v []byte, binary bool) []byte {
665 pos := len(buf)
666 if binary {
667 buf = reserveBuffer(buf, len(v)*2+9)
668 copy(buf[pos:], []byte("_binary'"))
669 pos += 8
670 } else {
671 buf = reserveBuffer(buf, len(v)*2+2)
672 buf[pos] = '\''
673 pos++
674 }
675 for _, c := range v {
676 if esc := backslashEscapeTable[c]; esc != 0 {
677 buf[pos+1] = esc
678 buf[pos] = '\\'
679 pos += 2
680 } else {
681 buf[pos] = c
682 pos++
683 }
684 }
685 buf[pos] = '\''
686 pos++
687 return buf[:pos]
688}
689
690// escapeBytesQuotes appends _binary'...' or '...' with single-quote escaping for bytes.
691func escapeBytesQuotes(buf, v []byte, binary bool) []byte {

Callers 2

TestEscapeBackslashFunction · 0.85
interpolateParamsMethod · 0.85

Calls 1

reserveBufferFunction · 0.85

Tested by 1

TestEscapeBackslashFunction · 0.68