2022-07-18 23:36:02 +00:00
|
|
|
package utf8
|
2018-07-11 03:40:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2023-08-18 13:37:04 +00:00
|
|
|
var _ io.RuneReader = WrapRuneReader(nil)
|
|
|
|
var _ io.RuneReader = NewRuneReader(nil)
|
|
|
|
|
2022-07-18 23:36:02 +00:00
|
|
|
// A utf8.RuneReader implements the io.RuneReader interface by reading from an io.Reader.
|
2018-07-11 03:40:40 +00:00
|
|
|
type RuneReader struct {
|
|
|
|
reader io.Reader
|
|
|
|
}
|
|
|
|
|
2023-08-18 13:37:04 +00:00
|
|
|
func WrapRuneReader(reader io.Reader) RuneReader {
|
2022-07-19 04:04:30 +00:00
|
|
|
return RuneReader{
|
2018-07-11 03:40:40 +00:00
|
|
|
reader: reader,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-18 13:37:04 +00:00
|
|
|
func NewRuneReader(reader io.Reader) *RuneReader {
|
|
|
|
var runereader RuneReader = WrapRuneReader(reader)
|
|
|
|
|
|
|
|
return &runereader
|
|
|
|
}
|
2018-07-11 03:56:30 +00:00
|
|
|
|
2023-08-18 13:37:04 +00:00
|
|
|
func (receiver RuneReader) ReadRune() (rune, int, error) {
|
2018-07-11 03:40:40 +00:00
|
|
|
reader := receiver.reader
|
|
|
|
if nil == reader {
|
|
|
|
return 0, 0, errNilReader
|
|
|
|
}
|
|
|
|
|
|
|
|
return ReadRune(reader)
|
|
|
|
}
|