MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / findPosInLine

Function findPosInLine

pkg/filter/ql/error.go:43–72  ·  view source on GitHub ↗

findPosInLine returns the parser position and the line number where the syntax error occurred when the expression is split over multiple lines.

(expr string, pos int)

Source from the content-addressed store, hash-verified

41// where the syntax error occurred when the expression is split
42// over multiple lines.
43func findPosInLine(expr string, pos int) (int, int) {
44 ln := 1
45 for i, c := range []rune(expr) {
46 if c == '\n' {
47 ln++
48 }
49 if i == pos {
50 switch {
51 case ln > 1:
52 // multiline expression. Calculate
53 // the position relative to the line
54 // number by looking back for the
55 // previous newline terminator
56 j := pos
57 for expr[j] != '\n' {
58 j--
59 // no newline found
60 if j == -1 {
61 break
62 }
63 }
64 return pos - j - 1, ln
65 default:
66 // single line expression
67 return pos, 1
68 }
69 }
70 }
71 return pos + 1, 1
72}
73
74type renderer struct {
75 strings.Builder

Callers 1

renderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected