]> err.no Git - scalable-opengroupware.org/blob - SOPE/NGCards/NSArray+NGCards.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1021 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SOPE / NGCards / NSArray+NGCards.m
1 /* NSArray+NGCards.m - this file is part of SOPE
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #import <Foundation/NSString.h>
24
25 #import "CardElement.h"
26 #import "NSString+NGCards.h"
27
28 #import "NSArray+NGCards.h"
29
30 @implementation NSArray (NGCardsExtensions)
31
32 - (NSString *) valueForCaseInsensitiveString: (NSString *) aString
33 {
34   NSString *currentString, *resultString, *cmpString;
35   unsigned int count, max;
36   BOOL found;
37
38   found = NO;
39
40   cmpString = [aString uppercaseString];
41   max = [self count];
42   count = 0;
43
44   currentString = nil;
45   while (!found && count < max)
46     {
47       currentString = [self objectAtIndex: count];
48       if ([[currentString uppercaseString] isEqualToString: cmpString])
49         found = YES;
50       else
51         count++;
52     }
53
54   if (found)
55     resultString = currentString;
56   else
57     resultString = nil;
58
59   return resultString;
60 }
61
62 - (BOOL) hasCaseInsensitiveString: (NSString *) aString
63 {
64   return ([self valueForCaseInsensitiveString: aString] != nil);
65 }
66
67 - (NSArray *) cardElementsWithTag: (NSString *) aTag
68 {
69   NSMutableArray *matchingElements;
70   NSEnumerator *allElements;
71   CardElement *currentElement;
72   NSString *cmpTag, *currentTag;
73
74   cmpTag = [aTag uppercaseString];
75
76   matchingElements = [NSMutableArray new];
77   [matchingElements autorelease];
78
79   allElements = [self objectEnumerator];
80   currentElement = [allElements nextObject];
81   while (currentElement)
82     {
83       currentTag = [[currentElement tag] uppercaseString];
84       if ([currentTag isEqualToString: cmpTag])
85         [matchingElements addObject: currentElement];
86       currentElement = [allElements nextObject];
87     }
88
89   return matchingElements;
90 }
91
92 - (NSArray *) cardElementsWithAttribute: (NSString *) anAttribute
93                             havingValue: (NSString *) aValue
94 {
95   NSMutableArray *matchingElements;
96   NSEnumerator *allElements;
97   CardElement *currentElement;
98
99   allElements = [self objectEnumerator];
100
101   matchingElements = [NSMutableArray new];
102   [matchingElements autorelease];
103   currentElement = [allElements nextObject];
104   while (currentElement)
105     {
106       if ([currentElement hasAttribute: anAttribute
107                           havingValue: aValue])
108         [matchingElements addObject: currentElement];
109       currentElement = [allElements nextObject];
110     }
111
112   return matchingElements;
113 }
114
115 - (NSArray *) renderedForCards
116 {
117   NSMutableArray *purified;
118   NSString *string;
119   NSEnumerator *strings;
120
121   purified = [NSMutableArray arrayWithCapacity: [self count]];
122   strings = [self objectEnumerator];
123   string = [strings nextObject];
124   while (string)
125     {
126       [purified addObject: [string escapedForCards]];
127       string = [strings nextObject];
128     }
129
130   return purified;
131 }
132
133 @end