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

Function QuoteString

internal/sanitize/sanitize.go:148–170  ·  view source on GitHub ↗
(dst []byte, str string)

Source from the content-addressed store, hash-verified

146}
147
148func QuoteString(dst []byte, str string) []byte {
149 const quote = '\''
150
151 // Preallocate space for the worst case scenario
152 dst = slices.Grow(dst, len(str)*2+2)
153
154 // Add opening quote
155 dst = append(dst, quote)
156
157 // Iterate through the string without allocating
158 for i := 0; i < len(str); i++ {
159 if str[i] == quote {
160 dst = append(dst, quote, quote)
161 } else {
162 dst = append(dst, str[i])
163 }
164 }
165
166 // Add closing quote
167 dst = append(dst, quote)
168
169 return dst
170}
171
172func QuoteBytes(dst, buf []byte) []byte {
173 if len(buf) == 0 {

Callers 3

TestQuoteStringFunction · 0.92
FuzzQuoteStringFunction · 0.92
SanitizeMethod · 0.85

Calls

no outgoing calls

Tested by 2

TestQuoteStringFunction · 0.74
FuzzQuoteStringFunction · 0.74