From 97f9609afb1b762633c938e480359e7b9d7b1102 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 10 Jun 2009 20:54:02 +0000 Subject: [PATCH] Monotone-Parent: 810ca1c510af3f2653d3478ccb575204bc309c5a Monotone-Revision: d3d21b70ee927b400d90095e3cd2ed9de1afc2f4 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2009-06-10T20:54:02 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 10 ++++++ SoObjects/SOGo/NSArray+Utilities.h | 6 +++- SoObjects/SOGo/NSArray+Utilities.m | 36 ++++++++++++++++++--- SoObjects/SOGo/NSString+Utilities.m | 49 +++++++++++++++-------------- 4 files changed, 72 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e8bd9180..d5cc529f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2009-06-10 Wolfgang Sourdeau + * SoObjects/SOGo/NSString+Utilities.m (-stringByDetectingURLs): + fixed a leak. Fixed a crash on GNUstep by using arrays of pointers + to NSRange instead of converting/parsing them to/from NSString. + + * SoObjects/SOGo/NSArray+Utilities.m (-addRange): removed method. + (-addNonNSObject:withSize:copy:): new helper method to add object + pointers to arrays. + (-freeNonNSObjects): new helper method to release the above object + pointers. + * UI/MailPartViewers/UIxMailPartHTMLViewer.m: fixed rendering of CSS content containing comment characters. Ignore certain HTML tags that can alter the appearance of the SOGo display altogether diff --git a/SoObjects/SOGo/NSArray+Utilities.h b/SoObjects/SOGo/NSArray+Utilities.h index 1f379d475..4f9cf4aab 100644 --- a/SoObjects/SOGo/NSArray+Utilities.h +++ b/SoObjects/SOGo/NSArray+Utilities.h @@ -53,9 +53,13 @@ @interface NSMutableArray (SOGoArrayUtilities) +- (void) addNonNSObject: (void *) objectPtr + withSize: (size_t) objectSize + copy: (BOOL) doCopy; +- (void) freeNonNSObjects; + - (void) addObjectUniquely: (id) object; -- (void) addRange: (NSRange) newRange; - (BOOL) hasRangeIntersection: (NSRange) testRange; @end diff --git a/SoObjects/SOGo/NSArray+Utilities.m b/SoObjects/SOGo/NSArray+Utilities.m index 857371f07..51b5f19b1 100644 --- a/SoObjects/SOGo/NSArray+Utilities.m +++ b/SoObjects/SOGo/NSArray+Utilities.m @@ -24,6 +24,7 @@ #import #import #import +#import #import "NSArray+Utilities.h" @@ -199,17 +200,42 @@ @implementation NSMutableArray (SOGoArrayUtilities) +- (void) addNonNSObject: (void *) objectPtr + withSize: (size_t) objectSize + copy: (BOOL) doCopy +{ + void *newObjectPtr; + + if (doCopy) + { + newObjectPtr = NSZoneMalloc (NULL, objectSize); + memcpy (newObjectPtr, objectPtr, objectSize); + } + else + newObjectPtr = objectPtr; + + [self addObject: [NSValue valueWithPointer: newObjectPtr]]; +} + +- (void) freeNonNSObjects +{ + unsigned int count, max; + void *objectPtr; + + max = [self count]; + for (count = 0; count < max; count++) + { + objectPtr = [[self objectAtIndex: count] pointerValue]; + NSZoneFree (NULL, objectPtr); + } +} + - (void) addObjectUniquely: (id) object { if (![self containsObject: object]) [self addObject: object]; } -- (void) addRange: (NSRange) newRange -{ - [self addObject: NSStringFromRange (newRange)]; -} - - (BOOL) hasRangeIntersection: (NSRange) testRange { NSEnumerator *ranges; diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index 66fdbafba..d9a2027d4 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -23,6 +23,7 @@ #import #import #import +#import #import @@ -88,7 +89,7 @@ static NSMutableCharacterSet *urlStartChars = nil; r = [self rangeOfString:@"?" options: NSBackwardsSearch]; if (r.length > 0) - newUrl = [self substringToIndex: NSMaxRange(r) - 1]; + newUrl = [self substringToIndex: NSMaxRange (r) - 1]; else newUrl = self; @@ -132,11 +133,10 @@ static NSMutableCharacterSet *urlStartChars = nil; { nsEnclosing = [self rangeOfString: @"}"]; length = [self length]; - if (nsEnclosing.length > 0 - && nsEnclosing.location < (length - 1)) + if (nsEnclosing.length > 0 && nsEnclosing.location < (length - 1)) { - methodEnclosing = NSMakeRange(nsEnclosing.location + 1, - length - nsEnclosing.location - 1); + methodEnclosing = NSMakeRange (nsEnclosing.location + 1, + length - nsEnclosing.location - 1); nsEnclosing.length = nsEnclosing.location - 1; nsEnclosing.location = 1; davInvocation = [NSMutableDictionary dictionaryWithCapacity: 2]; @@ -176,7 +176,7 @@ static NSMutableCharacterSet *urlStartChars = nil; start--; start++; length = [self length] - start; - workRange = NSMakeRange(start, length); + workRange = NSMakeRange (start, length); workRange = [self rangeOfCharacterFromSet: urlAfterEndingChars options: NSLiteralSearch range: workRange]; if (workRange.location != NSNotFound) @@ -198,7 +198,8 @@ static NSMutableCharacterSet *urlStartChars = nil; NSEnumerator *enumRanges; NSMutableArray *newRanges; NSRange matchRange, currentUrlRange, rest; - NSString *urlText, *newUrlText, *range; + NSRange *rangePtr; + NSString *urlText, *newUrlText; unsigned int length, matchLength, offset; int startLocation; @@ -209,10 +210,11 @@ static NSMutableCharacterSet *urlStartChars = nil; @"ABCDEFGHIJKLMNOPQRSTUVWXYZ" @"0123456789:@"]; } - newRanges = [NSMutableArray new]; + + newRanges = [NSMutableArray array]; matchLength = [match length]; rest.location = -1; - + matchRange = [selfCopy rangeOfString: match]; while (matchRange.location != NSNotFound) { @@ -225,12 +227,14 @@ static NSMutableCharacterSet *urlStartChars = nil; currentUrlRange = [selfCopy _rangeOfURLInRange: matchRange]; if ([ranges hasRangeIntersection: currentUrlRange]) - rest.location = NSMaxRange(currentUrlRange); + rest.location = NSMaxRange (currentUrlRange); else { if (currentUrlRange.length > matchLength) - [newRanges addRange: currentUrlRange]; - rest.location = NSMaxRange(currentUrlRange); + [newRanges addNonNSObject: ¤tUrlRange + withSize: sizeof (NSRange) + copy: YES]; + rest.location = NSMaxRange (currentUrlRange); } length = [selfCopy length]; @@ -242,25 +246,24 @@ static NSMutableCharacterSet *urlStartChars = nil; // Make the substitutions, keep track of the new offset offset = 0; enumRanges = [newRanges objectEnumerator]; - range = [enumRanges nextObject]; - while (range) + while ((rangePtr = [[enumRanges nextObject] pointerValue])) { - currentUrlRange = NSRangeFromString(range); - currentUrlRange.location += offset; - urlText = [selfCopy substringFromRange: currentUrlRange]; + rangePtr->location += offset; + urlText = [selfCopy substringFromRange: *rangePtr]; if ([urlText hasPrefix: prefix]) prefix = @""; newUrlText = [NSString stringWithFormat: @"%@", prefix, urlText, urlText]; - [selfCopy replaceCharactersInRange: currentUrlRange + [selfCopy replaceCharactersInRange: *rangePtr withString: newUrlText]; offset += ([newUrlText length] - [urlText length]); // Add range for further substitutions currentUrlRange = NSMakeRange (currentUrlRange.location, [newUrlText length]); - [ranges addRange: currentUrlRange]; - - range = [enumRanges nextObject]; + [ranges addNonNSObject: ¤tUrlRange + withSize: sizeof (NSRange) + copy: YES]; } + [newRanges freeNonNSObjects]; } - (NSString *) stringByDetectingURLs @@ -268,7 +271,7 @@ static NSMutableCharacterSet *urlStartChars = nil; NSMutableString *selfCopy; NSMutableArray *ranges; - ranges = [NSMutableArray new]; + ranges = [NSMutableArray array]; selfCopy = [NSMutableString stringWithString: self]; [self _handleURLs: selfCopy textToMatch: @"://" @@ -278,7 +281,7 @@ static NSMutableCharacterSet *urlStartChars = nil; textToMatch: @"@" prefix: @"mailto:" inRanges: ranges]; - [ranges release]; + [ranges freeNonNSObjects]; return selfCopy; }