go-utf8/runewriter.go

29 lines
603 B
Go
Raw Permalink Normal View History

2022-07-18 23:36:02 +00:00
package utf8
2019-09-11 19:36:02 +00:00
import (
"io"
)
2023-08-18 13:37:04 +00:00
type runeWriter interface {
WriteRune(rune) (int, error)
}
var _ runeWriter = WrapRuneWriter(nil)
2019-09-11 19:36:02 +00:00
// RuneWriter writes a single UTF-8 encoded Unicode characters.
type RuneWriter struct {
writer io.Writer
}
2023-08-18 13:37:04 +00:00
// WrapRuneWriter wraps an io.Writer and returns a RuneWriter.
func WrapRuneWriter(writer io.Writer) RuneWriter {
2022-07-19 03:54:16 +00:00
return RuneWriter{
2019-09-11 19:36:02 +00:00
writer: writer,
}
}
// WriteRune writes a single UTF-8 encoded Unicode character and returns the number of bytes written.
2023-08-18 13:37:04 +00:00
func (receiver RuneWriter) WriteRune(r rune) (int, error) {
2019-09-11 19:36:02 +00:00
return WriteRune(receiver.writer, r)
}