(dst []byte, str string)
| 146 | } |
| 147 | |
| 148 | func 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 | |
| 172 | func QuoteBytes(dst, buf []byte) []byte { |
| 173 | if len(buf) == 0 { |
no outgoing calls