mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-10-13 11:04:03 +08:00
chore: upgrade coredns version (#550)
This commit is contained in:
48
vendor/github.com/expr-lang/expr/file/source.go
generated
vendored
Normal file
48
vendor/github.com/expr-lang/expr/file/source.go
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type Source []rune
|
||||
|
||||
func NewSource(contents string) Source {
|
||||
return []rune(contents)
|
||||
}
|
||||
|
||||
func (s Source) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
func (s Source) Snippet(line int) (string, bool) {
|
||||
if s == nil {
|
||||
return "", false
|
||||
}
|
||||
lines := strings.Split(string(s), "\n")
|
||||
lineOffsets := make([]int, len(lines))
|
||||
var offset int
|
||||
for i, line := range lines {
|
||||
offset = offset + utf8.RuneCountInString(line) + 1
|
||||
lineOffsets[i] = offset
|
||||
}
|
||||
charStart, found := getLineOffset(lineOffsets, line)
|
||||
if !found || len(s) == 0 {
|
||||
return "", false
|
||||
}
|
||||
charEnd, found := getLineOffset(lineOffsets, line+1)
|
||||
if found {
|
||||
return string(s[charStart : charEnd-1]), true
|
||||
}
|
||||
return string(s[charStart:]), true
|
||||
}
|
||||
|
||||
func getLineOffset(lineOffsets []int, line int) (int, bool) {
|
||||
if line == 1 {
|
||||
return 0, true
|
||||
} else if line > 1 && line <= len(lineOffsets) {
|
||||
offset := lineOffsets[line-2]
|
||||
return offset, true
|
||||
}
|
||||
return -1, false
|
||||
}
|
Reference in New Issue
Block a user