GetLocationByOffset returns the line and column information for a given character offset.
(offset int32)
| 403 | |
| 404 | // GetLocationByOffset returns the line and column information for a given character offset. |
| 405 | func (s *SourceInfo) GetLocationByOffset(offset int32) common.Location { |
| 406 | line := 1 |
| 407 | col := int(offset) |
| 408 | for _, lineOffset := range s.LineOffsets() { |
| 409 | if lineOffset > offset { |
| 410 | break |
| 411 | } |
| 412 | line++ |
| 413 | col = int(offset - lineOffset) |
| 414 | } |
| 415 | return common.NewLocation(line, col) |
| 416 | } |
| 417 | |
| 418 | // ComputeOffset calculates the 0-based character offset from a 1-based line and 0-based column. |
| 419 | func (s *SourceInfo) ComputeOffset(line, col int32) int32 { |
no test coverage detected