summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-03-19 16:49:52 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-03-19 16:49:52 -0400
commit216247b030000937ba029b8ccbf8e74f88bb861d (patch)
tree20d9a9f28e32feff23f20282a6790804c8765ae0
parent7c8614b8d520059aa856df95f786b61dfde635a2 (diff)
downloadqtlocation-mapboxgl-216247b030000937ba029b8ccbf8e74f88bb861d.tar.gz
[ios, macos] Add coalesce operator support.
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm19
1 files changed, 17 insertions, 2 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 1d3c573e4e..d2c5958ff8 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -507,7 +507,14 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
return [NSExpression expressionForFunction:operand
selectorName:@"mgl_matchWithOptions:default:"
arguments:@[optionsExpression, defaultOption]];
- } else {
+ } else if ([op isEqualToString:@"coalesce"]) {
+ NSMutableArray *expressions = [NSMutableArray array];
+ for (id operand in argumentObjects) {
+ [expressions addObject:[NSExpression mgl_expressionWithJSONObject:operand]];
+ }
+
+ return [NSExpression expressionWithFormat:@"FUNCTION(%@, 'coalesce:')", expressions];
+ }else {
[NSException raise:NSInvalidArgumentException
format:@"Expression operator %@ not yet implemented.", op];
}
@@ -533,7 +540,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
@"ln:": @"ln",
@"raise:toPower:": @"^",
@"uppercase:": @"upcase",
- @"lowercase:": @"downcase",
+ @"lowercase:": @"downcase"
};
});
@@ -710,6 +717,14 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
[expressionObject addObject:[self.arguments[1] mgl_jsonExpressionObject]];
return expressionObject;
+ } else if ([function isEqualToString:@"coalesce:"]) {
+ NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"coalesce", nil];
+
+ for (NSExpression *expression in self.operand.constantValue) {
+ [expressionObject addObject:[expression mgl_jsonExpressionObject]];
+ }
+
+ return expressionObject;
} else if ([function isEqualToString:@"median:"] ||
[function isEqualToString:@"mode:"] ||
[function isEqualToString:@"stddev:"] ||