merge of 'd5bcd77c68cb679b5a1b9a23a4cc86038b0e615e'

and 'ed0cae805a538abfe1c738e426b04f59baa43949'

Monotone-Parent: d5bcd77c68cb679b5a1b9a23a4cc86038b0e615e
Monotone-Parent: ed0cae805a538abfe1c738e426b04f59baa43949
Monotone-Revision: b1d9b0e8b48341b65d5f440bceeee81fb590bb3e

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2008-08-22T18:44:10
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau 2008-08-22 18:44:10 +00:00
commit 7f03974b4f

View file

@ -161,12 +161,12 @@ static NSMutableCharacterSet *urlStartChars = nil;
if (!urlNonEndingChars)
{
urlNonEndingChars = [NSMutableCharacterSet new];
[urlNonEndingChars addCharactersInString: @"=,.:;\t \r\n"];
[urlNonEndingChars addCharactersInString: @"=,.:;&\t \r\n"];
}
if (!urlAfterEndingChars)
{
urlAfterEndingChars = [NSMutableCharacterSet new];
[urlAfterEndingChars addCharactersInString: @"&[]\t \r\n"];
[urlAfterEndingChars addCharactersInString: @"[]\t \r\n"];
}
start = refRange.location;
@ -199,7 +199,7 @@ static NSMutableCharacterSet *urlStartChars = nil;
NSMutableArray *newRanges;
NSRange matchRange, currentUrlRange, rest;
NSString *urlText, *newUrlText, *range;
unsigned int length, matchLength;
unsigned int length, matchLength, offset;
int startLocation;
if (!urlStartChars)
@ -224,7 +224,6 @@ static NSMutableCharacterSet *urlStartChars = nil;
matchRange.location = startLocation + 1;
currentUrlRange = [selfCopy _rangeOfURLInRange: matchRange];
if ([ranges hasRangeIntersection: currentUrlRange])
rest.location = NSMaxRange(currentUrlRange);
else
@ -240,18 +239,21 @@ static NSMutableCharacterSet *urlStartChars = nil;
options: 0 range: rest];
}
// Make the substitutions, in reverse order
enumRanges = [newRanges reverseObjectEnumerator];
// Make the substitutions, keep track of the new offset
offset = 0;
enumRanges = [newRanges objectEnumerator];
range = [enumRanges nextObject];
while (range)
{
currentUrlRange = NSRangeFromString(range);
currentUrlRange = NSRangeFromString(range);
currentUrlRange.location += offset;
urlText = [selfCopy substringFromRange: currentUrlRange];
if ([urlText hasPrefix: prefix]) prefix = @"";
newUrlText = [NSString stringWithFormat: @"<a href=\"%@%@\">%@</a>",
prefix, urlText, urlText];
[selfCopy replaceCharactersInRange: currentUrlRange
withString: newUrlText];
offset += ([newUrlText length] - [urlText length]);
// Add range for further substitutions
currentUrlRange = NSMakeRange (currentUrlRange.location, [newUrlText length]);