MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / EncodeSQLBytesInner

Function EncodeSQLBytesInner

pkg/sql/lexbase/encode.go:224–251  ·  view source on GitHub ↗

EncodeSQLBytesInner is like EncodeSQLBytes but does not include the outer quote delimiter and the 'b' prefix.

(buf *bytes.Buffer, in string)

Source from the content-addressed store, hash-verified

222// EncodeSQLBytesInner is like EncodeSQLBytes but does not include the
223// outer quote delimiter and the 'b' prefix.
224func EncodeSQLBytesInner(buf *bytes.Buffer, in string) {
225 start := 0
226 // Loop over the bytes of the string (i.e., don't use range over unicode
227 // code points).
228 for i, n := 0, len(in); i < n; i++ {
229 ch := in[i]
230 if encodedChar := stringencoding.EncodeMap[ch]; encodedChar != stringencoding.DontEscape {
231 buf.WriteString(in[start:i])
232 buf.WriteByte('\\')
233 buf.WriteByte(encodedChar)
234 start = i + 1
235 } else if ch == '\'' {
236 // We can't just fold this into stringencoding.EncodeMap because
237 // stringencoding.EncodeMap is also used for strings which
238 // aren't quoted with single-quotes
239 buf.WriteString(in[start:i])
240 buf.WriteByte('\\')
241 buf.WriteByte(ch)
242 start = i + 1
243 } else if ch < 0x20 || ch >= 0x7F {
244 buf.WriteString(in[start:i])
245 // Escape non-printable characters.
246 buf.Write(stringencoding.HexMap[ch])
247 start = i + 1
248 }
249 }
250 buf.WriteString(in[start:])
251}

Callers 1

EncodeSQLBytesFunction · 0.85

Calls 1

WriteMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…