repochecker/grammalecte: Refactor grammar passage extraction

This commit is contained in:
nemunaire 2022-11-24 19:38:15 +01:00
commit 2381dfe4f5
2 changed files with 25 additions and 10 deletions

View file

@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"strings"
"unicode/utf8"
)
const LOG_PREFIX_LEN = 20
@ -72,6 +73,22 @@ func (e GrammarError) Error() string {
)
}
func (e GrammarError) GetPassage() string {
nb := 0
var ret []byte
for _, r := range e.Source {
if nb >= e.End {
break
}
if nb >= e.Start {
ret = utf8.AppendRune(ret, r)
}
nb += 1
}
return string(ret)
}
func underline(prefix, start, end int) string {
var b bytes.Buffer