EncodeEscapedSQLIdent writes the identifier in s to buf. The identifier is always quoted. Double quotes inside the identifier are escaped.
(buf *bytes.Buffer, s string)
| 99 | // identifier is always quoted. Double quotes inside the identifier |
| 100 | // are escaped. |
| 101 | func EncodeEscapedSQLIdent(buf *bytes.Buffer, s string) { |
| 102 | buf.WriteByte('"') |
| 103 | start := 0 |
| 104 | for i, n := 0, len(s); i < n; i++ { |
| 105 | ch := s[i] |
| 106 | // The only character that requires escaping is a double quote. |
| 107 | if ch == '"' { |
| 108 | if start != i { |
| 109 | buf.WriteString(s[start:i]) |
| 110 | } |
| 111 | start = i + 1 |
| 112 | buf.WriteByte(ch) |
| 113 | buf.WriteByte(ch) // add extra copy of ch |
| 114 | } |
| 115 | } |
| 116 | if start < len(s) { |
| 117 | buf.WriteString(s[start:]) |
| 118 | } |
| 119 | buf.WriteByte('"') |
| 120 | } |
| 121 | |
| 122 | const ( |
| 123 | minPrintableChar = 0x20 // ' ' |
no outgoing calls
no test coverage detected
searching dependent graphs…