1
0
mirror of https://github.com/golang/go synced 2024-11-23 21:10:05 -07:00

fmt: fix bug in UnreadRune: must clear memory of previous

rune if input implements UnreadRune; otherwise the lookahead
will lie.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4548082
This commit is contained in:
Rob Pike 2011-06-03 07:53:50 +10:00
parent 4e9e925002
commit ce5c1cf036

View File

@ -226,20 +226,12 @@ func (s *ss) mustReadRune() (rune int) {
}
func (s *ss) UnreadRune() os.Error {
// Don't use strings.Reader.UnreadRune for now - appears to cause a problem.
// TODO(r, gri): Fix this and remove code between --- lines!
// ---
if _, ok := s.rr.(*strings.Reader); ok {
s.peekRune = s.prevRune
s.count--
return nil
}
// ---
if u, ok := s.rr.(runeUnreader); ok {
u.UnreadRune()
} else {
s.peekRune = s.prevRune
}
s.prevRune = -1
s.count--
return nil
}