mirror of https://github.com/dirtbags/fluffy.git
Make GapRead a function
This commit is contained in:
parent
262462af53
commit
f85d32c600
|
@ -147,7 +147,7 @@ func (g *Gapstr) Slice(beg, end int) *Gapstr {
|
|||
type GapstrReader struct {
|
||||
g *Gapstr
|
||||
pos int
|
||||
GapRead bool
|
||||
gapread bool
|
||||
}
|
||||
|
||||
func NewGapstrReader(g *Gapstr) (*GapstrReader) {
|
||||
|
@ -157,11 +157,15 @@ func NewGapstrReader(g *Gapstr) (*GapstrReader) {
|
|||
func (gr *GapstrReader) Read(p []byte) (n int, err error) {
|
||||
gs := gr.g.Slice(gr.pos, gr.pos + len(p))
|
||||
if gs.HasGaps() {
|
||||
gr.GapRead = true
|
||||
gr.gapread = true
|
||||
}
|
||||
|
||||
s := []byte(gs.String())
|
||||
nread := copy(p, s)
|
||||
gr.pos += nread
|
||||
return nread, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (gr *GapstrReader) GapRead() bool {
|
||||
return gr.gapread
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ func TestGapstr(t *testing.T) {
|
|||
|
||||
func TestGapstrReader(t *testing.T) {
|
||||
g := new(Gapstr)
|
||||
g = g.AppendString("\xff\xff")
|
||||
g = g.AppendString("\xff\xffaoeu")
|
||||
g = g.AppendGap(8)
|
||||
g = g.AppendString("\xff\xff\xff")
|
||||
|
||||
|
@ -68,6 +68,7 @@ func TestGapstrReader(t *testing.T) {
|
|||
truth := gs[beg:end]
|
||||
nread, err := gr.Read(b)
|
||||
|
||||
DUMP(gr.GapRead())
|
||||
AssertEqual(t, nread, len(truth))
|
||||
AssertEqual(t, err, nil)
|
||||
AssertEqual(t, string(b[:nread]), truth)
|
||||
|
|
Loading…
Reference in New Issue