]> err.no Git - sope/blob - sope-core/NGExtensions/FdExt.subproj/NSArray+enumerator.m
removed & as a URL safe char
[sope] / sope-core / NGExtensions / FdExt.subproj / NSArray+enumerator.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "NSArray+enumerator.h"
24 #include "common.h"
25
26 @implementation NSArray(enumerator)
27
28 - (id)initWithObjectsFromEnumerator:(NSEnumerator *)_enumerator {
29   NSMutableArray *array = nil;
30   
31   array = [[NSMutableArray alloc]
32                            initWithObjectsFromEnumerator:_enumerator];
33   self = [self initWithArray:array];
34   [array release]; array = nil;
35   return self;
36 }
37
38 /* mapping */
39
40 - (NSArray *)mappedArrayUsingSelector:(SEL)_selector {
41   int i, count = [self count];
42   id  objects[count];
43   IMP objAtIndex;
44   
45   if (_selector == NULL) return self;
46
47   objAtIndex = [self methodForSelector:@selector(objectAtIndex:)];
48
49   for (i = 0; i < count; i++) {
50     objects[i] = objAtIndex(self, @selector(objectAtIndex:), i);
51     objects[i] = [objects[i] performSelector:_selector];
52     if (objects[i] == nil)
53       objects[i] = [NSNull null];
54   }
55
56   return [NSArray arrayWithObjects:objects count:count];
57 }
58 - (NSArray *)mappedArrayUsingSelector:(SEL)_selector withObject:(id)_object {
59   int i, count = [self count];
60   id  objects[count];
61   IMP objAtIndex;
62   
63   if (_selector == NULL) return self;
64
65   objAtIndex = [self methodForSelector:@selector(objectAtIndex:)];
66
67   for (i = 0; i < count; i++) {
68     objects[i] = [objAtIndex(self, @selector(objectAtIndex:), i)
69                             performSelector:_selector withObject:_object];
70
71     if (objects[i] == nil)
72       objects[i] = [NSNull null];
73   }
74
75   return [NSArray arrayWithObjects:objects count:count];
76 }
77
78 - (NSSet *)mappedSetUsingSelector:(SEL)_selector {
79   return [NSSet setWithArray:[self mappedArrayUsingSelector:_selector]];
80 }
81 - (NSSet *)mappedSetUsingSelector:(SEL)_selector withObject:(id)_object {
82   return [NSSet setWithArray:[self mappedArrayUsingSelector:_selector
83                                    withObject:_object]];
84 }
85
86 #if !LIB_FOUNDATION_LIBRARY
87
88 - (NSArray *)map:(SEL)_sel {
89   unsigned int index, count;
90   id array;
91   
92   count = [self count];
93   array = [NSMutableArray arrayWithCapacity:count];
94   for (index = 0; index < count; index++) {
95     [array insertObject:[[self objectAtIndex:index] performSelector:_sel]
96            atIndex:index];
97   }
98   return array;
99 }
100
101 - (NSArray *)map:(SEL)_sel with:(id)_arg {
102   unsigned int index, count;
103   id array;
104   
105   count = [self count];
106   array = [NSMutableArray arrayWithCapacity:count];
107   for (index = 0; index < count; index++) {
108     [array insertObject:[[self objectAtIndex:index]
109                                performSelector:_sel withObject:_arg]
110            atIndex:index];
111   }
112   return array;
113 }
114
115 #endif
116
117 @end /* NSArray(enumerator) */
118
119 @implementation NSMutableArray(enumerator) 
120
121 - (id)initWithObjectsFromEnumerator:(NSEnumerator *)_enumerator {
122   if ((self = [self init])) {
123     id obj = nil;
124      
125     while ((obj = [_enumerator nextObject]))
126       [self addObject:obj];
127   }
128   return self;
129 }
130
131 @end /* NSMutableArray(enumerator)  */
132
133 void __link_NGExtensions_NSArrayEnumerator() {
134   __link_NGExtensions_NSArrayEnumerator();
135 }