From c4886149ac3025ce7c197a12e7657f168f158751 Mon Sep 17 00:00:00 2001 From: Petter Rodhelind Date: Fri, 23 Feb 2018 19:35:38 +0100 Subject: Add error handling to NextWord. --- text.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/text.go b/text.go index 548f792..5b50be9 100644 --- a/text.go +++ b/text.go @@ -324,10 +324,19 @@ func (t *Text) PrevSpace(offset int) (n int) { func (t *Text) NextWord(offset int) (n int) { offset, _ = t.Seek(offset, io.SeekStart) - r, size, _ := t.ReadRune() + r, size, err := t.ReadRune() + if err != nil { + return 0 + } for unicode.IsLetter(r) || unicode.IsDigit(r) { n += size - r, size, _ = t.ReadRune() + r, size, err = t.ReadRune() + if err != nil { + if err == io.EOF { + return n + } + return 0 + } } return n -- cgit v1.2.3