Changeset 1798

Show
Ignore:
Timestamp:
08/18/04 13:09:22 (4 years ago)
Author:
timothy
Message:

Fixes www. hyper-linked URLs. URLs containing other URLs should work now also.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/NSAttributedStringMoreAdditions.m

    r1793 r1798  
    294294- (void) makeLinkAttributesAutomatically { 
    295295        // catch well-formed urls like "http://www.apple.com", "www.apple.com" or "irc://irc.javelin.cc" 
    296         AGRegex *regex = [AGRegex regexWithPattern:@"(?:[\\w-]+://|www\\.)(?:[\\w-:]+@)?(?:[\\w-]+\\.)+[\\w{2,4}]+(?:\\:\\d+)?(?:/[\\w$\\-_.+!*',=\\\\()%@&;#?~]*)*" options:AGRegexCaseInsensitive]; 
     296        AGRegex *regex = [AGRegex regexWithPattern:@"(?:[\\w-]+://|www\\.)(?:[\\w-:]+@)?(?:[\\w-]+\\.)+[\\w{2,4}]+(?:\\:\\d+)?(?:/[\\w$\\-_.+!*',=:/\\\\()%@&;#?~]*)*" options:AGRegexCaseInsensitive]; 
    297297        NSArray *matches = [regex findAllInString:[self string]]; 
    298298        NSEnumerator *enumerator = [matches objectEnumerator]; 
     
    302302                NSRange foundRange = [match range]; 
    303303                NSString *currentLink = [self attribute:NSLinkAttributeName atIndex:foundRange.location effectiveRange:NULL]; 
    304                 if( ! currentLink ) [self addAttribute:NSLinkAttributeName value:[match group] range:foundRange]; 
     304                if( ! currentLink ) [self addAttribute:NSLinkAttributeName value:( [[match group] hasPrefix:@"www."] ? [@"http://" stringByAppendingString:[match group]] : [match group] ) range:foundRange]; 
    305305        } 
    306306