mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-09 10:25:08 +00:00
Monotone-Parent: e7c4dbba9509da25ddf92578482021c0d944d8f1
Monotone-Revision: b54cbfbf869e5f43716f3c46ec9c9461fca6684f Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-05-30T20:02:27 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
2007-05-30 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* SoObjects/SOGo/NSString+Utilities.m ([-stringByDetectingURLs]):
|
||||
store ranges in an array to prevent them from intersecting with
|
||||
each other during the passes.
|
||||
|
||||
2007-05-29 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* SoObjects/Mailer/SOGoMailFolder.m ([SOGoMailFolder
|
||||
|
||||
@@ -24,9 +24,11 @@
|
||||
#import <Foundation/NSCharacterSet.h>
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
|
||||
#import "NSString+Utilities.h"
|
||||
#import "NSArray+Utilities.h"
|
||||
#import "NSDictionary+URL.h"
|
||||
|
||||
#import "NSString+Utilities.h"
|
||||
|
||||
static NSMutableCharacterSet *urlNonEndingChars = nil;
|
||||
static NSMutableCharacterSet *urlAfterEndingChars = nil;
|
||||
|
||||
@@ -145,6 +147,7 @@ static NSMutableCharacterSet *urlAfterEndingChars = nil;
|
||||
- (void) _handleURLs: (NSMutableString *) selfCopy
|
||||
textToMatch: (NSString *) match
|
||||
prefix: (NSString *) prefix
|
||||
inRanges: (NSMutableArray *) ranges
|
||||
{
|
||||
NSRange httpRange, currentURL, rest;
|
||||
NSString *urlText, *newUrlText;
|
||||
@@ -154,18 +157,24 @@ static NSMutableCharacterSet *urlAfterEndingChars = nil;
|
||||
httpRange = [selfCopy rangeOfString: match];
|
||||
while (httpRange.location != NSNotFound)
|
||||
{
|
||||
currentURL = [selfCopy _rangeOfURLInRange: httpRange];
|
||||
urlText = [selfCopy substringFromRange: currentURL];
|
||||
if ([urlText length] > matchLength)
|
||||
{
|
||||
newUrlText = [NSString stringWithFormat: @"<a href=\"%@%@\">%@</a>",
|
||||
prefix, urlText, urlText];
|
||||
[selfCopy replaceCharactersInRange: currentURL
|
||||
withString: newUrlText];
|
||||
rest.location = currentURL.location + [newUrlText length];
|
||||
}
|
||||
if ([ranges hasRangeIntersection: httpRange])
|
||||
rest.location = NSMaxRange (httpRange);
|
||||
else
|
||||
rest.location = currentURL.location + currentURL.length;
|
||||
{
|
||||
currentURL = [selfCopy _rangeOfURLInRange: httpRange];
|
||||
urlText = [selfCopy substringFromRange: currentURL];
|
||||
if ([urlText length] > matchLength)
|
||||
{
|
||||
newUrlText = [NSString stringWithFormat: @"<a href=\"%@%@\">%@</a>",
|
||||
prefix, urlText, urlText];
|
||||
[selfCopy replaceCharactersInRange: currentURL
|
||||
withString: newUrlText];
|
||||
currentURL
|
||||
= NSMakeRange (currentURL.location, [newUrlText length]);
|
||||
[ranges addRange: currentURL];
|
||||
}
|
||||
rest.location = NSMaxRange (currentURL);
|
||||
}
|
||||
length = [selfCopy length];
|
||||
rest.length = length - rest.location;
|
||||
httpRange = [selfCopy rangeOfString: match
|
||||
@@ -176,10 +185,19 @@ static NSMutableCharacterSet *urlAfterEndingChars = nil;
|
||||
- (NSString *) stringByDetectingURLs
|
||||
{
|
||||
NSMutableString *selfCopy;
|
||||
NSMutableArray *ranges;
|
||||
|
||||
ranges = [NSMutableArray new];
|
||||
selfCopy = [NSMutableString stringWithString: self];
|
||||
[self _handleURLs: selfCopy textToMatch: @"://" prefix: @""];
|
||||
[self _handleURLs: selfCopy textToMatch: @"@" prefix: @"mailto:"];
|
||||
[self _handleURLs: selfCopy
|
||||
textToMatch: @"://"
|
||||
prefix: @""
|
||||
inRanges: ranges];
|
||||
[self _handleURLs: selfCopy
|
||||
textToMatch: @"@"
|
||||
prefix: @"mailto:"
|
||||
inRanges: ranges];
|
||||
[ranges release];
|
||||
|
||||
return selfCopy;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user