From 843be30a45c905ac54ac900c2dbf4f2edd42b33f Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 30 Dec 2011 19:45:58 +0000 Subject: [PATCH] Monotone-Parent: 28ce727aaf05b14f23fbcec914f8b827755f3483 Monotone-Revision: ec02ae62fee05e50774a4da52cc17e4811526340 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-12-30T19:45:58 Monotone-Branch: ca.inverse.sogo --- SOPE/NGCards/CardGroup.h | 5 ++++- SOPE/NGCards/CardGroup.m | 30 ++++++++++++++++++++++++++++++ SOPE/NGCards/ChangeLog | 6 ++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/SOPE/NGCards/CardGroup.h b/SOPE/NGCards/CardGroup.h index 4535f041d..117d00c54 100644 --- a/SOPE/NGCards/CardGroup.h +++ b/SOPE/NGCards/CardGroup.h @@ -46,12 +46,15 @@ - (CardElement *) uniqueChildWithTag: (NSString *) aTag; - (void) setUniqueChild: (CardElement *) aChild; +- (NSMutableArray *) children; + - (void) addChild: (CardElement *) aChild; - (void) addChildren: (NSArray *) someChildren; - (void) removeChild: (CardElement *) aChild; - (void) removeChildren: (NSArray *) someChildren; -- (NSMutableArray *) children; +- (void) cleanupEmptyChildren; + - (CardElement *) firstChildWithTag: (NSString *) aTag; - (NSArray *) childrenWithTag: (NSString *) aTag; - (NSArray *) childrenWithAttribute: (NSString *) anAttribute diff --git a/SOPE/NGCards/CardGroup.m b/SOPE/NGCards/CardGroup.m index c6ef8bb62..d19b1a321 100644 --- a/SOPE/NGCards/CardGroup.m +++ b/SOPE/NGCards/CardGroup.m @@ -142,6 +142,19 @@ static NGCardsSaxHandler *sax = nil; return nil; } +- (BOOL) isVoid +{ + BOOL isVoid = YES; + NSUInteger count, max; + + max = [children count]; + for (count = 0; isVoid && count < max; count++) + if (![[children objectAtIndex: count] isVoid]) + isVoid = NO; + + return isVoid; +} + - (void) addChild: (CardElement *) aChild { Class mappedClass; @@ -366,6 +379,23 @@ static NGCardsSaxHandler *sax = nil; [self addChild: newChild]; } +- (void) cleanupEmptyChildren +{ + NSUInteger max; + NSInteger count; + CardElement *child; + + max = [children count]; + for (count = max - 1; count > -1; count--) + { + child = [children objectAtIndex: count]; + if ([child isKindOfClass: [CardGroup class]]) + [(CardGroup *) child cleanupEmptyChildren]; + if ([child isVoid]) + [children removeObjectAtIndex: count]; + } +} + - (NSString *) description { NSMutableString *str; diff --git a/SOPE/NGCards/ChangeLog b/SOPE/NGCards/ChangeLog index b78570076..5b111eefd 100644 --- a/SOPE/NGCards/ChangeLog +++ b/SOPE/NGCards/ChangeLog @@ -1,3 +1,9 @@ +2011-12-30 Wolfgang Sourdeau + + * CardGroup.m (-isVoid): overriden method. + (-cleanupEmptyChildren): make use of "isVoid" to detect and remove + empty children. + 2011-11-21 Francis Lachapelle * iCalTimeZone.m (+knownTimeZoneNames): ignore files that don't