go-rfc2396/escaped/bytes.go

28 lines
397 B
Go
Raw Permalink Normal View History

2023-12-08 05:34:43 +00:00
package escaped
import (
"sourcecode.social/reiver/go-rfc2396/hex"
)
func Bytes(p []byte) (result []byte, rest []byte, ok bool) {
length := len(p)
if length < 3 {
return nil, p, false
}
p0, p1, p2 := p[0], p[1], p[2]
if '%' != p0 {
return nil, p, false
}
if !hex.ByteIs(p1) {
return nil, p, false
}
if !hex.ByteIs(p2) {
return nil, p, false
}
return p[:3], p[3:], true
}