From be982cdc3540fa375678b7cdf28cb74876cd7231 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 21 Aug 2008 21:40:28 +0000 Subject: [PATCH] Monotone-Parent: f4a48c355ec45a380e52409f4443bd4198ea038a Monotone-Revision: 2067a16090e68b1eac6c1e860f41b09c466ff2f5 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2008-08-21T21:40:28 Monotone-Branch: ca.inverse.sogo --- SoObjects/SOGo/NSArray+Utilities.h | 2 +- SoObjects/SOGo/NSArray+Utilities.m | 4 +++- SoObjects/SOGo/NSString+Utilities.m | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/SoObjects/SOGo/NSArray+Utilities.h b/SoObjects/SOGo/NSArray+Utilities.h index 96825c3d5..e65bef886 100644 --- a/SoObjects/SOGo/NSArray+Utilities.h +++ b/SoObjects/SOGo/NSArray+Utilities.h @@ -55,7 +55,7 @@ - (void) addObjectUniquely: (id) object; - (void) addRange: (NSRange) newRange; -- (BOOL) hasRangeIntersection: (NSRange) testRange; +- (BOOL) hasRangeIntersection: (NSRange) testRange withOffset: (unsigned int) offset; @end diff --git a/SoObjects/SOGo/NSArray+Utilities.m b/SoObjects/SOGo/NSArray+Utilities.m index a2b212d3a..c96654ecd 100644 --- a/SoObjects/SOGo/NSArray+Utilities.m +++ b/SoObjects/SOGo/NSArray+Utilities.m @@ -206,7 +206,7 @@ [self addObject: NSStringFromRange (newRange)]; } -- (BOOL) hasRangeIntersection: (NSRange) testRange +- (BOOL) hasRangeIntersection: (NSRange) testRange withOffset: (unsigned int) offset { NSEnumerator *ranges; NSString *currentRangeString; @@ -217,9 +217,11 @@ ranges = [self objectEnumerator]; currentRangeString = [ranges nextObject]; + while (!response && currentRangeString) { currentRange = NSRangeFromString (currentRangeString); + currentRange.location = currentRange.location + offset; if (NSLocationInRange (testRange.location, currentRange) || NSLocationInRange (NSMaxRange (testRange), currentRange)) response = YES; diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index 2f792e779..adc0c6763 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -197,7 +197,7 @@ static NSMutableCharacterSet *urlStartChars = nil; { NSRange httpRange, currentURL, rest; NSString *urlText, *newUrlText; - unsigned int length, matchLength; + unsigned int length, matchLength, offset; int startLocation; if (!urlStartChars) @@ -211,6 +211,7 @@ static NSMutableCharacterSet *urlStartChars = nil; httpRange = [selfCopy rangeOfString: match]; if (httpRange.location != NSNotFound) { + offset = 0; startLocation = httpRange.location; while (startLocation > -1 && [urlStartChars characterIsMember: @@ -220,7 +221,8 @@ static NSMutableCharacterSet *urlStartChars = nil; } while (httpRange.location != NSNotFound) { - if ([ranges hasRangeIntersection: httpRange]) + currentURL = [selfCopy _rangeOfURLInRange: httpRange]; + if ([ranges hasRangeIntersection: httpRange withOffset: offset]) rest.location = NSMaxRange(httpRange); else { @@ -237,6 +239,7 @@ static NSMutableCharacterSet *urlStartChars = nil; currentURL = NSMakeRange (currentURL.location, [newUrlText length]); [ranges addRange: currentURL]; + offset = offset + 9 + [prefix length]; } rest.location = NSMaxRange(currentURL); } @@ -245,6 +248,15 @@ static NSMutableCharacterSet *urlStartChars = nil; rest.length = length - rest.location; httpRange = [selfCopy rangeOfString: match options: 0 range: rest]; + if (httpRange.location != NSNotFound) + { + startLocation = httpRange.location; + while (startLocation > -1 + && [urlStartChars characterIsMember: + [selfCopy characterAtIndex: startLocation]]) + startLocation--; + httpRange.location = startLocation + 1; + } } }