1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00
birdwatcher/bird/line_iterator.go

34 lines
563 B
Go
Raw Permalink Normal View History

package bird
import (
"bufio"
"io"
)
type lineIterator struct {
scanner *bufio.Scanner
skipEmptyLines bool
}
func newLineIterator(reader io.Reader, skipEmptyLines bool) *lineIterator {
scanner := bufio.NewScanner(reader)
return &lineIterator{scanner: scanner, skipEmptyLines: skipEmptyLines}
}
func (l *lineIterator) next() bool {
res := l.scanner.Scan()
if !res || !l.skipEmptyLines {
return res
}
if emptyString(l.scanner.Text()) {
return l.next()
}
return res
}
func (l *lineIterator) string() string {
return l.scanner.Text()
}