| 1234567891011121314151617181920212223242526272829303132333435363738 |
- 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
- }
|