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;
40 cmpString = [aString uppercaseString];
45 while (!found && count < max)
47 currentString = [self objectAtIndex: count];
48 if ([[currentString uppercaseString] isEqualToString: cmpString])
55 resultString = currentString;
62 - (BOOL) hasCaseInsensitiveString: (NSString *) aString
64 return ([self valueForCaseInsensitiveString: aString] != nil);
67 - (NSArray *) cardElementsWithTag: (NSString *) aTag
69 NSMutableArray *matchingElements;
70 NSEnumerator *allElements;
71 CardElement *currentElement;
72 NSString *cmpTag, *currentTag;
74 cmpTag = [aTag uppercaseString];
76 matchingElements = [NSMutableArray new];
77 [matchingElements autorelease];
79 allElements = [self objectEnumerator];
80 currentElement = [allElements nextObject];
81 while (currentElement)
83 currentTag = [[currentElement tag] uppercaseString];
84 if ([currentTag isEqualToString: cmpTag])
85 [matchingElements addObject: currentElement];
86 currentElement = [allElements nextObject];
89 return matchingElements;
92 - (NSArray *) cardElementsWithAttribute: (NSString *) anAttribute
93 havingValue: (NSString *) aValue
95 NSMutableArray *matchingElements;
96 NSEnumerator *allElements;
97 CardElement *currentElement;
99 allElements = [self objectEnumerator];
101 matchingElements = [NSMutableArray new];
102 [matchingElements autorelease];
103 currentElement = [allElements nextObject];
104 while (currentElement)
106 if ([currentElement hasAttribute: anAttribute
107 havingValue: aValue])
108 [matchingElements addObject: currentElement];
109 currentElement = [allElements nextObject];
112 return matchingElements;
115 - (NSArray *) renderedForCards
117 NSMutableArray *purified;
119 NSEnumerator *strings;
121 purified = [NSMutableArray arrayWithCapacity: [self count]];
122 strings = [self objectEnumerator];
123 string = [strings nextObject];
126 [purified addObject: [string escapedForCards]];
127 string = [strings nextObject];