MCPcopy Index your code
hub / github.com/expr-lang/expr / Snippet

Method Snippet

file/source.go:19–36  ·  view source on GitHub ↗
(line int)

Source from the content-addressed store, hash-verified

17}
18
19func (s Source) Snippet(line int) (string, bool) {
20 if s.raw == "" {
21 return "", false
22 }
23 var start int
24 for i := 1; i < line; i++ {
25 pos := strings.IndexByte(s.raw[start:], '\n')
26 if pos < 0 {
27 return "", false
28 }
29 start += pos + 1
30 }
31 end := start + strings.IndexByte(s.raw[start:], '\n')
32 if end < start {
33 end = len(s.raw)
34 }
35 return s.raw[start:end], true
36}

Calls

no outgoing calls