Changeset 24391
- Timestamp:
- 07/17/2008 12:21:34 AM (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m
r24380 r24391 45 45 static NSCharacterSet *endSet = nil; 46 46 static NSCharacterSet *startSet = nil; 47 static NSCharacterSet *puncSet = nil; 47 48 static NSCharacterSet *hostnameComponentSeparatorSet = nil; 48 49 static NSArray *enclosureStartArray = nil; … … 123 124 124 125 if (!endSet) { 125 endSet = [[NSCharacterSet characterSetWithCharactersInString:@"\"',:;>)]}.?! "] retain];126 endSet = [[NSCharacterSet characterSetWithCharactersInString:@"\"',:;>)]}.?!@"] retain]; 126 127 } 127 128 … … 129 130 NSMutableCharacterSet *mutableStartSet = [[NSMutableCharacterSet alloc] init]; 130 131 [mutableStartSet formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 131 [mutableStartSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"\"' ,:;<.?!-@"]];132 [mutableStartSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"\"'.,:;<?!-@"]]; 132 133 startSet = [[NSCharacterSet characterSetWithBitmapRepresentation:[mutableStartSet bitmapRepresentation]] retain]; 133 134 [mutableStartSet release]; 135 } 136 137 if (!puncSet) { 138 puncSet = [[NSCharacterSet characterSetWithCharactersInString:@"\"'.,:;<?!"] retain]; 134 139 } 135 140 … … 250 255 // otherwise we end up validating urls that look like this "http://www.adiumx.com/ <--cool" 251 256 [self _scanString:m_scanString charactersFromSet:startSet intoRange:nil fromIndex:&scannedLocation]; 252 257 253 258 // main scanning loop 254 259 while([self _scanString:m_scanString upToCharactersFromSet:skipSet intoRange:&scannedRange fromIndex:&scannedLocation]) { 255 260 256 unsigned long _scanLoc = scannedLocation;257 258 261 // Check for and filter enclosures. We can't add (, [, etc. to the skipSet as they may be in a URI 259 262 if([enclosureSet characterIsMember:[m_scanString characterAtIndex:scannedRange.location]]){ … … 263 266 encRange = [m_scanString rangeOfString:[enclosureStopArray objectAtIndex:encIdx] options:NSBackwardsSearch range:scannedRange]; 264 267 if(NSNotFound != encRange.location){ 265 _scanLoc -= scannedRange.length - encRange.location;266 268 scannedRange.location++; scannedRange.length -= 2; 267 269 } … … 282 284 // parent string, its validation status (valid, file, degenerate, etc), and its range in the parent string 283 285 AH_URI_VERIFICATION_STATUS validStatus; 284 NSString *_scanString = [m_scanString substringWithRange:scannedRange]; 285 if(_scanString && [[self class] isStringValidURI:_scanString usingStrict:m_strictChecking fromIndex:&m_scanLocation withStatus:&validStatus]){ 286 NSString *_scanString = nil; 287 if(3 < scannedRange.length) _scanString = [m_scanString substringWithRange:scannedRange]; 288 if((3 < scannedRange.length) && [[self class] isStringValidURI:_scanString usingStrict:m_strictChecking fromIndex:&m_scanLocation withStatus:&validStatus]){ 286 289 AHMarkedHyperlink *markedLink; 287 290 … … 324 327 } 325 328 326 //step location after scanning a string 327 NSRange startRange = [m_scanString rangeOfCharacterFromSet:startSet options:0 range:scannedRange]; 328 if (startRange.location != NSNotFound) { 329 m_scanLocation += startRange.length; 330 if(m_scanLocation > m_scanStringLength) 331 m_scanLocation--; 332 }else{ 329 //step location after scanning a string 330 NSRange startRange = [m_scanString rangeOfCharacterFromSet:puncSet options:NSLiteralSearch range:scannedRange]; 331 if (startRange.location != NSNotFound) 332 m_scanLocation = startRange.location + startRange.length; 333 else 333 334 m_scanLocation += scannedRange.length; 334 if(m_scanLocation > m_scanStringLength)335 m_scanLocation--;336 } 335 336 if(m_scanLocation > m_scanStringLength) m_scanLocation--; 337 337 338 scannedLocation = m_scanLocation; 338 339 }