Monotone-Parent: 1af347fe96abc17587172e207fcbf80e98d7f6f8

Monotone-Revision: 81291ebd761827191a007b02ee603cd1f31fc8a3

Monotone-Author: flachapelle@inverse.ca
Monotone-Date: 2008-08-21T23:35:34
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Francis Lachapelle 2008-08-21 23:35:34 +00:00
parent 98d6032638
commit 4e8a929769
3 changed files with 45 additions and 45 deletions

View File

@ -55,7 +55,7 @@
- (void) addObjectUniquely: (id) object;
- (void) addRange: (NSRange) newRange;
- (BOOL) hasRangeIntersection: (NSRange) testRange withOffset: (unsigned int) offset;
- (BOOL) hasRangeIntersection: (NSRange) testRange;
@end

View File

@ -206,7 +206,7 @@
[self addObject: NSStringFromRange (newRange)];
}
- (BOOL) hasRangeIntersection: (NSRange) testRange withOffset: (unsigned int) offset
- (BOOL) hasRangeIntersection: (NSRange) testRange
{
NSEnumerator *ranges;
NSString *currentRangeString;
@ -221,7 +221,6 @@
while (!response && currentRangeString)
{
currentRange = NSRangeFromString (currentRangeString);
currentRange.location = currentRange.location + offset;
if (NSLocationInRange (testRange.location, currentRange)
|| NSLocationInRange (NSMaxRange (testRange), currentRange))
response = YES;

View File

@ -195,9 +195,11 @@ static NSMutableCharacterSet *urlStartChars = nil;
prefix: (NSString *) prefix
inRanges: (NSMutableArray *) ranges
{
NSRange httpRange, currentURL, rest;
NSString *urlText, *newUrlText;
unsigned int length, matchLength, offset;
NSEnumerator *enumRanges;
NSMutableArray *newRanges;
NSRange matchRange, currentUrlRange, rest;
NSString *urlText, *newUrlText, *range;
unsigned int length, matchLength;
int startLocation;
if (!urlStartChars)
@ -207,56 +209,55 @@ static NSMutableCharacterSet *urlStartChars = nil;
@"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@"0123456789:@"];
}
newRanges = [NSMutableArray new];
matchLength = [match length];
httpRange = [selfCopy rangeOfString: match];
if (httpRange.location != NSNotFound)
rest.location = -1;
matchRange = [selfCopy rangeOfString: match];
while (matchRange.location != NSNotFound)
{
offset = 0;
startLocation = httpRange.location;
while (startLocation > -1
startLocation = matchRange.location;
while (startLocation > rest.location
&& [urlStartChars characterIsMember:
[selfCopy characterAtIndex: startLocation]])
startLocation--;
httpRange.location = startLocation + 1;
}
while (httpRange.location != NSNotFound)
{
currentURL = [selfCopy _rangeOfURLInRange: httpRange];
if ([ranges hasRangeIntersection: httpRange withOffset: offset])
rest.location = NSMaxRange(httpRange);
matchRange.location = startLocation + 1;
currentUrlRange = [selfCopy _rangeOfURLInRange: matchRange];
if ([ranges hasRangeIntersection: currentUrlRange])
rest.location = NSMaxRange(currentUrlRange);
else
{
currentURL = [selfCopy _rangeOfURLInRange: httpRange];
urlText = [selfCopy substringFromRange: currentURL];
if ([urlText length] > matchLength)
{
if ([urlText hasPrefix: prefix]) prefix = @"";
newUrlText = [NSString stringWithFormat: @"<a href=\"%@%@\">%@</a>",
prefix, urlText, urlText];
[selfCopy replaceCharactersInRange: currentURL
withString: newUrlText];
currentURL
= NSMakeRange (currentURL.location, [newUrlText length]);
[ranges addRange: currentURL];
offset = offset + 9 + [prefix length];
}
rest.location = NSMaxRange(currentURL);
if (currentUrlRange.length > matchLength)
[newRanges addRange: currentUrlRange];
rest.location = NSMaxRange(currentUrlRange);
}
length = [selfCopy length];
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;
}
matchRange = [selfCopy rangeOfString: match
options: 0 range: rest];
}
// Make the substitutions, in reverse order
enumRanges = [newRanges reverseObjectEnumerator];
range = [enumRanges nextObject];
while (range)
{
currentUrlRange = NSRangeFromString(range);
urlText = [selfCopy substringFromRange: currentUrlRange];
if ([urlText hasPrefix: prefix]) prefix = @"";
newUrlText = [NSString stringWithFormat: @"<a href=\"%@%@\">%@</a>",
prefix, urlText, urlText];
[selfCopy replaceCharactersInRange: currentUrlRange
withString: newUrlText];
// Add range for further substitutions
currentUrlRange = NSMakeRange (currentUrlRange.location, [newUrlText length]);
[ranges addRange: currentUrlRange];
range = [enumRanges nextObject];
}
}