go-rfc2616/eol/bytes_tolerant.go

37 lines
481 B
Go
Raw Permalink Normal View History

2023-12-09 18:40:10 +00:00
package eol
func BytesTolerant(p []byte) (result []byte, rest []byte, ok bool) {
length := len(p)
if length <= 0 {
return nil, p, false
}
var p0 byte = p[0]
switch p0 {
case '\n':
return p[:1], p[1:], true
case '\r':
// Nothing here.
default:
return nil, p, false
}
// If we got here then p0 == '\r'
if length < 2 {
return nil, p, false
}
var p1 byte = p[1]
switch p1 {
case '\n':
return p[:2], p[2:], true
default:
return nil, p, false
}
}