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