mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-10-12 15:27:12 +00:00
Monotone-Parent: 2657547ae0e611fd831e211fb69fd2bd09cea1e4
Monotone-Revision: cb234862194e72608212740a10db0004798a152d Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-05-16T21:42:47 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
1 parent
d30e350fa8
commit
fe29404491
3 files changed
+42
-15
No files matched your search
@@ -113,12 +113,12 @@ static NSMutableCharacterSet *urlAfterEndingChars = 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;
|
||||
@@ -142,30 +142,44 @@ static NSMutableCharacterSet *urlAfterEndingChars = nil;
|
||||
return NSMakeRange (start, length);
|
||||
}
|
||||
|
||||
- (NSString *) stringByDetectingURLs
|
||||
- (void) _handleURLs: (NSMutableString *) selfCopy
|
||||
textToMatch: (NSString *) match
|
||||
prefix: (NSString *) prefix
|
||||
{
|
||||
NSMutableString *selfCopy;
|
||||
NSRange httpRange, currentURL, rest;
|
||||
NSString *urlText, *newUrlText;
|
||||
unsigned int length;
|
||||
unsigned int length, matchLength;
|
||||
|
||||
selfCopy = [NSMutableString stringWithString: self];
|
||||
|
||||
httpRange = [selfCopy rangeOfString: @"://"];
|
||||
matchLength = [match length];
|
||||
httpRange = [selfCopy rangeOfString: match];
|
||||
while (httpRange.location != NSNotFound)
|
||||
{
|
||||
currentURL = [selfCopy _rangeOfURLInRange: httpRange];
|
||||
urlText = [selfCopy substringFromRange: currentURL];
|
||||
newUrlText = [NSString stringWithFormat: @"<a href=\"%@\">%@</a>",
|
||||
urlText, urlText];
|
||||
[selfCopy replaceCharactersInRange: currentURL
|
||||
withString: newUrlText];
|
||||
if ([urlText length] > matchLength)
|
||||
{
|
||||
newUrlText = [NSString stringWithFormat: @"<a href=\"%@%@\">%@</a>",
|
||||
prefix, urlText, urlText];
|
||||
[selfCopy replaceCharactersInRange: currentURL
|
||||
withString: newUrlText];
|
||||
rest.location = currentURL.location + [newUrlText length];
|
||||
}
|
||||
else
|
||||
rest.location = currentURL.location + currentURL.length;
|
||||
length = [selfCopy length];
|
||||
rest.location = currentURL.location + [newUrlText length];
|
||||
rest.length = length - rest.location;
|
||||
httpRange = [selfCopy rangeOfString: @"://"
|
||||
httpRange = [selfCopy rangeOfString: match
|
||||
options: 0 range: rest];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *) stringByDetectingURLs
|
||||
{
|
||||
NSMutableString *selfCopy;
|
||||
|
||||
selfCopy = [NSMutableString stringWithString: self];
|
||||
[self _handleURLs: selfCopy textToMatch: @"://" prefix: @""];
|
||||
[self _handleURLs: selfCopy textToMatch: @"@" prefix: @"mailto:"];
|
||||
|
||||
return selfCopy;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user