MCPcopy
hub / github.com/jackc/pgx / QuoteBytes

Function QuoteBytes

internal/sanitize/sanitize.go:172–203  ·  view source on GitHub ↗
(dst, buf []byte)

Source from the content-addressed store, hash-verified

170}
171
172func QuoteBytes(dst, buf []byte) []byte {
173 if len(buf) == 0 {
174 return append(dst, `'\x'`...)
175 }
176
177 // Calculate required length
178 requiredLen := 3 + hex.EncodedLen(len(buf)) + 1
179
180 // Ensure dst has enough capacity
181 if cap(dst)-len(dst) < requiredLen {
182 newDst := make([]byte, len(dst), len(dst)+requiredLen)
183 copy(newDst, dst)
184 dst = newDst
185 }
186
187 // Record original length and extend slice
188 origLen := len(dst)
189 dst = dst[:origLen+requiredLen]
190
191 // Add prefix
192 dst[origLen] = '\''
193 dst[origLen+1] = '\\'
194 dst[origLen+2] = 'x'
195
196 // Encode bytes directly into dst
197 hex.Encode(dst[origLen+3:len(dst)-1], buf)
198
199 // Add suffix
200 dst[len(dst)-1] = '\''
201
202 return dst
203}
204
205type sqlLexer struct {
206 src string

Callers 3

TestQuoteBytesFunction · 0.92
FuzzQuoteBytesFunction · 0.92
SanitizeMethod · 0.85

Calls 1

EncodeMethod · 0.65

Tested by 2

TestQuoteBytesFunction · 0.74
FuzzQuoteBytesFunction · 0.74