diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-07-17 12:21:50 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-07-20 12:35:00 -0700 |
commit | 2c5d0e74a1ef6743a23dbd346b79958e4b2f8614 (patch) | |
tree | 5dd56c0079294b6cebf2d26970bcb12852add27e /platform/darwin/src/NSExpression+MGLAdditions.mm | |
parent | af89318b1d3bef15e92e591887c9d65b10be54ce (diff) | |
download | qtlocation-mapboxgl-2c5d0e74a1ef6743a23dbd346b79958e4b2f8614.tar.gz |
[ios, macos] Convert token strings to expressions on input
Removes mgl_expressionByReplacingTokensWithKeyPaths and associated code. Converting on output is no longer necessary: from the prior commit, core converts token strings to expressions at parse time; all that's necessary is to ensure that the runtime styling API does so as well.
Diffstat (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm')
-rw-r--r-- | platform/darwin/src/NSExpression+MGLAdditions.mm | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 5cb69d11dc..2a4c80bee6 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -389,112 +389,6 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = return {}; } -// Selectors of functions that can contain tokens in arguments. -static NSArray * const MGLTokenizedFunctions = @[ - @"mgl_interpolateWithCurveType:parameters:stops:", - @"mgl_interpolate:withCurveType:parameters:stops:", - @"mgl_stepWithMinimum:stops:", - @"mgl_step:from:stops:", -]; - -/** - Returns a copy of the given collection with tokens replaced by key path - expressions. - - If no replacements take place, this method returns the original collection. - */ -NSArray<NSExpression *> *MGLCollectionByReplacingTokensWithKeyPaths(NSArray<NSExpression *> *collection) { - __block NSMutableArray *upgradedCollection; - [collection enumerateObjectsUsingBlock:^(NSExpression * _Nonnull item, NSUInteger idx, BOOL * _Nonnull stop) { - NSExpression *upgradedItem = item.mgl_expressionByReplacingTokensWithKeyPaths; - if (upgradedItem != item) { - if (!upgradedCollection) { - upgradedCollection = [collection mutableCopy]; - } - upgradedCollection[idx] = upgradedItem; - } - }]; - return upgradedCollection ?: collection; -}; - -/** - Returns a copy of the given stop dictionary with tokens replaced by key path - expressions. - - If no replacements take place, this method returns the original stop - dictionary. - */ -NSDictionary<NSNumber *, NSExpression *> *MGLStopDictionaryByReplacingTokensWithKeyPaths(NSDictionary<NSNumber *, NSExpression *> *stops) { - __block NSMutableDictionary *upgradedStops; - [stops enumerateKeysAndObjectsUsingBlock:^(id _Nonnull zoomLevel, NSExpression * _Nonnull value, BOOL * _Nonnull stop) { - if (![value isKindOfClass:[NSExpression class]]) { - value = [NSExpression expressionForConstantValue:value]; - } - NSExpression *upgradedValue = value.mgl_expressionByReplacingTokensWithKeyPaths; - if (upgradedValue != value) { - if (!upgradedStops) { - upgradedStops = [stops mutableCopy]; - } - upgradedStops[zoomLevel] = upgradedValue; - } - }]; - return upgradedStops ?: stops; -}; - -- (NSExpression *)mgl_expressionByReplacingTokensWithKeyPaths { - switch (self.expressionType) { - case NSConstantValueExpressionType: { - NSString *constantValue = self.constantValue; - if ([constantValue isKindOfClass:[NSString class]] && - [constantValue containsString:@"{"] && [constantValue containsString:@"}"]) { - NSMutableArray *components = [NSMutableArray array]; - NSScanner *scanner = [NSScanner scannerWithString:constantValue]; - scanner.charactersToBeSkipped = nil; - while (!scanner.isAtEnd) { - NSString *string; - if ([scanner scanUpToString:@"{" intoString:&string]) { - [components addObject:[NSExpression expressionForConstantValue:string]]; - } - - NSString *token; - if ([scanner scanString:@"{" intoString:NULL] - && [scanner scanUpToString:@"}" intoString:&token] - && [scanner scanString:@"}" intoString:NULL]) { - [components addObject:[NSExpression expressionForKeyPath:token]]; - } - } - if (components.count == 1) { - return components.firstObject; - } - return [NSExpression expressionForFunction:@"mgl_join:" - arguments:@[[NSExpression expressionForAggregate:components]]]; - } - NSDictionary *stops = self.constantValue; - if ([stops isKindOfClass:[NSDictionary class]]) { - NSDictionary *localizedStops = MGLStopDictionaryByReplacingTokensWithKeyPaths(stops); - if (localizedStops != stops) { - return [NSExpression expressionForConstantValue:localizedStops]; - } - } - return self; - } - - case NSFunctionExpressionType: { - if ([MGLTokenizedFunctions containsObject:self.function]) { - NSArray *arguments = self.arguments; - NSArray *localizedArguments = MGLCollectionByReplacingTokensWithKeyPaths(arguments); - if (localizedArguments != arguments) { - return [NSExpression expressionForFunction:self.operand selectorName:self.function arguments:localizedArguments]; - } - } - return self; - } - - default: - return self; - } -} - @end @implementation NSObject (MGLExpressionAdditions) |