2012-02-22 08:36:27 +11:00
|
|
|
package dns
|
2012-02-22 08:43:24 +11:00
|
|
|
|
2012-02-22 08:36:27 +11:00
|
|
|
// Implement a simple scanner, return a byte stream from an io reader.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"io"
|
|
|
|
"text/scanner"
|
|
|
|
)
|
|
|
|
|
|
|
|
type scan struct {
|
2012-02-22 08:43:24 +11:00
|
|
|
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)
|
2012-02-22 08:43:24 +11:00
|
|
|
s.position.Line = 1
|
2012-02-22 08:36:27 +11:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// tokenText returns the next byte from the input
|
|
|
|
func (s *scan) tokenText() (byte, error) {
|
2012-02-22 08:43:24 +11:00
|
|
|
c, err := s.src.ReadByte()
|
|
|
|
if err != nil {
|
|
|
|
return c, err
|
|
|
|
}
|
|
|
|
if c == '\n' {
|
|
|
|
s.position.Line++
|
|
|
|
s.position.Column = 0
|
|
|
|
}
|
|
|
|
s.position.Column++
|
|
|
|
return c, nil
|
2012-02-22 08:36:27 +11:00
|
|
|
}
|