| 170 | } |
| 171 | |
| 172 | func 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 | |
| 205 | type sqlLexer struct { |
| 206 | src string |