aboutsummaryrefslogtreecommitdiff
path: root/lib/bytes
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bytes')
-rw-r--r--lib/bytes/bytes.go10
1 files changed, 2 insertions, 8 deletions
diff --git a/lib/bytes/bytes.go b/lib/bytes/bytes.go
index f0f55555..b79fd7cb 100644
--- a/lib/bytes/bytes.go
+++ b/lib/bytes/bytes.go
@@ -342,14 +342,8 @@ func SkipAfterToken(text, token []byte, startAt int, checkEsc bool) (int, bool)
func SnippetByIndexes(s []byte, indexes []int, sniplen int) (snippets [][]byte) {
var start, end int
for _, idx := range indexes {
- start = idx - sniplen
- if start < 0 {
- start = 0
- }
- end = idx + sniplen
- if end > len(s) {
- end = len(s)
- }
+ start = max(idx-sniplen, 0)
+ end = min(idx+sniplen, len(s))
snippets = append(snippets, s[start:end])
}