<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/lex.go
blob: 74bf370e0974ccaf2c0b459de6455c0163bc7e30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package subex

import (
	"unicode/utf8"
)

const eof rune = -1
type StringRuneReader struct {
	input string
	pos, width int
}
func (l *StringRuneReader) Next() rune {
	if l.pos >= len(l.input) {
		l.width = 0
		return eof
	}
	var r rune
	r, l.width = utf8.DecodeRuneInString(l.input[l.pos:])
	l.pos += l.width
	return r
}
func (l *StringRuneReader) Rewind() {
	l.pos -= l.width
}