go-rfc2616/method/bytes_tolerant.go

31 lines
441 B
Go
Raw Normal View History

2023-12-08 19:42:28 +00:00
package method
2023-12-08 21:03:12 +00:00
import (
"sourcecode.social/reiver/go-rfc2616/sp"
)
2023-12-08 19:42:28 +00:00
func BytesTolerant(p []byte) (result []byte, rest []byte, ok bool) {
if len(p) <= 0 {
return nil, nil, false
}
{
p0 := p[0]
2023-12-08 21:03:12 +00:00
if sp.ByteIsTolerant(p0) || '\r' == p0 || '\n' == p0 {
2023-12-08 19:42:28 +00:00
return nil, p, false
}
}
{
for i,b := range p {
2023-12-09 11:26:10 +00:00
if sp.ByteIsTolerant(b) || '\r' == b || '\n' == b {
2023-12-08 19:42:28 +00:00
return p[:i], p[i:], true
}
}
return p, nil, true
}
}