aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetter Rodhelind <petter.rodhelind@gmail.com>2018-02-23 19:35:38 +0100
committerPetter Rodhelind <petter.rodhelind@gmail.com>2018-02-23 19:35:38 +0100
commitc4886149ac3025ce7c197a12e7657f168f158751 (patch)
tree4b92ee419b71a5af9f46e9d04459e4203e3fe2f0
parent790b4d4e6d20d43cccf4ebf2c4723d3ed5d65733 (diff)
downloadpoe-c4886149ac3025ce7c197a12e7657f168f158751.tar.gz
poe-c4886149ac3025ce7c197a12e7657f168f158751.tar.bz2
poe-c4886149ac3025ce7c197a12e7657f168f158751.zip
Add error handling to NextWord.
-rw-r--r--text.go13
1 files 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