Browse Source

runes: rework NewFeeder() to prevent double wrapping

Signed-off-by: Alejandro Mery <amery@jpi.io>
v0.2.x
Alejandro Mery 4 years ago
parent
commit
23f53c4da7
  1. 12
      runes/feeder.go

12
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

Loading…
Cancel
Save