(ctx expr.EvalContext, args []value.Value)
| 128 | } |
| 129 | |
| 130 | func arraySliceEval(ctx expr.EvalContext, args []value.Value) (value.Value, bool) { |
| 131 | |
| 132 | if args[0] == nil || args[0].Err() || args[0].Nil() { |
| 133 | return nil, false |
| 134 | } |
| 135 | |
| 136 | idx, ok := value.ValueToInt(args[1]) |
| 137 | if !ok { |
| 138 | return nil, false |
| 139 | } |
| 140 | |
| 141 | idx2 := 0 |
| 142 | if len(args) == 3 { |
| 143 | idx2, ok = value.ValueToInt(args[2]) |
| 144 | if !ok { |
| 145 | return nil, false |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | switch node := args[0].(type) { |
| 150 | case value.StringsValue: |
| 151 | |
| 152 | svals := node.Val() |
| 153 | |
| 154 | if idx < 0 { |
| 155 | idx = len(svals) + idx |
| 156 | } |
| 157 | if idx2 < 0 { |
| 158 | idx2 = len(svals) + idx2 |
| 159 | if idx2 < idx { |
| 160 | return nil, false |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | if len(svals) <= idx || idx < 0 { |
| 165 | return nil, false |
| 166 | } |
| 167 | if len(svals) < idx2 || idx2 < 0 { |
| 168 | return nil, false |
| 169 | } |
| 170 | if len(args) == 2 { |
| 171 | // array.slice(item, start) |
| 172 | return value.NewStringsValue(svals[idx:]), true |
| 173 | } else { |
| 174 | // array.slice(item, start, end) |
| 175 | return value.NewStringsValue(svals[idx:idx2]), true |
| 176 | } |
| 177 | case value.SliceValue: |
| 178 | |
| 179 | svals := node.Val() |
| 180 | |
| 181 | if idx < 0 { |
| 182 | idx = len(svals) + idx |
| 183 | } |
| 184 | if idx2 < 0 { |
| 185 | idx2 = len(svals) + idx2 |
| 186 | if idx2 < idx { |
| 187 | return nil, false |
nothing calls this directly
no test coverage detected