Added simple scanner impl.

This commit is contained in:
Miek Gieben 2012-02-21 22:36:27 +01:00
parent 3b4840e847
commit f8fb563af9
1 changed files with 33 additions and 0 deletions

33
scanner.go Normal file
View File

@ -0,0 +1,33 @@
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
scanner.Position
}
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.Postion.Line++
s.Postion.Column = 0
}
s.Position.Column++
return c, nil
}