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
* Source/NSPredicate.m: Implement MATCHES and LIKE using ICU
@ -6,7 +10,8 @@
2010-11-13 Riccardo Mottola
* 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>

View file

@ -812,8 +812,9 @@ static NSExpression *evaluatedObjectExpression = nil;
}
}
#if defined(GS_USE_ICU)
static BOOL GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOptions opts)
#if GS_USE_ICU == 1
static BOOL
GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOptions opts)
{
BOOL result = NO;
UErrorCode error = 0;
@ -908,17 +909,22 @@ static BOOL GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringC
case NSNotEqualToPredicateOperatorType:
return ![leftResult isEqual: rightResult];
case NSMatchesPredicateOperatorType:
#if defined(GS_USE_ICU)
#if GS_USE_ICU == 1
return GSICUStringMatchesRegex(leftResult, rightResult, compareOptions);
#else
return [leftResult compare: rightResult options: compareOptions] == NSOrderedSame;
return [leftResult compare: rightResult options: compareOptions]
== NSOrderedSame;
#endif
case NSLikePredicateOperatorType:
#if defined(GS_USE_ICU)
#if GS_USE_ICU == 1
{
// The right hand is a pattern with ? meaning match one character, and
// * meaning match zero or more characters, so translate that into a regex
NSString *regex = [rightResult stringByReplacingOccurrencesOfString: @"*"
NSString *regex;
/* 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: @".*"];
regex = [regex stringByReplacingOccurrencesOfString: @"?"
withString: @".?"];
@ -926,20 +932,30 @@ static BOOL GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringC
return GSICUStringMatchesRegex(leftResult, regex, compareOptions);
}
#else
return [leftResult compare: rightResult options: compareOptions] == NSOrderedSame;
return [leftResult compare: rightResult options: compareOptions]
== NSOrderedSame;
#endif
case NSBeginsWithPredicateOperatorType:
{
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:
{
NSRange range = NSMakeRange([leftResult length] - [rightResult length], [rightResult length]);
return ([leftResult compare: rightResult options: compareOptions range: range] == NSOrderedSame);
NSRange range;
range = NSMakeRange([leftResult length] - [rightResult length],
[rightResult length]);
return ([leftResult compare: rightResult
options: compareOptions
range: range] == NSOrderedSame);
}
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]])
{
NSEnumerator *e;
@ -948,7 +964,8 @@ static BOOL GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringC
if (![rightResult respondsToSelector: @selector(objectEnumerator)])
{
[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];
@ -960,7 +977,9 @@ static BOOL GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringC
return NO;
}
return ([rightResult rangeOfString: leftResult options: compareOptions].location != NSNotFound);
return ([rightResult rangeOfString: leftResult
options: compareOptions].location
!= NSNotFound);
case NSCustomSelectorPredicateOperatorType:
{
BOOL (*function)(id,SEL,id) = (BOOL (*)(id,SEL,id))[leftResult methodForSelector: _selector];