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

Method GetLocationByOffset

common/ast/ast.go:397–408  ·  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

395
396// GetLocationByOffset returns the line and column information for a given character offset.
397func (s *SourceInfo) GetLocationByOffset(offset int32) common.Location {
398 line := 1
399 col := int(offset)
400 for _, lineOffset := range s.LineOffsets() {
401 if lineOffset > offset {
402 break
403 }
404 line++
405 col = int(offset - lineOffset)
406 }
407 return common.NewLocation(line, col)
408}
409
410// ComputeOffset calculates the 0-based character offset from a 1-based line and 0-based column.
411func (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