go-eol/readthisrune.go

37 lines
617 B
Go
Raw Normal View History

2023-11-27 19:32:08 +00:00
package eol
import (
"io"
)
2023-11-28 16:05:15 +00:00
func readthisrune(circumstance internalCircumstance, runescanner io.RuneScanner, expected rune) (size int, err error) {
2023-11-27 19:32:08 +00:00
if nil == runescanner {
return 0, errNilRuneScanner
}
var r rune
{
var err error
r, size, err = runescanner.ReadRune()
if nil != err {
2023-11-28 16:05:15 +00:00
return size, errProblemReadingRune(circumstance, err)
2023-11-27 19:32:08 +00:00
}
}
{
actual := r
if expected != actual {
err := runescanner.UnreadRune()
if nil != err {
2023-11-28 16:05:15 +00:00
return size, errProblemUnreadingRune(circumstance, err, r)
2023-11-27 19:32:08 +00:00
}
2023-11-28 16:05:15 +00:00
return 0, errNotFound(circumstance, expected, actual)
2023-11-27 19:32:08 +00:00
}
}
return size, nil
}