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 { type GapstrReader struct {
g *Gapstr g *Gapstr
pos int pos int
GapRead bool gapread bool
} }
func NewGapstrReader(g *Gapstr) (*GapstrReader) { func NewGapstrReader(g *Gapstr) (*GapstrReader) {
@ -157,7 +157,7 @@ func NewGapstrReader(g *Gapstr) (*GapstrReader) {
func (gr *GapstrReader) Read(p []byte) (n int, err error) { func (gr *GapstrReader) Read(p []byte) (n int, err error) {
gs := gr.g.Slice(gr.pos, gr.pos + len(p)) gs := gr.g.Slice(gr.pos, gr.pos + len(p))
if gs.HasGaps() { if gs.HasGaps() {
gr.GapRead = true gr.gapread = true
} }
s := []byte(gs.String()) s := []byte(gs.String())
@ -165,3 +165,7 @@ func (gr *GapstrReader) Read(p []byte) (n int, err error) {
gr.pos += nread gr.pos += nread
return nread, nil 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) { func TestGapstrReader(t *testing.T) {
g := new(Gapstr) g := new(Gapstr)
g = g.AppendString("\xff\xff") g = g.AppendString("\xff\xffaoeu")
g = g.AppendGap(8) g = g.AppendGap(8)
g = g.AppendString("\xff\xff\xff") g = g.AppendString("\xff\xff\xff")
@ -68,6 +68,7 @@ func TestGapstrReader(t *testing.T) {
truth := gs[beg:end] truth := gs[beg:end]
nread, err := gr.Read(b) nread, err := gr.Read(b)
DUMP(gr.GapRead())
AssertEqual(t, nread, len(truth)) AssertEqual(t, nread, len(truth))
AssertEqual(t, err, nil) AssertEqual(t, err, nil)
AssertEqual(t, string(b[:nread]), truth) AssertEqual(t, string(b[:nread]), truth)