fix use of preprocessor constants.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31621 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-11-18 09:46:51 +00:00
parent 4f86b23b2d
commit e594ebafce
2 changed files with 108 additions and 84 deletions

View file

@ -1,3 +1,7 @@
2010-11-18 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPredicate.m: Fixup use of preprocessor constants.
2010-11-17 Eric Wasylishen 2010-11-17 Eric Wasylishen
* Source/NSPredicate.m: Implement MATCHES and LIKE using ICU * Source/NSPredicate.m: Implement MATCHES and LIKE using ICU
@ -6,7 +10,8 @@
2010-11-13 Riccardo Mottola 2010-11-13 Riccardo Mottola
* Source/NSPathUtilities.m: * Source/NSPathUtilities.m:
Make NSDownloadDirectory and NSDocumentDIrectory relative to the user home and for the user domain only. Behaviour checked on the Mac. Make NSDownloadDirectory and NSDocumentDIrectory relative to the
user home and for the user domain only. Behaviour checked on the Mac.
2010-11-05 Richard Frith-Macdonald <rfm@gnu.org> 2010-11-05 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -812,8 +812,9 @@ static NSExpression *evaluatedObjectExpression = nil;
} }
} }
#if defined(GS_USE_ICU) #if GS_USE_ICU == 1
static BOOL GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOptions opts) static BOOL
GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOptions opts)
{ {
BOOL result = NO; BOOL result = NO;
UErrorCode error = 0; UErrorCode error = 0;
@ -908,17 +909,22 @@ static BOOL GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringC
case NSNotEqualToPredicateOperatorType: case NSNotEqualToPredicateOperatorType:
return ![leftResult isEqual: rightResult]; return ![leftResult isEqual: rightResult];
case NSMatchesPredicateOperatorType: case NSMatchesPredicateOperatorType:
#if defined(GS_USE_ICU) #if GS_USE_ICU == 1
return GSICUStringMatchesRegex(leftResult, rightResult, compareOptions); return GSICUStringMatchesRegex(leftResult, rightResult, compareOptions);
#else #else
return [leftResult compare: rightResult options: compareOptions] == NSOrderedSame; return [leftResult compare: rightResult options: compareOptions]
== NSOrderedSame;
#endif #endif
case NSLikePredicateOperatorType: case NSLikePredicateOperatorType:
#if defined(GS_USE_ICU) #if GS_USE_ICU == 1
{ {
// The right hand is a pattern with ? meaning match one character, and NSString *regex;
// * meaning match zero or more characters, so translate that into a regex
NSString *regex = [rightResult stringByReplacingOccurrencesOfString: @"*" /* The right hand is a pattern with '?' meaning match one character,
* and '*' meaning match zero or more characters, so translate that
* into a regex.
*/
regex = [rightResult stringByReplacingOccurrencesOfString: @"*"
withString: @".*"]; withString: @".*"];
regex = [regex stringByReplacingOccurrencesOfString: @"?" regex = [regex stringByReplacingOccurrencesOfString: @"?"
withString: @".?"]; withString: @".?"];
@ -926,20 +932,30 @@ static BOOL GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringC
return GSICUStringMatchesRegex(leftResult, regex, compareOptions); return GSICUStringMatchesRegex(leftResult, regex, compareOptions);
} }
#else #else
return [leftResult compare: rightResult options: compareOptions] == NSOrderedSame; return [leftResult compare: rightResult options: compareOptions]
== NSOrderedSame;
#endif #endif
case NSBeginsWithPredicateOperatorType: case NSBeginsWithPredicateOperatorType:
{ {
NSRange range = NSMakeRange(0, [rightResult length]); NSRange range = NSMakeRange(0, [rightResult length]);
return ([leftResult compare: rightResult options: compareOptions range: range] == NSOrderedSame); return ([leftResult compare: rightResult
options: compareOptions
range: range] == NSOrderedSame);
} }
case NSEndsWithPredicateOperatorType: case NSEndsWithPredicateOperatorType:
{ {
NSRange range = NSMakeRange([leftResult length] - [rightResult length], [rightResult length]); NSRange range;
return ([leftResult compare: rightResult options: compareOptions range: range] == NSOrderedSame);
range = NSMakeRange([leftResult length] - [rightResult length],
[rightResult length]);
return ([leftResult compare: rightResult
options: compareOptions
range: range] == NSOrderedSame);
} }
case NSInPredicateOperatorType: case NSInPredicateOperatorType:
// Handle special case where rightResult is a collection and leftResult an element of it. /* Handle special case where rightResult is a collection
* and leftResult an element of it.
*/
if (![rightResult isKindOfClass: [NSString class]]) if (![rightResult isKindOfClass: [NSString class]])
{ {
NSEnumerator *e; NSEnumerator *e;
@ -948,7 +964,8 @@ static BOOL GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringC
if (![rightResult respondsToSelector: @selector(objectEnumerator)]) if (![rightResult respondsToSelector: @selector(objectEnumerator)])
{ {
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"The right hand side for an IN operator must be a collection"]; format: @"The right hand side for an IN operator "
@"must be a collection"];
} }
e = [rightResult objectEnumerator]; e = [rightResult objectEnumerator];
@ -960,7 +977,9 @@ static BOOL GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringC
return NO; return NO;
} }
return ([rightResult rangeOfString: leftResult options: compareOptions].location != NSNotFound); return ([rightResult rangeOfString: leftResult
options: compareOptions].location
!= NSNotFound);
case NSCustomSelectorPredicateOperatorType: case NSCustomSelectorPredicateOperatorType:
{ {
BOOL (*function)(id,SEL,id) = (BOOL (*)(id,SEL,id))[leftResult methodForSelector: _selector]; BOOL (*function)(id,SEL,id) = (BOOL (*)(id,SEL,id))[leftResult methodForSelector: _selector];