go-eol/readthisrune.go

37 lines
654 B
Go
Raw Normal View History

2023-11-27 19:32:08 +00:00
package eol
import (
"io"
)
2023-11-28 14:26:36 +00:00
func readthisrune(runescanner io.RuneScanner, expected rune, characterNumber uint64) (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 14:26:36 +00:00
return size, errProblemReadingRune(err, characterNumber)
2023-11-27 19:32:08 +00:00
}
}
{
actual := r
if expected != actual {
err := runescanner.UnreadRune()
if nil != err {
2023-11-28 14:26:36 +00:00
return size, errProblemUnreadingRune(err, characterNumber, r)
2023-11-27 19:32:08 +00:00
}
2023-11-28 14:26:36 +00:00
return 0, internalNotFoundError{expected: expected, actual: r, characterNumber:characterNumber}
2023-11-27 19:32:08 +00:00
}
}
return size, nil
}