Esempio n. 1
0
func (t text) run(dst []byte, up *reader) (int, error, state) {
	n, err := io.ReadFull(t.r, dst)
	if err == finder.Found {
		return n, nil, comment{finder.NewReader(up.end, up.r)}
	}
	return n, err, t
}
Esempio n. 2
0
func (c copier) run(dst []byte, up *reader) (int, error, state) {
	n := copy(dst, c)
	if n == len(c) {
		return n, nil, text{finder.NewReader(up.begin, up.r)}
	}
	return n, nil, c[n:]
}
Esempio n. 3
0
// NewCustomReader returns an io.Reader that copies directly from r, replacing
// any string between begin and end with add.
func NewCustomReader(r io.Reader, begin, end, add []byte) io.Reader {
	br, ok := r.(io.ByteReader)
	if !ok {
		br = bufio.NewReader(r)
	}
	ret := &reader{
		r:     br,
		begin: finder.Compile(begin),
		end:   finder.Compile(end),
		add:   add,
	}
	ret.state = text{finder.NewReader(ret.begin, ret.r)}
	return ret
}