NSPredicate fixes

This commit is contained in:
Christopher Lloyd 2010-10-20 11:06:44 -04:00
parent 0cd1d0ccac
commit 39fe18177f
2 changed files with 19 additions and 6 deletions

View File

@ -227,11 +227,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
case NSMatchesPredicateOperatorType:
NSUnimplementedMethod();
return NO;
return YES;
case NSLikePredicateOperatorType:
NSUnimplementedMethod();
return NO;
return YES;
case NSBeginsWithPredicateOperatorType:{
NSRange range = NSMakeRange(0,[rightResult length]);
@ -260,11 +260,17 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(BOOL)evaluateWithObject:(id)object{
NSMutableArray *values = [NSMutableArray array];
NSComparisonPredicateModifier modifier = [self comparisonPredicateModifier];
id leftValue = [[self leftExpression] expressionValueWithObject:object context:NULL];
if(modifier==NSDirectPredicateModifier)
if(modifier==NSDirectPredicateModifier){
/* It is possible for an expression to return nil (constant or keypath for example), comparisons consider
NSNull and nil equal (right?), so we just use NSNull here since you can use nil in an array */
if(leftValue==nil)
leftValue=[NSNull null];
[values addObject:leftValue];
}
else{
if ([[self leftExpression] expressionType] != NSKeyPathExpressionType || !([leftValue isKindOfClass:[NSArray class]] || [leftValue isKindOfClass:[NSSet class]]))
[NSException raise:NSInvalidArgumentException format:@"The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet"];
@ -276,8 +282,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
id value;
while ((value = [e nextObject])!=nil) {
BOOL eval = [self _evaluateValue:value withObject:(id)object];
if (eval == (modifier != NSAllPredicateModifier)) return eval;
if (eval == (modifier != NSAllPredicateModifier))
return eval;
}
return result;
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
/* Copyright (c) 2007 Christopher J. W. Lloyd <cjwl@objc.net>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@ -6,6 +6,7 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import "NSExpression_constant.h"
#import <Foundation/NSString.h>
@implementation NSExpression_constant
@ -29,6 +30,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-(NSString *)description {
if(_value==nil)
return @"nil";
// FIX, strings should be quoted, others ?
return [_value description];
}