diff options
author | Fabian Guerra Soto <fabian.guerra@mapbox.com> | 2018-05-04 13:30:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-04 13:30:06 -0400 |
commit | 1c847b321b401a473a45f839d7e53c27836c1393 (patch) | |
tree | 9fee40ba2dab3b96faac2540ab29e994e4547d4f /platform/darwin/src/NSExpression+MGLAdditions.mm | |
parent | 4f0241c1afcf46370eb325e80c1d52a4b490df38 (diff) | |
download | qtlocation-mapboxgl-1c847b321b401a473a45f839d7e53c27836c1393.tar.gz |
[ios, macos] Add support for subscripting in expressions. (#11770)
* [ios, macos] Add support for subscripting in expressions.
* [ios, macos] Update changelogs.
* [ios, macos] Refactor LAST subscripting expression.
Diffstat (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm')
-rw-r--r-- | platform/darwin/src/NSExpression+MGLAdditions.mm | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 633f433a8f..7881b79370 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -1097,7 +1097,22 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { NSArray *arguments = self.arguments.mgl_jsonExpressionObject; return [@[@"concat", self.operand.mgl_jsonExpressionObject] arrayByAddingObjectsFromArray:arguments]; } else if ([function isEqualToString:@"objectFrom:withIndex:"]) { - return @[@"at", self.arguments[1].mgl_jsonExpressionObject, self.arguments[0].mgl_jsonExpressionObject]; + id index = self.arguments[1].mgl_jsonExpressionObject; + + if ([self.arguments[1] expressionType] == NSConstantValueExpressionType + && [[self.arguments[1] constantValue] isKindOfClass:[NSString class]]) { + id value = self.arguments[1].constantValue; + + if ([value isEqualToString:@"FIRST"]) { + index = [NSExpression expressionForConstantValue:@0].mgl_jsonExpressionObject; + } else if ([value isEqualToString:@"LAST"]) { + index = [NSExpression expressionWithFormat:@"count(%@) - 1", self.arguments[0]].mgl_jsonExpressionObject; + } else if ([value isEqualToString:@"SIZE"]) { + return [NSExpression expressionWithFormat:@"count(%@)", self.arguments[0]].mgl_jsonExpressionObject; + } + } + + return @[@"at", index, self.arguments[0].mgl_jsonExpressionObject]; } else if ([function isEqualToString:@"boolValue"]) { return @[@"to-boolean", self.operand.mgl_jsonExpressionObject]; } else if ([function isEqualToString:@"mgl_number"] || |