EncodeSQLBytesInner is like EncodeSQLBytes but does not include the outer quote delimiter and the 'b' prefix.
(buf *bytes.Buffer, in string)
| 222 | // EncodeSQLBytesInner is like EncodeSQLBytes but does not include the |
| 223 | // outer quote delimiter and the 'b' prefix. |
| 224 | func 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 | } |
no test coverage detected
searching dependent graphs…