initial commits

master
Charles Iliya Krempeaux 2022-11-13 20:43:14 -08:00
parent 1b41d2f679
commit 9dcc5386e5
1 changed files with 33 additions and 0 deletions

33
readrune.go 100644
View File

@ -0,0 +1,33 @@
package netln
import (
"github.com/reiver/go-utf8"
"errors"
"fmt"
"io"
)
// readRune deals with reading a single rune.
//
// It also makes sure that any error condition is represented as a Go error,
// rather than a utf8.RuneError.
//
// It also wraps any errors, and provides a more appropriate error message.
func readRune(reader io.Reader) (r rune, size int, err error) {
r, size, err = utf8.ReadRune(reader)
if nil != err && !errors.Is(err, io.EOF) {
err = fmt.Errorf("problem reading UTF-8 character: %w", err)
/////////////// RETURN
return
}
if utf8.RuneError == r {
err = fmt.Errorf("problem reading UTF-8 character: %w", errRuneError)
/////////////// RETURN
return
}
/////// RETURN
return
}