summaryrefslogtreecommitdiff
path: root/unxml.go
diff options
context:
space:
mode:
Diffstat (limited to 'unxml.go')
-rw-r--r--unxml.go22
1 files changed, 10 insertions, 12 deletions
diff --git a/unxml.go b/unxml.go
index aa6bc8a..ff04b2d 100644
--- a/unxml.go
+++ b/unxml.go
@@ -85,10 +85,13 @@ func (r *Reader) Read(out []byte) (int, error) {
lenlr := len(r.lastread)
if lenlr > 0 {
- n = copy(out[0:], r.lastread)
+ n = copy(out, r.lastread)
r.count += n
- r.lastread = make([]byte, len(out))
- lenout -= n
+ if n < lenlr {
+ r.lastread = r.lastread[n:]
+ return r.count, nil
+ }
+ r.lastread = make([]byte, lenout)
}
for {
@@ -100,15 +103,10 @@ func (r *Reader) Read(out []byte) (int, error) {
case html.TextToken:
text := r.tokenizer.Text()
- lentext := len(text)
- if lentext <= lenout {
- n = copy(out[r.count:], text)
- r.count += n
- lenout -= n
- } else {
- n = copy(out[r.count:], text[:lenout-1])
- r.count += n
- r.lastread = text[lenout-1:]
+ n = copy(out[r.count:], text)
+ r.count += n
+ if n < len(text) {
+ r.lastread = text[n:]
return r.count, err
}