Move to utils.go

pull/268/head
Anton Medvedev 9 months ago
parent 2f381f0bc7
commit 00196482cf
No known key found for this signature in database

@ -22,34 +22,10 @@ func splitBytesByIndexes(b []byte, indexes []match) []кусочек {
return out
}
func safeSlice(b []byte, start, end int) []byte {
length := len(b)
if start > length {
start = length
}
if end > length {
end = length
}
if start < 0 {
start = 0
}
if end < 0 {
end = 0
}
if start > end {
start = end
}
return b[start:end]
}
func splitIndexesToChunks(chunks [][]byte, indexes [][]int, searchIndex int) (chunkIndexes [][]match) {
// Initialize a slice for indexes of each chunk
chunkIndexes = make([][]match, len(chunks))
// Iterate over each index pair from regex results
for index, idx := range indexes {
// Calculate the current position in the whole byte slice
position := 0
for i, chunk := range chunks {
// If start index lies in this chunk

@ -35,3 +35,23 @@ func regexCase(code string) (string, bool) {
func flex(width int, a, b string) string {
return a + strings.Repeat(" ", max(1, width-len(a)-len(b))) + b
}
func safeSlice(b []byte, start, end int) []byte {
length := len(b)
if start > length {
start = length
}
if end > length {
end = length
}
if start < 0 {
start = 0
}
if end < 0 {
end = 0
}
if start > end {
start = end
}
return b[start:end]
}

Loading…
Cancel
Save