From 9dcc5386e539f66543062b8285e837b7ebc89281 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sun, 13 Nov 2022 20:43:14 -0800 Subject: [PATCH] initial commits --- readrune.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 readrune.go diff --git a/readrune.go b/readrune.go new file mode 100644 index 0000000..b407305 --- /dev/null +++ b/readrune.go @@ -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 +}