-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.go
37 lines (34 loc) · 909 Bytes
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package mpq
import "bytes"
type List interface {
// Each time Next() returns true
Next() bool
// Path() will return a unique path
Path() string
// Close your list when you are done
Close() error
}
// CRLF-friendly alternative to the default Scan function
// (listfile) uses CRLF which sucks
func scan_lines(data []byte, atEOF bool) (advance int, token []byte, err error) {
if atEOF && len(data) == 0 {
return 0, nil, nil
}
if i := bytes.IndexAny(data, "\r\n"); i >= 0 {
if data[i] == '\n' {
// We have a line terminated by single newline.
return i + 1, data[0:i], nil
}
advance = i + 1
if len(data) > i+1 && data[i+1] == '\n' {
advance += 1
}
return advance, data[0:i], 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
}