Update to fix remaining issues with new NSExpression classes

This commit is contained in:
Gregory John Casamento 2024-05-28 19:10:11 -04:00
parent 48ab2e2bc7
commit 5c1e4e8eda

View file

@ -1298,7 +1298,7 @@ GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOption
e = [[GSAggregateExpression alloc]
initWithExpressionType: NSAggregateExpressionType];
ASSIGN(e->_collection, subExpressions);
ASSIGN(e->_collection, [NSSet setWithArray: subExpressions]);
return AUTORELEASE(e);
}
@ -1737,6 +1737,30 @@ GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOption
@end
// Macro for checking set related expressions
#define CHECK_SETS \
do { \
if ([rightValue isKindOfClass: [NSArray class]]) \
{ \
rightSet = [NSSet setWithArray: rightValue]; \
} \
if (!rightSet) \
{ \
[NSException raise: NSInvalidArgumentException \
format: @"Can't evaluate set expression; right subexpression is not a set (lhs = %@ rhs = %@)", leftValue, rightValue]; \
} \
if ([leftValue isKindOfClass: [NSArray class]]) \
{ \
leftSet = [NSSet setWithArray: leftValue]; \
} \
if (!leftSet) \
{ \
[NSException raise: NSInvalidArgumentException \
format: @"Can't evaluate set expression; left subexpression is not a set (lhs = %@ rhs = %@)", leftValue, rightValue]; \
} \
} while (0)
@implementation GSUnionSetExpression
- (NSString *) description
@ -1754,6 +1778,23 @@ GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOption
return _right;
}
- (id) expressionValueWithObject: (id)object
context: (NSMutableDictionary *)context
{
id leftValue = [_left expressionValueWithObject: object context: context];
id rightValue = [_right expressionValueWithObject: object context: context];
NSSet *leftSet = nil;
NSSet *rightSet = nil;
NSMutableSet *result = nil;
CHECK_SETS;
result = [NSMutableSet setWithSet: leftSet];
[result unionSet: rightSet];
return result;
}
@end
@implementation GSIntersectSetExpression
@ -1773,6 +1814,23 @@ GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOption
return _right;
}
- (id) expressionValueWithObject: (id)object
context: (NSMutableDictionary *)context
{
id leftValue = [_left expressionValueWithObject: object context: context];
id rightValue = [_right expressionValueWithObject: object context: context];
NSSet *leftSet = nil;
NSSet *rightSet = nil;
NSMutableSet *result = nil;
CHECK_SETS;
result = [NSMutableSet setWithSet: leftSet];
[result intersectSet: rightSet];
return result;
}
@end
@implementation GSMinusSetExpression
@ -1792,6 +1850,23 @@ GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOption
return _right;
}
- (id) expressionValueWithObject: (id)object
context: (NSMutableDictionary *)context
{
id leftValue = [_left expressionValueWithObject: object context: context];
id rightValue = [_right expressionValueWithObject: object context: context];
NSSet *leftSet = nil;
NSSet *rightSet = nil;
NSMutableSet *result = nil;
CHECK_SETS;
result = [NSMutableSet setWithSet: leftSet];
[result minusSet: rightSet];
return result;
}
@end
@implementation GSSubqueryExpression