Files
gitleaks/detect/location.go
T
Zachary Rice 93f292c3df Introducing v8.0.0 changes (#701)
* Introducing v8.0.0 changes
2021-11-22 10:43:51 -06:00

39 lines
911 B
Go

package detect
// Location represents a location in a file
type Location struct {
startLine int
endLine int
startColumn int
endColumn int
startLineIndex int
endLineIndex int
}
func getLocation(linePairs [][]int, start int, end int) Location {
var (
prevNewLine int
location Location
)
for lineNum, pair := range linePairs {
newLineByteIndex := pair[0]
if prevNewLine <= start && start < newLineByteIndex {
location.startLine = lineNum
location.endLine = lineNum
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
location.startLineIndex = prevNewLine
location.endLineIndex = newLineByteIndex
}
if prevNewLine < end && end <= newLineByteIndex {
location.endLine = lineNum
location.endColumn = (end - prevNewLine)
location.endLineIndex = newLineByteIndex
}
prevNewLine = pair[0]
}
return location
}