2008-02-14 14:07:10 +00:00
|
|
|
//
|
|
|
|
// NSComparisonPredicate+CogPredicate.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Matthew Grinshpun on 14/02/08.
|
|
|
|
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "NSComparisonPredicate+CogPredicate.h"
|
|
|
|
|
|
|
|
// Ignore case and diacritics
|
2022-02-07 05:49:27 +00:00
|
|
|
static const unsigned OPTIONS = (NSCaseInsensitivePredicateOption |
|
2008-02-14 14:07:10 +00:00
|
|
|
NSDiacriticInsensitivePredicateOption);
|
|
|
|
|
|
|
|
@implementation NSComparisonPredicate (CogPredicate)
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSPredicate *)predicateForMdKey:(NSString *)key
|
|
|
|
withString:(NSString *)aString
|
|
|
|
exactString:(BOOL)exactString {
|
|
|
|
// We don't want an exact string, so wrap it in wildcards
|
|
|
|
if(!exactString)
|
|
|
|
aString = [NSString stringWithFormat:@"*%@*", aString];
|
|
|
|
|
|
|
|
return [NSComparisonPredicate
|
|
|
|
predicateWithLeftExpression:[NSExpression expressionForKeyPath:key]
|
|
|
|
rightExpression:[NSExpression expressionForConstantValue:aString]
|
|
|
|
modifier:NSDirectPredicateModifier
|
|
|
|
type:NSLikePredicateOperatorType
|
|
|
|
options:OPTIONS];
|
2008-02-14 14:07:10 +00:00
|
|
|
}
|
|
|
|
|
2008-02-14 17:48:32 +00:00
|
|
|
@end
|