dns/scanner.go

34 lines
643 B
Go
Raw Normal View History

2012-02-22 08:36:27 +11:00
package dns
// Implement a simple scanner, return a byte stream from an io reader.
import (
"bufio"
"io"
"text/scanner"
)
type scan struct {
src *bufio.Reader
position scanner.Position
2012-02-22 08:36:27 +11:00
}
func scanInit(r io.Reader) *scan {
s := new(scan)
s.src = bufio.NewReader(r)
return s
}
// tokenText returns the next byte from the input
func (s *scan) tokenText() (byte, error) {
c, err := s.src.ReadByte()
if err != nil {
return c, err
}
if c == '\n' {
s.position.Line++
s.position.Column = 0
2012-02-22 08:36:27 +11:00
}
s.position.Column++
2012-02-22 08:36:27 +11:00
return c, nil
}