MCPcopy
hub / github.com/gofiber/fiber / quoteRawString

Method quoteRawString

helpers.go:180–209  ·  view source on GitHub ↗

quoteRawString escapes only characters that need quoting according to https://www.rfc-editor.org/rfc/rfc9110#section-5.6.4 so the result may contain non-ASCII bytes.

(raw string)

Source from the content-addressed store, hash-verified

178// https://www.rfc-editor.org/rfc/rfc9110#section-5.6.4 so the result may
179// contain non-ASCII bytes.
180func (*App) quoteRawString(raw string) string {
181 const hex = "0123456789ABCDEF"
182 bb := bytebufferpool.Get()
183 defer bytebufferpool.Put(bb)
184
185 for i := 0; i < len(raw); i++ {
186 c := raw[i]
187 switch {
188 case c == '\\' || c == '"':
189 // escape backslash and quote
190 bb.B = append(bb.B, '\\', c)
191 case c == '\n':
192 bb.B = append(bb.B, '\\', 'n')
193 case c == '\r':
194 bb.B = append(bb.B, '\\', 'r')
195 case c < 0x20 || c == 0x7f:
196 // percent-encode control and DEL
197 bb.B = append(
198 bb.B,
199 '%',
200 hex[c>>4],
201 hex[c&0x0f],
202 )
203 default:
204 bb.B = append(bb.B, c)
205 }
206 }
207
208 return string(bb.B)
209}
210
211// isASCII reports whether the provided string contains only ASCII characters.
212// See: https://www.rfc-editor.org/rfc/rfc0020

Callers 4

Test_App_quoteRawStringFunction · 0.80
AttachmentMethod · 0.80
DownloadMethod · 0.80

Calls 2

GetMethod · 0.65
PutMethod · 0.65