MCPcopy Create free account
hub / github.com/brimdata/super / sliceIndex

Method sliceIndex

runtime/sam/expr/slice.go:88–103  ·  view source on GitHub ↗
(val super.Value, length int, base1 bool)

Source from the content-addressed store, hash-verified

86}
87
88func (s *Slice) sliceIndex(val super.Value, length int, base1 bool) super.Value {
89 if val.IsNull() || val.IsError() {
90 return val
91 }
92 index, ok := coerce.ToInt(val, super.TypeInt64)
93 if !ok {
94 return s.sctx.NewError(errors.New("slice index is not a number"))
95 }
96 if base1 && index > 0 {
97 index--
98 }
99 if index < 0 {
100 index += int64(length)
101 }
102 return super.NewInt64(index)
103}
104
105func FixSliceBounds(start, end, size int) (int, int) {
106 if start > end || end < 0 {

Callers 1

EvalMethod · 0.95

Calls 6

ToIntFunction · 0.92
NewInt64Function · 0.92
IsNullMethod · 0.80
IsErrorMethod · 0.80
NewErrorMethod · 0.80
NewMethod · 0.80

Tested by

no test coverage detected