[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.
This commit is contained in:
committed by
GitHub
parent
4f0241c1af
commit
1c847b321b
@@ -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"] ||
|
||||
|
||||
@@ -837,6 +837,33 @@ using namespace std::string_literals;
|
||||
}
|
||||
|
||||
- (void)testLookupExpressionObject {
|
||||
{
|
||||
NSExpression *array = [NSExpression expressionForAggregate:@[MGLConstantExpression(@9),
|
||||
MGLConstantExpression(@8),
|
||||
MGLConstantExpression(@7)]];
|
||||
NSExpression *expression = [NSExpression expressionForFunction:@"objectFrom:withIndex:"
|
||||
arguments:@[array, MGLConstantExpression(@"FIRST")]];
|
||||
NSArray *jsonExpression = @[@"at", @0, @[ @"literal", @[@9, @8, @7]]];
|
||||
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
|
||||
}
|
||||
{
|
||||
NSExpression *array = [NSExpression expressionForAggregate:@[MGLConstantExpression(@9),
|
||||
MGLConstantExpression(@8),
|
||||
MGLConstantExpression(@7)]];
|
||||
NSExpression *expression = [NSExpression expressionForFunction:@"objectFrom:withIndex:"
|
||||
arguments:@[array, MGLConstantExpression(@"LAST")]];
|
||||
NSArray *jsonExpression = @[@"at", @[@"-", @[@"length", @[ @"literal", @[@9, @8, @7]]], @1], @[ @"literal", @[@9, @8, @7]]];
|
||||
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
|
||||
}
|
||||
{
|
||||
NSExpression *array = [NSExpression expressionForAggregate:@[MGLConstantExpression(@9),
|
||||
MGLConstantExpression(@8),
|
||||
MGLConstantExpression(@7)]];
|
||||
NSExpression *expression = [NSExpression expressionForFunction:@"objectFrom:withIndex:"
|
||||
arguments:@[array, MGLConstantExpression(@"SIZE")]];
|
||||
NSArray *jsonExpression = @[@"length", @[ @"literal", @[@9, @8, @7]]];
|
||||
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
|
||||
}
|
||||
{
|
||||
NSExpression *array = [NSExpression expressionForAggregate:@[MGLConstantExpression(@9),
|
||||
MGLConstantExpression(@8),
|
||||
|
||||
@@ -7,6 +7,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
|
||||
### Style layers
|
||||
|
||||
* Deprecated `+[NSExpression featurePropertiesVariableExpression]` use `+[NSExpression featureAttributesVariableExpression]` instead. ([#11748](https://github.com/mapbox/mapbox-gl-native/pull/11748))
|
||||
* Added `FISRT`, `LAST`, and `SIZE` symbolic array subscripting support to expressions. ([#11770](https://github.com/mapbox/mapbox-gl-native/pull/11770))
|
||||
|
||||
|
||||
### Annotations
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
### Style layers
|
||||
|
||||
* Deprecated `+[NSExpression featurePropertiesVariableExpression]` use `+[NSExpression featureAttributesVariableExpression]` instead. ([#11748](https://github.com/mapbox/mapbox-gl-native/pull/11748))
|
||||
* Added `FISRT`, `LAST`, and `SIZE` symbolic array subscripting support to expressions. ([#11770](https://github.com/mapbox/mapbox-gl-native/pull/11770))
|
||||
|
||||
### Other changes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user