Parent Directory
|
Revision Log
|
Patch
| revision 77 by nigel, Sat Feb 24 21:40:45 2007 UTC | revision 392 by ph10, Tue Mar 17 21:30:30 2009 UTC | |
|---|---|---|
| # | Line 6 | Line 6 |
| 6 | and semantics are as close as possible to those of the Perl 5 language. | and semantics are as close as possible to those of the Perl 5 language. |
| 7 | ||
| 8 | Written by Philip Hazel | Written by Philip Hazel |
| 9 | Copyright (c) 1997-2005 University of Cambridge | Copyright (c) 1997-2009 University of Cambridge |
| 10 | ||
| 11 | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| 12 | Redistribution and use in source and binary forms, with or without | Redistribution and use in source and binary forms, with or without |
| # | Line 42 POSSIBILITY OF SUCH DAMAGE. | Line 42 POSSIBILITY OF SUCH DAMAGE. |
| 42 | pattern matching using an NFA algorithm, trying to mimic Perl as closely as | pattern matching using an NFA algorithm, trying to mimic Perl as closely as |
| 43 | possible. There are also some static supporting functions. */ | possible. There are also some static supporting functions. */ |
| 44 | ||
| 45 | #ifdef HAVE_CONFIG_H | |
| 46 | #include "config.h" | |
| 47 | #endif | |
| 48 | ||
| 49 | #define NLBLOCK md /* Block containing newline information */ | |
| 50 | #define PSSTART start_subject /* Field containing processed string start */ | |
| 51 | #define PSEND end_subject /* Field containing processed string end */ | |
| 52 | ||
| 53 | #include "pcre_internal.h" | #include "pcre_internal.h" |
| 54 | ||
| 55 | /* Undefine some potentially clashing cpp symbols */ | |
| 56 | ||
| 57 | /* Structure for building a chain of data that actually lives on the | #undef min |
| 58 | stack, for holding the values of the subject pointer at the start of each | #undef max |
| subpattern, so as to detect when an empty string has been matched by a | ||
| subpattern - to break infinite loops. When NO_RECURSE is set, these blocks | ||
| are on the heap, not on the stack. */ | ||
| typedef struct eptrblock { | ||
| struct eptrblock *epb_prev; | ||
| const uschar *epb_saved_eptr; | ||
| } eptrblock; | ||
| 59 | ||
| 60 | /* Flag bits for the match() function */ | /* Flag bits for the match() function */ |
| 61 | ||
| 62 | #define match_condassert 0x01 /* Called to check a condition assertion */ | #define match_condassert 0x01 /* Called to check a condition assertion */ |
| 63 | #define match_isgroup 0x02 /* Set if start of bracketed group */ | #define match_cbegroup 0x02 /* Could-be-empty unlimited repeat group */ |
| 64 | ||
| 65 | /* Non-error returns from the match() function. Error returns are externally | /* Non-error returns from the match() function. Error returns are externally |
| 66 | defined PCRE_ERROR_xxx codes, which are all negative. */ | defined PCRE_ERROR_xxx codes, which are all negative. */ |
| # | Line 68 defined PCRE_ERROR_xxx codes, which are | Line 68 defined PCRE_ERROR_xxx codes, which are |
| 68 | #define MATCH_MATCH 1 | #define MATCH_MATCH 1 |
| 69 | #define MATCH_NOMATCH 0 | #define MATCH_NOMATCH 0 |
| 70 | ||
| 71 | /* Special internal returns from the match() function. Make them sufficiently | |
| 72 | negative to avoid the external error codes. */ | |
| 73 | ||
| 74 | #define MATCH_COMMIT (-999) | |
| 75 | #define MATCH_PRUNE (-998) | |
| 76 | #define MATCH_SKIP (-997) | |
| 77 | #define MATCH_THEN (-996) | |
| 78 | ||
| 79 | /* Maximum number of ints of offset to save on the stack for recursive calls. | /* Maximum number of ints of offset to save on the stack for recursive calls. |
| 80 | If the offset vector is bigger, malloc is used. This should be a multiple of 3, | If the offset vector is bigger, malloc is used. This should be a multiple of 3, |
| 81 | because the offset vector is always a multiple of 3 long. */ | because the offset vector is always a multiple of 3 long. */ |
| # | Line 101 Returns: nothing | Line 109 Returns: nothing |
| 109 | static void | static void |
| 110 | pchars(const uschar *p, int length, BOOL is_subject, match_data *md) | pchars(const uschar *p, int length, BOOL is_subject, match_data *md) |
| 111 | { | { |
| 112 | int c; | unsigned int c; |
| 113 | if (is_subject && length > md->end_subject - p) length = md->end_subject - p; | if (is_subject && length > md->end_subject - p) length = md->end_subject - p; |
| 114 | while (length-- > 0) | while (length-- > 0) |
| 115 | if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c); | if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c); |
| # | Line 128 Returns: TRUE if matched | Line 136 Returns: TRUE if matched |
| 136 | */ | */ |
| 137 | ||
| 138 | static BOOL | static BOOL |
| 139 | match_ref(int offset, register const uschar *eptr, int length, match_data *md, | match_ref(int offset, register USPTR eptr, int length, match_data *md, |
| 140 | unsigned long int ims) | unsigned long int ims) |
| 141 | { | { |
| 142 | const uschar *p = md->start_subject + md->offset_vector[offset]; | USPTR p = md->start_subject + md->offset_vector[offset]; |
| 143 | ||
| 144 | #ifdef DEBUG | #ifdef DEBUG |
| 145 | if (eptr >= md->end_subject) | if (eptr >= md->end_subject) |
| # | Line 150 printf("\n"); | Line 158 printf("\n"); |
| 158 | ||
| 159 | if (length > md->end_subject - eptr) return FALSE; | if (length > md->end_subject - eptr) return FALSE; |
| 160 | ||
| 161 | /* Separate the caselesss case for speed */ | /* Separate the caseless case for speed. In UTF-8 mode we can only do this |
| 162 | properly if Unicode properties are supported. Otherwise, we can check only | |
| 163 | ASCII characters. */ | |
| 164 | ||
| 165 | if ((ims & PCRE_CASELESS) != 0) | if ((ims & PCRE_CASELESS) != 0) |
| 166 | { | { |
| 167 | #ifdef SUPPORT_UTF8 | |
| 168 | #ifdef SUPPORT_UCP | |
| 169 | if (md->utf8) | |
| 170 | { | |
| 171 | USPTR endptr = eptr + length; | |
| 172 | while (eptr < endptr) | |
| 173 | { | |
| 174 | int c, d; | |
| 175 | GETCHARINC(c, eptr); | |
| 176 | GETCHARINC(d, p); | |
| 177 | if (c != d && c != UCD_OTHERCASE(d)) return FALSE; | |
| 178 | } | |
| 179 | } | |
| 180 | else | |
| 181 | #endif | |
| 182 | #endif | |
| 183 | ||
| 184 | /* The same code works when not in UTF-8 mode and in UTF-8 mode when there | |
| 185 | is no UCP support. */ | |
| 186 | ||
| 187 | while (length-- > 0) | while (length-- > 0) |
| 188 | if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; | { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; } |
| 189 | } | } |
| 190 | ||
| 191 | /* In the caseful case, we can just compare the bytes, whether or not we | |
| 192 | are in UTF-8 mode. */ | |
| 193 | ||
| 194 | else | else |
| 195 | { while (length-- > 0) if (*p++ != *eptr++) return FALSE; } | { while (length-- > 0) if (*p++ != *eptr++) return FALSE; } |
| 196 | ||
| # | Line 169 return TRUE; | Line 203 return TRUE; |
| 203 | **************************************************************************** | **************************************************************************** |
| 204 | RECURSION IN THE match() FUNCTION | RECURSION IN THE match() FUNCTION |
| 205 | ||
| 206 | The match() function is highly recursive. Some regular expressions can cause | The match() function is highly recursive, though not every recursive call |
| 207 | it to recurse thousands of times. I was writing for Unix, so I just let it | increases the recursive depth. Nevertheless, some regular expressions can cause |
| 208 | call itself recursively. This uses the stack for saving everything that has | it to recurse to a great depth. I was writing for Unix, so I just let it call |
| 209 | to be saved for a recursive call. On Unix, the stack can be large, and this | itself recursively. This uses the stack for saving everything that has to be |
| 210 | works fine. | saved for a recursive call. On Unix, the stack can be large, and this works |
| 211 | fine. | |
| 212 | It turns out that on non-Unix systems there are problems with programs that | |
| 213 | use a lot of stack. (This despite the fact that every last chip has oodles | It turns out that on some non-Unix-like systems there are problems with |
| 214 | of memory these days, and techniques for extending the stack have been known | programs that use a lot of stack. (This despite the fact that every last chip |
| 215 | for decades.) So.... | has oodles of memory these days, and techniques for extending the stack have |
| 216 | been known for decades.) So.... | |
| 217 | ||
| 218 | There is a fudge, triggered by defining NO_RECURSE, which avoids recursive | There is a fudge, triggered by defining NO_RECURSE, which avoids recursive |
| 219 | calls by keeping local variables that need to be preserved in blocks of memory | calls by keeping local variables that need to be preserved in blocks of memory |
| 220 | obtained from malloc instead instead of on the stack. Macros are used to | obtained from malloc() instead instead of on the stack. Macros are used to |
| 221 | achieve this so that the actual code doesn't look very different to what it | achieve this so that the actual code doesn't look very different to what it |
| 222 | always used to. | always used to. |
| 223 | ||
| 224 | The original heap-recursive code used longjmp(). However, it seems that this | |
| 225 | can be very slow on some operating systems. Following a suggestion from Stan | |
| 226 | Switzer, the use of longjmp() has been abolished, at the cost of having to | |
| 227 | provide a unique number for each call to RMATCH. There is no way of generating | |
| 228 | a sequence of numbers at compile time in C. I have given them names, to make | |
| 229 | them stand out more clearly. | |
| 230 | ||
| 231 | Crude tests on x86 Linux show a small speedup of around 5-8%. However, on | |
| 232 | FreeBSD, avoiding longjmp() more than halves the time taken to run the standard | |
| 233 | tests. Furthermore, not using longjmp() means that local dynamic variables | |
| 234 | don't have indeterminate values; this has meant that the frame size can be | |
| 235 | reduced because the result can be "passed back" by straight setting of the | |
| 236 | variable instead of being passed in the frame. | |
| 237 | **************************************************************************** | **************************************************************************** |
| 238 | ***************************************************************************/ | ***************************************************************************/ |
| 239 | ||
| 240 | /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN | |
| 241 | below must be updated in sync. */ | |
| 242 | ||
| 243 | /* These versions of the macros use the stack, as normal */ | enum { RM1=1, RM2, RM3, RM4, RM5, RM6, RM7, RM8, RM9, RM10, |
| 244 | RM11, RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20, | |
| 245 | RM21, RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30, | |
| 246 | RM31, RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40, | |
| 247 | RM41, RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50, | |
| 248 | RM51, RM52, RM53, RM54 }; | |
| 249 | ||
| 250 | /* These versions of the macros use the stack, as normal. There are debugging | |
| 251 | versions and production versions. Note that the "rw" argument of RMATCH isn't | |
| 252 | actuall used in this definition. */ | |
| 253 | ||
| 254 | #ifndef NO_RECURSE | #ifndef NO_RECURSE |
| 255 | #define REGISTER register | #define REGISTER register |
| 256 | #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) rx = match(ra,rb,rc,rd,re,rf,rg) | |
| 257 | #ifdef DEBUG | |
| 258 | #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \ | |
| 259 | { \ | |
| 260 | printf("match() called in line %d\n", __LINE__); \ | |
| 261 | rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \ | |
| 262 | printf("to line %d\n", __LINE__); \ | |
| 263 | } | |
| 264 | #define RRETURN(ra) \ | |
| 265 | { \ | |
| 266 | printf("match() returned %d from line %d ", ra, __LINE__); \ | |
| 267 | return ra; \ | |
| 268 | } | |
| 269 | #else | |
| 270 | #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \ | |
| 271 | rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1) | |
| 272 | #define RRETURN(ra) return ra | #define RRETURN(ra) return ra |
| 273 | #endif | |
| 274 | ||
| 275 | #else | #else |
| 276 | ||
| 277 | ||
| 278 | /* These versions of the macros manage a private stack on the heap. Note | /* These versions of the macros manage a private stack on the heap. Note that |
| 279 | that the rd argument of RMATCH isn't actually used. It's the md argument of | the "rd" argument of RMATCH isn't actually used in this definition. It's the md |
| 280 | match(), which never changes. */ | argument of match(), which never changes. */ |
| 281 | ||
| 282 | #define REGISTER | #define REGISTER |
| 283 | ||
| 284 | #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\ | #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\ |
| 285 | {\ | {\ |
| 286 | heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\ | heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\ |
| 287 | if (setjmp(frame->Xwhere) == 0)\ | frame->Xwhere = rw; \ |
| 288 | {\ | newframe->Xeptr = ra;\ |
| 289 | newframe->Xeptr = ra;\ | newframe->Xecode = rb;\ |
| 290 | newframe->Xecode = rb;\ | newframe->Xmstart = mstart;\ |
| 291 | newframe->Xoffset_top = rc;\ | newframe->Xoffset_top = rc;\ |
| 292 | newframe->Xims = re;\ | newframe->Xims = re;\ |
| 293 | newframe->Xeptrb = rf;\ | newframe->Xeptrb = rf;\ |
| 294 | newframe->Xflags = rg;\ | newframe->Xflags = rg;\ |
| 295 | newframe->Xprevframe = frame;\ | newframe->Xrdepth = frame->Xrdepth + 1;\ |
| 296 | frame = newframe;\ | newframe->Xprevframe = frame;\ |
| 297 | DPRINTF(("restarting from line %d\n", __LINE__));\ | frame = newframe;\ |
| 298 | goto HEAP_RECURSE;\ | DPRINTF(("restarting from line %d\n", __LINE__));\ |
| 299 | }\ | goto HEAP_RECURSE;\ |
| 300 | else\ | L_##rw:\ |
| 301 | {\ | DPRINTF(("jumped back to line %d\n", __LINE__));\ |
| DPRINTF(("longjumped back to line %d\n", __LINE__));\ | ||
| frame = md->thisframe;\ | ||
| rx = frame->Xresult;\ | ||
| }\ | ||
| 302 | } | } |
| 303 | ||
| 304 | #define RRETURN(ra)\ | #define RRETURN(ra)\ |
| # | Line 235 match(), which never changes. */ | Line 308 match(), which never changes. */ |
| 308 | (pcre_stack_free)(newframe);\ | (pcre_stack_free)(newframe);\ |
| 309 | if (frame != NULL)\ | if (frame != NULL)\ |
| 310 | {\ | {\ |
| 311 | frame->Xresult = ra;\ | rrc = ra;\ |
| 312 | md->thisframe = frame;\ | goto HEAP_RETURN;\ |
| longjmp(frame->Xwhere, 1);\ | ||
| 313 | }\ | }\ |
| 314 | return ra;\ | return ra;\ |
| 315 | } | } |
| # | Line 252 typedef struct heapframe { | Line 324 typedef struct heapframe { |
| 324 | ||
| 325 | const uschar *Xeptr; | const uschar *Xeptr; |
| 326 | const uschar *Xecode; | const uschar *Xecode; |
| 327 | const uschar *Xmstart; | |
| 328 | int Xoffset_top; | int Xoffset_top; |
| 329 | long int Xims; | long int Xims; |
| 330 | eptrblock *Xeptrb; | eptrblock *Xeptrb; |
| 331 | int Xflags; | int Xflags; |
| 332 | unsigned int Xrdepth; | |
| 333 | ||
| 334 | /* Function local variables */ | /* Function local variables */ |
| 335 | ||
| # | Line 271 typedef struct heapframe { | Line 345 typedef struct heapframe { |
| 345 | ||
| 346 | BOOL Xcur_is_word; | BOOL Xcur_is_word; |
| 347 | BOOL Xcondition; | BOOL Xcondition; |
| BOOL Xminimize; | ||
| 348 | BOOL Xprev_is_word; | BOOL Xprev_is_word; |
| 349 | ||
| 350 | unsigned long int Xoriginal_ims; | unsigned long int Xoriginal_ims; |
| 351 | ||
| 352 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 353 | int Xprop_type; | int Xprop_type; |
| 354 | int Xprop_value; | |
| 355 | int Xprop_fail_result; | int Xprop_fail_result; |
| 356 | int Xprop_category; | int Xprop_category; |
| 357 | int Xprop_chartype; | int Xprop_chartype; |
| 358 | int Xprop_othercase; | int Xprop_script; |
| 359 | int Xprop_test_against; | int Xoclength; |
| 360 | int *Xprop_test_variable; | uschar Xocchars[8]; |
| 361 | #endif | #endif |
| 362 | ||
| 363 | int Xctype; | int Xctype; |
| 364 | int Xfc; | unsigned int Xfc; |
| 365 | int Xfi; | int Xfi; |
| 366 | int Xlength; | int Xlength; |
| 367 | int Xmax; | int Xmax; |
| # | Line 301 typedef struct heapframe { | Line 375 typedef struct heapframe { |
| 375 | ||
| 376 | eptrblock Xnewptrb; | eptrblock Xnewptrb; |
| 377 | ||
| 378 | /* Place to pass back result, and where to jump back to */ | /* Where to jump back to */ |
| 379 | ||
| 380 | int Xresult; | int Xwhere; |
| jmp_buf Xwhere; | ||
| 381 | ||
| 382 | } heapframe; | } heapframe; |
| 383 | ||
| # | Line 320 typedef struct heapframe { | Line 393 typedef struct heapframe { |
| 393 | * Match from current position * | * Match from current position * |
| 394 | *************************************************/ | *************************************************/ |
| 395 | ||
| 396 | /* On entry ecode points to the first opcode, and eptr to the first character | /* This function is called recursively in many circumstances. Whenever it |
| in the subject string, while eptrb holds the value of eptr at the start of the | ||
| last bracketed group - used for breaking infinite loops matching zero-length | ||
| strings. This function is called recursively in many circumstances. Whenever it | ||
| 397 | returns a negative (error) response, the outer incarnation must also return the | returns a negative (error) response, the outer incarnation must also return the |
| 398 | same response. | same response. |
| 399 | ||
| # | Line 333 performance. Tests using gcc on a SPARC | Line 403 performance. Tests using gcc on a SPARC |
| 403 | made performance worse. | made performance worse. |
| 404 | ||
| 405 | Arguments: | Arguments: |
| 406 | eptr pointer in subject | eptr pointer to current character in subject |
| 407 | ecode position in code | ecode pointer to current position in compiled code |
| 408 | mstart pointer to the current match start position (can be modified | |
| 409 | by encountering \K) | |
| 410 | offset_top current top pointer | offset_top current top pointer |
| 411 | md pointer to "static" info for the match | md pointer to "static" info for the match |
| 412 | ims current /i, /m, and /s options | ims current /i, /m, and /s options |
| # | Line 342 Arguments: | Line 414 Arguments: |
| 414 | brackets - for testing for empty matches | brackets - for testing for empty matches |
| 415 | flags can contain | flags can contain |
| 416 | match_condassert - this is an assertion condition | match_condassert - this is an assertion condition |
| 417 | match_isgroup - this is the start of a bracketed group | match_cbegroup - this is the start of an unlimited repeat |
| 418 | group that can match an empty string | |
| 419 | rdepth the recursion depth | |
| 420 | ||
| 421 | Returns: MATCH_MATCH if matched ) these values are >= 0 | Returns: MATCH_MATCH if matched ) these values are >= 0 |
| 422 | MATCH_NOMATCH if failed to match ) | MATCH_NOMATCH if failed to match ) |
| 423 | a negative PCRE_ERROR_xxx value if aborted by an error condition | a negative PCRE_ERROR_xxx value if aborted by an error condition |
| 424 | (e.g. stopped by recursion limit) | (e.g. stopped by repeated call or recursion limit) |
| 425 | */ | */ |
| 426 | ||
| 427 | static int | static int |
| 428 | match(REGISTER const uschar *eptr, REGISTER const uschar *ecode, | match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart, |
| 429 | int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, | int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, |
| 430 | int flags) | int flags, unsigned int rdepth) |
| 431 | { | { |
| 432 | /* These variables do not need to be preserved over recursion in this function, | /* These variables do not need to be preserved over recursion in this function, |
| 433 | so they can be ordinary variables in all cases. Mark them with "register" | so they can be ordinary variables in all cases. Mark some of them with |
| 434 | because they are used a lot in loops. */ | "register" because they are used a lot in loops. */ |
| 435 | ||
| 436 | register int rrc; /* Returns from recursive calls */ | |
| 437 | register int i; /* Used for loops not involving calls to RMATCH() */ | |
| 438 | register unsigned int c; /* Character values not kept over RMATCH() calls */ | |
| 439 | register BOOL utf8; /* Local copy of UTF-8 flag for speed */ | |
| 440 | ||
| 441 | register int rrc; /* Returns from recursive calls */ | BOOL minimize, possessive; /* Quantifier options */ |
| register int i; /* Used for loops not involving calls to RMATCH() */ | ||
| register int c; /* Character values not kept over RMATCH() calls */ | ||
| register BOOL utf8; /* Local copy of UTF-8 flag for speed */ | ||
| 442 | ||
| 443 | /* When recursion is not being used, all "local" variables that have to be | /* When recursion is not being used, all "local" variables that have to be |
| 444 | preserved over calls to RMATCH() are part of a "frame" which is obtained from | preserved over calls to RMATCH() are part of a "frame" which is obtained from |
| # | Line 377 frame->Xprevframe = NULL; /* | Line 453 frame->Xprevframe = NULL; /* |
| 453 | ||
| 454 | frame->Xeptr = eptr; | frame->Xeptr = eptr; |
| 455 | frame->Xecode = ecode; | frame->Xecode = ecode; |
| 456 | frame->Xmstart = mstart; | |
| 457 | frame->Xoffset_top = offset_top; | frame->Xoffset_top = offset_top; |
| 458 | frame->Xims = ims; | frame->Xims = ims; |
| 459 | frame->Xeptrb = eptrb; | frame->Xeptrb = eptrb; |
| 460 | frame->Xflags = flags; | frame->Xflags = flags; |
| 461 | frame->Xrdepth = rdepth; | |
| 462 | ||
| 463 | /* This is where control jumps back to to effect "recursion" */ | /* This is where control jumps back to to effect "recursion" */ |
| 464 | ||
| # | Line 390 HEAP_RECURSE: | Line 468 HEAP_RECURSE: |
| 468 | ||
| 469 | #define eptr frame->Xeptr | #define eptr frame->Xeptr |
| 470 | #define ecode frame->Xecode | #define ecode frame->Xecode |
| 471 | #define mstart frame->Xmstart | |
| 472 | #define offset_top frame->Xoffset_top | #define offset_top frame->Xoffset_top |
| 473 | #define ims frame->Xims | #define ims frame->Xims |
| 474 | #define eptrb frame->Xeptrb | #define eptrb frame->Xeptrb |
| 475 | #define flags frame->Xflags | #define flags frame->Xflags |
| 476 | #define rdepth frame->Xrdepth | |
| 477 | ||
| 478 | /* Ditto for the local variables */ | /* Ditto for the local variables */ |
| 479 | ||
| # | Line 411 HEAP_RECURSE: | Line 491 HEAP_RECURSE: |
| 491 | ||
| 492 | #define cur_is_word frame->Xcur_is_word | #define cur_is_word frame->Xcur_is_word |
| 493 | #define condition frame->Xcondition | #define condition frame->Xcondition |
| #define minimize frame->Xminimize | ||
| 494 | #define prev_is_word frame->Xprev_is_word | #define prev_is_word frame->Xprev_is_word |
| 495 | ||
| 496 | #define original_ims frame->Xoriginal_ims | #define original_ims frame->Xoriginal_ims |
| 497 | ||
| 498 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 499 | #define prop_type frame->Xprop_type | #define prop_type frame->Xprop_type |
| 500 | #define prop_value frame->Xprop_value | |
| 501 | #define prop_fail_result frame->Xprop_fail_result | #define prop_fail_result frame->Xprop_fail_result |
| 502 | #define prop_category frame->Xprop_category | #define prop_category frame->Xprop_category |
| 503 | #define prop_chartype frame->Xprop_chartype | #define prop_chartype frame->Xprop_chartype |
| 504 | #define prop_othercase frame->Xprop_othercase | #define prop_script frame->Xprop_script |
| 505 | #define prop_test_against frame->Xprop_test_against | #define oclength frame->Xoclength |
| 506 | #define prop_test_variable frame->Xprop_test_variable | #define occhars frame->Xocchars |
| 507 | #endif | #endif |
| 508 | ||
| 509 | #define ctype frame->Xctype | #define ctype frame->Xctype |
| # | Line 447 HEAP_RECURSE: | Line 527 HEAP_RECURSE: |
| 527 | get preserved during recursion in the normal way. In this environment, fi and | get preserved during recursion in the normal way. In this environment, fi and |
| 528 | i, and fc and c, can be the same variables. */ | i, and fc and c, can be the same variables. */ |
| 529 | ||
| 530 | #else | #else /* NO_RECURSE not defined */ |
| 531 | #define fi i | #define fi i |
| 532 | #define fc c | #define fc c |
| 533 | ||
| 534 | ||
| 535 | #ifdef SUPPORT_UTF8 /* Many of these variables are used ony */ | #ifdef SUPPORT_UTF8 /* Many of these variables are used only */ |
| 536 | const uschar *charptr; /* small blocks of the code. My normal */ | const uschar *charptr; /* in small blocks of the code. My normal */ |
| 537 | #endif /* style of coding would have declared */ | #endif /* style of coding would have declared */ |
| 538 | const uschar *callpat; /* them within each of those blocks. */ | const uschar *callpat; /* them within each of those blocks. */ |
| 539 | const uschar *data; /* However, in order to accommodate the */ | const uschar *data; /* However, in order to accommodate the */ |
| 540 | const uschar *next; /* version of this code that uses an */ | const uschar *next; /* version of this code that uses an */ |
| 541 | const uschar *pp; /* external "stack" implemented on the */ | USPTR pp; /* external "stack" implemented on the */ |
| 542 | const uschar *prev; /* heap, it is easier to declare them */ | const uschar *prev; /* heap, it is easier to declare them all */ |
| 543 | const uschar *saved_eptr; /* all here, so the declarations can */ | USPTR saved_eptr; /* here, so the declarations can be cut */ |
| 544 | /* be cut out in a block. The only */ | /* out in a block. The only declarations */ |
| 545 | recursion_info new_recursive; /* declarations within blocks below are */ | recursion_info new_recursive; /* within blocks below are for variables */ |
| 546 | /* for variables that do not have to */ | /* that do not have to be preserved over */ |
| 547 | BOOL cur_is_word; /* be preserved over a recursive call */ | BOOL cur_is_word; /* a recursive call to RMATCH(). */ |
| 548 | BOOL condition; /* to RMATCH(). */ | BOOL condition; |
| BOOL minimize; | ||
| 549 | BOOL prev_is_word; | BOOL prev_is_word; |
| 550 | ||
| 551 | unsigned long int original_ims; | unsigned long int original_ims; |
| 552 | ||
| 553 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 554 | int prop_type; | int prop_type; |
| 555 | int prop_value; | |
| 556 | int prop_fail_result; | int prop_fail_result; |
| 557 | int prop_category; | int prop_category; |
| 558 | int prop_chartype; | int prop_chartype; |
| 559 | int prop_othercase; | int prop_script; |
| 560 | int prop_test_against; | int oclength; |
| 561 | int *prop_test_variable; | uschar occhars[8]; |
| 562 | #endif | #endif |
| 563 | ||
| 564 | int ctype; | int ctype; |
| # | Line 493 int save_offset1, save_offset2, save_off | Line 573 int save_offset1, save_offset2, save_off |
| 573 | int stacksave[REC_STACK_SAVE_MAX]; | int stacksave[REC_STACK_SAVE_MAX]; |
| 574 | ||
| 575 | eptrblock newptrb; | eptrblock newptrb; |
| 576 | #endif | #endif /* NO_RECURSE */ |
| 577 | ||
| 578 | /* These statements are here to stop the compiler complaining about unitialized | /* These statements are here to stop the compiler complaining about unitialized |
| 579 | variables. */ | variables. */ |
| 580 | ||
| 581 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 582 | prop_value = 0; | |
| 583 | prop_fail_result = 0; | prop_fail_result = 0; |
| prop_test_against = 0; | ||
| prop_test_variable = NULL; | ||
| 584 | #endif | #endif |
| 585 | ||
| 586 | /* OK, now we can get on with the real code of the function. Recursion is | |
| 587 | specified by the macros RMATCH and RRETURN. When NO_RECURSE is *not* defined, | /* This label is used for tail recursion, which is used in a few cases even |
| 588 | these just turn into a recursive call to match() and a "return", respectively. | when NO_RECURSE is not defined, in order to reduce the amount of stack that is |
| 589 | However, RMATCH isn't like a function call because it's quite a complicated | used. Thanks to Ian Taylor for noticing this possibility and sending the |
| 590 | macro. It has to be used in one particular way. This shouldn't, however, impact | original patch. */ |
| 591 | performance when true recursion is being used. */ | |
| 592 | TAIL_RECURSE: | |
| 593 | ||
| 594 | /* OK, now we can get on with the real code of the function. Recursive calls | |
| 595 | are specified by the macro RMATCH and RRETURN is used to return. When | |
| 596 | NO_RECURSE is *not* defined, these just turn into a recursive call to match() | |
| 597 | and a "return", respectively (possibly with some debugging if DEBUG is | |
| 598 | defined). However, RMATCH isn't like a function call because it's quite a | |
| 599 | complicated macro. It has to be used in one particular way. This shouldn't, | |
| 600 | however, impact performance when true recursion is being used. */ | |
| 601 | ||
| 602 | #ifdef SUPPORT_UTF8 | |
| 603 | utf8 = md->utf8; /* Local copy of the flag */ | |
| 604 | #else | |
| 605 | utf8 = FALSE; | |
| 606 | #endif | |
| 607 | ||
| 608 | /* First check that we haven't called match() too many times, or that we | |
| 609 | haven't exceeded the recursive call limit. */ | |
| 610 | ||
| 611 | if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT); | if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT); |
| 612 | if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); | |
| 613 | ||
| 614 | original_ims = ims; /* Save for resetting on ')' */ | original_ims = ims; /* Save for resetting on ')' */ |
| utf8 = md->utf8; /* Local copy of the flag */ | ||
| 615 | ||
| 616 | /* At the start of a bracketed group, add the current subject pointer to the | /* At the start of a group with an unlimited repeat that may match an empty |
| 617 | stack of such pointers, to be re-instated at the end of the group when we hit | string, the match_cbegroup flag is set. When this is the case, add the current |
| 618 | the closing ket. When match() is called in other circumstances, we don't add to | subject pointer to the chain of such remembered pointers, to be checked when we |
| 619 | this stack. */ | hit the closing ket, in order to break infinite loops that match no characters. |
| 620 | When match() is called in other circumstances, don't add to the chain. The | |
| 621 | match_cbegroup flag must NOT be used with tail recursion, because the memory | |
| 622 | block that is used is on the stack, so a new one may be required for each | |
| 623 | match(). */ | |
| 624 | ||
| 625 | if ((flags & match_isgroup) != 0) | if ((flags & match_cbegroup) != 0) |
| 626 | { | { |
| newptrb.epb_prev = eptrb; | ||
| 627 | newptrb.epb_saved_eptr = eptr; | newptrb.epb_saved_eptr = eptr; |
| 628 | newptrb.epb_prev = eptrb; | |
| 629 | eptrb = &newptrb; | eptrb = &newptrb; |
| 630 | } | } |
| 631 | ||
| 632 | /* Now start processing the operations. */ | /* Now start processing the opcodes. */ |
| 633 | ||
| 634 | for (;;) | for (;;) |
| 635 | { | { |
| 636 | minimize = possessive = FALSE; | |
| 637 | op = *ecode; | op = *ecode; |
| minimize = FALSE; | ||
| 638 | ||
| 639 | /* For partial matching, remember if we ever hit the end of the subject after | /* For partial matching, remember if we ever hit the end of the subject after |
| 640 | matching at least one subject character. */ | matching at least one subject character. */ |
| 641 | ||
| 642 | if (md->partial && | if (md->partial && |
| 643 | eptr >= md->end_subject && | eptr >= md->end_subject && |
| 644 | eptr > md->start_match) | eptr > mstart) |
| 645 | md->hitend = TRUE; | md->hitend = TRUE; |
| 646 | ||
| 647 | /* Opening capturing bracket. If there is space in the offset vector, save | switch(op) |
| the current subject position in the working slot at the top of the vector. We | ||
| mustn't change the current values of the data slot, because they may be set | ||
| from a previous iteration of this group, and be referred to by a reference | ||
| inside the group. | ||
| If the bracket fails to match, we need to restore this value and also the | ||
| values of the final offsets, in case they were set by a previous iteration of | ||
| the same bracket. | ||
| If there isn't enough space in the offset vector, treat this as if it were a | ||
| non-capturing bracket. Don't worry about setting the flag for the error case | ||
| here; that is handled in the code for KET. */ | ||
| if (op > OP_BRA) | ||
| 648 | { | { |
| 649 | number = op - OP_BRA; | case OP_FAIL: |
| 650 | RRETURN(MATCH_NOMATCH); | |
| /* For extended extraction brackets (large number), we have to fish out the | ||
| number from a dummy opcode at the start. */ | ||
| 651 | ||
| 652 | if (number > EXTRACT_BASIC_MAX) | case OP_PRUNE: |
| 653 | number = GET2(ecode, 2+LINK_SIZE); | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, |
| 654 | ims, eptrb, flags, RM51); | |
| 655 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 656 | RRETURN(MATCH_PRUNE); | |
| 657 | ||
| 658 | case OP_COMMIT: | |
| 659 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 660 | ims, eptrb, flags, RM52); | |
| 661 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 662 | RRETURN(MATCH_COMMIT); | |
| 663 | ||
| 664 | case OP_SKIP: | |
| 665 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 666 | ims, eptrb, flags, RM53); | |
| 667 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 668 | md->start_match_ptr = eptr; /* Pass back current position */ | |
| 669 | RRETURN(MATCH_SKIP); | |
| 670 | ||
| 671 | case OP_THEN: | |
| 672 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 673 | ims, eptrb, flags, RM54); | |
| 674 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 675 | RRETURN(MATCH_THEN); | |
| 676 | ||
| 677 | /* Handle a capturing bracket. If there is space in the offset vector, save | |
| 678 | the current subject position in the working slot at the top of the vector. | |
| 679 | We mustn't change the current values of the data slot, because they may be | |
| 680 | set from a previous iteration of this group, and be referred to by a | |
| 681 | reference inside the group. | |
| 682 | ||
| 683 | If the bracket fails to match, we need to restore this value and also the | |
| 684 | values of the final offsets, in case they were set by a previous iteration | |
| 685 | of the same bracket. | |
| 686 | ||
| 687 | If there isn't enough space in the offset vector, treat this as if it were | |
| 688 | a non-capturing bracket. Don't worry about setting the flag for the error | |
| 689 | case here; that is handled in the code for KET. */ | |
| 690 | ||
| 691 | case OP_CBRA: | |
| 692 | case OP_SCBRA: | |
| 693 | number = GET2(ecode, 1+LINK_SIZE); | |
| 694 | offset = number << 1; | offset = number << 1; |
| 695 | ||
| 696 | #ifdef DEBUG | #ifdef DEBUG |
| 697 | printf("start bracket %d subject=", number); | printf("start bracket %d\n", number); |
| 698 | printf("subject="); | |
| 699 | pchars(eptr, 16, TRUE, md); | pchars(eptr, 16, TRUE, md); |
| 700 | printf("\n"); | printf("\n"); |
| 701 | #endif | #endif |
| # | Line 584 for (;;) | Line 710 for (;;) |
| 710 | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); |
| 711 | md->offset_vector[md->offset_end - number] = eptr - md->start_subject; | md->offset_vector[md->offset_end - number] = eptr - md->start_subject; |
| 712 | ||
| 713 | flags = (op == OP_SCBRA)? match_cbegroup : 0; | |
| 714 | do | do |
| 715 | { | { |
| 716 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, |
| 717 | match_isgroup); | ims, eptrb, flags, RM1); |
| 718 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 719 | md->capture_last = save_capture_last; | md->capture_last = save_capture_last; |
| 720 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 721 | } | } |
| # | Line 603 for (;;) | Line 730 for (;;) |
| 730 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 731 | } | } |
| 732 | ||
| 733 | /* Insufficient room for saving captured contents */ | /* FALL THROUGH ... Insufficient room for saving captured contents. Treat |
| 734 | as a non-capturing bracket. */ | |
| 735 | ||
| 736 | else op = OP_BRA; | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 737 | } | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 738 | ||
| 739 | /* Other types of node can be handled by a switch */ | DPRINTF(("insufficient capture room: treat as non-capturing\n")); |
| 740 | ||
| 741 | switch(op) | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 742 | { | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 743 | case OP_BRA: /* Non-capturing bracket: optimized */ | |
| 744 | DPRINTF(("start bracket 0\n")); | /* Non-capturing bracket. Loop for all the alternatives. When we get to the |
| 745 | do | final alternative within the brackets, we would return the result of a |
| 746 | recursive call to match() whatever happened. We can reduce stack usage by | |
| 747 | turning this into a tail recursion, except in the case when match_cbegroup | |
| 748 | is set.*/ | |
| 749 | ||
| 750 | case OP_BRA: | |
| 751 | case OP_SBRA: | |
| 752 | DPRINTF(("start non-capturing bracket\n")); | |
| 753 | flags = (op >= OP_SBRA)? match_cbegroup : 0; | |
| 754 | for (;;) | |
| 755 | { | { |
| 756 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, | if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */ |
| 757 | match_isgroup); | { |
| 758 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (flags == 0) /* Not a possibly empty group */ |
| 759 | { | |
| 760 | ecode += _pcre_OP_lengths[*ecode]; | |
| 761 | DPRINTF(("bracket 0 tail recursion\n")); | |
| 762 | goto TAIL_RECURSE; | |
| 763 | } | |
| 764 | ||
| 765 | /* Possibly empty group; can't use tail recursion. */ | |
| 766 | ||
| 767 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, | |
| 768 | eptrb, flags, RM48); | |
| 769 | RRETURN(rrc); | |
| 770 | } | |
| 771 | ||
| 772 | /* For non-final alternatives, continue the loop for a NOMATCH result; | |
| 773 | otherwise return. */ | |
| 774 | ||
| 775 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, | |
| 776 | eptrb, flags, RM2); | |
| 777 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); | |
| 778 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 779 | } | } |
| 780 | while (*ecode == OP_ALT); | /* Control never reaches here. */ |
| DPRINTF(("bracket 0 failed\n")); | ||
| RRETURN(MATCH_NOMATCH); | ||
| 781 | ||
| 782 | /* Conditional group: compilation checked that there are no more than | /* Conditional group: compilation checked that there are no more than |
| 783 | two branches. If the condition is false, skipping the first branch takes us | two branches. If the condition is false, skipping the first branch takes us |
| 784 | past the end if there is only one branch, but that's OK because that is | past the end if there is only one branch, but that's OK because that is |
| 785 | exactly what going to the ket would do. */ | exactly what going to the ket would do. As there is only one branch to be |
| 786 | obeyed, we can use tail recursion to avoid using another stack frame. */ | |
| 787 | ||
| 788 | case OP_COND: | case OP_COND: |
| 789 | if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */ | case OP_SCOND: |
| 790 | /* Because of the way auto-callout works during compile, a callout item is | |
| 791 | inserted between OP_COND and an assertion condition. */ | |
| 792 | ||
| 793 | if (ecode[LINK_SIZE+1] == OP_CALLOUT) | |
| 794 | { | |
| 795 | if (pcre_callout != NULL) | |
| 796 | { | |
| 797 | pcre_callout_block cb; | |
| 798 | cb.version = 1; /* Version 1 of the callout block */ | |
| 799 | cb.callout_number = ecode[LINK_SIZE+2]; | |
| 800 | cb.offset_vector = md->offset_vector; | |
| 801 | cb.subject = (PCRE_SPTR)md->start_subject; | |
| 802 | cb.subject_length = md->end_subject - md->start_subject; | |
| 803 | cb.start_match = mstart - md->start_subject; | |
| 804 | cb.current_position = eptr - md->start_subject; | |
| 805 | cb.pattern_position = GET(ecode, LINK_SIZE + 3); | |
| 806 | cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE); | |
| 807 | cb.capture_top = offset_top/2; | |
| 808 | cb.capture_last = md->capture_last; | |
| 809 | cb.callout_data = md->callout_data; | |
| 810 | if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH); | |
| 811 | if (rrc < 0) RRETURN(rrc); | |
| 812 | } | |
| 813 | ecode += _pcre_OP_lengths[OP_CALLOUT]; | |
| 814 | } | |
| 815 | ||
| 816 | /* Now see what the actual condition is */ | |
| 817 | ||
| 818 | if (ecode[LINK_SIZE+1] == OP_RREF) /* Recursion test */ | |
| 819 | { | |
| 820 | offset = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ | |
| 821 | condition = md->recursive != NULL && | |
| 822 | (offset == RREF_ANY || offset == md->recursive->group_num); | |
| 823 | ecode += condition? 3 : GET(ecode, 1); | |
| 824 | } | |
| 825 | ||
| 826 | else if (ecode[LINK_SIZE+1] == OP_CREF) /* Group used test */ | |
| 827 | { | { |
| 828 | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ |
| 829 | condition = (offset == CREF_RECURSE * 2)? | condition = offset < offset_top && md->offset_vector[offset] >= 0; |
| 830 | (md->recursive != NULL) : | ecode += condition? 3 : GET(ecode, 1); |
| 831 | (offset < offset_top && md->offset_vector[offset] >= 0); | } |
| 832 | RMATCH(rrc, eptr, ecode + (condition? | |
| 833 | (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1))), | else if (ecode[LINK_SIZE+1] == OP_DEF) /* DEFINE - always false */ |
| 834 | offset_top, md, ims, eptrb, match_isgroup); | { |
| 835 | RRETURN(rrc); | condition = FALSE; |
| 836 | ecode += GET(ecode, 1); | |
| 837 | } | } |
| 838 | ||
| 839 | /* The condition is an assertion. Call match() to evaluate it - setting | /* The condition is an assertion. Call match() to evaluate it - setting |
| 840 | the final argument TRUE causes it to stop at the end of an assertion. */ | the final argument match_condassert causes it to stop at the end of an |
| 841 | assertion. */ | |
| 842 | ||
| 843 | else | else |
| 844 | { | { |
| 845 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, |
| 846 | match_condassert | match_isgroup); | match_condassert, RM3); |
| 847 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
| 848 | { | { |
| 849 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2); | condition = TRUE; |
| 850 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); | |
| 851 | while (*ecode == OP_ALT) ecode += GET(ecode, 1); | while (*ecode == OP_ALT) ecode += GET(ecode, 1); |
| 852 | } | } |
| 853 | else if (rrc != MATCH_NOMATCH) | else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
| 854 | { | { |
| 855 | RRETURN(rrc); /* Need braces because of following else */ | RRETURN(rrc); /* Need braces because of following else */ |
| 856 | } | } |
| 857 | else ecode += GET(ecode, 1); | else |
| 858 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, | { |
| 859 | match_isgroup); | condition = FALSE; |
| 860 | RRETURN(rrc); | ecode += GET(ecode, 1); |
| 861 | } | |
| 862 | } | } |
| /* Control never reaches here */ | ||
| 863 | ||
| 864 | /* Skip over conditional reference or large extraction number data if | /* We are now at the branch that is to be obeyed. As there is only one, |
| 865 | encountered. */ | we can use tail recursion to avoid using another stack frame, except when |
| 866 | match_cbegroup is required for an unlimited repeat of a possibly empty | |
| 867 | group. If the second alternative doesn't exist, we can just plough on. */ | |
| 868 | ||
| 869 | case OP_CREF: | if (condition || *ecode == OP_ALT) |
| 870 | case OP_BRANUMBER: | { |
| 871 | ecode += 3; | ecode += 1 + LINK_SIZE; |
| 872 | if (op == OP_SCOND) /* Possibly empty group */ | |
| 873 | { | |
| 874 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49); | |
| 875 | RRETURN(rrc); | |
| 876 | } | |
| 877 | else /* Group must match something */ | |
| 878 | { | |
| 879 | flags = 0; | |
| 880 | goto TAIL_RECURSE; | |
| 881 | } | |
| 882 | } | |
| 883 | else /* Condition false & no 2nd alternative */ | |
| 884 | { | |
| 885 | ecode += 1 + LINK_SIZE; | |
| 886 | } | |
| 887 | break; | break; |
| 888 | ||
| /* End of the pattern. If we are in a recursion, we should restore the | ||
| offsets appropriately and continue from after the call. */ | ||
| 889 | ||
| 890 | /* End of the pattern, either real or forced. If we are in a top-level | |
| 891 | recursion, we should restore the offsets appropriately and continue from | |
| 892 | after the call. */ | |
| 893 | ||
| 894 | case OP_ACCEPT: | |
| 895 | case OP_END: | case OP_END: |
| 896 | if (md->recursive != NULL && md->recursive->group_num == 0) | if (md->recursive != NULL && md->recursive->group_num == 0) |
| 897 | { | { |
| 898 | recursion_info *rec = md->recursive; | recursion_info *rec = md->recursive; |
| 899 | DPRINTF(("Hit the end in a (?0) recursion\n")); | DPRINTF(("End of pattern in a (?0) recursion\n")); |
| 900 | md->recursive = rec->prevrec; | md->recursive = rec->prevrec; |
| 901 | memmove(md->offset_vector, rec->offset_save, | memmove(md->offset_vector, rec->offset_save, |
| 902 | rec->saved_max * sizeof(int)); | rec->saved_max * sizeof(int)); |
| 903 | md->start_match = rec->save_start; | mstart = rec->save_start; |
| 904 | ims = original_ims; | ims = original_ims; |
| 905 | ecode = rec->after_call; | ecode = rec->after_call; |
| 906 | break; | break; |
| # | Line 694 for (;;) | Line 909 for (;;) |
| 909 | /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty | /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty |
| 910 | string - backtracking will then try other alternatives, if any. */ | string - backtracking will then try other alternatives, if any. */ |
| 911 | ||
| 912 | if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH); | if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH); |
| 913 | md->end_match_ptr = eptr; /* Record where we ended */ | md->end_match_ptr = eptr; /* Record where we ended */ |
| 914 | md->end_offset_top = offset_top; /* and how many extracts were taken */ | md->end_offset_top = offset_top; /* and how many extracts were taken */ |
| 915 | md->start_match_ptr = mstart; /* and the start (\K can modify) */ | |
| 916 | RRETURN(MATCH_MATCH); | RRETURN(MATCH_MATCH); |
| 917 | ||
| 918 | /* Change option settings */ | /* Change option settings */ |
| # | Line 717 for (;;) | Line 933 for (;;) |
| 933 | case OP_ASSERTBACK: | case OP_ASSERTBACK: |
| 934 | do | do |
| 935 | { | { |
| 936 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, |
| 937 | match_isgroup); | RM4); |
| 938 | if (rrc == MATCH_MATCH) break; | if (rrc == MATCH_MATCH) break; |
| 939 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 940 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 941 | } | } |
| 942 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| # | Line 744 for (;;) | Line 960 for (;;) |
| 960 | case OP_ASSERTBACK_NOT: | case OP_ASSERTBACK_NOT: |
| 961 | do | do |
| 962 | { | { |
| 963 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, |
| 964 | match_isgroup); | RM5); |
| 965 | if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); | if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); |
| 966 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 967 | ecode += GET(ecode,1); | ecode += GET(ecode,1); |
| 968 | } | } |
| 969 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| # | Line 766 for (;;) | Line 982 for (;;) |
| 982 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 983 | if (utf8) | if (utf8) |
| 984 | { | { |
| 985 | c = GET(ecode,1); | i = GET(ecode, 1); |
| 986 | for (i = 0; i < c; i++) | while (i-- > 0) |
| 987 | { | { |
| 988 | eptr--; | eptr--; |
| 989 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); |
| 990 | BACKCHAR(eptr) | BACKCHAR(eptr); |
| 991 | } | } |
| 992 | } | } |
| 993 | else | else |
| # | Line 780 for (;;) | Line 996 for (;;) |
| 996 | /* No UTF-8 support, or not in UTF-8 mode: count is byte count */ | /* No UTF-8 support, or not in UTF-8 mode: count is byte count */ |
| 997 | ||
| 998 | { | { |
| 999 | eptr -= GET(ecode,1); | eptr -= GET(ecode, 1); |
| 1000 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1001 | } | } |
| 1002 | ||
| # | Line 800 for (;;) | Line 1016 for (;;) |
| 1016 | cb.version = 1; /* Version 1 of the callout block */ | cb.version = 1; /* Version 1 of the callout block */ |
| 1017 | cb.callout_number = ecode[1]; | cb.callout_number = ecode[1]; |
| 1018 | cb.offset_vector = md->offset_vector; | cb.offset_vector = md->offset_vector; |
| 1019 | cb.subject = (const char *)md->start_subject; | cb.subject = (PCRE_SPTR)md->start_subject; |
| 1020 | cb.subject_length = md->end_subject - md->start_subject; | cb.subject_length = md->end_subject - md->start_subject; |
| 1021 | cb.start_match = md->start_match - md->start_subject; | cb.start_match = mstart - md->start_subject; |
| 1022 | cb.current_position = eptr - md->start_subject; | cb.current_position = eptr - md->start_subject; |
| 1023 | cb.pattern_position = GET(ecode, 2); | cb.pattern_position = GET(ecode, 2); |
| 1024 | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); |
| # | Line 837 for (;;) | Line 1053 for (;;) |
| 1053 | case OP_RECURSE: | case OP_RECURSE: |
| 1054 | { | { |
| 1055 | callpat = md->start_code + GET(ecode, 1); | callpat = md->start_code + GET(ecode, 1); |
| 1056 | new_recursive.group_num = *callpat - OP_BRA; | new_recursive.group_num = (callpat == md->start_code)? 0 : |
| 1057 | GET2(callpat, 1 + LINK_SIZE); | |
| /* For extended extraction brackets (large number), we have to fish out | ||
| the number from a dummy opcode at the start. */ | ||
| if (new_recursive.group_num > EXTRACT_BASIC_MAX) | ||
| new_recursive.group_num = GET2(callpat, 2+LINK_SIZE); | ||
| 1058 | ||
| 1059 | /* Add to "recursing stack" */ | /* Add to "recursing stack" */ |
| 1060 | ||
| # | Line 869 for (;;) | Line 1080 for (;;) |
| 1080 | ||
| 1081 | memcpy(new_recursive.offset_save, md->offset_vector, | memcpy(new_recursive.offset_save, md->offset_vector, |
| 1082 | new_recursive.saved_max * sizeof(int)); | new_recursive.saved_max * sizeof(int)); |
| 1083 | new_recursive.save_start = md->start_match; | new_recursive.save_start = mstart; |
| 1084 | md->start_match = eptr; | mstart = eptr; |
| 1085 | ||
| 1086 | /* OK, now we can do the recursion. For each top-level alternative we | /* OK, now we can do the recursion. For each top-level alternative we |
| 1087 | restore the offset and recursion data. */ | restore the offset and recursion data. */ |
| 1088 | ||
| 1089 | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); |
| 1090 | flags = (*callpat >= OP_SBRA)? match_cbegroup : 0; | |
| 1091 | do | do |
| 1092 | { | { |
| 1093 | RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims, | RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, |
| 1094 | eptrb, match_isgroup); | md, ims, eptrb, flags, RM6); |
| 1095 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
| 1096 | { | { |
| 1097 | DPRINTF(("Recursion matched\n")); | |
| 1098 | md->recursive = new_recursive.prevrec; | md->recursive = new_recursive.prevrec; |
| 1099 | if (new_recursive.offset_save != stacksave) | if (new_recursive.offset_save != stacksave) |
| 1100 | (pcre_free)(new_recursive.offset_save); | (pcre_free)(new_recursive.offset_save); |
| 1101 | RRETURN(MATCH_MATCH); | RRETURN(MATCH_MATCH); |
| 1102 | } | } |
| 1103 | else if (rrc != MATCH_NOMATCH) RRETURN(rrc); | else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
| 1104 | { | |
| 1105 | DPRINTF(("Recursion gave error %d\n", rrc)); | |
| 1106 | RRETURN(rrc); | |
| 1107 | } | |
| 1108 | ||
| 1109 | md->recursive = &new_recursive; | md->recursive = &new_recursive; |
| 1110 | memcpy(md->offset_vector, new_recursive.offset_save, | memcpy(md->offset_vector, new_recursive.offset_save, |
| # | Line 912 for (;;) | Line 1129 for (;;) |
| 1129 | the end of a normal bracket, leaving the subject pointer. */ | the end of a normal bracket, leaving the subject pointer. */ |
| 1130 | ||
| 1131 | case OP_ONCE: | case OP_ONCE: |
| 1132 | { | prev = ecode; |
| 1133 | prev = ecode; | saved_eptr = eptr; |
| saved_eptr = eptr; | ||
| 1134 | ||
| 1135 | do | do |
| 1136 | { | { |
| 1137 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7); |
| 1138 | eptrb, match_isgroup); | if (rrc == MATCH_MATCH) break; |
| 1139 | if (rrc == MATCH_MATCH) break; | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 1140 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ecode += GET(ecode,1); |
| 1141 | ecode += GET(ecode,1); | } |
| 1142 | } | while (*ecode == OP_ALT); |
| while (*ecode == OP_ALT); | ||
| 1143 | ||
| 1144 | /* If hit the end of the group (which could be repeated), fail */ | /* If hit the end of the group (which could be repeated), fail */ |
| 1145 | ||
| 1146 | if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); | if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); |
| 1147 | ||
| 1148 | /* Continue as from after the assertion, updating the offsets high water | /* Continue as from after the assertion, updating the offsets high water |
| 1149 | mark, since extracts may have been taken. */ | mark, since extracts may have been taken. */ |
| 1150 | ||
| 1151 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | do ecode += GET(ecode, 1); while (*ecode == OP_ALT); |
| 1152 | ||
| 1153 | offset_top = md->end_offset_top; | offset_top = md->end_offset_top; |
| 1154 | eptr = md->end_match_ptr; | eptr = md->end_match_ptr; |
| 1155 | ||
| 1156 | /* For a non-repeating ket, just continue at this level. This also | /* For a non-repeating ket, just continue at this level. This also |
| 1157 | happens for a repeating ket if no characters were matched in the group. | happens for a repeating ket if no characters were matched in the group. |
| 1158 | This is the forcible breaking of infinite loops as implemented in Perl | This is the forcible breaking of infinite loops as implemented in Perl |
| 1159 | 5.005. If there is an options reset, it will get obeyed in the normal | 5.005. If there is an options reset, it will get obeyed in the normal |
| 1160 | course of events. */ | course of events. */ |
| 1161 | ||
| 1162 | if (*ecode == OP_KET || eptr == saved_eptr) | if (*ecode == OP_KET || eptr == saved_eptr) |
| 1163 | { | { |
| 1164 | ecode += 1+LINK_SIZE; | ecode += 1+LINK_SIZE; |
| 1165 | break; | break; |
| 1166 | } | } |
| 1167 | ||
| 1168 | /* The repeating kets try the rest of the pattern or restart from the | /* The repeating kets try the rest of the pattern or restart from the |
| 1169 | preceding bracket, in the appropriate order. We need to reset any options | preceding bracket, in the appropriate order. The second "call" of match() |
| 1170 | that changed within the bracket before re-running it, so check the next | uses tail recursion, to avoid using another stack frame. We need to reset |
| 1171 | opcode. */ | any options that changed within the bracket before re-running it, so |
| 1172 | check the next opcode. */ | |
| 1173 | ||
| 1174 | if (ecode[1+LINK_SIZE] == OP_OPT) | if (ecode[1+LINK_SIZE] == OP_OPT) |
| 1175 | { | { |
| 1176 | ims = (ims & ~PCRE_IMS) | ecode[4]; | ims = (ims & ~PCRE_IMS) | ecode[4]; |
| 1177 | DPRINTF(("ims set to %02lx at group repeat\n", ims)); | DPRINTF(("ims set to %02lx at group repeat\n", ims)); |
| 1178 | } | } |
| 1179 | ||
| 1180 | if (*ecode == OP_KETRMIN) | if (*ecode == OP_KETRMIN) |
| 1181 | { | { |
| 1182 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8); |
| 1183 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1184 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | ecode = prev; |
| 1185 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | flags = 0; |
| 1186 | } | goto TAIL_RECURSE; |
| else /* OP_KETRMAX */ | ||
| { | ||
| RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | ||
| if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ||
| RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); | ||
| if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ||
| } | ||
| 1187 | } | } |
| 1188 | RRETURN(MATCH_NOMATCH); | else /* OP_KETRMAX */ |
| 1189 | { | |
| 1190 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9); | |
| 1191 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 1192 | ecode += 1 + LINK_SIZE; | |
| 1193 | flags = 0; | |
| 1194 | goto TAIL_RECURSE; | |
| 1195 | } | |
| 1196 | /* Control never gets here */ | |
| 1197 | ||
| 1198 | /* An alternation is the end of a branch; scan along to find the end of the | /* An alternation is the end of a branch; scan along to find the end of the |
| 1199 | bracketed group and go to there. */ | bracketed group and go to there. */ |
| # | Line 985 for (;;) | Line 1202 for (;;) |
| 1202 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
| 1203 | break; | break; |
| 1204 | ||
| 1205 | /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating | /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group, |
| 1206 | that it may occur zero times. It may repeat infinitely, or not at all - | indicating that it may occur zero times. It may repeat infinitely, or not |
| 1207 | i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper | at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets |
| 1208 | repeat limits are compiled as a number of copies, with the optional ones | with fixed upper repeat limits are compiled as a number of copies, with the |
| 1209 | preceded by BRAZERO or BRAMINZERO. */ | optional ones preceded by BRAZERO or BRAMINZERO. */ |
| 1210 | ||
| 1211 | case OP_BRAZERO: | case OP_BRAZERO: |
| 1212 | { | { |
| 1213 | next = ecode+1; | next = ecode+1; |
| 1214 | RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10); |
| 1215 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1216 | do next += GET(next,1); while (*next == OP_ALT); | do next += GET(next,1); while (*next == OP_ALT); |
| 1217 | ecode = next + 1+LINK_SIZE; | ecode = next + 1 + LINK_SIZE; |
| 1218 | } | } |
| 1219 | break; | break; |
| 1220 | ||
| 1221 | case OP_BRAMINZERO: | case OP_BRAMINZERO: |
| 1222 | { | { |
| 1223 | next = ecode+1; | next = ecode+1; |
| 1224 | do next += GET(next,1); while (*next == OP_ALT); | do next += GET(next, 1); while (*next == OP_ALT); |
| 1225 | RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, | RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11); |
| match_isgroup); | ||
| 1226 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1227 | ecode++; | ecode++; |
| 1228 | } | } |
| 1229 | break; | break; |
| 1230 | ||
| 1231 | /* End of a group, repeated or non-repeating. If we are at the end of | case OP_SKIPZERO: |
| 1232 | an assertion "group", stop matching and return MATCH_MATCH, but record the | { |
| 1233 | current high water mark for use by positive assertions. Do this also | next = ecode+1; |
| 1234 | for the "once" (not-backup up) groups. */ | do next += GET(next,1); while (*next == OP_ALT); |
| 1235 | ecode = next + 1 + LINK_SIZE; | |
| 1236 | } | |
| 1237 | break; | |
| 1238 | ||
| 1239 | /* End of a group, repeated or non-repeating. */ | |
| 1240 | ||
| 1241 | case OP_KET: | case OP_KET: |
| 1242 | case OP_KETRMIN: | case OP_KETRMIN: |
| 1243 | case OP_KETRMAX: | case OP_KETRMAX: |
| 1244 | { | prev = ecode - GET(ecode, 1); |
| prev = ecode - GET(ecode, 1); | ||
| saved_eptr = eptrb->epb_saved_eptr; | ||
| 1245 | ||
| 1246 | /* Back up the stack of bracket start pointers. */ | /* If this was a group that remembered the subject start, in order to break |
| 1247 | infinite repeats of empty string matches, retrieve the subject start from | |
| 1248 | the chain. Otherwise, set it NULL. */ | |
| 1249 | ||
| 1250 | eptrb = eptrb->epb_prev; | if (*prev >= OP_SBRA) |
| 1251 | { | |
| 1252 | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || | saved_eptr = eptrb->epb_saved_eptr; /* Value at start of group */ |
| 1253 | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || | eptrb = eptrb->epb_prev; /* Backup to previous group */ |
| 1254 | *prev == OP_ONCE) | } |
| 1255 | { | else saved_eptr = NULL; |
| md->end_match_ptr = eptr; /* For ONCE */ | ||
| md->end_offset_top = offset_top; | ||
| RRETURN(MATCH_MATCH); | ||
| } | ||
| 1256 | ||
| 1257 | /* In all other cases except a conditional group we have to check the | /* If we are at the end of an assertion group, stop matching and return |
| 1258 | group number back at the start and if necessary complete handling an | MATCH_MATCH, but record the current high water mark for use by positive |
| 1259 | extraction by setting the offsets and bumping the high water mark. */ | assertions. Do this also for the "once" (atomic) groups. */ |
| 1260 | ||
| 1261 | if (*prev != OP_COND) | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || |
| 1262 | { | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || |
| 1263 | number = *prev - OP_BRA; | *prev == OP_ONCE) |
| 1264 | { | |
| 1265 | md->end_match_ptr = eptr; /* For ONCE */ | |
| 1266 | md->end_offset_top = offset_top; | |
| 1267 | RRETURN(MATCH_MATCH); | |
| 1268 | } | |
| 1269 | ||
| 1270 | /* For extended extraction brackets (large number), we have to fish out | /* For capturing groups we have to check the group number back at the start |
| 1271 | the number from a dummy opcode at the start. */ | and if necessary complete handling an extraction by setting the offsets and |
| 1272 | bumping the high water mark. Note that whole-pattern recursion is coded as | |
| 1273 | a recurse into group 0, so it won't be picked up here. Instead, we catch it | |
| 1274 | when the OP_END is reached. Other recursion is handled here. */ | |
| 1275 | ||
| 1276 | if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE); | if (*prev == OP_CBRA || *prev == OP_SCBRA) |
| 1277 | offset = number << 1; | { |
| 1278 | number = GET2(prev, 1+LINK_SIZE); | |
| 1279 | offset = number << 1; | |
| 1280 | ||
| 1281 | #ifdef DEBUG | #ifdef DEBUG |
| 1282 | printf("end bracket %d", number); | printf("end bracket %d", number); |
| 1283 | printf("\n"); | printf("\n"); |
| 1284 | #endif | #endif |
| 1285 | ||
| 1286 | /* Test for a numbered group. This includes groups called as a result | md->capture_last = number; |
| 1287 | of recursion. Note that whole-pattern recursion is coded as a recurse | if (offset >= md->offset_max) md->offset_overflow = TRUE; else |
| 1288 | into group 0, so it won't be picked up here. Instead, we catch it when | { |
| 1289 | the OP_END is reached. */ | md->offset_vector[offset] = |
| 1290 | md->offset_vector[md->offset_end - number]; | |
| 1291 | if (number > 0) | md->offset_vector[offset+1] = eptr - md->start_subject; |
| 1292 | { | if (offset_top <= offset) offset_top = offset + 2; |
| 1293 | md->capture_last = number; | } |
| 1294 | if (offset >= md->offset_max) md->offset_overflow = TRUE; else | |
| 1295 | { | /* Handle a recursively called group. Restore the offsets |
| 1296 | md->offset_vector[offset] = | appropriately and continue from after the call. */ |
| 1297 | md->offset_vector[md->offset_end - number]; | |
| 1298 | md->offset_vector[offset+1] = eptr - md->start_subject; | if (md->recursive != NULL && md->recursive->group_num == number) |
| 1299 | if (offset_top <= offset) offset_top = offset + 2; | { |
| 1300 | } | recursion_info *rec = md->recursive; |
| 1301 | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); | |
| 1302 | /* Handle a recursively called group. Restore the offsets | md->recursive = rec->prevrec; |
| 1303 | appropriately and continue from after the call. */ | mstart = rec->save_start; |
| 1304 | memcpy(md->offset_vector, rec->offset_save, | |
| 1305 | if (md->recursive != NULL && md->recursive->group_num == number) | rec->saved_max * sizeof(int)); |
| 1306 | { | ecode = rec->after_call; |
| 1307 | recursion_info *rec = md->recursive; | ims = original_ims; |
| 1308 | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); | break; |
| md->recursive = rec->prevrec; | ||
| md->start_match = rec->save_start; | ||
| memcpy(md->offset_vector, rec->offset_save, | ||
| rec->saved_max * sizeof(int)); | ||
| ecode = rec->after_call; | ||
| ims = original_ims; | ||
| break; | ||
| } | ||
| } | ||
| 1309 | } | } |
| 1310 | } | |
| 1311 | ||
| 1312 | /* Reset the value of the ims flags, in case they got changed during | /* For both capturing and non-capturing groups, reset the value of the ims |
| 1313 | the group. */ | flags, in case they got changed during the group. */ |
| 1314 | ||
| 1315 | ims = original_ims; | ims = original_ims; |
| 1316 | DPRINTF(("ims reset to %02lx\n", ims)); | DPRINTF(("ims reset to %02lx\n", ims)); |
| 1317 | ||
| 1318 | /* For a non-repeating ket, just continue at this level. This also | /* For a non-repeating ket, just continue at this level. This also |
| 1319 | happens for a repeating ket if no characters were matched in the group. | happens for a repeating ket if no characters were matched in the group. |
| 1320 | This is the forcible breaking of infinite loops as implemented in Perl | This is the forcible breaking of infinite loops as implemented in Perl |
| 1321 | 5.005. If there is an options reset, it will get obeyed in the normal | 5.005. If there is an options reset, it will get obeyed in the normal |
| 1322 | course of events. */ | course of events. */ |
| 1323 | ||
| 1324 | if (*ecode == OP_KET || eptr == saved_eptr) | if (*ecode == OP_KET || eptr == saved_eptr) |
| 1325 | { | { |
| 1326 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1327 | break; | break; |
| 1328 | } | } |
| 1329 | ||
| 1330 | /* The repeating kets try the rest of the pattern or restart from the | /* The repeating kets try the rest of the pattern or restart from the |
| 1331 | preceding bracket, in the appropriate order. */ | preceding bracket, in the appropriate order. In the second case, we can use |
| 1332 | tail recursion to avoid using another stack frame, unless we have an | |
| 1333 | unlimited repeat of a group that can match an empty string. */ | |
| 1334 | ||
| 1335 | if (*ecode == OP_KETRMIN) | flags = (*prev >= OP_SBRA)? match_cbegroup : 0; |
| 1336 | { | |
| 1337 | RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); | if (*ecode == OP_KETRMIN) |
| 1338 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | { |
| 1339 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12); |
| 1340 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1341 | } | if (flags != 0) /* Could match an empty string */ |
| else /* OP_KETRMAX */ | ||
| 1342 | { | { |
| 1343 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50); |
| 1344 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | RRETURN(rrc); |
| RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); | ||
| if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ||
| 1345 | } | } |
| 1346 | ecode = prev; | |
| 1347 | goto TAIL_RECURSE; | |
| 1348 | } | } |
| 1349 | else /* OP_KETRMAX */ | |
| 1350 | RRETURN(MATCH_NOMATCH); | { |
| 1351 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13); | |
| 1352 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 1353 | ecode += 1 + LINK_SIZE; | |
| 1354 | flags = 0; | |
| 1355 | goto TAIL_RECURSE; | |
| 1356 | } | |
| 1357 | /* Control never gets here */ | |
| 1358 | ||
| 1359 | /* Start of subject unless notbol, or after internal newline if multiline */ | /* Start of subject unless notbol, or after internal newline if multiline */ |
| 1360 | ||
| # | Line 1135 for (;;) | Line 1362 for (;;) |
| 1362 | if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); | if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1363 | if ((ims & PCRE_MULTILINE) != 0) | if ((ims & PCRE_MULTILINE) != 0) |
| 1364 | { | { |
| 1365 | if (eptr != md->start_subject && eptr[-1] != NEWLINE) | if (eptr != md->start_subject && |
| 1366 | (eptr == md->end_subject || !WAS_NEWLINE(eptr))) | |
| 1367 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1368 | ecode++; | ecode++; |
| 1369 | break; | break; |
| # | Line 1156 for (;;) | Line 1384 for (;;) |
| 1384 | ecode++; | ecode++; |
| 1385 | break; | break; |
| 1386 | ||
| 1387 | /* Reset the start of match point */ | |
| 1388 | ||
| 1389 | case OP_SET_SOM: | |
| 1390 | mstart = eptr; | |
| 1391 | ecode++; | |
| 1392 | break; | |
| 1393 | ||
| 1394 | /* Assert before internal newline if multiline, or before a terminating | /* Assert before internal newline if multiline, or before a terminating |
| 1395 | newline unless endonly is set, else end of subject unless noteol is set. */ | newline unless endonly is set, else end of subject unless noteol is set. */ |
| 1396 | ||
| # | Line 1163 for (;;) | Line 1398 for (;;) |
| 1398 | if ((ims & PCRE_MULTILINE) != 0) | if ((ims & PCRE_MULTILINE) != 0) |
| 1399 | { | { |
| 1400 | if (eptr < md->end_subject) | if (eptr < md->end_subject) |
| 1401 | { if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); } | { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); } |
| 1402 | else | else |
| 1403 | { if (md->noteol) RRETURN(MATCH_NOMATCH); } | { if (md->noteol) RRETURN(MATCH_NOMATCH); } |
| 1404 | ecode++; | ecode++; |
| # | Line 1174 for (;;) | Line 1409 for (;;) |
| 1409 | if (md->noteol) RRETURN(MATCH_NOMATCH); | if (md->noteol) RRETURN(MATCH_NOMATCH); |
| 1410 | if (!md->endonly) | if (!md->endonly) |
| 1411 | { | { |
| 1412 | if (eptr < md->end_subject - 1 || | if (eptr != md->end_subject && |
| 1413 | (eptr == md->end_subject - 1 && *eptr != NEWLINE)) | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
| 1414 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1415 | ecode++; | ecode++; |
| 1416 | break; | break; |
| 1417 | } | } |
| 1418 | } | } |
| 1419 | /* ... else fall through */ | /* ... else fall through for endonly */ |
| 1420 | ||
| 1421 | /* End of subject assertion (\z) */ | /* End of subject assertion (\z) */ |
| 1422 | ||
| # | Line 1193 for (;;) | Line 1428 for (;;) |
| 1428 | /* End of subject or ending \n assertion (\Z) */ | /* End of subject or ending \n assertion (\Z) */ |
| 1429 | ||
| 1430 | case OP_EODN: | case OP_EODN: |
| 1431 | if (eptr < md->end_subject - 1 || | if (eptr != md->end_subject && |
| 1432 | (eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH); | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
| 1433 | RRETURN(MATCH_NOMATCH); | |
| 1434 | ecode++; | ecode++; |
| 1435 | break; | break; |
| 1436 | ||
| # | Line 1247 for (;;) | Line 1483 for (;;) |
| 1483 | /* Match a single character type; inline for speed */ | /* Match a single character type; inline for speed */ |
| 1484 | ||
| 1485 | case OP_ANY: | case OP_ANY: |
| 1486 | if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE) | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); |
| 1487 | RRETURN(MATCH_NOMATCH); | /* Fall through */ |
| 1488 | ||
| 1489 | case OP_ALLANY: | |
| 1490 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 1491 | #ifdef SUPPORT_UTF8 | if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| if (utf8) | ||
| while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
| #endif | ||
| 1492 | ecode++; | ecode++; |
| 1493 | break; | break; |
| 1494 | ||
| # | Line 1343 for (;;) | Line 1578 for (;;) |
| 1578 | ecode++; | ecode++; |
| 1579 | break; | break; |
| 1580 | ||
| 1581 | #ifdef SUPPORT_UCP | case OP_ANYNL: |
| /* Check the next character by Unicode property. We will get here only | ||
| if the support is in the binary; otherwise a compile-time error occurs. */ | ||
| case OP_PROP: | ||
| case OP_NOTPROP: | ||
| 1582 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 1583 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1584 | switch(c) | |
| 1585 | { | { |
| 1586 | int chartype, rqdtype; | default: RRETURN(MATCH_NOMATCH); |
| 1587 | int othercase; | case 0x000d: |
| 1588 | int category = ucp_findchar(c, &chartype, &othercase); | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
| 1589 | break; | |
| 1590 | ||
| 1591 | rqdtype = *(++ecode); | case 0x000a: |
| 1592 | ecode++; | break; |
| 1593 | ||
| 1594 | if (rqdtype >= 128) | case 0x000b: |
| 1595 | { | case 0x000c: |
| 1596 | if ((rqdtype - 128 != category) == (op == OP_PROP)) | case 0x0085: |
| 1597 | RRETURN(MATCH_NOMATCH); | case 0x2028: |
| 1598 | } | case 0x2029: |
| 1599 | else | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); |
| 1600 | { | break; |
| if ((rqdtype != chartype) == (op == OP_PROP)) | ||
| RRETURN(MATCH_NOMATCH); | ||
| } | ||
| 1601 | } | } |
| 1602 | ecode++; | |
| 1603 | break; | break; |
| 1604 | ||
| 1605 | /* Match an extended Unicode sequence. We will get here only if the support | case OP_NOT_HSPACE: |
| is in the binary; otherwise a compile-time error occurs. */ | ||
| case OP_EXTUNI: | ||
| 1606 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 1607 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1608 | switch(c) | |
| 1609 | { | { |
| 1610 | int chartype; | default: break; |
| 1611 | int othercase; | case 0x09: /* HT */ |
| 1612 | int category = ucp_findchar(c, &chartype, &othercase); | case 0x20: /* SPACE */ |
| 1613 | if (category == ucp_M) RRETURN(MATCH_NOMATCH); | case 0xa0: /* NBSP */ |
| 1614 | while (eptr < md->end_subject) | case 0x1680: /* OGHAM SPACE MARK */ |
| 1615 | { | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 1616 | int len = 1; | case 0x2000: /* EN QUAD */ |
| 1617 | if (!utf8) c = *eptr; else | case 0x2001: /* EM QUAD */ |
| 1618 | { | case 0x2002: /* EN SPACE */ |
| 1619 | GETCHARLEN(c, eptr, len); | case 0x2003: /* EM SPACE */ |
| 1620 | } | case 0x2004: /* THREE-PER-EM SPACE */ |
| 1621 | category = ucp_findchar(c, &chartype, &othercase); | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 1622 | if (category != ucp_M) break; | case 0x2006: /* SIX-PER-EM SPACE */ |
| 1623 | eptr += len; | case 0x2007: /* FIGURE SPACE */ |
| 1624 | } | case 0x2008: /* PUNCTUATION SPACE */ |
| 1625 | case 0x2009: /* THIN SPACE */ | |
| 1626 | case 0x200A: /* HAIR SPACE */ | |
| 1627 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 1628 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 1629 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 1630 | RRETURN(MATCH_NOMATCH); | |
| 1631 | } | } |
| 1632 | ecode++; | ecode++; |
| 1633 | break; | break; |
| #endif | ||
| /* Match a back reference, possibly repeatedly. Look past the end of the | ||
| item to see if there is repeat information following. The code is similar | ||
| to that for character classes, but repeated for efficiency. Then obey | ||
| similar code to character type repeats - written out again for speed. | ||
| However, if the referenced string is the empty string, always treat | ||
| it as matched, any number of times (otherwise there could be infinite | ||
| loops). */ | ||
| 1634 | ||
| 1635 | case OP_REF: | case OP_HSPACE: |
| 1636 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 1637 | GETCHARINCTEST(c, eptr); | |
| 1638 | switch(c) | |
| 1639 | { | { |
| 1640 | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ | default: RRETURN(MATCH_NOMATCH); |
| 1641 | ecode += 3; /* Advance past item */ | case 0x09: /* HT */ |
| 1642 | case 0x20: /* SPACE */ | |
| 1643 | case 0xa0: /* NBSP */ | |
| 1644 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 1645 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 1646 | case 0x2000: /* EN QUAD */ | |
| 1647 | case 0x2001: /* EM QUAD */ | |
| 1648 | case 0x2002: /* EN SPACE */ | |
| 1649 | case 0x2003: /* EM SPACE */ | |
| 1650 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 1651 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 1652 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 1653 | case 0x2007: /* FIGURE SPACE */ | |
| 1654 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 1655 | case 0x2009: /* THIN SPACE */ | |
| 1656 | case 0x200A: /* HAIR SPACE */ | |
| 1657 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 1658 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 1659 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 1660 | break; | |
| 1661 | } | |
| 1662 | ecode++; | |
| 1663 | break; | |
| 1664 | ||
| 1665 | /* If the reference is unset, set the length to be longer than the amount | case OP_NOT_VSPACE: |
| 1666 | of subject left; this ensures that every attempt at a match fails. We | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 1667 | can't just fail here, because of the possibility of quantifiers with zero | GETCHARINCTEST(c, eptr); |
| 1668 | minima. */ | switch(c) |
| 1669 | { | |
| 1670 | length = (offset >= offset_top || md->offset_vector[offset] < 0)? | default: break; |
| 1671 | md->end_subject - eptr + 1 : | case 0x0a: /* LF */ |
| 1672 | md->offset_vector[offset+1] - md->offset_vector[offset]; | case 0x0b: /* VT */ |
| 1673 | case 0x0c: /* FF */ | |
| 1674 | case 0x0d: /* CR */ | |
| 1675 | case 0x85: /* NEL */ | |
| 1676 | case 0x2028: /* LINE SEPARATOR */ | |
| 1677 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 1678 | RRETURN(MATCH_NOMATCH); | |
| 1679 | } | |
| 1680 | ecode++; | |
| 1681 | break; | |
| 1682 | ||
| 1683 | case OP_VSPACE: | |
| 1684 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 1685 | GETCHARINCTEST(c, eptr); | |
| 1686 | switch(c) | |
| 1687 | { | |
| 1688 | default: RRETURN(MATCH_NOMATCH); | |
| 1689 | case 0x0a: /* LF */ | |
| 1690 | case 0x0b: /* VT */ | |
| 1691 | case 0x0c: /* FF */ | |
| 1692 | case 0x0d: /* CR */ | |
| 1693 | case 0x85: /* NEL */ | |
| 1694 | case 0x2028: /* LINE SEPARATOR */ | |
| 1695 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 1696 | break; | |
| 1697 | } | |
| 1698 | ecode++; | |
| 1699 | break; | |
| 1700 | ||
| 1701 | #ifdef SUPPORT_UCP | |
| 1702 | /* Check the next character by Unicode property. We will get here only | |
| 1703 | if the support is in the binary; otherwise a compile-time error occurs. */ | |
| 1704 | ||
| 1705 | case OP_PROP: | |
| 1706 | case OP_NOTPROP: | |
| 1707 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 1708 | GETCHARINCTEST(c, eptr); | |
| 1709 | { | |
| 1710 | const ucd_record *prop = GET_UCD(c); | |
| 1711 | ||
| 1712 | switch(ecode[1]) | |
| 1713 | { | |
| 1714 | case PT_ANY: | |
| 1715 | if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH); | |
| 1716 | break; | |
| 1717 | ||
| 1718 | case PT_LAMP: | |
| 1719 | if ((prop->chartype == ucp_Lu || | |
| 1720 | prop->chartype == ucp_Ll || | |
| 1721 | prop->chartype == ucp_Lt) == (op == OP_NOTPROP)) | |
| 1722 | RRETURN(MATCH_NOMATCH); | |
| 1723 | break; | |
| 1724 | ||
| 1725 | case PT_GC: | |
| 1726 | if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP)) | |
| 1727 | RRETURN(MATCH_NOMATCH); | |
| 1728 | break; | |
| 1729 | ||
| 1730 | case PT_PC: | |
| 1731 | if ((ecode[2] != prop->chartype) == (op == OP_PROP)) | |
| 1732 | RRETURN(MATCH_NOMATCH); | |
| 1733 | break; | |
| 1734 | ||
| 1735 | case PT_SC: | |
| 1736 | if ((ecode[2] != prop->script) == (op == OP_PROP)) | |
| 1737 | RRETURN(MATCH_NOMATCH); | |
| 1738 | break; | |
| 1739 | ||
| 1740 | default: | |
| 1741 | RRETURN(PCRE_ERROR_INTERNAL); | |
| 1742 | } | |
| 1743 | ||
| 1744 | ecode += 3; | |
| 1745 | } | |
| 1746 | break; | |
| 1747 | ||
| 1748 | /* Match an extended Unicode sequence. We will get here only if the support | |
| 1749 | is in the binary; otherwise a compile-time error occurs. */ | |
| 1750 | ||
| 1751 | case OP_EXTUNI: | |
| 1752 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 1753 | GETCHARINCTEST(c, eptr); | |
| 1754 | { | |
| 1755 | int category = UCD_CATEGORY(c); | |
| 1756 | if (category == ucp_M) RRETURN(MATCH_NOMATCH); | |
| 1757 | while (eptr < md->end_subject) | |
| 1758 | { | |
| 1759 | int len = 1; | |
| 1760 | if (!utf8) c = *eptr; else | |
| 1761 | { | |
| 1762 | GETCHARLEN(c, eptr, len); | |
| 1763 | } | |
| 1764 | category = UCD_CATEGORY(c); | |
| 1765 | if (category != ucp_M) break; | |
| 1766 | eptr += len; | |
| 1767 | } | |
| 1768 | } | |
| 1769 | ecode++; | |
| 1770 | break; | |
| 1771 | #endif | |
| 1772 | ||
| 1773 | ||
| 1774 | /* Match a back reference, possibly repeatedly. Look past the end of the | |
| 1775 | item to see if there is repeat information following. The code is similar | |
| 1776 | to that for character classes, but repeated for efficiency. Then obey | |
| 1777 | similar code to character type repeats - written out again for speed. | |
| 1778 | However, if the referenced string is the empty string, always treat | |
| 1779 | it as matched, any number of times (otherwise there could be infinite | |
| 1780 | loops). */ | |
| 1781 | ||
| 1782 | case OP_REF: | |
| 1783 | { | |
| 1784 | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ | |
| 1785 | ecode += 3; | |
| 1786 | ||
| 1787 | /* If the reference is unset, there are two possibilities: | |
| 1788 | ||
| 1789 | (a) In the default, Perl-compatible state, set the length to be longer | |
| 1790 | than the amount of subject left; this ensures that every attempt at a | |
| 1791 | match fails. We can't just fail here, because of the possibility of | |
| 1792 | quantifiers with zero minima. | |
| 1793 | ||
| 1794 | (b) If the JavaScript compatibility flag is set, set the length to zero | |
| 1795 | so that the back reference matches an empty string. | |
| 1796 | ||
| 1797 | Otherwise, set the length to the length of what was matched by the | |
| 1798 | referenced subpattern. */ | |
| 1799 | ||
| 1800 | if (offset >= offset_top || md->offset_vector[offset] < 0) | |
| 1801 | length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1; | |
| 1802 | else | |
| 1803 | length = md->offset_vector[offset+1] - md->offset_vector[offset]; | |
| 1804 | ||
| 1805 | /* Set up for repetition, or handle the non-repeated case */ | /* Set up for repetition, or handle the non-repeated case */ |
| 1806 | ||
| # | Line 1480 for (;;) | Line 1860 for (;;) |
| 1860 | { | { |
| 1861 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 1862 | { | { |
| 1863 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14); |
| 1864 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1865 | if (fi >= max || !match_ref(offset, eptr, length, md, ims)) | if (fi >= max || !match_ref(offset, eptr, length, md, ims)) |
| 1866 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| # | Line 1501 for (;;) | Line 1881 for (;;) |
| 1881 | } | } |
| 1882 | while (eptr >= pp) | while (eptr >= pp) |
| 1883 | { | { |
| 1884 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15); |
| 1885 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1886 | eptr -= length; | eptr -= length; |
| 1887 | } | } |
| # | Line 1606 for (;;) | Line 1986 for (;;) |
| 1986 | { | { |
| 1987 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 1988 | { | { |
| 1989 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16); |
| 1990 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1991 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 1992 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| # | Line 1626 for (;;) | Line 2006 for (;;) |
| 2006 | { | { |
| 2007 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2008 | { | { |
| 2009 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17); |
| 2010 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2011 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 2012 | c = *eptr++; | c = *eptr++; |
| # | Line 1663 for (;;) | Line 2043 for (;;) |
| 2043 | } | } |
| 2044 | for (;;) | for (;;) |
| 2045 | { | { |
| 2046 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18); |
| 2047 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2048 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2049 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 1682 for (;;) | Line 2062 for (;;) |
| 2062 | } | } |
| 2063 | while (eptr >= pp) | while (eptr >= pp) |
| 2064 | { | { |
| 2065 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19); |
| eptr--; | ||
| 2066 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2067 | eptr--; | |
| 2068 | } | } |
| 2069 | } | } |
| 2070 | ||
| # | Line 1695 for (;;) | Line 2075 for (;;) |
| 2075 | ||
| 2076 | ||
| 2077 | /* Match an extended character class. This opcode is encountered only | /* Match an extended character class. This opcode is encountered only |
| 2078 | in UTF-8 mode, because that's the only time it is compiled. */ | when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8 |
| 2079 | mode, because Unicode properties are supported in non-UTF-8 mode. */ | |
| 2080 | ||
| 2081 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 2082 | case OP_XCLASS: | case OP_XCLASS: |
| # | Line 1737 for (;;) | Line 2118 for (;;) |
| 2118 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2119 | { | { |
| 2120 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 2121 | GETCHARINC(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2122 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
| 2123 | } | } |
| 2124 | ||
| # | Line 1753 for (;;) | Line 2134 for (;;) |
| 2134 | { | { |
| 2135 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2136 | { | { |
| 2137 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20); |
| 2138 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2139 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 2140 | GETCHARINC(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2141 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
| 2142 | } | } |
| 2143 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 1771 for (;;) | Line 2152 for (;;) |
| 2152 | { | { |
| 2153 | int len = 1; | int len = 1; |
| 2154 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) break; |
| 2155 | GETCHARLEN(c, eptr, len); | GETCHARLENTEST(c, eptr, len); |
| 2156 | if (!_pcre_xclass(c, data)) break; | if (!_pcre_xclass(c, data)) break; |
| 2157 | eptr += len; | eptr += len; |
| 2158 | } | } |
| 2159 | for(;;) | for(;;) |
| 2160 | { | { |
| 2161 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21); |
| 2162 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2163 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2164 | BACKCHAR(eptr) | if (utf8) BACKCHAR(eptr); |
| 2165 | } | } |
| 2166 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2167 | } | } |
| # | Line 1836 for (;;) | Line 2217 for (;;) |
| 2217 | ||
| 2218 | else | else |
| 2219 | { | { |
| 2220 | int dc; | unsigned int dc; |
| 2221 | GETCHARINC(dc, eptr); | GETCHARINC(dc, eptr); |
| 2222 | ecode += length; | ecode += length; |
| 2223 | ||
| 2224 | /* If we have Unicode property support, we can use it to test the other | /* If we have Unicode property support, we can use it to test the other |
| 2225 | case of the character, if there is one. The result of ucp_findchar() is | case of the character, if there is one. */ |
| < 0 if the char isn't found, and othercase is returned as zero if there | ||
| isn't one. */ | ||
| 2226 | ||
| 2227 | if (fc != dc) | if (fc != dc) |
| 2228 | { | { |
| 2229 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2230 | int chartype; | if (dc != UCD_OTHERCASE(fc)) |
| int othercase; | ||
| if (ucp_findchar(fc, &chartype, &othercase) < 0 || dc != othercase) | ||
| 2231 | #endif | #endif |
| 2232 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2233 | } | } |
| # | Line 1867 for (;;) | Line 2244 for (;;) |
| 2244 | } | } |
| 2245 | break; | break; |
| 2246 | ||
| 2247 | /* Match a single character repeatedly; different opcodes share code. */ | /* Match a single character repeatedly. */ |
| 2248 | ||
| 2249 | case OP_EXACT: | case OP_EXACT: |
| 2250 | min = max = GET2(ecode, 1); | min = max = GET2(ecode, 1); |
| 2251 | ecode += 3; | ecode += 3; |
| 2252 | goto REPEATCHAR; | goto REPEATCHAR; |
| 2253 | ||
| 2254 | case OP_POSUPTO: | |
| 2255 | possessive = TRUE; | |
| 2256 | /* Fall through */ | |
| 2257 | ||
| 2258 | case OP_UPTO: | case OP_UPTO: |
| 2259 | case OP_MINUPTO: | case OP_MINUPTO: |
| 2260 | min = 0; | min = 0; |
| # | Line 1882 for (;;) | Line 2263 for (;;) |
| 2263 | ecode += 3; | ecode += 3; |
| 2264 | goto REPEATCHAR; | goto REPEATCHAR; |
| 2265 | ||
| 2266 | case OP_POSSTAR: | |
| 2267 | possessive = TRUE; | |
| 2268 | min = 0; | |
| 2269 | max = INT_MAX; | |
| 2270 | ecode++; | |
| 2271 | goto REPEATCHAR; | |
| 2272 | ||
| 2273 | case OP_POSPLUS: | |
| 2274 | possessive = TRUE; | |
| 2275 | min = 1; | |
| 2276 | max = INT_MAX; | |
| 2277 | ecode++; | |
| 2278 | goto REPEATCHAR; | |
| 2279 | ||
| 2280 | case OP_POSQUERY: | |
| 2281 | possessive = TRUE; | |
| 2282 | min = 0; | |
| 2283 | max = 1; | |
| 2284 | ecode++; | |
| 2285 | goto REPEATCHAR; | |
| 2286 | ||
| 2287 | case OP_STAR: | case OP_STAR: |
| 2288 | case OP_MINSTAR: | case OP_MINSTAR: |
| 2289 | case OP_PLUS: | case OP_PLUS: |
| # | Line 1913 for (;;) | Line 2315 for (;;) |
| 2315 | ||
| 2316 | if (length > 1) | if (length > 1) |
| 2317 | { | { |
| int oclength = 0; | ||
| uschar occhars[8]; | ||
| 2318 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2319 | int othercase; | unsigned int othercase; |
| int chartype; | ||
| 2320 | if ((ims & PCRE_CASELESS) != 0 && | if ((ims & PCRE_CASELESS) != 0 && |
| 2321 | ucp_findchar(fc, &chartype, &othercase) >= 0 && | (othercase = UCD_OTHERCASE(fc)) != fc) |
| othercase > 0) | ||
| 2322 | oclength = _pcre_ord2utf8(othercase, occhars); | oclength = _pcre_ord2utf8(othercase, occhars); |
| 2323 | else oclength = 0; | |
| 2324 | #endif /* SUPPORT_UCP */ | #endif /* SUPPORT_UCP */ |
| 2325 | ||
| 2326 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2327 | { | { |
| 2328 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2329 | #ifdef SUPPORT_UCP | |
| 2330 | /* Need braces because of following else */ | /* Need braces because of following else */ |
| 2331 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } |
| 2332 | else | else |
| # | Line 1935 for (;;) | Line 2334 for (;;) |
| 2334 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); |
| 2335 | eptr += oclength; | eptr += oclength; |
| 2336 | } | } |
| 2337 | #else /* without SUPPORT_UCP */ | |
| 2338 | else { RRETURN(MATCH_NOMATCH); } | |
| 2339 | #endif /* SUPPORT_UCP */ | |
| 2340 | } | } |
| 2341 | ||
| 2342 | if (min == max) continue; | if (min == max) continue; |
| # | Line 1943 for (;;) | Line 2345 for (;;) |
| 2345 | { | { |
| 2346 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2347 | { | { |
| 2348 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22); |
| 2349 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2350 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 2351 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2352 | #ifdef SUPPORT_UCP | |
| 2353 | /* Need braces because of following else */ | /* Need braces because of following else */ |
| 2354 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } |
| 2355 | else | else |
| # | Line 1954 for (;;) | Line 2357 for (;;) |
| 2357 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); |
| 2358 | eptr += oclength; | eptr += oclength; |
| 2359 | } | } |
| 2360 | #else /* without SUPPORT_UCP */ | |
| 2361 | else { RRETURN (MATCH_NOMATCH); } | |
| 2362 | #endif /* SUPPORT_UCP */ | |
| 2363 | } | } |
| 2364 | /* Control never gets here */ | /* Control never gets here */ |
| 2365 | } | } |
| 2366 | else | |
| 2367 | else /* Maximize */ | |
| 2368 | { | { |
| 2369 | pp = eptr; | pp = eptr; |
| 2370 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2371 | { | { |
| 2372 | if (eptr > md->end_subject - length) break; | if (eptr > md->end_subject - length) break; |
| 2373 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2374 | #ifdef SUPPORT_UCP | |
| 2375 | else if (oclength == 0) break; | else if (oclength == 0) break; |
| 2376 | else | else |
| 2377 | { | { |
| 2378 | if (memcmp(eptr, occhars, oclength) != 0) break; | if (memcmp(eptr, occhars, oclength) != 0) break; |
| 2379 | eptr += oclength; | eptr += oclength; |
| 2380 | } | } |
| 2381 | #else /* without SUPPORT_UCP */ | |
| 2382 | else break; | |
| 2383 | #endif /* SUPPORT_UCP */ | |
| 2384 | } | } |
| 2385 | while (eptr >= pp) | |
| 2386 | if (possessive) continue; | |
| 2387 | for(;;) | |
| 2388 | { | { |
| 2389 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23); |
| 2390 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2391 | if (eptr == pp) RRETURN(MATCH_NOMATCH); | |
| 2392 | #ifdef SUPPORT_UCP | |
| 2393 | eptr--; | |
| 2394 | BACKCHAR(eptr); | |
| 2395 | #else /* without SUPPORT_UCP */ | |
| 2396 | eptr -= length; | eptr -= length; |
| 2397 | #endif /* SUPPORT_UCP */ | |
| 2398 | } | } |
| RRETURN(MATCH_NOMATCH); | ||
| 2399 | } | } |
| 2400 | /* Control never gets here */ | /* Control never gets here */ |
| 2401 | } | } |
| # | Line 2017 for (;;) | Line 2435 for (;;) |
| 2435 | { | { |
| 2436 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2437 | { | { |
| 2438 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24); |
| 2439 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2440 | if (fi >= max || eptr >= md->end_subject || | if (fi >= max || eptr >= md->end_subject || |
| 2441 | fc != md->lcc[*eptr++]) | fc != md->lcc[*eptr++]) |
| # | Line 2025 for (;;) | Line 2443 for (;;) |
| 2443 | } | } |
| 2444 | /* Control never gets here */ | /* Control never gets here */ |
| 2445 | } | } |
| 2446 | else | else /* Maximize */ |
| 2447 | { | { |
| 2448 | pp = eptr; | pp = eptr; |
| 2449 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| # | Line 2033 for (;;) | Line 2451 for (;;) |
| 2451 | if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break; | if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break; |
| 2452 | eptr++; | eptr++; |
| 2453 | } | } |
| 2454 | if (possessive) continue; | |
| 2455 | while (eptr >= pp) | while (eptr >= pp) |
| 2456 | { | { |
| 2457 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25); |
| 2458 | eptr--; | eptr--; |
| 2459 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2460 | } | } |
| # | Line 2054 for (;;) | Line 2473 for (;;) |
| 2473 | { | { |
| 2474 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2475 | { | { |
| 2476 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26); |
| 2477 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2478 | if (fi >= max || eptr >= md->end_subject || fc != *eptr++) | if (fi >= max || eptr >= md->end_subject || fc != *eptr++) |
| 2479 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2480 | } | } |
| 2481 | /* Control never gets here */ | /* Control never gets here */ |
| 2482 | } | } |
| 2483 | else | else /* Maximize */ |
| 2484 | { | { |
| 2485 | pp = eptr; | pp = eptr; |
| 2486 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| # | Line 2069 for (;;) | Line 2488 for (;;) |
| 2488 | if (eptr >= md->end_subject || fc != *eptr) break; | if (eptr >= md->end_subject || fc != *eptr) break; |
| 2489 | eptr++; | eptr++; |
| 2490 | } | } |
| 2491 | if (possessive) continue; | |
| 2492 | while (eptr >= pp) | while (eptr >= pp) |
| 2493 | { | { |
| 2494 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27); |
| 2495 | eptr--; | eptr--; |
| 2496 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2497 | } | } |
| # | Line 2121 for (;;) | Line 2541 for (;;) |
| 2541 | ecode += 3; | ecode += 3; |
| 2542 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
| 2543 | ||
| 2544 | case OP_NOTPOSSTAR: | |
| 2545 | possessive = TRUE; | |
| 2546 | min = 0; | |
| 2547 | max = INT_MAX; | |
| 2548 | ecode++; | |
| 2549 | goto REPEATNOTCHAR; | |
| 2550 | ||
| 2551 | case OP_NOTPOSPLUS: | |
| 2552 | possessive = TRUE; | |
| 2553 | min = 1; | |
| 2554 | max = INT_MAX; | |
| 2555 | ecode++; | |
| 2556 | goto REPEATNOTCHAR; | |
| 2557 | ||
| 2558 | case OP_NOTPOSQUERY: | |
| 2559 | possessive = TRUE; | |
| 2560 | min = 0; | |
| 2561 | max = 1; | |
| 2562 | ecode++; | |
| 2563 | goto REPEATNOTCHAR; | |
| 2564 | ||
| 2565 | case OP_NOTPOSUPTO: | |
| 2566 | possessive = TRUE; | |
| 2567 | min = 0; | |
| 2568 | max = GET2(ecode, 1); | |
| 2569 | ecode += 3; | |
| 2570 | goto REPEATNOTCHAR; | |
| 2571 | ||
| 2572 | case OP_NOTSTAR: | case OP_NOTSTAR: |
| 2573 | case OP_NOTMINSTAR: | case OP_NOTMINSTAR: |
| 2574 | case OP_NOTPLUS: | case OP_NOTPLUS: |
| # | Line 2160 for (;;) | Line 2608 for (;;) |
| 2608 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2609 | if (utf8) | if (utf8) |
| 2610 | { | { |
| 2611 | register int d; | register unsigned int d; |
| 2612 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2613 | { | { |
| 2614 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| # | Line 2185 for (;;) | Line 2633 for (;;) |
| 2633 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2634 | if (utf8) | if (utf8) |
| 2635 | { | { |
| 2636 | register int d; | register unsigned int d; |
| 2637 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2638 | { | { |
| 2639 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28); |
| 2640 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2641 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2642 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 2643 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
| 2644 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (fc == d) RRETURN(MATCH_NOMATCH); |
| 2645 | RRETURN(MATCH_NOMATCH); | |
| 2646 | } | } |
| 2647 | } | } |
| 2648 | else | else |
| # | Line 2202 for (;;) | Line 2651 for (;;) |
| 2651 | { | { |
| 2652 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2653 | { | { |
| 2654 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29); |
| 2655 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2656 | if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++]) | if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++]) |
| 2657 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| # | Line 2221 for (;;) | Line 2670 for (;;) |
| 2670 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2671 | if (utf8) | if (utf8) |
| 2672 | { | { |
| 2673 | register int d; | register unsigned int d; |
| 2674 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2675 | { | { |
| 2676 | int len = 1; | int len = 1; |
| # | Line 2231 for (;;) | Line 2680 for (;;) |
| 2680 | if (fc == d) break; | if (fc == d) break; |
| 2681 | eptr += len; | eptr += len; |
| 2682 | } | } |
| 2683 | for(;;) | if (possessive) continue; |
| 2684 | for(;;) | |
| 2685 | { | { |
| 2686 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30); |
| 2687 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2688 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2689 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 2248 for (;;) | Line 2698 for (;;) |
| 2698 | if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break; | if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break; |
| 2699 | eptr++; | eptr++; |
| 2700 | } | } |
| 2701 | if (possessive) continue; | |
| 2702 | while (eptr >= pp) | while (eptr >= pp) |
| 2703 | { | { |
| 2704 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31); |
| 2705 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2706 | eptr--; | eptr--; |
| 2707 | } | } |
| # | Line 2269 for (;;) | Line 2720 for (;;) |
| 2720 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2721 | if (utf8) | if (utf8) |
| 2722 | { | { |
| 2723 | register int d; | register unsigned int d; |
| 2724 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2725 | { | { |
| 2726 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| # | Line 2292 for (;;) | Line 2743 for (;;) |
| 2743 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2744 | if (utf8) | if (utf8) |
| 2745 | { | { |
| 2746 | register int d; | register unsigned int d; |
| 2747 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2748 | { | { |
| 2749 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32); |
| 2750 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2751 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2752 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 2753 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (fc == d) RRETURN(MATCH_NOMATCH); |
| RRETURN(MATCH_NOMATCH); | ||
| 2754 | } | } |
| 2755 | } | } |
| 2756 | else | else |
| # | Line 2308 for (;;) | Line 2759 for (;;) |
| 2759 | { | { |
| 2760 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2761 | { | { |
| 2762 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33); |
| 2763 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2764 | if (fi >= max || eptr >= md->end_subject || fc == *eptr++) | if (fi >= max || eptr >= md->end_subject || fc == *eptr++) |
| 2765 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| # | Line 2327 for (;;) | Line 2778 for (;;) |
| 2778 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2779 | if (utf8) | if (utf8) |
| 2780 | { | { |
| 2781 | register int d; | register unsigned int d; |
| 2782 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2783 | { | { |
| 2784 | int len = 1; | int len = 1; |
| # | Line 2336 for (;;) | Line 2787 for (;;) |
| 2787 | if (fc == d) break; | if (fc == d) break; |
| 2788 | eptr += len; | eptr += len; |
| 2789 | } | } |
| 2790 | if (possessive) continue; | |
| 2791 | for(;;) | for(;;) |
| 2792 | { | { |
| 2793 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34); |
| 2794 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2795 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2796 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 2353 for (;;) | Line 2805 for (;;) |
| 2805 | if (eptr >= md->end_subject || fc == *eptr) break; | if (eptr >= md->end_subject || fc == *eptr) break; |
| 2806 | eptr++; | eptr++; |
| 2807 | } | } |
| 2808 | if (possessive) continue; | |
| 2809 | while (eptr >= pp) | while (eptr >= pp) |
| 2810 | { | { |
| 2811 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35); |
| 2812 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2813 | eptr--; | eptr--; |
| 2814 | } | } |
| # | Line 2384 for (;;) | Line 2837 for (;;) |
| 2837 | ecode += 3; | ecode += 3; |
| 2838 | goto REPEATTYPE; | goto REPEATTYPE; |
| 2839 | ||
| 2840 | case OP_TYPEPOSSTAR: | |
| 2841 | possessive = TRUE; | |
| 2842 | min = 0; | |
| 2843 | max = INT_MAX; | |
| 2844 | ecode++; | |
| 2845 | goto REPEATTYPE; | |
| 2846 | ||
| 2847 | case OP_TYPEPOSPLUS: | |
| 2848 | possessive = TRUE; | |
| 2849 | min = 1; | |
| 2850 | max = INT_MAX; | |
| 2851 | ecode++; | |
| 2852 | goto REPEATTYPE; | |
| 2853 | ||
| 2854 | case OP_TYPEPOSQUERY: | |
| 2855 | possessive = TRUE; | |
| 2856 | min = 0; | |
| 2857 | max = 1; | |
| 2858 | ecode++; | |
| 2859 | goto REPEATTYPE; | |
| 2860 | ||
| 2861 | case OP_TYPEPOSUPTO: | |
| 2862 | possessive = TRUE; | |
| 2863 | min = 0; | |
| 2864 | max = GET2(ecode, 1); | |
| 2865 | ecode += 3; | |
| 2866 | goto REPEATTYPE; | |
| 2867 | ||
| 2868 | case OP_TYPESTAR: | case OP_TYPESTAR: |
| 2869 | case OP_TYPEMINSTAR: | case OP_TYPEMINSTAR: |
| 2870 | case OP_TYPEPLUS: | case OP_TYPEPLUS: |
| # | Line 2408 for (;;) | Line 2889 for (;;) |
| 2889 | { | { |
| 2890 | prop_fail_result = ctype == OP_NOTPROP; | prop_fail_result = ctype == OP_NOTPROP; |
| 2891 | prop_type = *ecode++; | prop_type = *ecode++; |
| 2892 | if (prop_type >= 128) | prop_value = *ecode++; |
| { | ||
| prop_test_against = prop_type - 128; | ||
| prop_test_variable = &prop_category; | ||
| } | ||
| else | ||
| { | ||
| prop_test_against = prop_type; | ||
| prop_test_variable = &prop_chartype; | ||
| } | ||
| 2893 | } | } |
| 2894 | else prop_type = -1; | else prop_type = -1; |
| 2895 | #endif | #endif |
| # | Line 2434 for (;;) | Line 2906 for (;;) |
| 2906 | if (min > 0) | if (min > 0) |
| 2907 | { | { |
| 2908 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2909 | if (prop_type > 0) | if (prop_type >= 0) |
| 2910 | { | { |
| 2911 | for (i = 1; i <= min; i++) | switch(prop_type) |
| 2912 | { | { |
| 2913 | GETCHARINC(c, eptr); | case PT_ANY: |
| 2914 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | if (prop_fail_result) RRETURN(MATCH_NOMATCH); |
| 2915 | if ((*prop_test_variable == prop_test_against) == prop_fail_result) | for (i = 1; i <= min; i++) |
| 2916 | RRETURN(MATCH_NOMATCH); | { |
| 2917 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2918 | GETCHARINCTEST(c, eptr); | |
| 2919 | } | |
| 2920 | break; | |
| 2921 | ||
| 2922 | case PT_LAMP: | |
| 2923 | for (i = 1; i <= min; i++) | |
| 2924 | { | |
| 2925 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2926 | GETCHARINCTEST(c, eptr); | |
| 2927 | prop_chartype = UCD_CHARTYPE(c); | |
| 2928 | if ((prop_chartype == ucp_Lu || | |
| 2929 | prop_chartype == ucp_Ll || | |
| 2930 | prop_chartype == ucp_Lt) == prop_fail_result) | |
| 2931 | RRETURN(MATCH_NOMATCH); | |
| 2932 | } | |
| 2933 | break; | |
| 2934 | ||
| 2935 | case PT_GC: | |
| 2936 | for (i = 1; i <= min; i++) | |
| 2937 | { | |
| 2938 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2939 | GETCHARINCTEST(c, eptr); | |
| 2940 | prop_category = UCD_CATEGORY(c); | |
| 2941 | if ((prop_category == prop_value) == prop_fail_result) | |
| 2942 | RRETURN(MATCH_NOMATCH); | |
| 2943 | } | |
| 2944 | break; | |
| 2945 | ||
| 2946 | case PT_PC: | |
| 2947 | for (i = 1; i <= min; i++) | |
| 2948 | { | |
| 2949 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2950 | GETCHARINCTEST(c, eptr); | |
| 2951 | prop_chartype = UCD_CHARTYPE(c); | |
| 2952 | if ((prop_chartype == prop_value) == prop_fail_result) | |
| 2953 | RRETURN(MATCH_NOMATCH); | |
| 2954 | } | |
| 2955 | break; | |
| 2956 | ||
| 2957 | case PT_SC: | |
| 2958 | for (i = 1; i <= min; i++) | |
| 2959 | { | |
| 2960 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2961 | GETCHARINCTEST(c, eptr); | |
| 2962 | prop_script = UCD_SCRIPT(c); | |
| 2963 | if ((prop_script == prop_value) == prop_fail_result) | |
| 2964 | RRETURN(MATCH_NOMATCH); | |
| 2965 | } | |
| 2966 | break; | |
| 2967 | ||
| 2968 | default: | |
| 2969 | RRETURN(PCRE_ERROR_INTERNAL); | |
| 2970 | } | } |
| 2971 | } | } |
| 2972 | ||
| # | Line 2453 for (;;) | Line 2978 for (;;) |
| 2978 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2979 | { | { |
| 2980 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2981 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 2982 | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 2983 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 2984 | { | { |
| # | Line 2462 for (;;) | Line 2987 for (;;) |
| 2987 | { | { |
| 2988 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 2989 | } | } |
| 2990 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 2991 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 2992 | eptr += len; | eptr += len; |
| 2993 | } | } |
| # | Line 2480 for (;;) | Line 3005 for (;;) |
| 3005 | case OP_ANY: | case OP_ANY: |
| 3006 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3007 | { | { |
| 3008 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) |
| (*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0)) | ||
| 3009 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3010 | eptr++; | |
| 3011 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | |
| 3012 | } | |
| 3013 | break; | |
| 3014 | ||
| 3015 | case OP_ALLANY: | |
| 3016 | for (i = 1; i <= min; i++) | |
| 3017 | { | |
| 3018 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3019 | eptr++; | |
| 3020 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| 3021 | } | } |
| 3022 | break; | break; |
| # | Line 2491 for (;;) | Line 3025 for (;;) |
| 3025 | eptr += min; | eptr += min; |
| 3026 | break; | break; |
| 3027 | ||
| 3028 | case OP_NOT_DIGIT: | case OP_ANYNL: |
| 3029 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3030 | { | { |
| 3031 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 3032 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3033 | if (c < 128 && (md->ctypes[c] & ctype_digit) != 0) | switch(c) |
| 3034 | RRETURN(MATCH_NOMATCH); | { |
| 3035 | default: RRETURN(MATCH_NOMATCH); | |
| 3036 | case 0x000d: | |
| 3037 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3038 | break; | |
| 3039 | ||
| 3040 | case 0x000a: | |
| 3041 | break; | |
| 3042 | ||
| 3043 | case 0x000b: | |
| 3044 | case 0x000c: | |
| 3045 | case 0x0085: | |
| 3046 | case 0x2028: | |
| 3047 | case 0x2029: | |
| 3048 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3049 | break; | |
| 3050 | } | |
| 3051 | } | } |
| 3052 | break; | break; |
| 3053 | ||
| 3054 | case OP_DIGIT: | case OP_NOT_HSPACE: |
| 3055 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3056 | { | { |
| 3057 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 3058 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0) | GETCHARINC(c, eptr); |
| 3059 | switch(c) | |
| 3060 | { | |
| 3061 | default: break; | |
| 3062 | case 0x09: /* HT */ | |
| 3063 | case 0x20: /* SPACE */ | |
| 3064 | case 0xa0: /* NBSP */ | |
| 3065 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3066 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3067 | case 0x2000: /* EN QUAD */ | |
| 3068 | case 0x2001: /* EM QUAD */ | |
| 3069 | case 0x2002: /* EN SPACE */ | |
| 3070 | case 0x2003: /* EM SPACE */ | |
| 3071 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3072 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3073 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3074 | case 0x2007: /* FIGURE SPACE */ | |
| 3075 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3076 | case 0x2009: /* THIN SPACE */ | |
| 3077 | case 0x200A: /* HAIR SPACE */ | |
| 3078 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3079 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3080 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3081 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3082 | /* No need to skip more bytes - we know it's a 1-byte character */ | } |
| 3083 | } | } |
| 3084 | break; | break; |
| 3085 | ||
| 3086 | case OP_NOT_WHITESPACE: | case OP_HSPACE: |
| 3087 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3088 | { | { |
| 3089 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 3090 | (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0)) | GETCHARINC(c, eptr); |
| 3091 | RRETURN(MATCH_NOMATCH); | switch(c) |
| 3092 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | { |
| 3093 | default: RRETURN(MATCH_NOMATCH); | |
| 3094 | case 0x09: /* HT */ | |
| 3095 | case 0x20: /* SPACE */ | |
| 3096 | case 0xa0: /* NBSP */ | |
| 3097 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3098 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3099 | case 0x2000: /* EN QUAD */ | |
| 3100 | case 0x2001: /* EM QUAD */ | |
| 3101 | case 0x2002: /* EN SPACE */ | |
| 3102 | case 0x2003: /* EM SPACE */ | |
| 3103 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3104 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3105 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3106 | case 0x2007: /* FIGURE SPACE */ | |
| 3107 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3108 | case 0x2009: /* THIN SPACE */ | |
| 3109 | case 0x200A: /* HAIR SPACE */ | |
| 3110 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3111 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3112 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3113 | break; | |
| 3114 | } | |
| 3115 | } | } |
| 3116 | break; | break; |
| 3117 | ||
| 3118 | case OP_WHITESPACE: | case OP_NOT_VSPACE: |
| 3119 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3120 | { | { |
| 3121 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 3122 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0) | GETCHARINC(c, eptr); |
| 3123 | switch(c) | |
| 3124 | { | |
| 3125 | default: break; | |
| 3126 | case 0x0a: /* LF */ | |
| 3127 | case 0x0b: /* VT */ | |
| 3128 | case 0x0c: /* FF */ | |
| 3129 | case 0x0d: /* CR */ | |
| 3130 | case 0x85: /* NEL */ | |
| 3131 | case 0x2028: /* LINE SEPARATOR */ | |
| 3132 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3133 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3134 | /* No need to skip more bytes - we know it's a 1-byte character */ | } |
| 3135 | } | } |
| 3136 | break; | break; |
| 3137 | ||
| 3138 | case OP_NOT_WORDCHAR: | case OP_VSPACE: |
| 3139 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3140 | { | { |
| 3141 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 3142 | (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0)) | GETCHARINC(c, eptr); |
| 3143 | RRETURN(MATCH_NOMATCH); | switch(c) |
| 3144 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | { |
| 3145 | default: RRETURN(MATCH_NOMATCH); | |
| 3146 | case 0x0a: /* LF */ | |
| 3147 | case 0x0b: /* VT */ | |
| 3148 | case 0x0c: /* FF */ | |
| 3149 | case 0x0d: /* CR */ | |
| 3150 | case 0x85: /* NEL */ | |
| 3151 | case 0x2028: /* LINE SEPARATOR */ | |
| 3152 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3153 | break; | |
| 3154 | } | |
| 3155 | } | } |
| 3156 | break; | break; |
| 3157 | ||
| 3158 | case OP_WORDCHAR: | case OP_NOT_DIGIT: |
| 3159 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3160 | { | { |
| 3161 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 3162 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0) | GETCHARINC(c, eptr); |
| 3163 | if (c < 128 && (md->ctypes[c] & ctype_digit) != 0) | |
| 3164 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| /* No need to skip more bytes - we know it's a 1-byte character */ | ||
| 3165 | } | } |
| 3166 | break; | break; |
| 3167 | ||
| 3168 | default: | case OP_DIGIT: |
| 3169 | for (i = 1; i <= min; i++) | |
| 3170 | { | |
| 3171 | if (eptr >= md->end_subject || | |
| 3172 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0) | |
| 3173 | RRETURN(MATCH_NOMATCH); | |
| 3174 | /* No need to skip more bytes - we know it's a 1-byte character */ | |
| 3175 | } | |
| 3176 | break; | |
| 3177 | ||
| 3178 | case OP_NOT_WHITESPACE: | |
| 3179 | for (i = 1; i <= min; i++) | |
| 3180 | { | |
| 3181 | if (eptr >= md->end_subject || | |
| 3182 | (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)) | |
| 3183 | RRETURN(MATCH_NOMATCH); | |
| 3184 | while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); | |
| 3185 | } | |
| 3186 | break; | |
| 3187 | ||
| 3188 | case OP_WHITESPACE: | |
| 3189 | for (i = 1; i <= min; i++) | |
| 3190 | { | |
| 3191 | if (eptr >= md->end_subject || | |
| 3192 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0) | |
| 3193 | RRETURN(MATCH_NOMATCH); | |
| 3194 | /* No need to skip more bytes - we know it's a 1-byte character */ | |
| 3195 | } | |
| 3196 | break; | |
| 3197 | ||
| 3198 | case OP_NOT_WORDCHAR: | |
| 3199 | for (i = 1; i <= min; i++) | |
| 3200 | { | |
| 3201 | if (eptr >= md->end_subject || | |
| 3202 | (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)) | |
| 3203 | RRETURN(MATCH_NOMATCH); | |
| 3204 | while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); | |
| 3205 | } | |
| 3206 | break; | |
| 3207 | ||
| 3208 | case OP_WORDCHAR: | |
| 3209 | for (i = 1; i <= min; i++) | |
| 3210 | { | |
| 3211 | if (eptr >= md->end_subject || | |
| 3212 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0) | |
| 3213 | RRETURN(MATCH_NOMATCH); | |
| 3214 | /* No need to skip more bytes - we know it's a 1-byte character */ | |
| 3215 | } | |
| 3216 | break; | |
| 3217 | ||
| 3218 | default: | |
| 3219 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
| 3220 | } /* End switch(ctype) */ | } /* End switch(ctype) */ |
| 3221 | ||
| # | Line 2559 for (;;) | Line 3223 for (;;) |
| 3223 | #endif /* SUPPORT_UTF8 */ | #endif /* SUPPORT_UTF8 */ |
| 3224 | ||
| 3225 | /* Code for the non-UTF-8 case for minimum matching of operators other | /* Code for the non-UTF-8 case for minimum matching of operators other |
| 3226 | than OP_PROP and OP_NOTPROP. */ | than OP_PROP and OP_NOTPROP. We can assume that there are the minimum |
| 3227 | number of bytes present, as this was tested above. */ | |
| 3228 | ||
| 3229 | switch(ctype) | switch(ctype) |
| 3230 | { | { |
| 3231 | case OP_ANY: | case OP_ANY: |
| 3232 | if ((ims & PCRE_DOTALL) == 0) | for (i = 1; i <= min; i++) |
| 3233 | { | { |
| 3234 | for (i = 1; i <= min; i++) | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); |
| 3235 | if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH); | eptr++; |
| 3236 | } | } |
| 3237 | else eptr += min; | break; |
| 3238 | ||
| 3239 | case OP_ALLANY: | |
| 3240 | eptr += min; | |
| 3241 | break; | break; |
| 3242 | ||
| 3243 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 3244 | eptr += min; | eptr += min; |
| 3245 | break; | break; |
| 3246 | ||
| 3247 | /* Because of the CRLF case, we can't assume the minimum number of | |
| 3248 | bytes are present in this case. */ | |
| 3249 | ||
| 3250 | case OP_ANYNL: | |
| 3251 | for (i = 1; i <= min; i++) | |
| 3252 | { | |
| 3253 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3254 | switch(*eptr++) | |
| 3255 | { | |
| 3256 | default: RRETURN(MATCH_NOMATCH); | |
| 3257 | case 0x000d: | |
| 3258 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3259 | break; | |
| 3260 | case 0x000a: | |
| 3261 | break; | |
| 3262 | ||
| 3263 | case 0x000b: | |
| 3264 | case 0x000c: | |
| 3265 | case 0x0085: | |
| 3266 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3267 | break; | |
| 3268 | } | |
| 3269 | } | |
| 3270 | break; | |
| 3271 | ||
| 3272 | case OP_NOT_HSPACE: | |
| 3273 | for (i = 1; i <= min; i++) | |
| 3274 | { | |
| 3275 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3276 | switch(*eptr++) | |
| 3277 | { | |
| 3278 | default: break; | |
| 3279 | case 0x09: /* HT */ | |
| 3280 | case 0x20: /* SPACE */ | |
| 3281 | case 0xa0: /* NBSP */ | |
| 3282 | RRETURN(MATCH_NOMATCH); | |
| 3283 | } | |
| 3284 | } | |
| 3285 | break; | |
| 3286 | ||
| 3287 | case OP_HSPACE: | |
| 3288 | for (i = 1; i <= min; i++) | |
| 3289 | { | |
| 3290 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3291 | switch(*eptr++) | |
| 3292 | { | |
| 3293 | default: RRETURN(MATCH_NOMATCH); | |
| 3294 | case 0x09: /* HT */ | |
| 3295 | case 0x20: /* SPACE */ | |
| 3296 | case 0xa0: /* NBSP */ | |
| 3297 | break; | |
| 3298 | } | |
| 3299 | } | |
| 3300 | break; | |
| 3301 | ||
| 3302 | case OP_NOT_VSPACE: | |
| 3303 | for (i = 1; i <= min; i++) | |
| 3304 | { | |
| 3305 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3306 | switch(*eptr++) | |
| 3307 | { | |
| 3308 | default: break; | |
| 3309 | case 0x0a: /* LF */ | |
| 3310 | case 0x0b: /* VT */ | |
| 3311 | case 0x0c: /* FF */ | |
| 3312 | case 0x0d: /* CR */ | |
| 3313 | case 0x85: /* NEL */ | |
| 3314 | RRETURN(MATCH_NOMATCH); | |
| 3315 | } | |
| 3316 | } | |
| 3317 | break; | |
| 3318 | ||
| 3319 | case OP_VSPACE: | |
| 3320 | for (i = 1; i <= min; i++) | |
| 3321 | { | |
| 3322 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3323 | switch(*eptr++) | |
| 3324 | { | |
| 3325 | default: RRETURN(MATCH_NOMATCH); | |
| 3326 | case 0x0a: /* LF */ | |
| 3327 | case 0x0b: /* VT */ | |
| 3328 | case 0x0c: /* FF */ | |
| 3329 | case 0x0d: /* CR */ | |
| 3330 | case 0x85: /* NEL */ | |
| 3331 | break; | |
| 3332 | } | |
| 3333 | } | |
| 3334 | break; | |
| 3335 | ||
| 3336 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 3337 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3338 | if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); | if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); |
| # | Line 2624 for (;;) | Line 3381 for (;;) |
| 3381 | if (minimize) | if (minimize) |
| 3382 | { | { |
| 3383 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 3384 | if (prop_type > 0) | if (prop_type >= 0) |
| 3385 | { | { |
| 3386 | for (fi = min;; fi++) | switch(prop_type) |
| 3387 | { | { |
| 3388 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | case PT_ANY: |
| 3389 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | for (fi = min;; fi++) |
| 3390 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | { |
| 3391 | GETCHARINC(c, eptr); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36); |
| 3392 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3393 | if ((*prop_test_variable == prop_test_against) == prop_fail_result) | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 3394 | RRETURN(MATCH_NOMATCH); | GETCHARINC(c, eptr); |
| 3395 | if (prop_fail_result) RRETURN(MATCH_NOMATCH); | |
| 3396 | } | |
| 3397 | /* Control never gets here */ | |
| 3398 | ||
| 3399 | case PT_LAMP: | |
| 3400 | for (fi = min;; fi++) | |
| 3401 | { | |
| 3402 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37); | |
| 3403 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 3404 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3405 | GETCHARINC(c, eptr); | |
| 3406 | prop_chartype = UCD_CHARTYPE(c); | |
| 3407 | if ((prop_chartype == ucp_Lu || | |
| 3408 | prop_chartype == ucp_Ll || | |
| 3409 | prop_chartype == ucp_Lt) == prop_fail_result) | |
| 3410 | RRETURN(MATCH_NOMATCH); | |
| 3411 | } | |
| 3412 | /* Control never gets here */ | |
| 3413 | ||
| 3414 | case PT_GC: | |
| 3415 | for (fi = min;; fi++) | |
| 3416 | { | |
| 3417 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38); | |
| 3418 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 3419 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3420 | GETCHARINC(c, eptr); | |
| 3421 | prop_category = UCD_CATEGORY(c); | |
| 3422 | if ((prop_category == prop_value) == prop_fail_result) | |
| 3423 | RRETURN(MATCH_NOMATCH); | |
| 3424 | } | |
| 3425 | /* Control never gets here */ | |
| 3426 | ||
| 3427 | case PT_PC: | |
| 3428 | for (fi = min;; fi++) | |
| 3429 | { | |
| 3430 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39); | |
| 3431 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 3432 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3433 | GETCHARINC(c, eptr); | |
| 3434 | prop_chartype = UCD_CHARTYPE(c); | |
| 3435 | if ((prop_chartype == prop_value) == prop_fail_result) | |
| 3436 | RRETURN(MATCH_NOMATCH); | |
| 3437 | } | |
| 3438 | /* Control never gets here */ | |
| 3439 | ||
| 3440 | case PT_SC: | |
| 3441 | for (fi = min;; fi++) | |
| 3442 | { | |
| 3443 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40); | |
| 3444 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 3445 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3446 | GETCHARINC(c, eptr); | |
| 3447 | prop_script = UCD_SCRIPT(c); | |
| 3448 | if ((prop_script == prop_value) == prop_fail_result) | |
| 3449 | RRETURN(MATCH_NOMATCH); | |
| 3450 | } | |
| 3451 | /* Control never gets here */ | |
| 3452 | ||
| 3453 | default: | |
| 3454 | RRETURN(PCRE_ERROR_INTERNAL); | |
| 3455 | } | } |
| 3456 | } | } |
| 3457 | ||
| # | Line 2645 for (;;) | Line 3462 for (;;) |
| 3462 | { | { |
| 3463 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3464 | { | { |
| 3465 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41); |
| 3466 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3467 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 3468 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3469 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3470 | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 3471 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 3472 | { | { |
| # | Line 2658 for (;;) | Line 3475 for (;;) |
| 3475 | { | { |
| 3476 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 3477 | } | } |
| 3478 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3479 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 3480 | eptr += len; | eptr += len; |
| 3481 | } | } |
| # | Line 2674 for (;;) | Line 3491 for (;;) |
| 3491 | { | { |
| 3492 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3493 | { | { |
| 3494 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42); |
| 3495 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3496 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject || |
| 3497 | (ctype == OP_ANY && IS_NEWLINE(eptr))) | |
| 3498 | RRETURN(MATCH_NOMATCH); | |
| 3499 | ||
| 3500 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3501 | switch(ctype) | switch(ctype) |
| 3502 | { | { |
| 3503 | case OP_ANY: | case OP_ANY: /* This is the non-NL case */ |
| 3504 | if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH); | case OP_ALLANY: |
| 3505 | case OP_ANYBYTE: | |
| 3506 | break; | break; |
| 3507 | ||
| 3508 | case OP_ANYBYTE: | case OP_ANYNL: |
| 3509 | switch(c) | |
| 3510 | { | |
| 3511 | default: RRETURN(MATCH_NOMATCH); | |
| 3512 | case 0x000d: | |
| 3513 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3514 | break; | |
| 3515 | case 0x000a: | |
| 3516 | break; | |
| 3517 | ||
| 3518 | case 0x000b: | |
| 3519 | case 0x000c: | |
| 3520 | case 0x0085: | |
| 3521 | case 0x2028: | |
| 3522 | case 0x2029: | |
| 3523 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3524 | break; | |
| 3525 | } | |
| 3526 | break; | |
| 3527 | ||
| 3528 | case OP_NOT_HSPACE: | |
| 3529 | switch(c) | |
| 3530 | { | |
| 3531 | default: break; | |
| 3532 | case 0x09: /* HT */ | |
| 3533 | case 0x20: /* SPACE */ | |
| 3534 | case 0xa0: /* NBSP */ | |
| 3535 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3536 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3537 | case 0x2000: /* EN QUAD */ | |
| 3538 | case 0x2001: /* EM QUAD */ | |
| 3539 | case 0x2002: /* EN SPACE */ | |
| 3540 | case 0x2003: /* EM SPACE */ | |
| 3541 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3542 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3543 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3544 | case 0x2007: /* FIGURE SPACE */ | |
| 3545 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3546 | case 0x2009: /* THIN SPACE */ | |
| 3547 | case 0x200A: /* HAIR SPACE */ | |
| 3548 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3549 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3550 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3551 | RRETURN(MATCH_NOMATCH); | |
| 3552 | } | |
| 3553 | break; | |
| 3554 | ||
| 3555 | case OP_HSPACE: | |
| 3556 | switch(c) | |
| 3557 | { | |
| 3558 | default: RRETURN(MATCH_NOMATCH); | |
| 3559 | case 0x09: /* HT */ | |
| 3560 | case 0x20: /* SPACE */ | |
| 3561 | case 0xa0: /* NBSP */ | |
| 3562 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3563 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3564 | case 0x2000: /* EN QUAD */ | |
| 3565 | case 0x2001: /* EM QUAD */ | |
| 3566 | case 0x2002: /* EN SPACE */ | |
| 3567 | case 0x2003: /* EM SPACE */ | |
| 3568 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3569 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3570 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3571 | case 0x2007: /* FIGURE SPACE */ | |
| 3572 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3573 | case 0x2009: /* THIN SPACE */ | |
| 3574 | case 0x200A: /* HAIR SPACE */ | |
| 3575 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3576 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3577 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3578 | break; | |
| 3579 | } | |
| 3580 | break; | |
| 3581 | ||
| 3582 | case OP_NOT_VSPACE: | |
| 3583 | switch(c) | |
| 3584 | { | |
| 3585 | default: break; | |
| 3586 | case 0x0a: /* LF */ | |
| 3587 | case 0x0b: /* VT */ | |
| 3588 | case 0x0c: /* FF */ | |
| 3589 | case 0x0d: /* CR */ | |
| 3590 | case 0x85: /* NEL */ | |
| 3591 | case 0x2028: /* LINE SEPARATOR */ | |
| 3592 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3593 | RRETURN(MATCH_NOMATCH); | |
| 3594 | } | |
| 3595 | break; | |
| 3596 | ||
| 3597 | case OP_VSPACE: | |
| 3598 | switch(c) | |
| 3599 | { | |
| 3600 | default: RRETURN(MATCH_NOMATCH); | |
| 3601 | case 0x0a: /* LF */ | |
| 3602 | case 0x0b: /* VT */ | |
| 3603 | case 0x0c: /* FF */ | |
| 3604 | case 0x0d: /* CR */ | |
| 3605 | case 0x85: /* NEL */ | |
| 3606 | case 0x2028: /* LINE SEPARATOR */ | |
| 3607 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3608 | break; | |
| 3609 | } | |
| 3610 | break; | break; |
| 3611 | ||
| 3612 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| # | Line 2729 for (;;) | Line 3650 for (;;) |
| 3650 | { | { |
| 3651 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3652 | { | { |
| 3653 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43); |
| 3654 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3655 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject || |
| 3656 | (ctype == OP_ANY && IS_NEWLINE(eptr))) | |
| 3657 | RRETURN(MATCH_NOMATCH); | |
| 3658 | ||
| 3659 | c = *eptr++; | c = *eptr++; |
| 3660 | switch(ctype) | switch(ctype) |
| 3661 | { | { |
| 3662 | case OP_ANY: | case OP_ANY: /* This is the non-NL case */ |
| 3663 | if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH); | case OP_ALLANY: |
| 3664 | case OP_ANYBYTE: | |
| 3665 | break; | break; |
| 3666 | ||
| 3667 | case OP_ANYBYTE: | case OP_ANYNL: |
| 3668 | switch(c) | |
| 3669 | { | |
| 3670 | default: RRETURN(MATCH_NOMATCH); | |
| 3671 | case 0x000d: | |
| 3672 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3673 | break; | |
| 3674 | ||
| 3675 | case 0x000a: | |
| 3676 | break; | |
| 3677 | ||
| 3678 | case 0x000b: | |
| 3679 | case 0x000c: | |
| 3680 | case 0x0085: | |
| 3681 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3682 | break; | |
| 3683 | } | |
| 3684 | break; | |
| 3685 | ||
| 3686 | case OP_NOT_HSPACE: | |
| 3687 | switch(c) | |
| 3688 | { | |
| 3689 | default: break; | |
| 3690 | case 0x09: /* HT */ | |
| 3691 | case 0x20: /* SPACE */ | |
| 3692 | case 0xa0: /* NBSP */ | |
| 3693 | RRETURN(MATCH_NOMATCH); | |
| 3694 | } | |
| 3695 | break; | |
| 3696 | ||
| 3697 | case OP_HSPACE: | |
| 3698 | switch(c) | |
| 3699 | { | |
| 3700 | default: RRETURN(MATCH_NOMATCH); | |
| 3701 | case 0x09: /* HT */ | |
| 3702 | case 0x20: /* SPACE */ | |
| 3703 | case 0xa0: /* NBSP */ | |
| 3704 | break; | |
| 3705 | } | |
| 3706 | break; | |
| 3707 | ||
| 3708 | case OP_NOT_VSPACE: | |
| 3709 | switch(c) | |
| 3710 | { | |
| 3711 | default: break; | |
| 3712 | case 0x0a: /* LF */ | |
| 3713 | case 0x0b: /* VT */ | |
| 3714 | case 0x0c: /* FF */ | |
| 3715 | case 0x0d: /* CR */ | |
| 3716 | case 0x85: /* NEL */ | |
| 3717 | RRETURN(MATCH_NOMATCH); | |
| 3718 | } | |
| 3719 | break; | |
| 3720 | ||
| 3721 | case OP_VSPACE: | |
| 3722 | switch(c) | |
| 3723 | { | |
| 3724 | default: RRETURN(MATCH_NOMATCH); | |
| 3725 | case 0x0a: /* LF */ | |
| 3726 | case 0x0b: /* VT */ | |
| 3727 | case 0x0c: /* FF */ | |
| 3728 | case 0x0d: /* CR */ | |
| 3729 | case 0x85: /* NEL */ | |
| 3730 | break; | |
| 3731 | } | |
| 3732 | break; | break; |
| 3733 | ||
| 3734 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| # | Line 2774 for (;;) | Line 3763 for (;;) |
| 3763 | /* Control never gets here */ | /* Control never gets here */ |
| 3764 | } | } |
| 3765 | ||
| 3766 | /* If maximizing it is worth using inline code for speed, doing the type | /* If maximizing, it is worth using inline code for speed, doing the type |
| 3767 | test once at the start (i.e. keep it out of the loop). Again, keep the | test once at the start (i.e. keep it out of the loop). Again, keep the |
| 3768 | UTF-8 and UCP stuff separate. */ | UTF-8 and UCP stuff separate. */ |
| 3769 | ||
| # | Line 2783 for (;;) | Line 3772 for (;;) |
| 3772 | pp = eptr; /* Remember where we started */ | pp = eptr; /* Remember where we started */ |
| 3773 | ||
| 3774 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 3775 | if (prop_type > 0) | if (prop_type >= 0) |
| 3776 | { | { |
| 3777 | for (i = min; i < max; i++) | switch(prop_type) |
| 3778 | { | { |
| 3779 | int len = 1; | case PT_ANY: |
| 3780 | if (eptr >= md->end_subject) break; | for (i = min; i < max; i++) |
| 3781 | GETCHARLEN(c, eptr, len); | { |
| 3782 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | int len = 1; |
| 3783 | if ((*prop_test_variable == prop_test_against) == prop_fail_result) | if (eptr >= md->end_subject) break; |
| 3784 | break; | GETCHARLEN(c, eptr, len); |
| 3785 | eptr+= len; | if (prop_fail_result) break; |
| 3786 | eptr+= len; | |
| 3787 | } | |
| 3788 | break; | |
| 3789 | ||
| 3790 | case PT_LAMP: | |
| 3791 | for (i = min; i < max; i++) | |
| 3792 | { | |
| 3793 | int len = 1; | |
| 3794 | if (eptr >= md->end_subject) break; | |
| 3795 | GETCHARLEN(c, eptr, len); | |
| 3796 | prop_chartype = UCD_CHARTYPE(c); | |
| 3797 | if ((prop_chartype == ucp_Lu || | |
| 3798 | prop_chartype == ucp_Ll || | |
| 3799 | prop_chartype == ucp_Lt) == prop_fail_result) | |
| 3800 | break; | |
| 3801 | eptr+= len; | |
| 3802 | } | |
| 3803 | break; | |
| 3804 | ||
| 3805 | case PT_GC: | |
| 3806 | for (i = min; i < max; i++) | |
| 3807 | { | |
| 3808 | int len = 1; | |
| 3809 | if (eptr >= md->end_subject) break; | |
| 3810 | GETCHARLEN(c, eptr, len); | |
| 3811 | prop_category = UCD_CATEGORY(c); | |
| 3812 | if ((prop_category == prop_value) == prop_fail_result) | |
| 3813 | break; | |
| 3814 | eptr+= len; | |
| 3815 | } | |
| 3816 | break; | |
| 3817 | ||
| 3818 | case PT_PC: | |
| 3819 | for (i = min; i < max; i++) | |
| 3820 | { | |
| 3821 | int len = 1; | |
| 3822 | if (eptr >= md->end_subject) break; | |
| 3823 | GETCHARLEN(c, eptr, len); | |
| 3824 | prop_chartype = UCD_CHARTYPE(c); | |
| 3825 | if ((prop_chartype == prop_value) == prop_fail_result) | |
| 3826 | break; | |
| 3827 | eptr+= len; | |
| 3828 | } | |
| 3829 | break; | |
| 3830 | ||
| 3831 | case PT_SC: | |
| 3832 | for (i = min; i < max; i++) | |
| 3833 | { | |
| 3834 | int len = 1; | |
| 3835 | if (eptr >= md->end_subject) break; | |
| 3836 | GETCHARLEN(c, eptr, len); | |
| 3837 | prop_script = UCD_SCRIPT(c); | |
| 3838 | if ((prop_script == prop_value) == prop_fail_result) | |
| 3839 | break; | |
| 3840 | eptr+= len; | |
| 3841 | } | |
| 3842 | break; | |
| 3843 | } | } |
| 3844 | ||
| 3845 | /* eptr is now past the end of the maximum run */ | /* eptr is now past the end of the maximum run */ |
| 3846 | ||
| 3847 | if (possessive) continue; | |
| 3848 | for(;;) | for(;;) |
| 3849 | { | { |
| 3850 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44); |
| 3851 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3852 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3853 | BACKCHAR(eptr); | if (utf8) BACKCHAR(eptr); |
| 3854 | } | } |
| 3855 | } | } |
| 3856 | ||
| # | Line 2816 for (;;) | Line 3863 for (;;) |
| 3863 | { | { |
| 3864 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) break; |
| 3865 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3866 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3867 | if (prop_category == ucp_M) break; | if (prop_category == ucp_M) break; |
| 3868 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 3869 | { | { |
| # | Line 2825 for (;;) | Line 3872 for (;;) |
| 3872 | { | { |
| 3873 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 3874 | } | } |
| 3875 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3876 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 3877 | eptr += len; | eptr += len; |
| 3878 | } | } |
| # | Line 2833 for (;;) | Line 3880 for (;;) |
| 3880 | ||
| 3881 | /* eptr is now past the end of the maximum run */ | /* eptr is now past the end of the maximum run */ |
| 3882 | ||
| 3883 | if (possessive) continue; | |
| 3884 | for(;;) | for(;;) |
| 3885 | { | { |
| 3886 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45); |
| 3887 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3888 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3889 | for (;;) /* Move back over one extended */ | for (;;) /* Move back over one extended */ |
| 3890 | { | { |
| 3891 | int len = 1; | int len = 1; |
| BACKCHAR(eptr); | ||
| 3892 | if (!utf8) c = *eptr; else | if (!utf8) c = *eptr; else |
| 3893 | { | { |
| 3894 | BACKCHAR(eptr); | |
| 3895 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 3896 | } | } |
| 3897 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3898 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 3899 | eptr--; | eptr--; |
| 3900 | } | } |
| # | Line 2864 for (;;) | Line 3912 for (;;) |
| 3912 | switch(ctype) | switch(ctype) |
| 3913 | { | { |
| 3914 | case OP_ANY: | case OP_ANY: |
| /* Special code is required for UTF8, but when the maximum is unlimited | ||
| we don't need it, so we repeat the non-UTF8 code. This is probably | ||
| worth it, because .* is quite a common idiom. */ | ||
| 3915 | if (max < INT_MAX) | if (max < INT_MAX) |
| 3916 | { | { |
| 3917 | if ((ims & PCRE_DOTALL) == 0) | for (i = min; i < max; i++) |
| { | ||
| for (i = min; i < max; i++) | ||
| { | ||
| if (eptr >= md->end_subject || *eptr == NEWLINE) break; | ||
| eptr++; | ||
| while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
| } | ||
| } | ||
| else | ||
| 3918 | { | { |
| 3919 | for (i = min; i < max; i++) | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; |
| 3920 | { | eptr++; |
| 3921 | eptr++; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
| } | ||
| 3922 | } | } |
| 3923 | } | } |
| 3924 | ||
| # | Line 2894 for (;;) | Line 3926 for (;;) |
| 3926 | ||
| 3927 | else | else |
| 3928 | { | { |
| 3929 | if ((ims & PCRE_DOTALL) == 0) | for (i = min; i < max; i++) |
| 3930 | { | { |
| 3931 | for (i = min; i < max; i++) | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; |
| 3932 | { | eptr++; |
| 3933 | if (eptr >= md->end_subject || *eptr == NEWLINE) break; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| eptr++; | ||
| } | ||
| break; | ||
| 3934 | } | } |
| 3935 | else | } |
| 3936 | break; | |
| 3937 | ||
| 3938 | case OP_ALLANY: | |
| 3939 | if (max < INT_MAX) | |
| 3940 | { | |
| 3941 | for (i = min; i < max; i++) | |
| 3942 | { | { |
| 3943 | c = max - min; | if (eptr >= md->end_subject) break; |
| 3944 | if (c > md->end_subject - eptr) c = md->end_subject - eptr; | eptr++; |
| 3945 | eptr += c; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| 3946 | } | } |
| 3947 | } | } |
| 3948 | else eptr = md->end_subject; /* Unlimited UTF-8 repeat */ | |
| 3949 | break; | break; |
| 3950 | ||
| 3951 | /* The byte case is the same as non-UTF8 */ | /* The byte case is the same as non-UTF8 */ |
| 3952 | ||
| 3953 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 3954 | c = max - min; | c = max - min; |
| 3955 | if (c > md->end_subject - eptr) c = md->end_subject - eptr; | if (c > (unsigned int)(md->end_subject - eptr)) |
| 3956 | c = md->end_subject - eptr; | |
| 3957 | eptr += c; | eptr += c; |
| 3958 | break; | break; |
| 3959 | ||
| 3960 | case OP_ANYNL: | |
| 3961 | for (i = min; i < max; i++) | |
| 3962 | { | |
| 3963 | int len = 1; | |
| 3964 | if (eptr >= md->end_subject) break; | |
| 3965 | GETCHARLEN(c, eptr, len); | |
| 3966 | if (c == 0x000d) | |
| 3967 | { | |
| 3968 | if (++eptr >= md->end_subject) break; | |
| 3969 | if (*eptr == 0x000a) eptr++; | |
| 3970 | } | |
| 3971 | else | |
| 3972 | { | |
| 3973 | if (c != 0x000a && | |
| 3974 | (md->bsr_anycrlf || | |
| 3975 | (c != 0x000b && c != 0x000c && | |
| 3976 | c != 0x0085 && c != 0x2028 && c != 0x2029))) | |
| 3977 | break; | |
| 3978 | eptr += len; | |
| 3979 | } | |
| 3980 | } | |
| 3981 | break; | |
| 3982 | ||
| 3983 | case OP_NOT_HSPACE: | |
| 3984 | case OP_HSPACE: | |
| 3985 | for (i = min; i < max; i++) | |
| 3986 | { | |
| 3987 | BOOL gotspace; | |
| 3988 | int len = 1; | |
| 3989 | if (eptr >= md->end_subject) break; | |
| 3990 | GETCHARLEN(c, eptr, len); | |
| 3991 | switch(c) | |
| 3992 | { | |
| 3993 | default: gotspace = FALSE; break; | |
| 3994 | case 0x09: /* HT */ | |
| 3995 | case 0x20: /* SPACE */ | |
| 3996 | case 0xa0: /* NBSP */ | |
| 3997 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3998 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3999 | case 0x2000: /* EN QUAD */ | |
| 4000 | case 0x2001: /* EM QUAD */ | |
| 4001 | case 0x2002: /* EN SPACE */ | |
| 4002 | case 0x2003: /* EM SPACE */ | |
| 4003 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 4004 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 4005 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 4006 | case 0x2007: /* FIGURE SPACE */ | |
| 4007 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 4008 | case 0x2009: /* THIN SPACE */ | |
| 4009 | case 0x200A: /* HAIR SPACE */ | |
| 4010 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 4011 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 4012 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 4013 | gotspace = TRUE; | |
| 4014 | break; | |
| 4015 | } | |
| 4016 | if (gotspace == (ctype == OP_NOT_HSPACE)) break; | |
| 4017 | eptr += len; | |
| 4018 | } | |
| 4019 | break; | |
| 4020 | ||
| 4021 | case OP_NOT_VSPACE: | |
| 4022 | case OP_VSPACE: | |
| 4023 | for (i = min; i < max; i++) | |
| 4024 | { | |
| 4025 | BOOL gotspace; | |
| 4026 | int len = 1; | |
| 4027 | if (eptr >= md->end_subject) break; | |
| 4028 | GETCHARLEN(c, eptr, len); | |
| 4029 | switch(c) | |
| 4030 | { | |
| 4031 | default: gotspace = FALSE; break; | |
| 4032 | case 0x0a: /* LF */ | |
| 4033 | case 0x0b: /* VT */ | |
| 4034 | case 0x0c: /* FF */ | |
| 4035 | case 0x0d: /* CR */ | |
| 4036 | case 0x85: /* NEL */ | |
| 4037 | case 0x2028: /* LINE SEPARATOR */ | |
| 4038 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 4039 | gotspace = TRUE; | |
| 4040 | break; | |
| 4041 | } | |
| 4042 | if (gotspace == (ctype == OP_NOT_VSPACE)) break; | |
| 4043 | eptr += len; | |
| 4044 | } | |
| 4045 | break; | |
| 4046 | ||
| 4047 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 4048 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 4049 | { | { |
| # | Line 2992 for (;;) | Line 4116 for (;;) |
| 4116 | ||
| 4117 | /* eptr is now past the end of the maximum run */ | /* eptr is now past the end of the maximum run */ |
| 4118 | ||
| 4119 | if (possessive) continue; | |
| 4120 | for(;;) | for(;;) |
| 4121 | { | { |
| 4122 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46); |
| 4123 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4124 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 4125 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| 4126 | } | } |
| 4127 | } | } |
| 4128 | else | else |
| 4129 | #endif | #endif /* SUPPORT_UTF8 */ |
| 4130 | ||
| 4131 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
| 4132 | { | { |
| 4133 | switch(ctype) | switch(ctype) |
| 4134 | { | { |
| 4135 | case OP_ANY: | case OP_ANY: |
| 4136 | if ((ims & PCRE_DOTALL) == 0) | for (i = min; i < max; i++) |
| 4137 | { | { |
| 4138 | for (i = min; i < max; i++) | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; |
| 4139 | { | eptr++; |
| if (eptr >= md->end_subject || *eptr == NEWLINE) break; | ||
| eptr++; | ||
| } | ||
| break; | ||
| 4140 | } | } |
| 4141 | /* For DOTALL case, fall through and treat as \C */ | break; |
| 4142 | ||
| 4143 | case OP_ALLANY: | |
| 4144 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 4145 | c = max - min; | c = max - min; |
| 4146 | if (c > md->end_subject - eptr) c = md->end_subject - eptr; | if (c > (unsigned int)(md->end_subject - eptr)) |
| 4147 | c = md->end_subject - eptr; | |
| 4148 | eptr += c; | eptr += c; |
| 4149 | break; | break; |
| 4150 | ||
| 4151 | case OP_ANYNL: | |
| 4152 | for (i = min; i < max; i++) | |
| 4153 | { | |
| 4154 | if (eptr >= md->end_subject) break; | |
| 4155 | c = *eptr; | |
| 4156 | if (c == 0x000d) | |
| 4157 | { | |
| 4158 | if (++eptr >= md->end_subject) break; | |
| 4159 | if (*eptr == 0x000a) eptr++; | |
| 4160 | } | |
| 4161 | else | |
| 4162 | { | |
| 4163 | if (c != 0x000a && | |
| 4164 | (md->bsr_anycrlf || | |
| 4165 | (c != 0x000b && c != 0x000c && c != 0x0085))) | |
| 4166 | break; | |
| 4167 | eptr++; | |
| 4168 | } | |
| 4169 | } | |
| 4170 | break; | |
| 4171 | ||
| 4172 | case OP_NOT_HSPACE: | |
| 4173 | for (i = min; i < max; i++) | |
| 4174 | { | |
| 4175 | if (eptr >= md->end_subject) break; | |
| 4176 | c = *eptr; | |
| 4177 | if (c == 0x09 || c == 0x20 || c == 0xa0) break; | |
| 4178 | eptr++; | |
| 4179 | } | |
| 4180 | break; | |
| 4181 | ||
| 4182 | case OP_HSPACE: | |
| 4183 | for (i = min; i < max; i++) | |
| 4184 | { | |
| 4185 | if (eptr >= md->end_subject) break; | |
| 4186 | c = *eptr; | |
| 4187 | if (c != 0x09 && c != 0x20 && c != 0xa0) break; | |
| 4188 | eptr++; | |
| 4189 | } | |
| 4190 | break; | |
| 4191 | ||
| 4192 | case OP_NOT_VSPACE: | |
| 4193 | for (i = min; i < max; i++) | |
| 4194 | { | |
| 4195 | if (eptr >= md->end_subject) break; | |
| 4196 | c = *eptr; | |
| 4197 | if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85) | |
| 4198 | break; | |
| 4199 | eptr++; | |
| 4200 | } | |
| 4201 | break; | |
| 4202 | ||
| 4203 | case OP_VSPACE: | |
| 4204 | for (i = min; i < max; i++) | |
| 4205 | { | |
| 4206 | if (eptr >= md->end_subject) break; | |
| 4207 | c = *eptr; | |
| 4208 | if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85) | |
| 4209 | break; | |
| 4210 | eptr++; | |
| 4211 | } | |
| 4212 | break; | |
| 4213 | ||
| 4214 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 4215 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 4216 | { | { |
| # | Line 3085 for (;;) | Line 4271 for (;;) |
| 4271 | ||
| 4272 | /* eptr is now past the end of the maximum run */ | /* eptr is now past the end of the maximum run */ |
| 4273 | ||
| 4274 | if (possessive) continue; | |
| 4275 | while (eptr >= pp) | while (eptr >= pp) |
| 4276 | { | { |
| 4277 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47); |
| 4278 | eptr--; | eptr--; |
| 4279 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4280 | } | } |
| # | Line 3099 for (;;) | Line 4286 for (;;) |
| 4286 | } | } |
| 4287 | /* Control never gets here */ | /* Control never gets here */ |
| 4288 | ||
| 4289 | /* There's been some horrible disaster. Since all codes > OP_BRA are | /* There's been some horrible disaster. Arrival here can only mean there is |
| 4290 | for capturing brackets, and there shouldn't be any gaps between 0 and | something seriously wrong in the code above or the OP_xxx definitions. */ |
| OP_BRA, arrival here can only mean there is something seriously wrong | ||
| in the code above or the OP_xxx definitions. */ | ||
| 4291 | ||
| 4292 | default: | default: |
| 4293 | DPRINTF(("Unknown opcode %d\n", *ecode)); | DPRINTF(("Unknown opcode %d\n", *ecode)); |
| 4294 | RRETURN(PCRE_ERROR_UNKNOWN_NODE); | RRETURN(PCRE_ERROR_UNKNOWN_OPCODE); |
| 4295 | } | } |
| 4296 | ||
| 4297 | /* Do not stick any code in here without much thought; it is assumed | /* Do not stick any code in here without much thought; it is assumed |
| # | Line 3115 for (;;) | Line 4300 for (;;) |
| 4300 | ||
| 4301 | } /* End of main loop */ | } /* End of main loop */ |
| 4302 | /* Control never reaches here */ | /* Control never reaches here */ |
| 4303 | ||
| 4304 | ||
| 4305 | /* When compiling to use the heap rather than the stack for recursive calls to | |
| 4306 | match(), the RRETURN() macro jumps here. The number that is saved in | |
| 4307 | frame->Xwhere indicates which label we actually want to return to. */ | |
| 4308 | ||
| 4309 | #ifdef NO_RECURSE | |
| 4310 | #define LBL(val) case val: goto L_RM##val; | |
| 4311 | HEAP_RETURN: | |
| 4312 | switch (frame->Xwhere) | |
| 4313 | { | |
| 4314 | LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8) | |
| 4315 | LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17) | |
| 4316 | LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33) | |
| 4317 | LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52) | |
| 4318 | LBL(53) LBL(54) | |
| 4319 | #ifdef SUPPORT_UTF8 | |
| 4320 | LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30) | |
| 4321 | LBL(32) LBL(34) LBL(42) LBL(46) | |
| 4322 | #ifdef SUPPORT_UCP | |
| 4323 | LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45) | |
| 4324 | #endif /* SUPPORT_UCP */ | |
| 4325 | #endif /* SUPPORT_UTF8 */ | |
| 4326 | default: | |
| 4327 | DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere)); | |
| 4328 | return PCRE_ERROR_INTERNAL; | |
| 4329 | } | |
| 4330 | #undef LBL | |
| 4331 | #endif /* NO_RECURSE */ | |
| 4332 | } | } |
| 4333 | ||
| 4334 | ||
| # | Line 3127 Undefine all the macros that were define | Line 4341 Undefine all the macros that were define |
| 4341 | #ifdef NO_RECURSE | #ifdef NO_RECURSE |
| 4342 | #undef eptr | #undef eptr |
| 4343 | #undef ecode | #undef ecode |
| 4344 | #undef mstart | |
| 4345 | #undef offset_top | #undef offset_top |
| 4346 | #undef ims | #undef ims |
| 4347 | #undef eptrb | #undef eptrb |
| # | Line 3144 Undefine all the macros that were define | Line 4359 Undefine all the macros that were define |
| 4359 | ||
| 4360 | #undef cur_is_word | #undef cur_is_word |
| 4361 | #undef condition | #undef condition |
| #undef minimize | ||
| 4362 | #undef prev_is_word | #undef prev_is_word |
| 4363 | ||
| 4364 | #undef original_ims | #undef original_ims |
| # | Line 3200 Returns: > 0 => success; value | Line 4414 Returns: > 0 => success; value |
| 4414 | < -1 => some kind of unexpected problem | < -1 => some kind of unexpected problem |
| 4415 | */ | */ |
| 4416 | ||
| 4417 | EXPORT int | PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
| 4418 | pcre_exec(const pcre *argument_re, const pcre_extra *extra_data, | pcre_exec(const pcre *argument_re, const pcre_extra *extra_data, |
| 4419 | const char *subject, int length, int start_offset, int options, int *offsets, | PCRE_SPTR subject, int length, int start_offset, int options, int *offsets, |
| 4420 | int offsetcount) | int offsetcount) |
| 4421 | { | { |
| 4422 | int rc, resetcount, ocount; | int rc, resetcount, ocount; |
| 4423 | int first_byte = -1; | int first_byte = -1; |
| 4424 | int req_byte = -1; | int req_byte = -1; |
| 4425 | int req_byte2 = -1; | int req_byte2 = -1; |
| 4426 | unsigned long int ims = 0; | int newline; |
| 4427 | unsigned long int ims; | |
| 4428 | BOOL using_temporary_offsets = FALSE; | BOOL using_temporary_offsets = FALSE; |
| 4429 | BOOL anchored; | BOOL anchored; |
| 4430 | BOOL startline; | BOOL startline; |
| 4431 | BOOL firstline; | BOOL firstline; |
| 4432 | BOOL first_byte_caseless = FALSE; | BOOL first_byte_caseless = FALSE; |
| 4433 | BOOL req_byte_caseless = FALSE; | BOOL req_byte_caseless = FALSE; |
| 4434 | BOOL utf8; | |
| 4435 | match_data match_block; | match_data match_block; |
| 4436 | match_data *md = &match_block; | |
| 4437 | const uschar *tables; | const uschar *tables; |
| 4438 | const uschar *start_bits = NULL; | const uschar *start_bits = NULL; |
| 4439 | const uschar *start_match = (const uschar *)subject + start_offset; | USPTR start_match = (USPTR)subject + start_offset; |
| 4440 | const uschar *end_subject; | USPTR end_subject; |
| 4441 | const uschar *req_byte_ptr = start_match - 1; | USPTR req_byte_ptr = start_match - 1; |
| 4442 | ||
| 4443 | pcre_study_data internal_study; | pcre_study_data internal_study; |
| 4444 | const pcre_study_data *study; | const pcre_study_data *study; |
| # | Line 3241 if (offsetcount < 0) return PCRE_ERROR_B | Line 4458 if (offsetcount < 0) return PCRE_ERROR_B |
| 4458 | the default values. */ | the default values. */ |
| 4459 | ||
| 4460 | study = NULL; | study = NULL; |
| 4461 | match_block.match_limit = MATCH_LIMIT; | md->match_limit = MATCH_LIMIT; |
| 4462 | match_block.callout_data = NULL; | md->match_limit_recursion = MATCH_LIMIT_RECURSION; |
| 4463 | md->callout_data = NULL; | |
| 4464 | ||
| 4465 | /* The table pointer is always in native byte order. */ | /* The table pointer is always in native byte order. */ |
| 4466 | ||
| # | Line 3254 if (extra_data != NULL) | Line 4472 if (extra_data != NULL) |
| 4472 | if ((flags & PCRE_EXTRA_STUDY_DATA) != 0) | if ((flags & PCRE_EXTRA_STUDY_DATA) != 0) |
| 4473 | study = (const pcre_study_data *)extra_data->study_data; | study = (const pcre_study_data *)extra_data->study_data; |
| 4474 | if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0) | if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0) |
| 4475 | match_block.match_limit = extra_data->match_limit; | md->match_limit = extra_data->match_limit; |
| 4476 | if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0) | |
| 4477 | md->match_limit_recursion = extra_data->match_limit_recursion; | |
| 4478 | if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0) | if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0) |
| 4479 | match_block.callout_data = extra_data->callout_data; | md->callout_data = extra_data->callout_data; |
| 4480 | if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables; | if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables; |
| 4481 | } | } |
| 4482 | ||
| # | Line 3281 if (re->magic_number != MAGIC_NUMBER) | Line 4501 if (re->magic_number != MAGIC_NUMBER) |
| 4501 | /* Set up other data */ | /* Set up other data */ |
| 4502 | ||
| 4503 | anchored = ((re->options | options) & PCRE_ANCHORED) != 0; | anchored = ((re->options | options) & PCRE_ANCHORED) != 0; |
| 4504 | startline = (re->options & PCRE_STARTLINE) != 0; | startline = (re->flags & PCRE_STARTLINE) != 0; |
| 4505 | firstline = (re->options & PCRE_FIRSTLINE) != 0; | firstline = (re->options & PCRE_FIRSTLINE) != 0; |
| 4506 | ||
| 4507 | /* The code starts after the real_pcre block and the capture name table. */ | /* The code starts after the real_pcre block and the capture name table. */ |
| 4508 | ||
| 4509 | match_block.start_code = (const uschar *)external_re + re->name_table_offset + | md->start_code = (const uschar *)external_re + re->name_table_offset + |
| 4510 | re->name_count * re->name_entry_size; | re->name_count * re->name_entry_size; |
| 4511 | ||
| 4512 | match_block.start_subject = (const uschar *)subject; | md->start_subject = (USPTR)subject; |
| 4513 | match_block.start_offset = start_offset; | md->start_offset = start_offset; |
| 4514 | match_block.end_subject = match_block.start_subject + length; | md->end_subject = md->start_subject + length; |
| 4515 | end_subject = match_block.end_subject; | end_subject = md->end_subject; |
| 4516 | ||
| 4517 | match_block.endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0; | md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0; |
| 4518 | match_block.utf8 = (re->options & PCRE_UTF8) != 0; | utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0; |
| 4519 | md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0; | |
| 4520 | match_block.notbol = (options & PCRE_NOTBOL) != 0; | |
| 4521 | match_block.noteol = (options & PCRE_NOTEOL) != 0; | md->notbol = (options & PCRE_NOTBOL) != 0; |
| 4522 | match_block.notempty = (options & PCRE_NOTEMPTY) != 0; | md->noteol = (options & PCRE_NOTEOL) != 0; |
| 4523 | match_block.partial = (options & PCRE_PARTIAL) != 0; | md->notempty = (options & PCRE_NOTEMPTY) != 0; |
| 4524 | match_block.hitend = FALSE; | md->partial = (options & PCRE_PARTIAL) != 0; |
| 4525 | md->hitend = FALSE; | |
| 4526 | ||
| 4527 | md->recursive = NULL; /* No recursion at top level */ | |
| 4528 | ||
| 4529 | md->lcc = tables + lcc_offset; | |
| 4530 | md->ctypes = tables + ctypes_offset; | |
| 4531 | ||
| 4532 | /* Handle different \R options. */ | |
| 4533 | ||
| 4534 | switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | |
| 4535 | { | |
| 4536 | case 0: | |
| 4537 | if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0) | |
| 4538 | md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0; | |
| 4539 | else | |
| 4540 | #ifdef BSR_ANYCRLF | |
| 4541 | md->bsr_anycrlf = TRUE; | |
| 4542 | #else | |
| 4543 | md->bsr_anycrlf = FALSE; | |
| 4544 | #endif | |
| 4545 | break; | |
| 4546 | ||
| 4547 | match_block.recursive = NULL; /* No recursion at top level */ | case PCRE_BSR_ANYCRLF: |
| 4548 | md->bsr_anycrlf = TRUE; | |
| 4549 | break; | |
| 4550 | ||
| 4551 | match_block.lcc = tables + lcc_offset; | case PCRE_BSR_UNICODE: |
| 4552 | match_block.ctypes = tables + ctypes_offset; | md->bsr_anycrlf = FALSE; |
| 4553 | break; | |
| 4554 | ||
| 4555 | default: return PCRE_ERROR_BADNEWLINE; | |
| 4556 | } | |
| 4557 | ||
| 4558 | /* Handle different types of newline. The three bits give eight cases. If | |
| 4559 | nothing is set at run time, whatever was used at compile time applies. */ | |
| 4560 | ||
| 4561 | switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : | |
| 4562 | (pcre_uint32)options) & PCRE_NEWLINE_BITS) | |
| 4563 | { | |
| 4564 | case 0: newline = NEWLINE; break; /* Compile-time default */ | |
| 4565 | case PCRE_NEWLINE_CR: newline = CHAR_CR; break; | |
| 4566 | case PCRE_NEWLINE_LF: newline = CHAR_NL; break; | |
| 4567 | case PCRE_NEWLINE_CR+ | |
| 4568 | PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break; | |
| 4569 | case PCRE_NEWLINE_ANY: newline = -1; break; | |
| 4570 | case PCRE_NEWLINE_ANYCRLF: newline = -2; break; | |
| 4571 | default: return PCRE_ERROR_BADNEWLINE; | |
| 4572 | } | |
| 4573 | ||
| 4574 | if (newline == -2) | |
| 4575 | { | |
| 4576 | md->nltype = NLTYPE_ANYCRLF; | |
| 4577 | } | |
| 4578 | else if (newline < 0) | |
| 4579 | { | |
| 4580 | md->nltype = NLTYPE_ANY; | |
| 4581 | } | |
| 4582 | else | |
| 4583 | { | |
| 4584 | md->nltype = NLTYPE_FIXED; | |
| 4585 | if (newline > 255) | |
| 4586 | { | |
| 4587 | md->nllen = 2; | |
| 4588 | md->nl[0] = (newline >> 8) & 255; | |
| 4589 | md->nl[1] = newline & 255; | |
| 4590 | } | |
| 4591 | else | |
| 4592 | { | |
| 4593 | md->nllen = 1; | |
| 4594 | md->nl[0] = newline; | |
| 4595 | } | |
| 4596 | } | |
| 4597 | ||
| 4598 | /* Partial matching is supported only for a restricted set of regexes at the | /* Partial matching is supported only for a restricted set of regexes at the |
| 4599 | moment. */ | moment. */ |
| 4600 | ||
| 4601 | if (match_block.partial && (re->options & PCRE_NOPARTIAL) != 0) | if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0) |
| 4602 | return PCRE_ERROR_BADPARTIAL; | return PCRE_ERROR_BADPARTIAL; |
| 4603 | ||
| 4604 | /* Check a UTF-8 string if required. Unfortunately there's no way of passing | /* Check a UTF-8 string if required. Unfortunately there's no way of passing |
| 4605 | back the character offset. */ | back the character offset. */ |
| 4606 | ||
| 4607 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 4608 | if (match_block.utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) | if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) |
| 4609 | { | { |
| 4610 | if (_pcre_valid_utf8((uschar *)subject, length) >= 0) | if (_pcre_valid_utf8((uschar *)subject, length) >= 0) |