diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-03-23 12:06:54 -0400 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-03-23 12:06:54 -0400 |
commit | 90f984cc5db3d36ad5c41ada30c5d41a9814d0cc (patch) | |
tree | 8749e564856aeb155e987f0722518ee8afccb69a /platform/darwin/src/NSExpression+MGLAdditions.mm | |
parent | e75bd22380d2f4fdcd6d0c20e1274cc927892ddc (diff) | |
download | qtlocation-mapboxgl-90f984cc5db3d36ad5c41ada30c5d41a9814d0cc.tar.gz |
[ios, macos] Match operator function implementation refactor.upstream/fabian-coalesce-match-operators-11009
Diffstat (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm')
-rw-r--r-- | platform/darwin/src/NSExpression+MGLAdditions.mm | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 933268efe4..a60b14b35d 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -258,6 +258,12 @@ return [self valueForKeyPath:@"mgl_jsonExpressionObject"]; } +- (id)mgl_coalesce { + [NSException raise:NSInvalidArgumentException + format:@"Coalesce expressions lack underlying Objective-C implementations."]; + return nil; +} + @end @implementation NSDictionary (MGLExpressionAdditions) @@ -478,23 +484,17 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { } else if ([op isEqualToString:@"match"]) { NSExpression *operand = [NSExpression mgl_expressionWithJSONObject:argumentObjects[0]]; NSArray *matchOptions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; - NSExpression *defaultOption; - if (matchOptions.count % 2) { - defaultOption = [NSExpression mgl_expressionWithJSONObject:matchOptions.lastObject]; - matchOptions = [matchOptions subarrayWithRange:NSMakeRange(0, matchOptions.count - 1)]; - } + NSMutableArray *optionsArray = [NSMutableArray array]; NSEnumerator *optionsEnumerator = matchOptions.objectEnumerator; - while (NSNumber *key = optionsEnumerator.nextObject) { - NSMutableDictionary *option = [NSMutableDictionary dictionaryWithCapacity:1]; - NSExpression *valueExpression = optionsEnumerator.nextObject; - option[key] = [NSExpression mgl_expressionWithJSONObject:valueExpression]; + while (id object = optionsEnumerator.nextObject) { + NSExpression *option = [NSExpression mgl_expressionWithJSONObject:object]; [optionsArray addObject:option]; } - NSExpression *optionsExpression = [NSExpression expressionForConstantValue:optionsArray]; + return [NSExpression expressionForFunction:operand - selectorName:@"mgl_matchWithOptions:default:" - arguments:@[optionsExpression, defaultOption]]; + selectorName:@"mgl_match:" + arguments:optionsArray]; } else if ([op isEqualToString:@"coalesce"]) { NSMutableArray *expressions = [NSMutableArray array]; for (id operand in argumentObjects) { @@ -693,17 +693,13 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { }]; [expressionObject addObject:self.operand.mgl_jsonExpressionObject]; return expressionObject; - } else if ([function isEqualToString:@"mgl_matchWithOptions:default:"]) { + } else if ([function isEqualToString:@"mgl_match:"]) { NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"match", self.operand.mgl_jsonExpressionObject, nil]; - NSArray *optionsArray = self.arguments[0].constantValue; - for (NSDictionary<id, NSExpression*> *options in optionsArray) { - for (NSNumber *key in options.allKeys) { - [expressionObject addObject:key]; - [expressionObject addObject:[options[key] mgl_jsonExpressionObject]]; - } + + for (NSExpression *option in self.arguments) { + [expressionObject addObject:option.mgl_jsonExpressionObject]; } - [expressionObject addObject:[self.arguments[1] mgl_jsonExpressionObject]]; return expressionObject; } else if ([function isEqualToString:@"mgl_coalesce"]) { NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"coalesce", nil]; |