1 /* NSArray+NGCards.m - this file is part of SOPE
3 * Copyright (C) 2006 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
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)
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.
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.
23 #import <Foundation/NSString.h>
25 #import "CardElement.h"
26 #import "NSString+NGCards.h"
28 #import "NSArray+NGCards.h"
30 @implementation NSArray (NGCardsExtensions)
32 - (NSString *) valueForCaseInsensitiveString: (NSString *) aString
34 NSString *currentString, *resultString, *cmpString;
35 unsigned int count, max;
41 cmpString = [aString uppercaseString];
43 while (!resultString && count < max)
45 currentString = [self objectAtIndex: count];
46 if ([[currentString uppercaseString] isEqualToString: cmpString])
47 resultString = currentString;
55 - (BOOL) hasCaseInsensitiveString: (NSString *) aString
57 return ([self valueForCaseInsensitiveString: aString] != nil);
60 - (NSArray *) cardElementsWithTag: (NSString *) aTag
62 NSMutableArray *matchingElements;
63 NSEnumerator *allElements;
64 CardElement *currentElement;
65 NSString *cmpTag, *currentTag;
67 cmpTag = [aTag uppercaseString];
69 matchingElements = [NSMutableArray new];
70 [matchingElements autorelease];
72 allElements = [self objectEnumerator];
73 currentElement = [allElements nextObject];
74 while (currentElement)
76 currentTag = [[currentElement tag] uppercaseString];
77 if ([currentTag isEqualToString: cmpTag])
78 [matchingElements addObject: currentElement];
79 currentElement = [allElements nextObject];
82 return matchingElements;
85 - (NSArray *) cardElementsWithAttribute: (NSString *) anAttribute
86 havingValue: (NSString *) aValue
88 NSMutableArray *matchingElements;
89 NSEnumerator *allElements;
90 CardElement *currentElement;
92 allElements = [self objectEnumerator];
94 matchingElements = [NSMutableArray new];
95 [matchingElements autorelease];
96 currentElement = [allElements nextObject];
97 while (currentElement)
99 if ([currentElement hasAttribute: anAttribute
100 havingValue: aValue])
101 [matchingElements addObject: currentElement];
102 currentElement = [allElements nextObject];
105 return matchingElements;
108 - (NSArray *) renderedForCards
110 NSMutableArray *purified;
112 NSEnumerator *strings;
114 purified = [NSMutableArray arrayWithCapacity: [self count]];
115 strings = [self objectEnumerator];
116 string = [strings nextObject];
119 [purified addObject: [string escapedForCards]];
120 string = [strings nextObject];