merge of '1f97aa49aa118c4b104e4fc4fa9c4f6a320435e9'

and '81291ebd761827191a007b02ee603cd1f31fc8a3'

Monotone-Parent: 1f97aa49aa118c4b104e4fc4fa9c4f6a320435e9
Monotone-Parent: 81291ebd761827191a007b02ee603cd1f31fc8a3
Monotone-Revision: 579be7a198049057f8c207da8274dadf1702c593

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2008-08-22T14:57:36
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau 2008-08-22 14:57:36 +00:00
commit ee13e8f792
3 changed files with 45 additions and 45 deletions

View file

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

View file

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

View file

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