added another error check.
parent
fc2455f7ec
commit
50a81feeba
|
@ -8,4 +8,5 @@ var (
|
||||||
errInternalError = errors.New("Internal Error")
|
errInternalError = errors.New("Internal Error")
|
||||||
errInvalidUTF8 = internalInvalidUTF8Complainer{}
|
errInvalidUTF8 = internalInvalidUTF8Complainer{}
|
||||||
errNilReader = internalNilReaderComplainer{}
|
errNilReader = internalNilReaderComplainer{}
|
||||||
|
errNilWriter = internalNilWriterComplainer{}
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package utf8s
|
||||||
|
|
||||||
|
type NilWriterComplainer interface {
|
||||||
|
error
|
||||||
|
NilWriterComplainer()
|
||||||
|
}
|
||||||
|
|
||||||
|
type internalNilWriterComplainer struct{}
|
||||||
|
|
||||||
|
func (complainer internalNilWriterComplainer) Error() string {
|
||||||
|
return "Nil Writer"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (complainer internalNilWriterComplainer) NilWriterComplainer() {
|
||||||
|
// Nothing here.
|
||||||
|
}
|
14
writerune.go
14
writerune.go
|
@ -5,8 +5,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// WriteRune writes a single UTF-8 encoded Unicode character and returns the number of bytes written.
|
// WriteRune writes a single UTF-8 encoded Unicode character and returns the number of bytes written.
|
||||||
func WriteRune(w io.Writer, r rune) (int, error) {
|
func WriteRune(writer io.Writer, r rune) (int, error) {
|
||||||
|
if nil == writer {
|
||||||
|
return 0, errNilWriter
|
||||||
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case 127 >= r:
|
case 127 >= r:
|
||||||
|
@ -16,7 +18,7 @@ func WriteRune(w io.Writer, r rune) (int, error) {
|
||||||
|
|
||||||
p := buffer[:]
|
p := buffer[:]
|
||||||
|
|
||||||
return w.Write(p)
|
return writer.Write(p)
|
||||||
|
|
||||||
case 0x7FF >= r:
|
case 0x7FF >= r:
|
||||||
var buffer [2]byte
|
var buffer [2]byte
|
||||||
|
@ -26,7 +28,7 @@ func WriteRune(w io.Writer, r rune) (int, error) {
|
||||||
|
|
||||||
p := buffer[:]
|
p := buffer[:]
|
||||||
|
|
||||||
return w.Write(p)
|
return writer.Write(p)
|
||||||
|
|
||||||
case 0xFFFF >= r:
|
case 0xFFFF >= r:
|
||||||
var buffer [3]byte
|
var buffer [3]byte
|
||||||
|
@ -37,7 +39,7 @@ func WriteRune(w io.Writer, r rune) (int, error) {
|
||||||
|
|
||||||
p := buffer[:]
|
p := buffer[:]
|
||||||
|
|
||||||
return w.Write(p)
|
return writer.Write(p)
|
||||||
|
|
||||||
case 0x10FFFF >= r:
|
case 0x10FFFF >= r:
|
||||||
var buffer [4]byte
|
var buffer [4]byte
|
||||||
|
@ -49,7 +51,7 @@ func WriteRune(w io.Writer, r rune) (int, error) {
|
||||||
|
|
||||||
p := buffer[:]
|
p := buffer[:]
|
||||||
|
|
||||||
return w.Write(p)
|
return writer.Write(p)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0, errInternalError
|
return 0, errInternalError
|
||||||
|
|
Loading…
Reference in New Issue