Changeset 3383

Show
Ignore:
Timestamp:
11/11/06 23:52:19 (2 years ago)
Author:
timothy
Message:

Improved the URL highlighting code to be more relaxed and still prevent punctuation at the end from being linked. Also upgraded to PCRE 6.7 for better unicode handling in regexs. The trailing slash is also now included in links. #170 #451 #466

Files:

Legend:

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

    r3072 r3383  
    309309- (void) makeLinkAttributesAutomatically { 
    310310        // catch well-formed urls like "http://www.apple.com", "www.apple.com" or "irc://irc.javelin.cc" 
    311         AGRegex *regex = [AGRegex regexWithPattern:@"(?:[a-zA-Z][a-zA-Z0-9+.-]*://|www\\.)(?:[\\w:-]+@)?(?:\\d{1,3}(?:\\.\\d{1,3}){3}|(?:[\\p{L}\\p{N}-]+\\.)+\\w{2,4}\\.?|localhost)(?:\\:\\d+)?(?:[/?][\\p{L}\\p{N}$\\-_.+!*',=:\\|/\\\\()%@&;#?~]*)*(?=[>}\\]):;,.!?'\"]|\\b)" options:AGRegexCaseInsensitive]; 
     311        AGRegex *regex = [AGRegex regexWithPattern:@"(?:[a-zA-Z][a-zA-Z0-9+.-]*:(?://)?|www\\.)[\\p{L}\\p{N}$\\-_+*'\"=:\\|/\\\\()%@&#~,;.!?]+[\\p{L}\\p{N}$\\-_+*=:\\|/\\\\()%@&#~]" options:AGRegexCaseInsensitive]; 
    312312        NSArray *matches = [regex findAllInString:[self string]]; 
    313313        NSEnumerator *enumerator = [matches objectEnumerator]; 
     
    321321 
    322322        // catch well-formed email addresses like "timothy@hatcher.name" or "timothy@javelin.cc" 
    323         regex = [AGRegex regexWithPattern:@"[\\w.+-]+@(?:[\\p{L}-]+\\.)+[\\w]{2,}" options:AGRegexCaseInsensitive]; 
     323        regex = [AGRegex regexWithPattern:@"[\\p{L}\\p{N}.+-]+@(?:[\\p{L}-]+\\.)+[\\w]{2,}" options:AGRegexCaseInsensitive]; 
    324324        matches = [regex findAllInString:[self string]]; 
    325325        enumerator = [matches objectEnumerator];