Changeset 24166
- Timestamp:
- 07/01/2008 08:08:31 PM (5 months ago)
- Files:
-
- trunk/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.h (modified) (1 diff)
- trunk/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m (modified) (3 diffs)
- trunk/Frameworks/AutoHyperlinks Framework/Source/AHLinkLexer.h (modified) (1 diff)
- trunk/Frameworks/AutoHyperlinks Framework/Source/AHLinkLexer.l (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.h
r24146 r24166 28 28 #import "AHLinkLexer.h" 29 29 30 typedef void* yyscan_t; 31 32 extern long AHlex( yyscan_t yyscanner ); 33 extern long AHlex_init( yyscan_t * ptr_yy_globals ); 34 extern long AHlex_destroy ( yyscan_t yyscanner ); 35 extern long AHget_leng ( yyscan_t scanner ); 36 extern void AHset_in ( FILE * in_str , yyscan_t scanner ); 37 30 extern long AHleng; 31 extern long AHlex(); 38 32 typedef struct AH_buffer_state *AH_BUFFER_STATE; 39 extern void AH_switch_to_buffer(AH_BUFFER_STATE, yyscan_t scanner);40 extern AH_BUFFER_STATE AH_scan_string (const char *, yyscan_t scanner);41 extern void AH_delete_buffer(AH_BUFFER_STATE, yyscan_t scanner);33 void AH_switch_to_buffer(AH_BUFFER_STATE); 34 AH_BUFFER_STATE AH_scan_string (const char *); 35 void AH_delete_buffer(AH_BUFFER_STATE); 42 36 43 37 @class AHMarkedHyperlink; trunk/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m
r24146 r24166 107 107 + (BOOL)isStringValidURI:(NSString *)inString usingStrict:(BOOL)useStrictChecking fromIndex:(unsigned long *)index withStatus:(AH_URI_VERIFICATION_STATUS *)validStatus 108 108 { 109 AH_BUFFER_STATE buf; // buffer for flex to scan from 110 yyscan_t scanner; // pointer to the flex scanner opaque type 109 AH_BUFFER_STATE buf; // buffer for flex to scan from 111 110 const char *inStringEnc; 112 111 unsigned long encodedLength; 113 112 static NSLock *linkLock = nil; 113 114 115 if(!linkLock) 116 linkLock = [[NSLock alloc] init]; 117 [linkLock lock]; 118 114 119 if(!validStatus){ 115 120 AH_URI_VERIFICATION_STATUS newStatus = AH_URL_INVALID; … … 125 130 126 131 if (!(inStringEnc = [inString cStringUsingEncoding:stringEnc])) { 132 [linkLock unlock]; 127 133 return NO; 128 134 } … … 132 138 133 139 // initialize the buffer (flex automatically switches to the buffer in this function) 134 AHlex_init(&scanner); 135 buf = AH_scan_string(inStringEnc, scanner); 140 buf = AH_scan_string(inStringEnc); 136 141 137 142 // call flex to parse the input 138 *validStatus = AHlex( scanner);139 if(index) *index += AH get_leng(scanner);143 *validStatus = AHlex(); 144 if(index) *index += AHleng; 140 145 141 146 // condition for valid URI's 142 147 if(*validStatus == AH_URL_VALID || *validStatus == AH_MAILTO_VALID || *validStatus == AH_FILE_VALID){ 143 AH_delete_buffer(buf , scanner); //remove the buffer from flex.148 AH_delete_buffer(buf); //remove the buffer from flex. 144 149 buf = NULL; //null the buffer pointer for safty's sake. 145 150 146 151 // check that the whole string was matched by flex. 147 152 // this prevents silly things like "blah...com" from being seen as links 148 if(AH get_leng(scanner)== encodedLength){149 AHlex_destroy(scanner);153 if(AHleng == encodedLength){ 154 [linkLock unlock]; 150 155 return YES; 151 156 } 152 157 // condition for degenerate URL's (A.K.A. URI's sans specifiers), requres strict checking to be NO. 153 158 }else if((*validStatus == AH_URL_DEGENERATE || *validStatus == AH_MAILTO_DEGENERATE) && !useStrictChecking){ 154 AH_delete_buffer(buf , scanner);159 AH_delete_buffer(buf); 155 160 buf = NULL; 156 if(AH get_leng(scanner)== encodedLength){157 AHlex_destroy(scanner);161 if(AHleng == encodedLength){ 162 [linkLock unlock]; 158 163 return YES; 159 164 } 160 165 // if it ain't vaild, and it ain't degenerate, then it's invalid. 161 166 }else{ 162 AH_delete_buffer(buf , scanner);167 AH_delete_buffer(buf); 163 168 buf = NULL; 164 AHlex_destroy(scanner);169 [linkLock unlock]; 165 170 return NO; 166 171 } 167 172 // default case, if the range checking above fails. 168 AHlex_destroy(scanner);173 [linkLock unlock]; 169 174 return NO; 170 175 } trunk/Frameworks/AutoHyperlinks Framework/Source/AHLinkLexer.h
r24146 r24166 34 34 AH_MAILTO_DEGENERATE 35 35 } AH_URI_VERIFICATION_STATUS; 36 37 #define YY_EXTRA_TYPE unsigned inttrunk/Frameworks/AutoHyperlinks Framework/Source/AHLinkLexer.l
r24146 r24166 43 43 * without a costly call to yymore(). 44 44 */ 45 long AHValidShift = 0; 45 46 #include "AHLinkLexer.h" 46 47 %} … … 88 89 ignoreable (b\.sc|m\.in) 89 90 90 %option noyywrap nounput 8bit caseless never-interactive reentrant warnprefix="AH"91 %option noyywrap nounput 8bit caseless never-interactive prefix="AH" 91 92 92 93 %x CANONICAL 93 94 %% 94 95 95 <CANONICAL>({userAndPass}@)?{urlCSpec}|{ipURL}|{ipv6URL} { yyleng += yyextra;96 <CANONICAL>({userAndPass}@)?{urlCSpec}|{ipURL}|{ipv6URL} {AHleng += AHValidShift; 96 97 BEGIN INITIAL; 97 98 return AH_URL_VALID;} … … 123 124 notes:\/\/ | 124 125 gopher:\/\/ | 125 x-man-page:\/\/ { yyextra = yyleng; BEGIN CANONICAL;}126 x-man-page:\/\/ {AHValidShift = AHleng; BEGIN CANONICAL;} 126 127 127 128 mailto:{mailSpec} {return AH_MAILTO_VALID;}