repochecker/grammalecte: Refactor grammar passage extraction
This commit is contained in:
parent
ccc2c5d1d7
commit
2381dfe4f5
2 changed files with 25 additions and 10 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Reference in a new issue