@@ -40,7 +40,8 @@ impl std::fmt::Display for ParseError {
40
40
41
41
impl std:: error:: Error for ParseError { }
42
42
43
- fn sindex_to_uindex ( index : isize , len : usize ) -> Option < usize > {
43
+ /// Convert a relative index into an absolute index
44
+ fn abs_index ( index : isize , len : usize ) -> Option < usize > {
44
45
if index >= 0 {
45
46
Some ( index as usize )
46
47
} else {
@@ -80,7 +81,7 @@ impl Expression {
80
81
Self :: Subscript ( expr, index) => match expr. get ( root) {
81
82
Some ( value) => match value. kind {
82
83
ValueKind :: Array ( ref array) => {
83
- let index = sindex_to_uindex ( index, array. len ( ) ) ?;
84
+ let index = abs_index ( index, array. len ( ) ) ?;
84
85
85
86
if index >= array. len ( ) {
86
87
None
@@ -141,7 +142,7 @@ impl Expression {
141
142
142
143
match value. kind {
143
144
ValueKind :: Array ( ref mut array) => {
144
- let index = sindex_to_uindex ( index, array. len ( ) ) ?;
145
+ let index = abs_index ( index, array. len ( ) ) ?;
145
146
146
147
if index >= array. len ( ) {
147
148
array. resize ( index + 1 , Value :: new ( None , ValueKind :: Nil ) ) ;
@@ -216,7 +217,7 @@ impl Expression {
216
217
}
217
218
218
219
if let ValueKind :: Array ( ref mut array) = parent. kind {
219
- let uindex = sindex_to_uindex ( index, array. len ( ) ) . unwrap ( ) ;
220
+ let uindex = abs_index ( index, array. len ( ) ) . unwrap ( ) ;
220
221
if uindex >= array. len ( ) {
221
222
array. resize ( uindex + 1 , Value :: new ( None , ValueKind :: Nil ) ) ;
222
223
}
0 commit comments