From b1f65b01e4c424fc61ce9cae2af9097366bb117f Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 30 May 2007 20:03:19 +0000 Subject: [PATCH] Monotone-Parent: b54cbfbf869e5f43716f3c46ec9c9461fca6684f Monotone-Revision: 13b85b286011f096c4141829b528972047581e57 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-05-30T20:03:19 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 ++++++ SoObjects/SOGo/NSArray+Utilities.h | 3 +++ SoObjects/SOGo/NSArray+Utilities.m | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/ChangeLog b/ChangeLog index db848da20..8d6d2b357 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-05-30 Wolfgang Sourdeau + * SoObjects/SOGo/NSArray+Utilities.m ([NSMutableArray + -addRange:newRange]): new method that store a string + representation of the NSRange passed as parameter. + ([NSMutableArray -hasRangeIntersection:testRange]): tests whether + any range contained in self intersect with the one passed as parameter. + * SoObjects/SOGo/NSString+Utilities.m ([-stringByDetectingURLs]): store ranges in an array to prevent them from intersecting with each other during the passes. diff --git a/SoObjects/SOGo/NSArray+Utilities.h b/SoObjects/SOGo/NSArray+Utilities.h index 1f8c1bd29..025b2bcea 100644 --- a/SoObjects/SOGo/NSArray+Utilities.h +++ b/SoObjects/SOGo/NSArray+Utilities.h @@ -45,6 +45,9 @@ - (void) addObjectUniquely: (id) object; +- (void) addRange: (NSRange) newRange; +- (BOOL) hasRangeIntersection: (NSRange) testRange; + @end #endif /* NSARRAY_UTILITIES_H */ diff --git a/SoObjects/SOGo/NSArray+Utilities.m b/SoObjects/SOGo/NSArray+Utilities.m index d30f93ac3..66054efb8 100644 --- a/SoObjects/SOGo/NSArray+Utilities.m +++ b/SoObjects/SOGo/NSArray+Utilities.m @@ -91,5 +91,34 @@ [self addObject: object]; } +- (void) addRange: (NSRange) newRange +{ + [self addObject: NSStringFromRange (newRange)]; +} + +- (BOOL) hasRangeIntersection: (NSRange) testRange +{ + NSEnumerator *ranges; + NSString *currentRangeString; + NSRange currentRange; + BOOL response; + + response = NO; + + ranges = [self objectEnumerator]; + currentRangeString = [ranges nextObject]; + while (!response && currentRangeString) + { + currentRange = NSRangeFromString (currentRangeString); + if (NSLocationInRange (testRange.location, currentRange) + || NSLocationInRange (NSMaxRange (testRange), currentRange)) + response = YES; + else + currentRangeString = [ranges nextObject]; + } + + return response; +} + @end