import (
"regexp"
"strings"
- "unicode/utf8"
)
func sliceStart(slc []byte, index int) []byte {
return slc[totalSize:]
}
- _, size := utf8.DecodeRune(slc[totalSize:])
+ _, _, size := DecodeCharacter(slc[totalSize:])
totalSize += size
i++
}
return slc[:totalSize]
}
- _, size := utf8.DecodeRune(slc[totalSize:])
+ _, _, size := DecodeCharacter(slc[totalSize:])
totalSize += size
i++
}
return 0
}
if p >= len(str) {
- return utf8.RuneCount(str)
+ return CharacterCount(str)
}
- return utf8.RuneCount(str[:p])
+ return CharacterCount(str[:p])
}
func combineLineMatch(src, dst LineMatch) LineMatch {
// A State represents the region at the end of a line
type State *region
+// EmptyDef is an empty definition.
var EmptyDef = Def{nil, &rules{}}
// LineStates is an interface for a buffer-like object which can also store the states and matches for every line
var strbytes []byte
if skip != nil {
strbytes = skip.ReplaceAllFunc(str, func(match []byte) []byte {
- res := make([]byte, utf8.RuneCount(match))
+ res := make([]byte, CharacterCount(match))
return res
})
} else {
}
func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchEnd bool, lineNum int, line []byte, curRegion *region, statesOnly bool) LineMatch {
- lineLen := utf8.RuneCount(line)
+ lineLen := CharacterCount(line)
if start == 0 {
if !statesOnly {
if _, ok := highlights[0]; !ok {
}
func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canMatchEnd bool, lineNum int, line []byte, statesOnly bool) LineMatch {
- lineLen := utf8.RuneCount(line)
+ lineLen := CharacterCount(line)
if lineLen == 0 {
if canMatchEnd {
h.lastRegion = nil
}
}
-// HighlightMatches sets the matches for each line in between startline and endline
+// HighlightMatches sets the matches for each line from startline to endline
// It sets all other matches in the buffer to nil to conserve memory
// This assumes that all the states are set correctly
func (h *Highlighter) HighlightMatches(input LineStates, startline, endline int) {
- for i := startline; i < endline; i++ {
+ for i := startline; i <= endline; i++ {
if i >= input.LinesNum() {
break
}