diff options
author | Petter Rodhelind <petter.rodhelind@gmail.com> | 2018-02-23 19:35:38 +0100 |
---|---|---|
committer | Petter Rodhelind <petter.rodhelind@gmail.com> | 2018-02-23 19:35:38 +0100 |
commit | c4886149ac3025ce7c197a12e7657f168f158751 (patch) | |
tree | 4b92ee419b71a5af9f46e9d04459e4203e3fe2f0 | |
parent | 790b4d4e6d20d43cccf4ebf2c4723d3ed5d65733 (diff) | |
download | poe-c4886149ac3025ce7c197a12e7657f168f158751.tar.gz poe-c4886149ac3025ce7c197a12e7657f168f158751.tar.bz2 poe-c4886149ac3025ce7c197a12e7657f168f158751.zip |
Add error handling to NextWord.
-rw-r--r-- | text.go | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -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 |