mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-01 09:02:01 +00:00
Add missing set filtering functionality
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27833 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
afb6e09fe8
commit
4c5051ce0f
3 changed files with 65 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2009-02-09 Xavier Glattard <xavier.glattard@online.fr>
|
||||||
|
|
||||||
|
* Headers/Foundation/NSPredicate.h:
|
||||||
|
* Source/NSPredicate.m: Declare and implement two new methods for
|
||||||
|
filtering NSSet:
|
||||||
|
* [-filterUsingPredicate:]
|
||||||
|
* [+filteredSetUsingPredicate:]
|
||||||
|
|
||||||
2009-02-09 Richard Frith-Macdonald <rfm@gnu.org>
|
2009-02-09 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/win32/NSMessagePortNameServer.m: Fix GC error on windows
|
* Source/win32/NSMessagePortNameServer.m: Fix GC error on windows
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#import <Foundation/NSObject.h>
|
#import <Foundation/NSObject.h>
|
||||||
#import <Foundation/NSArray.h>
|
#import <Foundation/NSArray.h>
|
||||||
|
#import <Foundation/NSSet.h>
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -64,6 +65,20 @@ extern "C" {
|
||||||
- (void) filterUsingPredicate: (NSPredicate *)predicate;
|
- (void) filterUsingPredicate: (NSPredicate *)predicate;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface NSSet (NSPredicate)
|
||||||
|
/** Evaluate each object in the set using the specified predicate and
|
||||||
|
* return an set containing all the objects which evaluate to YES.
|
||||||
|
*/
|
||||||
|
- (NSSet *) filteredSetUsingPredicate: (NSPredicate *)predicate;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSMutableSet (NSPredicate)
|
||||||
|
/** Evaluate each object in the set using the specified predicate and
|
||||||
|
* remove each objects which evaluates to NO.
|
||||||
|
*/
|
||||||
|
- (void) filterUsingPredicate: (NSPredicate *)predicate;
|
||||||
|
@end
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1534,6 +1534,48 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation NSSet (NSPredicate)
|
||||||
|
|
||||||
|
- (NSSet *) filteredSetUsingPredicate: (NSPredicate *)predicate
|
||||||
|
{
|
||||||
|
NSMutableSet *result;
|
||||||
|
NSEnumerator *e = [self objectEnumerator];
|
||||||
|
id object;
|
||||||
|
|
||||||
|
result = [NSMutableSet setWithCapacity: [self count]];
|
||||||
|
while ((object = [e nextObject]) != nil)
|
||||||
|
{
|
||||||
|
if ([predicate evaluateWithObject: object] == YES)
|
||||||
|
{
|
||||||
|
[result addObject: object]; // passes filter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [result makeImmutableCopyOnFail: NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation NSMutableSet (NSPredicate)
|
||||||
|
|
||||||
|
- (void) filterUsingPredicate: (NSPredicate *)predicate
|
||||||
|
{
|
||||||
|
NSMutableSet *rejected;
|
||||||
|
NSEnumerator *e = [self objectEnumerator];
|
||||||
|
id object;
|
||||||
|
|
||||||
|
rejected = [NSMutableSet setWithCapacity: [self count]];
|
||||||
|
while ((object = [e nextObject]) != nil)
|
||||||
|
{
|
||||||
|
if ([predicate evaluateWithObject: object] == NO)
|
||||||
|
{
|
||||||
|
[rejected addObject: object];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[self minusSet: rejected];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@implementation GSPredicateScanner
|
@implementation GSPredicateScanner
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue