summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-04-11 10:37:43 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-04-12 10:11:53 -0400
commitb889e608c569a53f3853055d6c2cbd60b09cada6 (patch)
tree6b23d8b16d0e84f4dfcb10e2805d5cc4d42a6308
parentd6139f0d0bec9cd489aa117a2cf956f31e5db9cf (diff)
downloadqtlocation-mapboxgl-b889e608c569a53f3853055d6c2cbd60b09cada6.tar.gz
[ios, macos] Add NSPredicate 'IN' expression filter support .
-rw-r--r--platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm5
-rw-r--r--platform/darwin/src/NSPredicate+MGLAdditions.mm4
-rw-r--r--platform/darwin/test/MGLPredicateTests.mm12
3 files changed, 20 insertions, 1 deletions
diff --git a/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm b/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm
index 8b29199c7c..d738132e8d 100644
--- a/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm
+++ b/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm
@@ -333,11 +333,14 @@
options:0];
return @[op, leftHandPredicate.mgl_jsonExpressionObject, rightHandPredicate.mgl_jsonExpressionObject];
}
+ case NSInPredicateOperatorType: {
+ op = @"match";
+ break;
+ }
case NSMatchesPredicateOperatorType:
case NSLikePredicateOperatorType:
case NSBeginsWithPredicateOperatorType:
case NSEndsWithPredicateOperatorType:
- case NSInPredicateOperatorType:
case NSCustomSelectorPredicateOperatorType:
case NSContainsPredicateOperatorType:
[NSException raise:NSInvalidArgumentException
diff --git a/platform/darwin/src/NSPredicate+MGLAdditions.mm b/platform/darwin/src/NSPredicate+MGLAdditions.mm
index ba616d2228..aeaf667b45 100644
--- a/platform/darwin/src/NSPredicate+MGLAdditions.mm
+++ b/platform/darwin/src/NSPredicate+MGLAdditions.mm
@@ -319,6 +319,10 @@ NSArray *MGLSubpredicatesWithJSONObjects(NSArray *objects) {
NSArray *subpredicates = MGLSubpredicatesWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]);
return [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates];
}
+ if ([op isEqualToString:@"match"]) {
+ NSArray *subpredicates = MGLSubexpressionsWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]);
+ return [NSPredicate predicateWithFormat:@"%@ IN %@" argumentArray:subpredicates];
+ }
NSAssert(NO, @"Unrecognized expression conditional operator %@.", op);
return nil;
diff --git a/platform/darwin/test/MGLPredicateTests.mm b/platform/darwin/test/MGLPredicateTests.mm
index 6cce110619..b80dcb581f 100644
--- a/platform/darwin/test/MGLPredicateTests.mm
+++ b/platform/darwin/test/MGLPredicateTests.mm
@@ -598,6 +598,18 @@ namespace mbgl {
XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected);
XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:expected], predicate);
}
+ {
+ NSArray *expected = @[@"match", @[@"id"], @[@"literal", @[@6, @5, @4, @3]]];
+ NSPredicate *predicate = [NSPredicate predicateWithFormat:@"$mgl_featureIdentifier IN { 6, 5, 4, 3}"];
+ XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected);
+ XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:expected], predicate);
+ }
+ {
+ NSArray *expected = @[@"!", @[@"match", @[@"get", @"x"], @[@"literal", @[@6, @5, @4, @3]]]];
+ NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT x IN { 6, 5, 4, 3}"];
+ XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected);
+ XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:expected], predicate);
+ }
}
@end