mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 16:39:57 +00:00
TUN-528: Move cloudflared into a separate repo
This commit is contained in:
52
vendor/zombiezen.com/go/capnproto2/internal/strquote/strquote.go
generated
vendored
Normal file
52
vendor/zombiezen.com/go/capnproto2/internal/strquote/strquote.go
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
// Package strquote provides a function for formatting a string as a
|
||||
// Cap'n Proto string literal.
|
||||
package strquote
|
||||
|
||||
// Append appends a Cap'n Proto string literal of s to buf.
|
||||
func Append(buf []byte, s []byte) []byte {
|
||||
buf = append(buf, '"')
|
||||
last := 0
|
||||
for i, b := range s {
|
||||
if !needsEscape(b) {
|
||||
continue
|
||||
}
|
||||
buf = append(buf, s[last:i]...)
|
||||
switch b {
|
||||
case '\a':
|
||||
buf = append(buf, '\\', 'a')
|
||||
case '\b':
|
||||
buf = append(buf, '\\', 'b')
|
||||
case '\f':
|
||||
buf = append(buf, '\\', 'f')
|
||||
case '\n':
|
||||
buf = append(buf, '\\', 'n')
|
||||
case '\r':
|
||||
buf = append(buf, '\\', 'r')
|
||||
case '\t':
|
||||
buf = append(buf, '\\', 't')
|
||||
case '\v':
|
||||
buf = append(buf, '\\', 'v')
|
||||
case '\'':
|
||||
buf = append(buf, '\\', '\'')
|
||||
case '"':
|
||||
buf = append(buf, '\\', '"')
|
||||
case '\\':
|
||||
buf = append(buf, '\\', '\\')
|
||||
default:
|
||||
buf = append(buf, '\\', 'x', hexDigit(b/16), hexDigit(b%16))
|
||||
}
|
||||
last = i + 1
|
||||
}
|
||||
buf = append(buf, s[last:]...)
|
||||
buf = append(buf, '"')
|
||||
return buf
|
||||
}
|
||||
|
||||
func needsEscape(b byte) bool {
|
||||
return b < 0x20 || b >= 0x7f
|
||||
}
|
||||
|
||||
func hexDigit(b byte) byte {
|
||||
const digits = "0123456789abcdef"
|
||||
return digits[b]
|
||||
}
|
Reference in New Issue
Block a user