From 23f53c4da74c17af122f05140880f65486f31f45 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Tue, 29 Jun 2021 12:30:46 +0100 Subject: [PATCH] runes: rework NewFeeder() to prevent double wrapping Signed-off-by: Alejandro Mery --- runes/feeder.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/runes/feeder.go b/runes/feeder.go index 465abf3..32c2eb1 100644 --- a/runes/feeder.go +++ b/runes/feeder.go @@ -20,17 +20,21 @@ type Feeder struct { // NewFeederBytes creates a new Feeder using an slice of bytes as input func NewFeederBytes(b []byte) *Feeder { - return &Feeder{in: bytes.NewReader(b)} + return NewFeeder(bytes.NewReader(b)) } // NewFeederString creates a new Feeder using a string as input func NewFeederString(s string) *Feeder { - return &Feeder{in: strings.NewReader(s)} + return NewFeeder(strings.NewReader(s)) } -// NewFeederString creates a new Feeder using a string as input +// NewFeederString creates a new Feeder using a Reader as input func NewFeeder(in io.Reader) *Feeder { - return &Feeder{in: bufio.NewReader(in)} + rd, ok := in.(io.RuneReader) + if !ok { + rd = bufio.NewReader(in) + } + return &Feeder{in: rd} } // Skip drops n runes from the head of the buffer