diff options
author | Fabian Guerra Soto <fabian.guerra@mapbox.com> | 2018-04-12 17:43:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-12 17:43:01 -0400 |
commit | 23f0222fd973956c5508f8ae879d8ce97c1b09c0 (patch) | |
tree | 0221cc9d5f9649eed1bc47315292a9be74c54f92 /platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm | |
parent | be3fc4413ab2e553c7957721bc3a7a03d414cd64 (diff) | |
download | qtlocation-mapboxgl-23f0222fd973956c5508f8ae879d8ce97c1b09c0.tar.gz |
[ios, macos] Add predicate like expressions to NSExpression (#11632)
* [ios, macos] Add NSPredicate between function.
* [ios, macos] Add NSPredicate 'IN' expression filter support .
* [ios, macos] Add NSPredicate 'CONTAINS' expression filter support.
* [ios, macos] Refactor NSPredicate operators.
* [ios, macos] Simplify NSPredicate's expression conversion code.
* [ios, macos] Make 'match' the default predicate conversion option.
Diffstat (limited to 'platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm')
-rw-r--r-- | platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm b/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm index 5b54d66aeb..c39e987d85 100644 --- a/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm +++ b/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm @@ -318,14 +318,45 @@ case NSNotEqualToPredicateOperatorType: op = @"!="; break; + case NSBetweenPredicateOperatorType: { + op = @"all"; + NSArray *limits = self.rightExpression.constantValue; + NSPredicate *leftHandPredicate = [NSComparisonPredicate predicateWithLeftExpression:limits[0] + rightExpression:self.leftExpression + modifier:NSDirectPredicateModifier + type:NSLessThanOrEqualToPredicateOperatorType + options:0]; + NSPredicate *rightHandPredicate = [NSComparisonPredicate predicateWithLeftExpression:self.leftExpression + rightExpression:limits[1] + modifier:NSDirectPredicateModifier + type:NSLessThanOrEqualToPredicateOperatorType + options:0]; + return @[op, leftHandPredicate.mgl_jsonExpressionObject, rightHandPredicate.mgl_jsonExpressionObject]; + } + case NSInPredicateOperatorType: { + NSMutableArray *elements = [NSMutableArray arrayWithObjects:@"match", self.leftExpression.mgl_jsonExpressionObject, nil]; + NSArray *optionsExpressions = self.rightExpression.constantValue; + for (id object in optionsExpressions) { + id option = ((NSExpression *)object).mgl_jsonExpressionObject; + [elements addObject:option]; + [elements addObject:@YES]; + } + [elements addObject:@NO]; + return elements; + } + case NSContainsPredicateOperatorType: { + NSPredicate *inPredicate = [NSComparisonPredicate predicateWithLeftExpression:self.rightExpression + rightExpression:self.leftExpression + modifier:self.comparisonPredicateModifier + type:NSInPredicateOperatorType + options:self.options]; + return inPredicate.mgl_jsonExpressionObject; + } case NSMatchesPredicateOperatorType: case NSLikePredicateOperatorType: case NSBeginsWithPredicateOperatorType: case NSEndsWithPredicateOperatorType: - case NSInPredicateOperatorType: case NSCustomSelectorPredicateOperatorType: - case NSContainsPredicateOperatorType: - case NSBetweenPredicateOperatorType: [NSException raise:NSInvalidArgumentException format:@"NSPredicateOperatorType:%lu is not supported.", (unsigned long)self.predicateOperatorType]; } |