Fix out of bounds error on syntax highlighting

Fixes #606
This commit is contained in:
Zachary Yedidia
2017-03-27 16:26:32 -04:00
parent d087a890ba
commit bde48c051a

View File

@@ -11,12 +11,12 @@ import (
// RunePos returns the rune index of a given byte index
// This could cause problems if the byte index is between code points
func runePos(p int, str string) int {
// if p < 0 {
// return -1
// }
// if p >= len(str) {
// return -1
// }
if p < 0 {
return 0
}
if p >= len(str) {
return utf8.RuneCountInString(str)
}
return utf8.RuneCountInString(str[:p])
}