mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
8307d14075
Signed-off-by: zu1k <i@zu1k.com>
27 lines
552 B
Go
27 lines
552 B
Go
package common
|
|
|
|
import (
|
|
"bytes"
|
|
)
|
|
|
|
// ScanLines scan lines but keep the suffix \r and \n
|
|
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
|
if atEOF && len(data) == 0 {
|
|
return 0, nil, nil
|
|
}
|
|
|
|
if i := bytes.IndexByte(data, '\n'); i >= 0 {
|
|
return i + 1, data[:i+1], nil
|
|
}
|
|
if i := bytes.IndexByte(data, '\r'); i >= 0 {
|
|
return i + 1, data[:i+1], nil
|
|
}
|
|
|
|
// If we're at EOF, we have a final, non-terminated line. Return it.
|
|
if atEOF {
|
|
return len(data), data, nil
|
|
}
|
|
// Request more data.
|
|
return 0, nil, nil
|
|
}
|