MCPcopy Create free account
hub / github.com/cel-expr/cel-go / GetLocationByOffset

Method GetLocationByOffset

common/ast/ast.go:405–416  ·  view source on GitHub ↗

GetLocationByOffset returns the line and column information for a given character offset.

(offset int32)

Source from the content-addressed store, hash-verified

403
404// GetLocationByOffset returns the line and column information for a given character offset.
405func (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.
419func (s *SourceInfo) ComputeOffset(line, col int32) int32 {

Callers 3

GetStartLocationMethod · 0.95
GetStopLocationMethod · 0.95
getLocationByOffsetMethod · 0.80

Calls 2

LineOffsetsMethod · 0.95
NewLocationFunction · 0.92

Tested by

no test coverage detected