Monotone-Parent: b5675f4c42d29fc479dac10dbd4e9d6269085d3d

Monotone-Revision: 0e5da06a5c5166a41629d40ff43cf8d9f3b4335c

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-05-15T20:52:01
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2007-05-15 20:52:01 +00:00
parent 7716d54a7b
commit 7c0c9e0ef9
3 changed files with 77 additions and 1 deletions
+6
View File
@@ -1,3 +1,9 @@
2007-05-15 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* SoObjects/SOGo/NSString+Utilities.m ([NSString
-stringByDetectingURLs]): this new method replaces passive URLS
with active ones for HTML resolution of the text.
2007-05-14 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* SoObjects/Mailer/SOGoDraftObject.m ([NSString
+2
View File
@@ -38,6 +38,8 @@
- (NSString *) davMethodToObjC;
- (NSString *) stringByDetectingURLs;
#ifndef GNUSTEP_BASE_LIBRARY
- (BOOL) boolValue;
#endif
+69 -1
View File
@@ -21,11 +21,15 @@
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSCharacterSet.h>
#import <Foundation/NSEnumerator.h>
#import "NSString+Utilities.h"
#import "NSDictionary+URL.h"
static NSMutableCharacterSet *urlNonEndingChars = nil;
static NSMutableCharacterSet *urlAfterEndingChars = nil;
@implementation NSString (SOGoURLExtension)
- (NSString *) composeURLWithAction: (NSString *) action
@@ -101,7 +105,71 @@
return newName;
}
#ifndef GNUSTEP_BASE_LIBRARY
- (NSRange) _rangeOfURLInRange: (NSRange) refRange
{
int start, length;
NSRange endRange;
if (!urlNonEndingChars)
{
urlNonEndingChars = [NSMutableCharacterSet new];
[urlNonEndingChars addCharactersInString: @",.:;\t \r\n"];
}
if (!urlAfterEndingChars)
{
urlAfterEndingChars = [NSMutableCharacterSet new];
[urlAfterEndingChars addCharactersInString: @"\t \r\n"];
}
start = refRange.location;
while (start > -1
&& [self characterAtIndex: start] != ' ')
start--;
start++;
length = [self length] - start;
endRange = NSMakeRange (start, length);
endRange = [self rangeOfCharacterFromSet: urlAfterEndingChars
options: NSLiteralSearch range: endRange];
if (endRange.location != NSNotFound)
length = endRange.location;
length -= start;
while
([urlNonEndingChars characterIsMember:
[self characterAtIndex: (start + length - 1)]])
length--;
return NSMakeRange (start, length);
}
- (NSString *) stringByDetectingURLs
{
NSMutableString *selfCopy;
NSRange httpRange, currentURL, rest;
NSString *urlText, *newUrlText;
unsigned int length;
selfCopy = [NSMutableString stringWithString: self];
httpRange = [selfCopy rangeOfString: @"://"];
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];
length = [selfCopy length];
rest.location = currentURL.location + [newUrlText length];
rest.length = length - rest.location;
httpRange = [selfCopy rangeOfString: @"://"
options: 0 range: rest];
}
return selfCopy;
}
#if LIB_FOUNDATION_LIBRARY
- (BOOL) boolValue
{
return !([self isEqualToString: @"0"]