Make GapRead a function

This commit is contained in:
Neale Pickett 2014-08-20 17:09:12 -06:00
parent 262462af53
commit f85d32c600
2 changed files with 9 additions and 4 deletions

View File

@ -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,7 +157,7 @@ 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())
@ -165,3 +165,7 @@ func (gr *GapstrReader) Read(p []byte) (n int, err error) {
gr.pos += nread
return nread, nil
}
func (gr *GapstrReader) GapRead() bool {
return gr.gapread
}

View File

@ -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)