Parent Directory
|
Revision Log
|
Patch
| revision 77 by nigel, Sat Feb 24 21:40:45 2007 UTC | revision 403 by ph10, Sat Mar 21 17:33:11 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 | ||
| 336 | const uschar *Xcallpat; | const uschar *Xcallpat; |
| 337 | #ifdef SUPPORT_UTF8 | |
| 338 | const uschar *Xcharptr; | const uschar *Xcharptr; |
| 339 | #endif | |
| 340 | const uschar *Xdata; | const uschar *Xdata; |
| 341 | const uschar *Xnext; | const uschar *Xnext; |
| 342 | const uschar *Xpp; | const uschar *Xpp; |
| # | Line 271 typedef struct heapframe { | Line 347 typedef struct heapframe { |
| 347 | ||
| 348 | BOOL Xcur_is_word; | BOOL Xcur_is_word; |
| 349 | BOOL Xcondition; | BOOL Xcondition; |
| BOOL Xminimize; | ||
| 350 | BOOL Xprev_is_word; | BOOL Xprev_is_word; |
| 351 | ||
| 352 | unsigned long int Xoriginal_ims; | unsigned long int Xoriginal_ims; |
| 353 | ||
| 354 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 355 | int Xprop_type; | int Xprop_type; |
| 356 | int Xprop_value; | |
| 357 | int Xprop_fail_result; | int Xprop_fail_result; |
| 358 | int Xprop_category; | int Xprop_category; |
| 359 | int Xprop_chartype; | int Xprop_chartype; |
| 360 | int Xprop_othercase; | int Xprop_script; |
| 361 | int Xprop_test_against; | int Xoclength; |
| 362 | int *Xprop_test_variable; | uschar Xocchars[8]; |
| 363 | #endif | #endif |
| 364 | ||
| 365 | int Xcodelink; | |
| 366 | int Xctype; | int Xctype; |
| 367 | int Xfc; | unsigned int Xfc; |
| 368 | int Xfi; | int Xfi; |
| 369 | int Xlength; | int Xlength; |
| 370 | int Xmax; | int Xmax; |
| # | Line 301 typedef struct heapframe { | Line 378 typedef struct heapframe { |
| 378 | ||
| 379 | eptrblock Xnewptrb; | eptrblock Xnewptrb; |
| 380 | ||
| 381 | /* Place to pass back result, and where to jump back to */ | /* Where to jump back to */ |
| 382 | ||
| 383 | int Xresult; | int Xwhere; |
| jmp_buf Xwhere; | ||
| 384 | ||
| 385 | } heapframe; | } heapframe; |
| 386 | ||
| # | Line 320 typedef struct heapframe { | Line 396 typedef struct heapframe { |
| 396 | * Match from current position * | * Match from current position * |
| 397 | *************************************************/ | *************************************************/ |
| 398 | ||
| 399 | /* 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 | ||
| 400 | returns a negative (error) response, the outer incarnation must also return the | returns a negative (error) response, the outer incarnation must also return the |
| 401 | same response. | same response. |
| 402 | ||
| # | Line 333 performance. Tests using gcc on a SPARC | Line 406 performance. Tests using gcc on a SPARC |
| 406 | made performance worse. | made performance worse. |
| 407 | ||
| 408 | Arguments: | Arguments: |
| 409 | eptr pointer in subject | eptr pointer to current character in subject |
| 410 | ecode position in code | ecode pointer to current position in compiled code |
| 411 | mstart pointer to the current match start position (can be modified | |
| 412 | by encountering \K) | |
| 413 | offset_top current top pointer | offset_top current top pointer |
| 414 | md pointer to "static" info for the match | md pointer to "static" info for the match |
| 415 | ims current /i, /m, and /s options | ims current /i, /m, and /s options |
| # | Line 342 Arguments: | Line 417 Arguments: |
| 417 | brackets - for testing for empty matches | brackets - for testing for empty matches |
| 418 | flags can contain | flags can contain |
| 419 | match_condassert - this is an assertion condition | match_condassert - this is an assertion condition |
| 420 | match_isgroup - this is the start of a bracketed group | match_cbegroup - this is the start of an unlimited repeat |
| 421 | group that can match an empty string | |
| 422 | rdepth the recursion depth | |
| 423 | ||
| 424 | Returns: MATCH_MATCH if matched ) these values are >= 0 | Returns: MATCH_MATCH if matched ) these values are >= 0 |
| 425 | MATCH_NOMATCH if failed to match ) | MATCH_NOMATCH if failed to match ) |
| 426 | a negative PCRE_ERROR_xxx value if aborted by an error condition | a negative PCRE_ERROR_xxx value if aborted by an error condition |
| 427 | (e.g. stopped by recursion limit) | (e.g. stopped by repeated call or recursion limit) |
| 428 | */ | */ |
| 429 | ||
| 430 | static int | static int |
| 431 | match(REGISTER const uschar *eptr, REGISTER const uschar *ecode, | match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart, |
| 432 | int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, | int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, |
| 433 | int flags) | int flags, unsigned int rdepth) |
| 434 | { | { |
| 435 | /* 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, |
| 436 | 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 |
| 437 | because they are used a lot in loops. */ | "register" because they are used a lot in loops. */ |
| 438 | ||
| 439 | register int rrc; /* Returns from recursive calls */ | |
| 440 | register int i; /* Used for loops not involving calls to RMATCH() */ | |
| 441 | register unsigned int c; /* Character values not kept over RMATCH() calls */ | |
| 442 | register BOOL utf8; /* Local copy of UTF-8 flag for speed */ | |
| 443 | ||
| 444 | register int rrc; /* Returns from recursive calls */ | BOOL minimize, possessive; /* Quantifier options */ |
| 445 | register int i; /* Used for loops not involving calls to RMATCH() */ | int condcode; |
| register int c; /* Character values not kept over RMATCH() calls */ | ||
| register BOOL utf8; /* Local copy of UTF-8 flag for speed */ | ||
| 446 | ||
| 447 | /* 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 |
| 448 | 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 457 frame->Xprevframe = NULL; /* |
| 457 | ||
| 458 | frame->Xeptr = eptr; | frame->Xeptr = eptr; |
| 459 | frame->Xecode = ecode; | frame->Xecode = ecode; |
| 460 | frame->Xmstart = mstart; | |
| 461 | frame->Xoffset_top = offset_top; | frame->Xoffset_top = offset_top; |
| 462 | frame->Xims = ims; | frame->Xims = ims; |
| 463 | frame->Xeptrb = eptrb; | frame->Xeptrb = eptrb; |
| 464 | frame->Xflags = flags; | frame->Xflags = flags; |
| 465 | frame->Xrdepth = rdepth; | |
| 466 | ||
| 467 | /* This is where control jumps back to to effect "recursion" */ | /* This is where control jumps back to to effect "recursion" */ |
| 468 | ||
| # | Line 390 HEAP_RECURSE: | Line 472 HEAP_RECURSE: |
| 472 | ||
| 473 | #define eptr frame->Xeptr | #define eptr frame->Xeptr |
| 474 | #define ecode frame->Xecode | #define ecode frame->Xecode |
| 475 | #define mstart frame->Xmstart | |
| 476 | #define offset_top frame->Xoffset_top | #define offset_top frame->Xoffset_top |
| 477 | #define ims frame->Xims | #define ims frame->Xims |
| 478 | #define eptrb frame->Xeptrb | #define eptrb frame->Xeptrb |
| 479 | #define flags frame->Xflags | #define flags frame->Xflags |
| 480 | #define rdepth frame->Xrdepth | |
| 481 | ||
| 482 | /* Ditto for the local variables */ | /* Ditto for the local variables */ |
| 483 | ||
| # | Line 401 HEAP_RECURSE: | Line 485 HEAP_RECURSE: |
| 485 | #define charptr frame->Xcharptr | #define charptr frame->Xcharptr |
| 486 | #endif | #endif |
| 487 | #define callpat frame->Xcallpat | #define callpat frame->Xcallpat |
| 488 | #define codelink frame->Xcodelink | |
| 489 | #define data frame->Xdata | #define data frame->Xdata |
| 490 | #define next frame->Xnext | #define next frame->Xnext |
| 491 | #define pp frame->Xpp | #define pp frame->Xpp |
| # | Line 411 HEAP_RECURSE: | Line 496 HEAP_RECURSE: |
| 496 | ||
| 497 | #define cur_is_word frame->Xcur_is_word | #define cur_is_word frame->Xcur_is_word |
| 498 | #define condition frame->Xcondition | #define condition frame->Xcondition |
| #define minimize frame->Xminimize | ||
| 499 | #define prev_is_word frame->Xprev_is_word | #define prev_is_word frame->Xprev_is_word |
| 500 | ||
| 501 | #define original_ims frame->Xoriginal_ims | #define original_ims frame->Xoriginal_ims |
| 502 | ||
| 503 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 504 | #define prop_type frame->Xprop_type | #define prop_type frame->Xprop_type |
| 505 | #define prop_value frame->Xprop_value | |
| 506 | #define prop_fail_result frame->Xprop_fail_result | #define prop_fail_result frame->Xprop_fail_result |
| 507 | #define prop_category frame->Xprop_category | #define prop_category frame->Xprop_category |
| 508 | #define prop_chartype frame->Xprop_chartype | #define prop_chartype frame->Xprop_chartype |
| 509 | #define prop_othercase frame->Xprop_othercase | #define prop_script frame->Xprop_script |
| 510 | #define prop_test_against frame->Xprop_test_against | #define oclength frame->Xoclength |
| 511 | #define prop_test_variable frame->Xprop_test_variable | #define occhars frame->Xocchars |
| 512 | #endif | #endif |
| 513 | ||
| 514 | #define ctype frame->Xctype | #define ctype frame->Xctype |
| # | Line 447 HEAP_RECURSE: | Line 532 HEAP_RECURSE: |
| 532 | 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 |
| 533 | i, and fc and c, can be the same variables. */ | i, and fc and c, can be the same variables. */ |
| 534 | ||
| 535 | #else | #else /* NO_RECURSE not defined */ |
| 536 | #define fi i | #define fi i |
| 537 | #define fc c | #define fc c |
| 538 | ||
| 539 | ||
| 540 | #ifdef SUPPORT_UTF8 /* Many of these variables are used ony */ | #ifdef SUPPORT_UTF8 /* Many of these variables are used only */ |
| 541 | const uschar *charptr; /* small blocks of the code. My normal */ | const uschar *charptr; /* in small blocks of the code. My normal */ |
| 542 | #endif /* style of coding would have declared */ | #endif /* style of coding would have declared */ |
| 543 | const uschar *callpat; /* them within each of those blocks. */ | const uschar *callpat; /* them within each of those blocks. */ |
| 544 | const uschar *data; /* However, in order to accommodate the */ | const uschar *data; /* However, in order to accommodate the */ |
| 545 | const uschar *next; /* version of this code that uses an */ | const uschar *next; /* version of this code that uses an */ |
| 546 | const uschar *pp; /* external "stack" implemented on the */ | USPTR pp; /* external "stack" implemented on the */ |
| 547 | const uschar *prev; /* heap, it is easier to declare them */ | const uschar *prev; /* heap, it is easier to declare them all */ |
| 548 | const uschar *saved_eptr; /* all here, so the declarations can */ | USPTR saved_eptr; /* here, so the declarations can be cut */ |
| 549 | /* be cut out in a block. The only */ | /* out in a block. The only declarations */ |
| 550 | recursion_info new_recursive; /* declarations within blocks below are */ | recursion_info new_recursive; /* within blocks below are for variables */ |
| 551 | /* for variables that do not have to */ | /* that do not have to be preserved over */ |
| 552 | BOOL cur_is_word; /* be preserved over a recursive call */ | BOOL cur_is_word; /* a recursive call to RMATCH(). */ |
| 553 | BOOL condition; /* to RMATCH(). */ | BOOL condition; |
| BOOL minimize; | ||
| 554 | BOOL prev_is_word; | BOOL prev_is_word; |
| 555 | ||
| 556 | unsigned long int original_ims; | unsigned long int original_ims; |
| 557 | ||
| 558 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 559 | int prop_type; | int prop_type; |
| 560 | int prop_value; | |
| 561 | int prop_fail_result; | int prop_fail_result; |
| 562 | int prop_category; | int prop_category; |
| 563 | int prop_chartype; | int prop_chartype; |
| 564 | int prop_othercase; | int prop_script; |
| 565 | int prop_test_against; | int oclength; |
| 566 | int *prop_test_variable; | uschar occhars[8]; |
| 567 | #endif | #endif |
| 568 | ||
| 569 | int codelink; | |
| 570 | int ctype; | int ctype; |
| 571 | int length; | int length; |
| 572 | int max; | int max; |
| # | Line 493 int save_offset1, save_offset2, save_off | Line 579 int save_offset1, save_offset2, save_off |
| 579 | int stacksave[REC_STACK_SAVE_MAX]; | int stacksave[REC_STACK_SAVE_MAX]; |
| 580 | ||
| 581 | eptrblock newptrb; | eptrblock newptrb; |
| 582 | #endif | #endif /* NO_RECURSE */ |
| 583 | ||
| 584 | /* These statements are here to stop the compiler complaining about unitialized | /* These statements are here to stop the compiler complaining about unitialized |
| 585 | variables. */ | variables. */ |
| 586 | ||
| 587 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 588 | prop_value = 0; | |
| 589 | prop_fail_result = 0; | prop_fail_result = 0; |
| prop_test_against = 0; | ||
| prop_test_variable = NULL; | ||
| 590 | #endif | #endif |
| 591 | ||
| 592 | /* OK, now we can get on with the real code of the function. Recursion is | |
| 593 | 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 |
| 594 | 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 |
| 595 | 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 |
| 596 | macro. It has to be used in one particular way. This shouldn't, however, impact | original patch. */ |
| 597 | performance when true recursion is being used. */ | |
| 598 | TAIL_RECURSE: | |
| 599 | ||
| 600 | /* OK, now we can get on with the real code of the function. Recursive calls | |
| 601 | are specified by the macro RMATCH and RRETURN is used to return. When | |
| 602 | NO_RECURSE is *not* defined, these just turn into a recursive call to match() | |
| 603 | and a "return", respectively (possibly with some debugging if DEBUG is | |
| 604 | defined). However, RMATCH isn't like a function call because it's quite a | |
| 605 | complicated macro. It has to be used in one particular way. This shouldn't, | |
| 606 | however, impact performance when true recursion is being used. */ | |
| 607 | ||
| 608 | #ifdef SUPPORT_UTF8 | |
| 609 | utf8 = md->utf8; /* Local copy of the flag */ | |
| 610 | #else | |
| 611 | utf8 = FALSE; | |
| 612 | #endif | |
| 613 | ||
| 614 | /* First check that we haven't called match() too many times, or that we | |
| 615 | haven't exceeded the recursive call limit. */ | |
| 616 | ||
| 617 | if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT); | if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT); |
| 618 | if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); | |
| 619 | ||
| 620 | original_ims = ims; /* Save for resetting on ')' */ | original_ims = ims; /* Save for resetting on ')' */ |
| utf8 = md->utf8; /* Local copy of the flag */ | ||
| 621 | ||
| 622 | /* 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 |
| 623 | 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 |
| 624 | 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 |
| 625 | this stack. */ | hit the closing ket, in order to break infinite loops that match no characters. |
| 626 | When match() is called in other circumstances, don't add to the chain. The | |
| 627 | match_cbegroup flag must NOT be used with tail recursion, because the memory | |
| 628 | block that is used is on the stack, so a new one may be required for each | |
| 629 | match(). */ | |
| 630 | ||
| 631 | if ((flags & match_isgroup) != 0) | if ((flags & match_cbegroup) != 0) |
| 632 | { | { |
| newptrb.epb_prev = eptrb; | ||
| 633 | newptrb.epb_saved_eptr = eptr; | newptrb.epb_saved_eptr = eptr; |
| 634 | newptrb.epb_prev = eptrb; | |
| 635 | eptrb = &newptrb; | eptrb = &newptrb; |
| 636 | } | } |
| 637 | ||
| 638 | /* Now start processing the operations. */ | /* Now start processing the opcodes. */ |
| 639 | ||
| 640 | for (;;) | for (;;) |
| 641 | { | { |
| 642 | minimize = possessive = FALSE; | |
| 643 | op = *ecode; | op = *ecode; |
| 644 | minimize = FALSE; | |
| 645 | /* 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 |
| 646 | matching at least one subject character. */ | matching at least one subject character. */ |
| 647 | ||
| 648 | if (md->partial && | if (md->partial && |
| 649 | eptr >= md->end_subject && | eptr >= md->end_subject && |
| 650 | eptr > md->start_match) | eptr > mstart) |
| 651 | md->hitend = TRUE; | md->hitend = TRUE; |
| 652 | ||
| 653 | /* 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) | ||
| 654 | { | { |
| 655 | number = op - OP_BRA; | case OP_FAIL: |
| 656 | RRETURN(MATCH_NOMATCH); | |
| /* For extended extraction brackets (large number), we have to fish out the | ||
| number from a dummy opcode at the start. */ | ||
| 657 | ||
| 658 | if (number > EXTRACT_BASIC_MAX) | case OP_PRUNE: |
| 659 | number = GET2(ecode, 2+LINK_SIZE); | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, |
| 660 | ims, eptrb, flags, RM51); | |
| 661 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 662 | RRETURN(MATCH_PRUNE); | |
| 663 | ||
| 664 | case OP_COMMIT: | |
| 665 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 666 | ims, eptrb, flags, RM52); | |
| 667 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 668 | RRETURN(MATCH_COMMIT); | |
| 669 | ||
| 670 | case OP_SKIP: | |
| 671 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 672 | ims, eptrb, flags, RM53); | |
| 673 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 674 | md->start_match_ptr = eptr; /* Pass back current position */ | |
| 675 | RRETURN(MATCH_SKIP); | |
| 676 | ||
| 677 | case OP_THEN: | |
| 678 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 679 | ims, eptrb, flags, RM54); | |
| 680 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 681 | RRETURN(MATCH_THEN); | |
| 682 | ||
| 683 | /* Handle a capturing bracket. If there is space in the offset vector, save | |
| 684 | the current subject position in the working slot at the top of the vector. | |
| 685 | We mustn't change the current values of the data slot, because they may be | |
| 686 | set from a previous iteration of this group, and be referred to by a | |
| 687 | reference inside the group. | |
| 688 | ||
| 689 | If the bracket fails to match, we need to restore this value and also the | |
| 690 | values of the final offsets, in case they were set by a previous iteration | |
| 691 | of the same bracket. | |
| 692 | ||
| 693 | If there isn't enough space in the offset vector, treat this as if it were | |
| 694 | a non-capturing bracket. Don't worry about setting the flag for the error | |
| 695 | case here; that is handled in the code for KET. */ | |
| 696 | ||
| 697 | case OP_CBRA: | |
| 698 | case OP_SCBRA: | |
| 699 | number = GET2(ecode, 1+LINK_SIZE); | |
| 700 | offset = number << 1; | offset = number << 1; |
| 701 | ||
| 702 | #ifdef DEBUG | #ifdef DEBUG |
| 703 | printf("start bracket %d subject=", number); | printf("start bracket %d\n", number); |
| 704 | printf("subject="); | |
| 705 | pchars(eptr, 16, TRUE, md); | pchars(eptr, 16, TRUE, md); |
| 706 | printf("\n"); | printf("\n"); |
| 707 | #endif | #endif |
| # | Line 584 for (;;) | Line 716 for (;;) |
| 716 | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); |
| 717 | md->offset_vector[md->offset_end - number] = eptr - md->start_subject; | md->offset_vector[md->offset_end - number] = eptr - md->start_subject; |
| 718 | ||
| 719 | flags = (op == OP_SCBRA)? match_cbegroup : 0; | |
| 720 | do | do |
| 721 | { | { |
| 722 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, |
| 723 | match_isgroup); | ims, eptrb, flags, RM1); |
| 724 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 725 | md->capture_last = save_capture_last; | md->capture_last = save_capture_last; |
| 726 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 727 | } | } |
| # | Line 603 for (;;) | Line 736 for (;;) |
| 736 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 737 | } | } |
| 738 | ||
| 739 | /* Insufficient room for saving captured contents */ | /* FALL THROUGH ... Insufficient room for saving captured contents. Treat |
| 740 | as a non-capturing bracket. */ | |
| 741 | ||
| 742 | else op = OP_BRA; | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 743 | } | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 744 | ||
| 745 | /* Other types of node can be handled by a switch */ | DPRINTF(("insufficient capture room: treat as non-capturing\n")); |
| 746 | ||
| 747 | switch(op) | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 748 | { | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 749 | case OP_BRA: /* Non-capturing bracket: optimized */ | |
| 750 | DPRINTF(("start bracket 0\n")); | /* Non-capturing bracket. Loop for all the alternatives. When we get to the |
| 751 | do | final alternative within the brackets, we would return the result of a |
| 752 | recursive call to match() whatever happened. We can reduce stack usage by | |
| 753 | turning this into a tail recursion, except in the case when match_cbegroup | |
| 754 | is set.*/ | |
| 755 | ||
| 756 | case OP_BRA: | |
| 757 | case OP_SBRA: | |
| 758 | DPRINTF(("start non-capturing bracket\n")); | |
| 759 | flags = (op >= OP_SBRA)? match_cbegroup : 0; | |
| 760 | for (;;) | |
| 761 | { | { |
| 762 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, | if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */ |
| 763 | match_isgroup); | { |
| 764 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (flags == 0) /* Not a possibly empty group */ |
| 765 | { | |
| 766 | ecode += _pcre_OP_lengths[*ecode]; | |
| 767 | DPRINTF(("bracket 0 tail recursion\n")); | |
| 768 | goto TAIL_RECURSE; | |
| 769 | } | |
| 770 | ||
| 771 | /* Possibly empty group; can't use tail recursion. */ | |
| 772 | ||
| 773 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, | |
| 774 | eptrb, flags, RM48); | |
| 775 | RRETURN(rrc); | |
| 776 | } | |
| 777 | ||
| 778 | /* For non-final alternatives, continue the loop for a NOMATCH result; | |
| 779 | otherwise return. */ | |
| 780 | ||
| 781 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, | |
| 782 | eptrb, flags, RM2); | |
| 783 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); | |
| 784 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 785 | } | } |
| 786 | while (*ecode == OP_ALT); | /* Control never reaches here. */ |
| DPRINTF(("bracket 0 failed\n")); | ||
| RRETURN(MATCH_NOMATCH); | ||
| 787 | ||
| 788 | /* Conditional group: compilation checked that there are no more than | /* Conditional group: compilation checked that there are no more than |
| 789 | 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 |
| 790 | 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 |
| 791 | exactly what going to the ket would do. */ | exactly what going to the ket would do. As there is only one branch to be |
| 792 | obeyed, we can use tail recursion to avoid using another stack frame. */ | |
| 793 | ||
| 794 | case OP_COND: | case OP_COND: |
| 795 | if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */ | case OP_SCOND: |
| 796 | codelink= GET(ecode, 1); | |
| 797 | ||
| 798 | /* Because of the way auto-callout works during compile, a callout item is | |
| 799 | inserted between OP_COND and an assertion condition. */ | |
| 800 | ||
| 801 | if (ecode[LINK_SIZE+1] == OP_CALLOUT) | |
| 802 | { | |
| 803 | if (pcre_callout != NULL) | |
| 804 | { | |
| 805 | pcre_callout_block cb; | |
| 806 | cb.version = 1; /* Version 1 of the callout block */ | |
| 807 | cb.callout_number = ecode[LINK_SIZE+2]; | |
| 808 | cb.offset_vector = md->offset_vector; | |
| 809 | cb.subject = (PCRE_SPTR)md->start_subject; | |
| 810 | cb.subject_length = md->end_subject - md->start_subject; | |
| 811 | cb.start_match = mstart - md->start_subject; | |
| 812 | cb.current_position = eptr - md->start_subject; | |
| 813 | cb.pattern_position = GET(ecode, LINK_SIZE + 3); | |
| 814 | cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE); | |
| 815 | cb.capture_top = offset_top/2; | |
| 816 | cb.capture_last = md->capture_last; | |
| 817 | cb.callout_data = md->callout_data; | |
| 818 | if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH); | |
| 819 | if (rrc < 0) RRETURN(rrc); | |
| 820 | } | |
| 821 | ecode += _pcre_OP_lengths[OP_CALLOUT]; | |
| 822 | } | |
| 823 | ||
| 824 | condcode = ecode[LINK_SIZE+1]; | |
| 825 | ||
| 826 | /* Now see what the actual condition is */ | |
| 827 | ||
| 828 | if (condcode == OP_RREF) /* Recursion test */ | |
| 829 | { | |
| 830 | offset = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ | |
| 831 | condition = md->recursive != NULL && | |
| 832 | (offset == RREF_ANY || offset == md->recursive->group_num); | |
| 833 | ecode += condition? 3 : GET(ecode, 1); | |
| 834 | } | |
| 835 | ||
| 836 | else if (condcode == OP_CREF) /* Group used test */ | |
| 837 | { | { |
| 838 | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ |
| 839 | condition = (offset == CREF_RECURSE * 2)? | condition = offset < offset_top && md->offset_vector[offset] >= 0; |
| 840 | (md->recursive != NULL) : | ecode += condition? 3 : GET(ecode, 1); |
| 841 | (offset < offset_top && md->offset_vector[offset] >= 0); | } |
| 842 | RMATCH(rrc, eptr, ecode + (condition? | |
| 843 | (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1))), | else if (condcode == OP_DEF) /* DEFINE - always false */ |
| 844 | offset_top, md, ims, eptrb, match_isgroup); | { |
| 845 | RRETURN(rrc); | condition = FALSE; |
| 846 | ecode += GET(ecode, 1); | |
| 847 | } | } |
| 848 | ||
| 849 | /* The condition is an assertion. Call match() to evaluate it - setting | /* The condition is an assertion. Call match() to evaluate it - setting |
| 850 | 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 |
| 851 | assertion. */ | |
| 852 | ||
| 853 | else | else |
| 854 | { | { |
| 855 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, |
| 856 | match_condassert | match_isgroup); | match_condassert, RM3); |
| 857 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
| 858 | { | { |
| 859 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2); | condition = TRUE; |
| 860 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); | |
| 861 | while (*ecode == OP_ALT) ecode += GET(ecode, 1); | while (*ecode == OP_ALT) ecode += GET(ecode, 1); |
| 862 | } | } |
| 863 | else if (rrc != MATCH_NOMATCH) | else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
| 864 | { | { |
| 865 | RRETURN(rrc); /* Need braces because of following else */ | RRETURN(rrc); /* Need braces because of following else */ |
| 866 | } | } |
| 867 | else ecode += GET(ecode, 1); | else |
| 868 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, | { |
| 869 | match_isgroup); | condition = FALSE; |
| 870 | RRETURN(rrc); | ecode += codelink; |
| 871 | } | |
| 872 | } | } |
| /* Control never reaches here */ | ||
| 873 | ||
| 874 | /* 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, |
| 875 | encountered. */ | we can use tail recursion to avoid using another stack frame, except when |
| 876 | match_cbegroup is required for an unlimited repeat of a possibly empty | |
| 877 | group. If the second alternative doesn't exist, we can just plough on. */ | |
| 878 | ||
| 879 | case OP_CREF: | if (condition || *ecode == OP_ALT) |
| 880 | case OP_BRANUMBER: | { |
| 881 | ecode += 3; | ecode += 1 + LINK_SIZE; |
| 882 | if (op == OP_SCOND) /* Possibly empty group */ | |
| 883 | { | |
| 884 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49); | |
| 885 | RRETURN(rrc); | |
| 886 | } | |
| 887 | else /* Group must match something */ | |
| 888 | { | |
| 889 | flags = 0; | |
| 890 | goto TAIL_RECURSE; | |
| 891 | } | |
| 892 | } | |
| 893 | else /* Condition false & no alternative */ | |
| 894 | { | |
| 895 | ecode += 1 + LINK_SIZE; | |
| 896 | } | |
| 897 | break; | break; |
| 898 | ||
| /* End of the pattern. If we are in a recursion, we should restore the | ||
| offsets appropriately and continue from after the call. */ | ||
| 899 | ||
| 900 | /* End of the pattern, either real or forced. If we are in a top-level | |
| 901 | recursion, we should restore the offsets appropriately and continue from | |
| 902 | after the call. */ | |
| 903 | ||
| 904 | case OP_ACCEPT: | |
| 905 | case OP_END: | case OP_END: |
| 906 | if (md->recursive != NULL && md->recursive->group_num == 0) | if (md->recursive != NULL && md->recursive->group_num == 0) |
| 907 | { | { |
| 908 | recursion_info *rec = md->recursive; | recursion_info *rec = md->recursive; |
| 909 | DPRINTF(("Hit the end in a (?0) recursion\n")); | DPRINTF(("End of pattern in a (?0) recursion\n")); |
| 910 | md->recursive = rec->prevrec; | md->recursive = rec->prevrec; |
| 911 | memmove(md->offset_vector, rec->offset_save, | memmove(md->offset_vector, rec->offset_save, |
| 912 | rec->saved_max * sizeof(int)); | rec->saved_max * sizeof(int)); |
| 913 | md->start_match = rec->save_start; | mstart = rec->save_start; |
| 914 | ims = original_ims; | ims = original_ims; |
| 915 | ecode = rec->after_call; | ecode = rec->after_call; |
| 916 | break; | break; |
| # | Line 694 for (;;) | Line 919 for (;;) |
| 919 | /* 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 |
| 920 | string - backtracking will then try other alternatives, if any. */ | string - backtracking will then try other alternatives, if any. */ |
| 921 | ||
| 922 | if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH); | if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH); |
| 923 | md->end_match_ptr = eptr; /* Record where we ended */ | md->end_match_ptr = eptr; /* Record where we ended */ |
| 924 | md->end_offset_top = offset_top; /* and how many extracts were taken */ | md->end_offset_top = offset_top; /* and how many extracts were taken */ |
| 925 | md->start_match_ptr = mstart; /* and the start (\K can modify) */ | |
| 926 | RRETURN(MATCH_MATCH); | RRETURN(MATCH_MATCH); |
| 927 | ||
| 928 | /* Change option settings */ | /* Change option settings */ |
| # | Line 717 for (;;) | Line 943 for (;;) |
| 943 | case OP_ASSERTBACK: | case OP_ASSERTBACK: |
| 944 | do | do |
| 945 | { | { |
| 946 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, |
| 947 | match_isgroup); | RM4); |
| 948 | if (rrc == MATCH_MATCH) break; | if (rrc == MATCH_MATCH) break; |
| 949 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 950 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 951 | } | } |
| 952 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| # | Line 744 for (;;) | Line 970 for (;;) |
| 970 | case OP_ASSERTBACK_NOT: | case OP_ASSERTBACK_NOT: |
| 971 | do | do |
| 972 | { | { |
| 973 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, |
| 974 | match_isgroup); | RM5); |
| 975 | if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); | if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); |
| 976 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 977 | ecode += GET(ecode,1); | ecode += GET(ecode,1); |
| 978 | } | } |
| 979 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| # | Line 766 for (;;) | Line 992 for (;;) |
| 992 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 993 | if (utf8) | if (utf8) |
| 994 | { | { |
| 995 | c = GET(ecode,1); | i = GET(ecode, 1); |
| 996 | for (i = 0; i < c; i++) | while (i-- > 0) |
| 997 | { | { |
| 998 | eptr--; | eptr--; |
| 999 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1000 | BACKCHAR(eptr) | BACKCHAR(eptr); |
| 1001 | } | } |
| 1002 | } | } |
| 1003 | else | else |
| # | Line 780 for (;;) | Line 1006 for (;;) |
| 1006 | /* 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 */ |
| 1007 | ||
| 1008 | { | { |
| 1009 | eptr -= GET(ecode,1); | eptr -= GET(ecode, 1); |
| 1010 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1011 | } | } |
| 1012 | ||
| # | Line 800 for (;;) | Line 1026 for (;;) |
| 1026 | cb.version = 1; /* Version 1 of the callout block */ | cb.version = 1; /* Version 1 of the callout block */ |
| 1027 | cb.callout_number = ecode[1]; | cb.callout_number = ecode[1]; |
| 1028 | cb.offset_vector = md->offset_vector; | cb.offset_vector = md->offset_vector; |
| 1029 | cb.subject = (const char *)md->start_subject; | cb.subject = (PCRE_SPTR)md->start_subject; |
| 1030 | cb.subject_length = md->end_subject - md->start_subject; | cb.subject_length = md->end_subject - md->start_subject; |
| 1031 | cb.start_match = md->start_match - md->start_subject; | cb.start_match = mstart - md->start_subject; |
| 1032 | cb.current_position = eptr - md->start_subject; | cb.current_position = eptr - md->start_subject; |
| 1033 | cb.pattern_position = GET(ecode, 2); | cb.pattern_position = GET(ecode, 2); |
| 1034 | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); |
| # | Line 837 for (;;) | Line 1063 for (;;) |
| 1063 | case OP_RECURSE: | case OP_RECURSE: |
| 1064 | { | { |
| 1065 | callpat = md->start_code + GET(ecode, 1); | callpat = md->start_code + GET(ecode, 1); |
| 1066 | new_recursive.group_num = *callpat - OP_BRA; | new_recursive.group_num = (callpat == md->start_code)? 0 : |
| 1067 | 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); | ||
| 1068 | ||
| 1069 | /* Add to "recursing stack" */ | /* Add to "recursing stack" */ |
| 1070 | ||
| # | Line 869 for (;;) | Line 1090 for (;;) |
| 1090 | ||
| 1091 | memcpy(new_recursive.offset_save, md->offset_vector, | memcpy(new_recursive.offset_save, md->offset_vector, |
| 1092 | new_recursive.saved_max * sizeof(int)); | new_recursive.saved_max * sizeof(int)); |
| 1093 | new_recursive.save_start = md->start_match; | new_recursive.save_start = mstart; |
| 1094 | md->start_match = eptr; | mstart = eptr; |
| 1095 | ||
| 1096 | /* 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 |
| 1097 | restore the offset and recursion data. */ | restore the offset and recursion data. */ |
| 1098 | ||
| 1099 | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); |
| 1100 | flags = (*callpat >= OP_SBRA)? match_cbegroup : 0; | |
| 1101 | do | do |
| 1102 | { | { |
| 1103 | RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims, | RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, |
| 1104 | eptrb, match_isgroup); | md, ims, eptrb, flags, RM6); |
| 1105 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
| 1106 | { | { |
| 1107 | DPRINTF(("Recursion matched\n")); | |
| 1108 | md->recursive = new_recursive.prevrec; | md->recursive = new_recursive.prevrec; |
| 1109 | if (new_recursive.offset_save != stacksave) | if (new_recursive.offset_save != stacksave) |
| 1110 | (pcre_free)(new_recursive.offset_save); | (pcre_free)(new_recursive.offset_save); |
| 1111 | RRETURN(MATCH_MATCH); | RRETURN(MATCH_MATCH); |
| 1112 | } | } |
| 1113 | else if (rrc != MATCH_NOMATCH) RRETURN(rrc); | else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
| 1114 | { | |
| 1115 | DPRINTF(("Recursion gave error %d\n", rrc)); | |
| 1116 | if (new_recursive.offset_save != stacksave) | |
| 1117 | (pcre_free)(new_recursive.offset_save); | |
| 1118 | RRETURN(rrc); | |
| 1119 | } | |
| 1120 | ||
| 1121 | md->recursive = &new_recursive; | md->recursive = &new_recursive; |
| 1122 | memcpy(md->offset_vector, new_recursive.offset_save, | memcpy(md->offset_vector, new_recursive.offset_save, |
| # | Line 912 for (;;) | Line 1141 for (;;) |
| 1141 | the end of a normal bracket, leaving the subject pointer. */ | the end of a normal bracket, leaving the subject pointer. */ |
| 1142 | ||
| 1143 | case OP_ONCE: | case OP_ONCE: |
| 1144 | { | prev = ecode; |
| 1145 | prev = ecode; | saved_eptr = eptr; |
| saved_eptr = eptr; | ||
| 1146 | ||
| 1147 | do | do |
| 1148 | { | { |
| 1149 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7); |
| 1150 | eptrb, match_isgroup); | if (rrc == MATCH_MATCH) break; |
| 1151 | if (rrc == MATCH_MATCH) break; | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 1152 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ecode += GET(ecode,1); |
| 1153 | ecode += GET(ecode,1); | } |
| 1154 | } | while (*ecode == OP_ALT); |
| while (*ecode == OP_ALT); | ||
| 1155 | ||
| 1156 | /* If hit the end of the group (which could be repeated), fail */ | /* If hit the end of the group (which could be repeated), fail */ |
| 1157 | ||
| 1158 | if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); | if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); |
| 1159 | ||
| 1160 | /* Continue as from after the assertion, updating the offsets high water | /* Continue as from after the assertion, updating the offsets high water |
| 1161 | mark, since extracts may have been taken. */ | mark, since extracts may have been taken. */ |
| 1162 | ||
| 1163 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | do ecode += GET(ecode, 1); while (*ecode == OP_ALT); |
| 1164 | ||
| 1165 | offset_top = md->end_offset_top; | offset_top = md->end_offset_top; |
| 1166 | eptr = md->end_match_ptr; | eptr = md->end_match_ptr; |
| 1167 | ||
| 1168 | /* For a non-repeating ket, just continue at this level. This also | /* For a non-repeating ket, just continue at this level. This also |
| 1169 | 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. |
| 1170 | This is the forcible breaking of infinite loops as implemented in Perl | This is the forcible breaking of infinite loops as implemented in Perl |
| 1171 | 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 |
| 1172 | course of events. */ | course of events. */ |
| 1173 | ||
| 1174 | if (*ecode == OP_KET || eptr == saved_eptr) | if (*ecode == OP_KET || eptr == saved_eptr) |
| 1175 | { | { |
| 1176 | ecode += 1+LINK_SIZE; | ecode += 1+LINK_SIZE; |
| 1177 | break; | break; |
| 1178 | } | } |
| 1179 | ||
| 1180 | /* 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 |
| 1181 | preceding bracket, in the appropriate order. We need to reset any options | preceding bracket, in the appropriate order. The second "call" of match() |
| 1182 | 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 |
| 1183 | opcode. */ | any options that changed within the bracket before re-running it, so |
| 1184 | check the next opcode. */ | |
| 1185 | ||
| 1186 | if (ecode[1+LINK_SIZE] == OP_OPT) | if (ecode[1+LINK_SIZE] == OP_OPT) |
| 1187 | { | { |
| 1188 | ims = (ims & ~PCRE_IMS) | ecode[4]; | ims = (ims & ~PCRE_IMS) | ecode[4]; |
| 1189 | DPRINTF(("ims set to %02lx at group repeat\n", ims)); | DPRINTF(("ims set to %02lx at group repeat\n", ims)); |
| 1190 | } | } |
| 1191 | ||
| 1192 | if (*ecode == OP_KETRMIN) | if (*ecode == OP_KETRMIN) |
| 1193 | { | { |
| 1194 | 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); |
| 1195 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1196 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | ecode = prev; |
| 1197 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | flags = 0; |
| 1198 | } | 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); | ||
| } | ||
| 1199 | } | } |
| 1200 | RRETURN(MATCH_NOMATCH); | else /* OP_KETRMAX */ |
| 1201 | { | |
| 1202 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9); | |
| 1203 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 1204 | ecode += 1 + LINK_SIZE; | |
| 1205 | flags = 0; | |
| 1206 | goto TAIL_RECURSE; | |
| 1207 | } | |
| 1208 | /* Control never gets here */ | |
| 1209 | ||
| 1210 | /* 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 |
| 1211 | bracketed group and go to there. */ | bracketed group and go to there. */ |
| # | Line 985 for (;;) | Line 1214 for (;;) |
| 1214 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
| 1215 | break; | break; |
| 1216 | ||
| 1217 | /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating | /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group, |
| 1218 | 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 |
| 1219 | 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 |
| 1220 | 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 |
| 1221 | preceded by BRAZERO or BRAMINZERO. */ | optional ones preceded by BRAZERO or BRAMINZERO. */ |
| 1222 | ||
| 1223 | case OP_BRAZERO: | case OP_BRAZERO: |
| 1224 | { | { |
| 1225 | next = ecode+1; | next = ecode+1; |
| 1226 | RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10); |
| 1227 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1228 | do next += GET(next,1); while (*next == OP_ALT); | do next += GET(next,1); while (*next == OP_ALT); |
| 1229 | ecode = next + 1+LINK_SIZE; | ecode = next + 1 + LINK_SIZE; |
| 1230 | } | } |
| 1231 | break; | break; |
| 1232 | ||
| 1233 | case OP_BRAMINZERO: | case OP_BRAMINZERO: |
| 1234 | { | { |
| 1235 | next = ecode+1; | next = ecode+1; |
| 1236 | do next += GET(next,1); while (*next == OP_ALT); | do next += GET(next, 1); while (*next == OP_ALT); |
| 1237 | 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); | ||
| 1238 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1239 | ecode++; | ecode++; |
| 1240 | } | } |
| 1241 | break; | break; |
| 1242 | ||
| 1243 | /* End of a group, repeated or non-repeating. If we are at the end of | case OP_SKIPZERO: |
| 1244 | an assertion "group", stop matching and return MATCH_MATCH, but record the | { |
| 1245 | current high water mark for use by positive assertions. Do this also | next = ecode+1; |
| 1246 | for the "once" (not-backup up) groups. */ | do next += GET(next,1); while (*next == OP_ALT); |
| 1247 | ecode = next + 1 + LINK_SIZE; | |
| 1248 | } | |
| 1249 | break; | |
| 1250 | ||
| 1251 | /* End of a group, repeated or non-repeating. */ | |
| 1252 | ||
| 1253 | case OP_KET: | case OP_KET: |
| 1254 | case OP_KETRMIN: | case OP_KETRMIN: |
| 1255 | case OP_KETRMAX: | case OP_KETRMAX: |
| 1256 | { | prev = ecode - GET(ecode, 1); |
| prev = ecode - GET(ecode, 1); | ||
| saved_eptr = eptrb->epb_saved_eptr; | ||
| 1257 | ||
| 1258 | /* Back up the stack of bracket start pointers. */ | /* If this was a group that remembered the subject start, in order to break |
| 1259 | infinite repeats of empty string matches, retrieve the subject start from | |
| 1260 | the chain. Otherwise, set it NULL. */ | |
| 1261 | ||
| 1262 | eptrb = eptrb->epb_prev; | if (*prev >= OP_SBRA) |
| 1263 | { | |
| 1264 | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || | saved_eptr = eptrb->epb_saved_eptr; /* Value at start of group */ |
| 1265 | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || | eptrb = eptrb->epb_prev; /* Backup to previous group */ |
| 1266 | *prev == OP_ONCE) | } |
| 1267 | { | else saved_eptr = NULL; |
| md->end_match_ptr = eptr; /* For ONCE */ | ||
| md->end_offset_top = offset_top; | ||
| RRETURN(MATCH_MATCH); | ||
| } | ||
| 1268 | ||
| 1269 | /* 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 |
| 1270 | 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 |
| 1271 | extraction by setting the offsets and bumping the high water mark. */ | assertions. Do this also for the "once" (atomic) groups. */ |
| 1272 | ||
| 1273 | if (*prev != OP_COND) | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || |
| 1274 | { | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || |
| 1275 | number = *prev - OP_BRA; | *prev == OP_ONCE) |
| 1276 | { | |
| 1277 | md->end_match_ptr = eptr; /* For ONCE */ | |
| 1278 | md->end_offset_top = offset_top; | |
| 1279 | RRETURN(MATCH_MATCH); | |
| 1280 | } | |
| 1281 | ||
| 1282 | /* 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 |
| 1283 | the number from a dummy opcode at the start. */ | and if necessary complete handling an extraction by setting the offsets and |
| 1284 | bumping the high water mark. Note that whole-pattern recursion is coded as | |
| 1285 | a recurse into group 0, so it won't be picked up here. Instead, we catch it | |
| 1286 | when the OP_END is reached. Other recursion is handled here. */ | |
| 1287 | ||
| 1288 | if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE); | if (*prev == OP_CBRA || *prev == OP_SCBRA) |
| 1289 | offset = number << 1; | { |
| 1290 | number = GET2(prev, 1+LINK_SIZE); | |
| 1291 | offset = number << 1; | |
| 1292 | ||
| 1293 | #ifdef DEBUG | #ifdef DEBUG |
| 1294 | printf("end bracket %d", number); | printf("end bracket %d", number); |
| 1295 | printf("\n"); | printf("\n"); |
| 1296 | #endif | #endif |
| 1297 | ||
| 1298 | /* Test for a numbered group. This includes groups called as a result | md->capture_last = number; |
| 1299 | of recursion. Note that whole-pattern recursion is coded as a recurse | if (offset >= md->offset_max) md->offset_overflow = TRUE; else |
| 1300 | into group 0, so it won't be picked up here. Instead, we catch it when | { |
| 1301 | the OP_END is reached. */ | md->offset_vector[offset] = |
| 1302 | md->offset_vector[md->offset_end - number]; | |
| 1303 | if (number > 0) | md->offset_vector[offset+1] = eptr - md->start_subject; |
| 1304 | { | if (offset_top <= offset) offset_top = offset + 2; |
| 1305 | md->capture_last = number; | } |
| 1306 | if (offset >= md->offset_max) md->offset_overflow = TRUE; else | |
| 1307 | { | /* Handle a recursively called group. Restore the offsets |
| 1308 | md->offset_vector[offset] = | appropriately and continue from after the call. */ |
| 1309 | md->offset_vector[md->offset_end - number]; | |
| 1310 | md->offset_vector[offset+1] = eptr - md->start_subject; | if (md->recursive != NULL && md->recursive->group_num == number) |
| 1311 | if (offset_top <= offset) offset_top = offset + 2; | { |
| 1312 | } | recursion_info *rec = md->recursive; |
| 1313 | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); | |
| 1314 | /* Handle a recursively called group. Restore the offsets | md->recursive = rec->prevrec; |
| 1315 | appropriately and continue from after the call. */ | mstart = rec->save_start; |
| 1316 | memcpy(md->offset_vector, rec->offset_save, | |
| 1317 | if (md->recursive != NULL && md->recursive->group_num == number) | rec->saved_max * sizeof(int)); |
| 1318 | { | ecode = rec->after_call; |
| 1319 | recursion_info *rec = md->recursive; | ims = original_ims; |
| 1320 | 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; | ||
| } | ||
| } | ||
| 1321 | } | } |
| 1322 | } | |
| 1323 | ||
| 1324 | /* 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 |
| 1325 | the group. */ | flags, in case they got changed during the group. */ |
| 1326 | ||
| 1327 | ims = original_ims; | ims = original_ims; |
| 1328 | DPRINTF(("ims reset to %02lx\n", ims)); | DPRINTF(("ims reset to %02lx\n", ims)); |
| 1329 | ||
| 1330 | /* For a non-repeating ket, just continue at this level. This also | /* For a non-repeating ket, just continue at this level. This also |
| 1331 | 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. |
| 1332 | This is the forcible breaking of infinite loops as implemented in Perl | This is the forcible breaking of infinite loops as implemented in Perl |
| 1333 | 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 |
| 1334 | course of events. */ | course of events. */ |
| 1335 | ||
| 1336 | if (*ecode == OP_KET || eptr == saved_eptr) | if (*ecode == OP_KET || eptr == saved_eptr) |
| 1337 | { | { |
| 1338 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1339 | break; | break; |
| 1340 | } | } |
| 1341 | ||
| 1342 | /* 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 |
| 1343 | preceding bracket, in the appropriate order. */ | preceding bracket, in the appropriate order. In the second case, we can use |
| 1344 | tail recursion to avoid using another stack frame, unless we have an | |
| 1345 | unlimited repeat of a group that can match an empty string. */ | |
| 1346 | ||
| 1347 | if (*ecode == OP_KETRMIN) | flags = (*prev >= OP_SBRA)? match_cbegroup : 0; |
| 1348 | { | |
| 1349 | RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); | if (*ecode == OP_KETRMIN) |
| 1350 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | { |
| 1351 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12); |
| 1352 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1353 | } | if (flags != 0) /* Could match an empty string */ |
| else /* OP_KETRMAX */ | ||
| 1354 | { | { |
| 1355 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50); |
| 1356 | 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); | ||
| 1357 | } | } |
| 1358 | ecode = prev; | |
| 1359 | goto TAIL_RECURSE; | |
| 1360 | } | } |
| 1361 | else /* OP_KETRMAX */ | |
| 1362 | RRETURN(MATCH_NOMATCH); | { |
| 1363 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13); | |
| 1364 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 1365 | ecode += 1 + LINK_SIZE; | |
| 1366 | flags = 0; | |
| 1367 | goto TAIL_RECURSE; | |
| 1368 | } | |
| 1369 | /* Control never gets here */ | |
| 1370 | ||
| 1371 | /* Start of subject unless notbol, or after internal newline if multiline */ | /* Start of subject unless notbol, or after internal newline if multiline */ |
| 1372 | ||
| # | Line 1135 for (;;) | Line 1374 for (;;) |
| 1374 | if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); | if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1375 | if ((ims & PCRE_MULTILINE) != 0) | if ((ims & PCRE_MULTILINE) != 0) |
| 1376 | { | { |
| 1377 | if (eptr != md->start_subject && eptr[-1] != NEWLINE) | if (eptr != md->start_subject && |
| 1378 | (eptr == md->end_subject || !WAS_NEWLINE(eptr))) | |
| 1379 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1380 | ecode++; | ecode++; |
| 1381 | break; | break; |
| # | Line 1156 for (;;) | Line 1396 for (;;) |
| 1396 | ecode++; | ecode++; |
| 1397 | break; | break; |
| 1398 | ||
| 1399 | /* Reset the start of match point */ | |
| 1400 | ||
| 1401 | case OP_SET_SOM: | |
| 1402 | mstart = eptr; | |
| 1403 | ecode++; | |
| 1404 | break; | |
| 1405 | ||
| 1406 | /* Assert before internal newline if multiline, or before a terminating | /* Assert before internal newline if multiline, or before a terminating |
| 1407 | 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. */ |
| 1408 | ||
| # | Line 1163 for (;;) | Line 1410 for (;;) |
| 1410 | if ((ims & PCRE_MULTILINE) != 0) | if ((ims & PCRE_MULTILINE) != 0) |
| 1411 | { | { |
| 1412 | if (eptr < md->end_subject) | if (eptr < md->end_subject) |
| 1413 | { if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); } | { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); } |
| 1414 | else | else |
| 1415 | { if (md->noteol) RRETURN(MATCH_NOMATCH); } | { if (md->noteol) RRETURN(MATCH_NOMATCH); } |
| 1416 | ecode++; | ecode++; |
| # | Line 1174 for (;;) | Line 1421 for (;;) |
| 1421 | if (md->noteol) RRETURN(MATCH_NOMATCH); | if (md->noteol) RRETURN(MATCH_NOMATCH); |
| 1422 | if (!md->endonly) | if (!md->endonly) |
| 1423 | { | { |
| 1424 | if (eptr < md->end_subject - 1 || | if (eptr != md->end_subject && |
| 1425 | (eptr == md->end_subject - 1 && *eptr != NEWLINE)) | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
| 1426 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1427 | ecode++; | ecode++; |
| 1428 | break; | break; |
| 1429 | } | } |
| 1430 | } | } |
| 1431 | /* ... else fall through */ | /* ... else fall through for endonly */ |
| 1432 | ||
| 1433 | /* End of subject assertion (\z) */ | /* End of subject assertion (\z) */ |
| 1434 | ||
| # | Line 1193 for (;;) | Line 1440 for (;;) |
| 1440 | /* End of subject or ending \n assertion (\Z) */ | /* End of subject or ending \n assertion (\Z) */ |
| 1441 | ||
| 1442 | case OP_EODN: | case OP_EODN: |
| 1443 | if (eptr < md->end_subject - 1 || | if (eptr != md->end_subject && |
| 1444 | (eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH); | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
| 1445 | RRETURN(MATCH_NOMATCH); | |
| 1446 | ecode++; | ecode++; |
| 1447 | break; | break; |
| 1448 | ||
| # | Line 1247 for (;;) | Line 1495 for (;;) |
| 1495 | /* Match a single character type; inline for speed */ | /* Match a single character type; inline for speed */ |
| 1496 | ||
| 1497 | case OP_ANY: | case OP_ANY: |
| 1498 | if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE) | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); |
| 1499 | RRETURN(MATCH_NOMATCH); | /* Fall through */ |
| 1500 | ||
| 1501 | case OP_ALLANY: | |
| 1502 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 1503 | #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 | ||
| 1504 | ecode++; | ecode++; |
| 1505 | break; | break; |
| 1506 | ||
| # | Line 1343 for (;;) | Line 1590 for (;;) |
| 1590 | ecode++; | ecode++; |
| 1591 | break; | break; |
| 1592 | ||
| 1593 | case OP_ANYNL: | |
| 1594 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 1595 | GETCHARINCTEST(c, eptr); | |
| 1596 | switch(c) | |
| 1597 | { | |
| 1598 | default: RRETURN(MATCH_NOMATCH); | |
| 1599 | case 0x000d: | |
| 1600 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 1601 | break; | |
| 1602 | ||
| 1603 | case 0x000a: | |
| 1604 | break; | |
| 1605 | ||
| 1606 | case 0x000b: | |
| 1607 | case 0x000c: | |
| 1608 | case 0x0085: | |
| 1609 | case 0x2028: | |
| 1610 | case 0x2029: | |
| 1611 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 1612 | break; | |
| 1613 | } | |
| 1614 | ecode++; | |
| 1615 | break; | |
| 1616 | ||
| 1617 | case OP_NOT_HSPACE: | |
| 1618 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 1619 | GETCHARINCTEST(c, eptr); | |
| 1620 | switch(c) | |
| 1621 | { | |
| 1622 | default: break; | |
| 1623 | case 0x09: /* HT */ | |
| 1624 | case 0x20: /* SPACE */ | |
| 1625 | case 0xa0: /* NBSP */ | |
| 1626 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 1627 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 1628 | case 0x2000: /* EN QUAD */ | |
| 1629 | case 0x2001: /* EM QUAD */ | |
| 1630 | case 0x2002: /* EN SPACE */ | |
| 1631 | case 0x2003: /* EM SPACE */ | |
| 1632 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 1633 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 1634 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 1635 | case 0x2007: /* FIGURE SPACE */ | |
| 1636 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 1637 | case 0x2009: /* THIN SPACE */ | |
| 1638 | case 0x200A: /* HAIR SPACE */ | |
| 1639 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 1640 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 1641 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 1642 | RRETURN(MATCH_NOMATCH); | |
| 1643 | } | |
| 1644 | ecode++; | |
| 1645 | break; | |
| 1646 | ||
| 1647 | case OP_HSPACE: | |
| 1648 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 1649 | GETCHARINCTEST(c, eptr); | |
| 1650 | switch(c) | |
| 1651 | { | |
| 1652 | default: RRETURN(MATCH_NOMATCH); | |
| 1653 | case 0x09: /* HT */ | |
| 1654 | case 0x20: /* SPACE */ | |
| 1655 | case 0xa0: /* NBSP */ | |
| 1656 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 1657 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 1658 | case 0x2000: /* EN QUAD */ | |
| 1659 | case 0x2001: /* EM QUAD */ | |
| 1660 | case 0x2002: /* EN SPACE */ | |
| 1661 | case 0x2003: /* EM SPACE */ | |
| 1662 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 1663 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 1664 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 1665 | case 0x2007: /* FIGURE SPACE */ | |
| 1666 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 1667 | case 0x2009: /* THIN SPACE */ | |
| 1668 | case 0x200A: /* HAIR SPACE */ | |
| 1669 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 1670 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 1671 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 1672 | break; | |
| 1673 | } | |
| 1674 | ecode++; | |
| 1675 | break; | |
| 1676 | ||
| 1677 | case OP_NOT_VSPACE: | |
| 1678 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 1679 | GETCHARINCTEST(c, eptr); | |
| 1680 | switch(c) | |
| 1681 | { | |
| 1682 | default: break; | |
| 1683 | case 0x0a: /* LF */ | |
| 1684 | case 0x0b: /* VT */ | |
| 1685 | case 0x0c: /* FF */ | |
| 1686 | case 0x0d: /* CR */ | |
| 1687 | case 0x85: /* NEL */ | |
| 1688 | case 0x2028: /* LINE SEPARATOR */ | |
| 1689 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 1690 | RRETURN(MATCH_NOMATCH); | |
| 1691 | } | |
| 1692 | ecode++; | |
| 1693 | break; | |
| 1694 | ||
| 1695 | case OP_VSPACE: | |
| 1696 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 1697 | GETCHARINCTEST(c, eptr); | |
| 1698 | switch(c) | |
| 1699 | { | |
| 1700 | default: RRETURN(MATCH_NOMATCH); | |
| 1701 | case 0x0a: /* LF */ | |
| 1702 | case 0x0b: /* VT */ | |
| 1703 | case 0x0c: /* FF */ | |
| 1704 | case 0x0d: /* CR */ | |
| 1705 | case 0x85: /* NEL */ | |
| 1706 | case 0x2028: /* LINE SEPARATOR */ | |
| 1707 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 1708 | break; | |
| 1709 | } | |
| 1710 | ecode++; | |
| 1711 | break; | |
| 1712 | ||
| 1713 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 1714 | /* Check the next character by Unicode property. We will get here only | /* Check the next character by Unicode property. We will get here only |
| 1715 | if the support is in the binary; otherwise a compile-time error occurs. */ | if the support is in the binary; otherwise a compile-time error occurs. */ |
| # | Line 1352 for (;;) | Line 1719 for (;;) |
| 1719 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 1720 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1721 | { | { |
| 1722 | int chartype, rqdtype; | const ucd_record *prop = GET_UCD(c); |
| int othercase; | ||
| int category = ucp_findchar(c, &chartype, &othercase); | ||
| rqdtype = *(++ecode); | ||
| ecode++; | ||
| 1723 | ||
| 1724 | if (rqdtype >= 128) | switch(ecode[1]) |
| 1725 | { | { |
| 1726 | if ((rqdtype - 128 != category) == (op == OP_PROP)) | case PT_ANY: |
| 1727 | if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH); | |
| 1728 | break; | |
| 1729 | ||
| 1730 | case PT_LAMP: | |
| 1731 | if ((prop->chartype == ucp_Lu || | |
| 1732 | prop->chartype == ucp_Ll || | |
| 1733 | prop->chartype == ucp_Lt) == (op == OP_NOTPROP)) | |
| 1734 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1735 | } | break; |
| 1736 | else | |
| 1737 | { | case PT_GC: |
| 1738 | if ((rqdtype != chartype) == (op == OP_PROP)) | if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP)) |
| 1739 | RRETURN(MATCH_NOMATCH); | |
| 1740 | break; | |
| 1741 | ||
| 1742 | case PT_PC: | |
| 1743 | if ((ecode[2] != prop->chartype) == (op == OP_PROP)) | |
| 1744 | RRETURN(MATCH_NOMATCH); | |
| 1745 | break; | |
| 1746 | ||
| 1747 | case PT_SC: | |
| 1748 | if ((ecode[2] != prop->script) == (op == OP_PROP)) | |
| 1749 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1750 | break; | |
| 1751 | ||
| 1752 | default: | |
| 1753 | RRETURN(PCRE_ERROR_INTERNAL); | |
| 1754 | } | } |
| 1755 | ||
| 1756 | ecode += 3; | |
| 1757 | } | } |
| 1758 | break; | break; |
| 1759 | ||
| # | Line 1379 for (;;) | Line 1764 for (;;) |
| 1764 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 1765 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1766 | { | { |
| 1767 | int chartype; | int category = UCD_CATEGORY(c); |
| int othercase; | ||
| int category = ucp_findchar(c, &chartype, &othercase); | ||
| 1768 | if (category == ucp_M) RRETURN(MATCH_NOMATCH); | if (category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 1769 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 1770 | { | { |
| # | Line 1390 for (;;) | Line 1773 for (;;) |
| 1773 | { | { |
| 1774 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 1775 | } | } |
| 1776 | category = ucp_findchar(c, &chartype, &othercase); | category = UCD_CATEGORY(c); |
| 1777 | if (category != ucp_M) break; | if (category != ucp_M) break; |
| 1778 | eptr += len; | eptr += len; |
| 1779 | } | } |
| # | Line 1411 for (;;) | Line 1794 for (;;) |
| 1794 | case OP_REF: | case OP_REF: |
| 1795 | { | { |
| 1796 | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ |
| 1797 | ecode += 3; /* Advance past item */ | ecode += 3; |
| 1798 | ||
| 1799 | /* If the reference is unset, set the length to be longer than the amount | /* If the reference is unset, there are two possibilities: |
| of subject left; this ensures that every attempt at a match fails. We | ||
| can't just fail here, because of the possibility of quantifiers with zero | ||
| minima. */ | ||
| length = (offset >= offset_top || md->offset_vector[offset] < 0)? | ||
| md->end_subject - eptr + 1 : | ||
| md->offset_vector[offset+1] - md->offset_vector[offset]; | ||
| 1800 | ||
| 1801 | /* Set up for repetition, or handle the non-repeated case */ | (a) In the default, Perl-compatible state, set the length to be longer |
| 1802 | than the amount of subject left; this ensures that every attempt at a | |
| 1803 | match fails. We can't just fail here, because of the possibility of | |
| 1804 | quantifiers with zero minima. | |
| 1805 | ||
| 1806 | switch (*ecode) | (b) If the JavaScript compatibility flag is set, set the length to zero |
| 1807 | so that the back reference matches an empty string. | |
| 1808 | ||
| 1809 | Otherwise, set the length to the length of what was matched by the | |
| 1810 | referenced subpattern. */ | |
| 1811 | ||
| 1812 | if (offset >= offset_top || md->offset_vector[offset] < 0) | |
| 1813 | length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1; | |
| 1814 | else | |
| 1815 | length = md->offset_vector[offset+1] - md->offset_vector[offset]; | |
| 1816 | ||
| 1817 | /* Set up for repetition, or handle the non-repeated case */ | |
| 1818 | ||
| 1819 | switch (*ecode) | |
| 1820 | { | { |
| 1821 | case OP_CRSTAR: | case OP_CRSTAR: |
| 1822 | case OP_CRMINSTAR: | case OP_CRMINSTAR: |
| # | Line 1480 for (;;) | Line 1872 for (;;) |
| 1872 | { | { |
| 1873 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 1874 | { | { |
| 1875 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14); |
| 1876 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1877 | if (fi >= max || !match_ref(offset, eptr, length, md, ims)) | if (fi >= max || !match_ref(offset, eptr, length, md, ims)) |
| 1878 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| # | Line 1501 for (;;) | Line 1893 for (;;) |
| 1893 | } | } |
| 1894 | while (eptr >= pp) | while (eptr >= pp) |
| 1895 | { | { |
| 1896 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15); |
| 1897 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1898 | eptr -= length; | eptr -= length; |
| 1899 | } | } |
| # | Line 1606 for (;;) | Line 1998 for (;;) |
| 1998 | { | { |
| 1999 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2000 | { | { |
| 2001 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16); |
| 2002 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2003 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 2004 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| # | Line 1626 for (;;) | Line 2018 for (;;) |
| 2018 | { | { |
| 2019 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2020 | { | { |
| 2021 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17); |
| 2022 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2023 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 2024 | c = *eptr++; | c = *eptr++; |
| # | Line 1663 for (;;) | Line 2055 for (;;) |
| 2055 | } | } |
| 2056 | for (;;) | for (;;) |
| 2057 | { | { |
| 2058 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18); |
| 2059 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2060 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2061 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 1682 for (;;) | Line 2074 for (;;) |
| 2074 | } | } |
| 2075 | while (eptr >= pp) | while (eptr >= pp) |
| 2076 | { | { |
| 2077 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19); |
| eptr--; | ||
| 2078 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2079 | eptr--; | |
| 2080 | } | } |
| 2081 | } | } |
| 2082 | ||
| # | Line 1695 for (;;) | Line 2087 for (;;) |
| 2087 | ||
| 2088 | ||
| 2089 | /* Match an extended character class. This opcode is encountered only | /* Match an extended character class. This opcode is encountered only |
| 2090 | 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 |
| 2091 | mode, because Unicode properties are supported in non-UTF-8 mode. */ | |
| 2092 | ||
| 2093 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 2094 | case OP_XCLASS: | case OP_XCLASS: |
| # | Line 1737 for (;;) | Line 2130 for (;;) |
| 2130 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2131 | { | { |
| 2132 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 2133 | GETCHARINC(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2134 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
| 2135 | } | } |
| 2136 | ||
| # | Line 1753 for (;;) | Line 2146 for (;;) |
| 2146 | { | { |
| 2147 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2148 | { | { |
| 2149 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20); |
| 2150 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2151 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 2152 | GETCHARINC(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2153 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
| 2154 | } | } |
| 2155 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 1771 for (;;) | Line 2164 for (;;) |
| 2164 | { | { |
| 2165 | int len = 1; | int len = 1; |
| 2166 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) break; |
| 2167 | GETCHARLEN(c, eptr, len); | GETCHARLENTEST(c, eptr, len); |
| 2168 | if (!_pcre_xclass(c, data)) break; | if (!_pcre_xclass(c, data)) break; |
| 2169 | eptr += len; | eptr += len; |
| 2170 | } | } |
| 2171 | for(;;) | for(;;) |
| 2172 | { | { |
| 2173 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21); |
| 2174 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2175 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2176 | BACKCHAR(eptr) | if (utf8) BACKCHAR(eptr); |
| 2177 | } | } |
| 2178 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2179 | } | } |
| # | Line 1836 for (;;) | Line 2229 for (;;) |
| 2229 | ||
| 2230 | else | else |
| 2231 | { | { |
| 2232 | int dc; | unsigned int dc; |
| 2233 | GETCHARINC(dc, eptr); | GETCHARINC(dc, eptr); |
| 2234 | ecode += length; | ecode += length; |
| 2235 | ||
| 2236 | /* 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 |
| 2237 | 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. */ | ||
| 2238 | ||
| 2239 | if (fc != dc) | if (fc != dc) |
| 2240 | { | { |
| 2241 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2242 | int chartype; | if (dc != UCD_OTHERCASE(fc)) |
| int othercase; | ||
| if (ucp_findchar(fc, &chartype, &othercase) < 0 || dc != othercase) | ||
| 2243 | #endif | #endif |
| 2244 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2245 | } | } |
| # | Line 1867 for (;;) | Line 2256 for (;;) |
| 2256 | } | } |
| 2257 | break; | break; |
| 2258 | ||
| 2259 | /* Match a single character repeatedly; different opcodes share code. */ | /* Match a single character repeatedly. */ |
| 2260 | ||
| 2261 | case OP_EXACT: | case OP_EXACT: |
| 2262 | min = max = GET2(ecode, 1); | min = max = GET2(ecode, 1); |
| 2263 | ecode += 3; | ecode += 3; |
| 2264 | goto REPEATCHAR; | goto REPEATCHAR; |
| 2265 | ||
| 2266 | case OP_POSUPTO: | |
| 2267 | possessive = TRUE; | |
| 2268 | /* Fall through */ | |
| 2269 | ||
| 2270 | case OP_UPTO: | case OP_UPTO: |
| 2271 | case OP_MINUPTO: | case OP_MINUPTO: |
| 2272 | min = 0; | min = 0; |
| # | Line 1882 for (;;) | Line 2275 for (;;) |
| 2275 | ecode += 3; | ecode += 3; |
| 2276 | goto REPEATCHAR; | goto REPEATCHAR; |
| 2277 | ||
| 2278 | case OP_POSSTAR: | |
| 2279 | possessive = TRUE; | |
| 2280 | min = 0; | |
| 2281 | max = INT_MAX; | |
| 2282 | ecode++; | |
| 2283 | goto REPEATCHAR; | |
| 2284 | ||
| 2285 | case OP_POSPLUS: | |
| 2286 | possessive = TRUE; | |
| 2287 | min = 1; | |
| 2288 | max = INT_MAX; | |
| 2289 | ecode++; | |
| 2290 | goto REPEATCHAR; | |
| 2291 | ||
| 2292 | case OP_POSQUERY: | |
| 2293 | possessive = TRUE; | |
| 2294 | min = 0; | |
| 2295 | max = 1; | |
| 2296 | ecode++; | |
| 2297 | goto REPEATCHAR; | |
| 2298 | ||
| 2299 | case OP_STAR: | case OP_STAR: |
| 2300 | case OP_MINSTAR: | case OP_MINSTAR: |
| 2301 | case OP_PLUS: | case OP_PLUS: |
| # | Line 1913 for (;;) | Line 2327 for (;;) |
| 2327 | ||
| 2328 | if (length > 1) | if (length > 1) |
| 2329 | { | { |
| int oclength = 0; | ||
| uschar occhars[8]; | ||
| 2330 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2331 | int othercase; | unsigned int othercase; |
| int chartype; | ||
| 2332 | if ((ims & PCRE_CASELESS) != 0 && | if ((ims & PCRE_CASELESS) != 0 && |
| 2333 | ucp_findchar(fc, &chartype, &othercase) >= 0 && | (othercase = UCD_OTHERCASE(fc)) != fc) |
| othercase > 0) | ||
| 2334 | oclength = _pcre_ord2utf8(othercase, occhars); | oclength = _pcre_ord2utf8(othercase, occhars); |
| 2335 | else oclength = 0; | |
| 2336 | #endif /* SUPPORT_UCP */ | #endif /* SUPPORT_UCP */ |
| 2337 | ||
| 2338 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2339 | { | { |
| 2340 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2341 | #ifdef SUPPORT_UCP | |
| 2342 | /* Need braces because of following else */ | /* Need braces because of following else */ |
| 2343 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } |
| 2344 | else | else |
| # | Line 1935 for (;;) | Line 2346 for (;;) |
| 2346 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); |
| 2347 | eptr += oclength; | eptr += oclength; |
| 2348 | } | } |
| 2349 | #else /* without SUPPORT_UCP */ | |
| 2350 | else { RRETURN(MATCH_NOMATCH); } | |
| 2351 | #endif /* SUPPORT_UCP */ | |
| 2352 | } | } |
| 2353 | ||
| 2354 | if (min == max) continue; | if (min == max) continue; |
| # | Line 1943 for (;;) | Line 2357 for (;;) |
| 2357 | { | { |
| 2358 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2359 | { | { |
| 2360 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22); |
| 2361 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2362 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 2363 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2364 | #ifdef SUPPORT_UCP | |
| 2365 | /* Need braces because of following else */ | /* Need braces because of following else */ |
| 2366 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } |
| 2367 | else | else |
| # | Line 1954 for (;;) | Line 2369 for (;;) |
| 2369 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); |
| 2370 | eptr += oclength; | eptr += oclength; |
| 2371 | } | } |
| 2372 | #else /* without SUPPORT_UCP */ | |
| 2373 | else { RRETURN (MATCH_NOMATCH); } | |
| 2374 | #endif /* SUPPORT_UCP */ | |
| 2375 | } | } |
| 2376 | /* Control never gets here */ | /* Control never gets here */ |
| 2377 | } | } |
| 2378 | else | |
| 2379 | else /* Maximize */ | |
| 2380 | { | { |
| 2381 | pp = eptr; | pp = eptr; |
| 2382 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2383 | { | { |
| 2384 | if (eptr > md->end_subject - length) break; | if (eptr > md->end_subject - length) break; |
| 2385 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2386 | #ifdef SUPPORT_UCP | |
| 2387 | else if (oclength == 0) break; | else if (oclength == 0) break; |
| 2388 | else | else |
| 2389 | { | { |
| 2390 | if (memcmp(eptr, occhars, oclength) != 0) break; | if (memcmp(eptr, occhars, oclength) != 0) break; |
| 2391 | eptr += oclength; | eptr += oclength; |
| 2392 | } | } |
| 2393 | #else /* without SUPPORT_UCP */ | |
| 2394 | else break; | |
| 2395 | #endif /* SUPPORT_UCP */ | |
| 2396 | } | } |
| 2397 | while (eptr >= pp) | |
| 2398 | if (possessive) continue; | |
| 2399 | for(;;) | |
| 2400 | { | { |
| 2401 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23); |
| 2402 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2403 | if (eptr == pp) RRETURN(MATCH_NOMATCH); | |
| 2404 | #ifdef SUPPORT_UCP | |
| 2405 | eptr--; | |
| 2406 | BACKCHAR(eptr); | |
| 2407 | #else /* without SUPPORT_UCP */ | |
| 2408 | eptr -= length; | eptr -= length; |
| 2409 | #endif /* SUPPORT_UCP */ | |
| 2410 | } | } |
| RRETURN(MATCH_NOMATCH); | ||
| 2411 | } | } |
| 2412 | /* Control never gets here */ | /* Control never gets here */ |
| 2413 | } | } |
| # | Line 2017 for (;;) | Line 2447 for (;;) |
| 2447 | { | { |
| 2448 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2449 | { | { |
| 2450 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24); |
| 2451 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2452 | if (fi >= max || eptr >= md->end_subject || | if (fi >= max || eptr >= md->end_subject || |
| 2453 | fc != md->lcc[*eptr++]) | fc != md->lcc[*eptr++]) |
| # | Line 2025 for (;;) | Line 2455 for (;;) |
| 2455 | } | } |
| 2456 | /* Control never gets here */ | /* Control never gets here */ |
| 2457 | } | } |
| 2458 | else | else /* Maximize */ |
| 2459 | { | { |
| 2460 | pp = eptr; | pp = eptr; |
| 2461 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| # | Line 2033 for (;;) | Line 2463 for (;;) |
| 2463 | if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break; | if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break; |
| 2464 | eptr++; | eptr++; |
| 2465 | } | } |
| 2466 | if (possessive) continue; | |
| 2467 | while (eptr >= pp) | while (eptr >= pp) |
| 2468 | { | { |
| 2469 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25); |
| 2470 | eptr--; | eptr--; |
| 2471 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2472 | } | } |
| # | Line 2054 for (;;) | Line 2485 for (;;) |
| 2485 | { | { |
| 2486 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2487 | { | { |
| 2488 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26); |
| 2489 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2490 | if (fi >= max || eptr >= md->end_subject || fc != *eptr++) | if (fi >= max || eptr >= md->end_subject || fc != *eptr++) |
| 2491 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2492 | } | } |
| 2493 | /* Control never gets here */ | /* Control never gets here */ |
| 2494 | } | } |
| 2495 | else | else /* Maximize */ |
| 2496 | { | { |
| 2497 | pp = eptr; | pp = eptr; |
| 2498 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| # | Line 2069 for (;;) | Line 2500 for (;;) |
| 2500 | if (eptr >= md->end_subject || fc != *eptr) break; | if (eptr >= md->end_subject || fc != *eptr) break; |
| 2501 | eptr++; | eptr++; |
| 2502 | } | } |
| 2503 | if (possessive) continue; | |
| 2504 | while (eptr >= pp) | while (eptr >= pp) |
| 2505 | { | { |
| 2506 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27); |
| 2507 | eptr--; | eptr--; |
| 2508 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2509 | } | } |
| # | Line 2121 for (;;) | Line 2553 for (;;) |
| 2553 | ecode += 3; | ecode += 3; |
| 2554 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
| 2555 | ||
| 2556 | case OP_NOTPOSSTAR: | |
| 2557 | possessive = TRUE; | |
| 2558 | min = 0; | |
| 2559 | max = INT_MAX; | |
| 2560 | ecode++; | |
| 2561 | goto REPEATNOTCHAR; | |
| 2562 | ||
| 2563 | case OP_NOTPOSPLUS: | |
| 2564 | possessive = TRUE; | |
| 2565 | min = 1; | |
| 2566 | max = INT_MAX; | |
| 2567 | ecode++; | |
| 2568 | goto REPEATNOTCHAR; | |
| 2569 | ||
| 2570 | case OP_NOTPOSQUERY: | |
| 2571 | possessive = TRUE; | |
| 2572 | min = 0; | |
| 2573 | max = 1; | |
| 2574 | ecode++; | |
| 2575 | goto REPEATNOTCHAR; | |
| 2576 | ||
| 2577 | case OP_NOTPOSUPTO: | |
| 2578 | possessive = TRUE; | |
| 2579 | min = 0; | |
| 2580 | max = GET2(ecode, 1); | |
| 2581 | ecode += 3; | |
| 2582 | goto REPEATNOTCHAR; | |
| 2583 | ||
| 2584 | case OP_NOTSTAR: | case OP_NOTSTAR: |
| 2585 | case OP_NOTMINSTAR: | case OP_NOTMINSTAR: |
| 2586 | case OP_NOTPLUS: | case OP_NOTPLUS: |
| # | Line 2160 for (;;) | Line 2620 for (;;) |
| 2620 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2621 | if (utf8) | if (utf8) |
| 2622 | { | { |
| 2623 | register int d; | register unsigned int d; |
| 2624 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2625 | { | { |
| 2626 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| # | Line 2185 for (;;) | Line 2645 for (;;) |
| 2645 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2646 | if (utf8) | if (utf8) |
| 2647 | { | { |
| 2648 | register int d; | register unsigned int d; |
| 2649 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2650 | { | { |
| 2651 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28); |
| 2652 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2653 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2654 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 2655 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
| 2656 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (fc == d) RRETURN(MATCH_NOMATCH); |
| 2657 | RRETURN(MATCH_NOMATCH); | |
| 2658 | } | } |
| 2659 | } | } |
| 2660 | else | else |
| # | Line 2202 for (;;) | Line 2663 for (;;) |
| 2663 | { | { |
| 2664 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2665 | { | { |
| 2666 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29); |
| 2667 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2668 | if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++]) | if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++]) |
| 2669 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| # | Line 2221 for (;;) | Line 2682 for (;;) |
| 2682 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2683 | if (utf8) | if (utf8) |
| 2684 | { | { |
| 2685 | register int d; | register unsigned int d; |
| 2686 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2687 | { | { |
| 2688 | int len = 1; | int len = 1; |
| # | Line 2231 for (;;) | Line 2692 for (;;) |
| 2692 | if (fc == d) break; | if (fc == d) break; |
| 2693 | eptr += len; | eptr += len; |
| 2694 | } | } |
| 2695 | for(;;) | if (possessive) continue; |
| 2696 | for(;;) | |
| 2697 | { | { |
| 2698 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30); |
| 2699 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2700 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2701 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 2248 for (;;) | Line 2710 for (;;) |
| 2710 | if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break; | if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break; |
| 2711 | eptr++; | eptr++; |
| 2712 | } | } |
| 2713 | if (possessive) continue; | |
| 2714 | while (eptr >= pp) | while (eptr >= pp) |
| 2715 | { | { |
| 2716 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31); |
| 2717 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2718 | eptr--; | eptr--; |
| 2719 | } | } |
| # | Line 2269 for (;;) | Line 2732 for (;;) |
| 2732 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2733 | if (utf8) | if (utf8) |
| 2734 | { | { |
| 2735 | register int d; | register unsigned int d; |
| 2736 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2737 | { | { |
| 2738 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| # | Line 2292 for (;;) | Line 2755 for (;;) |
| 2755 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2756 | if (utf8) | if (utf8) |
| 2757 | { | { |
| 2758 | register int d; | register unsigned int d; |
| 2759 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2760 | { | { |
| 2761 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32); |
| 2762 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2763 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2764 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 2765 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (fc == d) RRETURN(MATCH_NOMATCH); |
| RRETURN(MATCH_NOMATCH); | ||
| 2766 | } | } |
| 2767 | } | } |
| 2768 | else | else |
| # | Line 2308 for (;;) | Line 2771 for (;;) |
| 2771 | { | { |
| 2772 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2773 | { | { |
| 2774 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33); |
| 2775 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2776 | if (fi >= max || eptr >= md->end_subject || fc == *eptr++) | if (fi >= max || eptr >= md->end_subject || fc == *eptr++) |
| 2777 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| # | Line 2327 for (;;) | Line 2790 for (;;) |
| 2790 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2791 | if (utf8) | if (utf8) |
| 2792 | { | { |
| 2793 | register int d; | register unsigned int d; |
| 2794 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2795 | { | { |
| 2796 | int len = 1; | int len = 1; |
| # | Line 2336 for (;;) | Line 2799 for (;;) |
| 2799 | if (fc == d) break; | if (fc == d) break; |
| 2800 | eptr += len; | eptr += len; |
| 2801 | } | } |
| 2802 | if (possessive) continue; | |
| 2803 | for(;;) | for(;;) |
| 2804 | { | { |
| 2805 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34); |
| 2806 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2807 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2808 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 2353 for (;;) | Line 2817 for (;;) |
| 2817 | if (eptr >= md->end_subject || fc == *eptr) break; | if (eptr >= md->end_subject || fc == *eptr) break; |
| 2818 | eptr++; | eptr++; |
| 2819 | } | } |
| 2820 | if (possessive) continue; | |
| 2821 | while (eptr >= pp) | while (eptr >= pp) |
| 2822 | { | { |
| 2823 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35); |
| 2824 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2825 | eptr--; | eptr--; |
| 2826 | } | } |
| # | Line 2384 for (;;) | Line 2849 for (;;) |
| 2849 | ecode += 3; | ecode += 3; |
| 2850 | goto REPEATTYPE; | goto REPEATTYPE; |
| 2851 | ||
| 2852 | case OP_TYPEPOSSTAR: | |
| 2853 | possessive = TRUE; | |
| 2854 | min = 0; | |
| 2855 | max = INT_MAX; | |
| 2856 | ecode++; | |
| 2857 | goto REPEATTYPE; | |
| 2858 | ||
| 2859 | case OP_TYPEPOSPLUS: | |
| 2860 | possessive = TRUE; | |
| 2861 | min = 1; | |
| 2862 | max = INT_MAX; | |
| 2863 | ecode++; | |
| 2864 | goto REPEATTYPE; | |
| 2865 | ||
| 2866 | case OP_TYPEPOSQUERY: | |
| 2867 | possessive = TRUE; | |
| 2868 | min = 0; | |
| 2869 | max = 1; | |
| 2870 | ecode++; | |
| 2871 | goto REPEATTYPE; | |
| 2872 | ||
| 2873 | case OP_TYPEPOSUPTO: | |
| 2874 | possessive = TRUE; | |
| 2875 | min = 0; | |
| 2876 | max = GET2(ecode, 1); | |
| 2877 | ecode += 3; | |
| 2878 | goto REPEATTYPE; | |
| 2879 | ||
| 2880 | case OP_TYPESTAR: | case OP_TYPESTAR: |
| 2881 | case OP_TYPEMINSTAR: | case OP_TYPEMINSTAR: |
| 2882 | case OP_TYPEPLUS: | case OP_TYPEPLUS: |
| # | Line 2408 for (;;) | Line 2901 for (;;) |
| 2901 | { | { |
| 2902 | prop_fail_result = ctype == OP_NOTPROP; | prop_fail_result = ctype == OP_NOTPROP; |
| 2903 | prop_type = *ecode++; | prop_type = *ecode++; |
| 2904 | 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; | ||
| } | ||
| 2905 | } | } |
| 2906 | else prop_type = -1; | else prop_type = -1; |
| 2907 | #endif | #endif |
| # | Line 2434 for (;;) | Line 2918 for (;;) |
| 2918 | if (min > 0) | if (min > 0) |
| 2919 | { | { |
| 2920 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2921 | if (prop_type > 0) | if (prop_type >= 0) |
| 2922 | { | { |
| 2923 | for (i = 1; i <= min; i++) | switch(prop_type) |
| 2924 | { | { |
| 2925 | GETCHARINC(c, eptr); | case PT_ANY: |
| 2926 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | if (prop_fail_result) RRETURN(MATCH_NOMATCH); |
| 2927 | if ((*prop_test_variable == prop_test_against) == prop_fail_result) | for (i = 1; i <= min; i++) |
| 2928 | RRETURN(MATCH_NOMATCH); | { |
| 2929 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2930 | GETCHARINCTEST(c, eptr); | |
| 2931 | } | |
| 2932 | break; | |
| 2933 | ||
| 2934 | case PT_LAMP: | |
| 2935 | for (i = 1; i <= min; i++) | |
| 2936 | { | |
| 2937 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2938 | GETCHARINCTEST(c, eptr); | |
| 2939 | prop_chartype = UCD_CHARTYPE(c); | |
| 2940 | if ((prop_chartype == ucp_Lu || | |
| 2941 | prop_chartype == ucp_Ll || | |
| 2942 | prop_chartype == ucp_Lt) == prop_fail_result) | |
| 2943 | RRETURN(MATCH_NOMATCH); | |
| 2944 | } | |
| 2945 | break; | |
| 2946 | ||
| 2947 | case PT_GC: | |
| 2948 | for (i = 1; i <= min; i++) | |
| 2949 | { | |
| 2950 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2951 | GETCHARINCTEST(c, eptr); | |
| 2952 | prop_category = UCD_CATEGORY(c); | |
| 2953 | if ((prop_category == prop_value) == prop_fail_result) | |
| 2954 | RRETURN(MATCH_NOMATCH); | |
| 2955 | } | |
| 2956 | break; | |
| 2957 | ||
| 2958 | case PT_PC: | |
| 2959 | for (i = 1; i <= min; i++) | |
| 2960 | { | |
| 2961 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2962 | GETCHARINCTEST(c, eptr); | |
| 2963 | prop_chartype = UCD_CHARTYPE(c); | |
| 2964 | if ((prop_chartype == prop_value) == prop_fail_result) | |
| 2965 | RRETURN(MATCH_NOMATCH); | |
| 2966 | } | |
| 2967 | break; | |
| 2968 | ||
| 2969 | case PT_SC: | |
| 2970 | for (i = 1; i <= min; i++) | |
| 2971 | { | |
| 2972 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 2973 | GETCHARINCTEST(c, eptr); | |
| 2974 | prop_script = UCD_SCRIPT(c); | |
| 2975 | if ((prop_script == prop_value) == prop_fail_result) | |
| 2976 | RRETURN(MATCH_NOMATCH); | |
| 2977 | } | |
| 2978 | break; | |
| 2979 | ||
| 2980 | default: | |
| 2981 | RRETURN(PCRE_ERROR_INTERNAL); | |
| 2982 | } | } |
| 2983 | } | } |
| 2984 | ||
| # | Line 2453 for (;;) | Line 2990 for (;;) |
| 2990 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2991 | { | { |
| 2992 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2993 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 2994 | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 2995 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 2996 | { | { |
| # | Line 2462 for (;;) | Line 2999 for (;;) |
| 2999 | { | { |
| 3000 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 3001 | } | } |
| 3002 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3003 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 3004 | eptr += len; | eptr += len; |
| 3005 | } | } |
| # | Line 2480 for (;;) | Line 3017 for (;;) |
| 3017 | case OP_ANY: | case OP_ANY: |
| 3018 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3019 | { | { |
| 3020 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) |
| (*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0)) | ||
| 3021 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3022 | eptr++; | |
| 3023 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | |
| 3024 | } | |
| 3025 | break; | |
| 3026 | ||
| 3027 | case OP_ALLANY: | |
| 3028 | for (i = 1; i <= min; i++) | |
| 3029 | { | |
| 3030 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3031 | eptr++; | |
| 3032 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| 3033 | } | } |
| 3034 | break; | break; |
| # | Line 2491 for (;;) | Line 3037 for (;;) |
| 3037 | eptr += min; | eptr += min; |
| 3038 | break; | break; |
| 3039 | ||
| 3040 | case OP_ANYNL: | |
| 3041 | for (i = 1; i <= min; i++) | |
| 3042 | { | |
| 3043 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3044 | GETCHARINC(c, eptr); | |
| 3045 | switch(c) | |
| 3046 | { | |
| 3047 | default: RRETURN(MATCH_NOMATCH); | |
| 3048 | case 0x000d: | |
| 3049 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3050 | break; | |
| 3051 | ||
| 3052 | case 0x000a: | |
| 3053 | break; | |
| 3054 | ||
| 3055 | case 0x000b: | |
| 3056 | case 0x000c: | |
| 3057 | case 0x0085: | |
| 3058 | case 0x2028: | |
| 3059 | case 0x2029: | |
| 3060 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3061 | break; | |
| 3062 | } | |
| 3063 | } | |
| 3064 | break; | |
| 3065 | ||
| 3066 | case OP_NOT_HSPACE: | |
| 3067 | for (i = 1; i <= min; i++) | |
| 3068 | { | |
| 3069 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3070 | GETCHARINC(c, eptr); | |
| 3071 | switch(c) | |
| 3072 | { | |
| 3073 | default: break; | |
| 3074 | case 0x09: /* HT */ | |
| 3075 | case 0x20: /* SPACE */ | |
| 3076 | case 0xa0: /* NBSP */ | |
| 3077 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3078 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3079 | case 0x2000: /* EN QUAD */ | |
| 3080 | case 0x2001: /* EM QUAD */ | |
| 3081 | case 0x2002: /* EN SPACE */ | |
| 3082 | case 0x2003: /* EM SPACE */ | |
| 3083 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3084 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3085 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3086 | case 0x2007: /* FIGURE SPACE */ | |
| 3087 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3088 | case 0x2009: /* THIN SPACE */ | |
| 3089 | case 0x200A: /* HAIR SPACE */ | |
| 3090 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3091 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3092 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3093 | RRETURN(MATCH_NOMATCH); | |
| 3094 | } | |
| 3095 | } | |
| 3096 | break; | |
| 3097 | ||
| 3098 | case OP_HSPACE: | |
| 3099 | for (i = 1; i <= min; i++) | |
| 3100 | { | |
| 3101 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3102 | GETCHARINC(c, eptr); | |
| 3103 | switch(c) | |
| 3104 | { | |
| 3105 | default: RRETURN(MATCH_NOMATCH); | |
| 3106 | case 0x09: /* HT */ | |
| 3107 | case 0x20: /* SPACE */ | |
| 3108 | case 0xa0: /* NBSP */ | |
| 3109 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3110 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3111 | case 0x2000: /* EN QUAD */ | |
| 3112 | case 0x2001: /* EM QUAD */ | |
| 3113 | case 0x2002: /* EN SPACE */ | |
| 3114 | case 0x2003: /* EM SPACE */ | |
| 3115 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3116 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3117 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3118 | case 0x2007: /* FIGURE SPACE */ | |
| 3119 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3120 | case 0x2009: /* THIN SPACE */ | |
| 3121 | case 0x200A: /* HAIR SPACE */ | |
| 3122 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3123 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3124 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3125 | break; | |
| 3126 | } | |
| 3127 | } | |
| 3128 | break; | |
| 3129 | ||
| 3130 | case OP_NOT_VSPACE: | |
| 3131 | for (i = 1; i <= min; i++) | |
| 3132 | { | |
| 3133 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3134 | GETCHARINC(c, eptr); | |
| 3135 | switch(c) | |
| 3136 | { | |
| 3137 | default: break; | |
| 3138 | case 0x0a: /* LF */ | |
| 3139 | case 0x0b: /* VT */ | |
| 3140 | case 0x0c: /* FF */ | |
| 3141 | case 0x0d: /* CR */ | |
| 3142 | case 0x85: /* NEL */ | |
| 3143 | case 0x2028: /* LINE SEPARATOR */ | |
| 3144 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3145 | RRETURN(MATCH_NOMATCH); | |
| 3146 | } | |
| 3147 | } | |
| 3148 | break; | |
| 3149 | ||
| 3150 | case OP_VSPACE: | |
| 3151 | for (i = 1; i <= min; i++) | |
| 3152 | { | |
| 3153 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3154 | GETCHARINC(c, eptr); | |
| 3155 | switch(c) | |
| 3156 | { | |
| 3157 | default: RRETURN(MATCH_NOMATCH); | |
| 3158 | case 0x0a: /* LF */ | |
| 3159 | case 0x0b: /* VT */ | |
| 3160 | case 0x0c: /* FF */ | |
| 3161 | case 0x0d: /* CR */ | |
| 3162 | case 0x85: /* NEL */ | |
| 3163 | case 0x2028: /* LINE SEPARATOR */ | |
| 3164 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3165 | break; | |
| 3166 | } | |
| 3167 | } | |
| 3168 | break; | |
| 3169 | ||
| 3170 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 3171 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3172 | { | { |
| # | Line 2515 for (;;) | Line 3191 for (;;) |
| 3191 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3192 | { | { |
| 3193 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject || |
| 3194 | (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0)) | (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)) |
| 3195 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3196 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); |
| 3197 | } | } |
| 3198 | break; | break; |
| 3199 | ||
| # | Line 2535 for (;;) | Line 3211 for (;;) |
| 3211 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3212 | { | { |
| 3213 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject || |
| 3214 | (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0)) | (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)) |
| 3215 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3216 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); |
| 3217 | } | } |
| 3218 | break; | break; |
| 3219 | ||
| # | Line 2559 for (;;) | Line 3235 for (;;) |
| 3235 | #endif /* SUPPORT_UTF8 */ | #endif /* SUPPORT_UTF8 */ |
| 3236 | ||
| 3237 | /* 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 |
| 3238 | than OP_PROP and OP_NOTPROP. */ | than OP_PROP and OP_NOTPROP. We can assume that there are the minimum |
| 3239 | number of bytes present, as this was tested above. */ | |
| 3240 | ||
| 3241 | switch(ctype) | switch(ctype) |
| 3242 | { | { |
| 3243 | case OP_ANY: | case OP_ANY: |
| 3244 | if ((ims & PCRE_DOTALL) == 0) | for (i = 1; i <= min; i++) |
| 3245 | { | { |
| 3246 | for (i = 1; i <= min; i++) | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); |
| 3247 | if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH); | eptr++; |
| 3248 | } | } |
| 3249 | else eptr += min; | break; |
| 3250 | ||
| 3251 | case OP_ALLANY: | |
| 3252 | eptr += min; | |
| 3253 | break; | break; |
| 3254 | ||
| 3255 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 3256 | eptr += min; | eptr += min; |
| 3257 | break; | break; |
| 3258 | ||
| 3259 | /* Because of the CRLF case, we can't assume the minimum number of | |
| 3260 | bytes are present in this case. */ | |
| 3261 | ||
| 3262 | case OP_ANYNL: | |
| 3263 | for (i = 1; i <= min; i++) | |
| 3264 | { | |
| 3265 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3266 | switch(*eptr++) | |
| 3267 | { | |
| 3268 | default: RRETURN(MATCH_NOMATCH); | |
| 3269 | case 0x000d: | |
| 3270 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3271 | break; | |
| 3272 | case 0x000a: | |
| 3273 | break; | |
| 3274 | ||
| 3275 | case 0x000b: | |
| 3276 | case 0x000c: | |
| 3277 | case 0x0085: | |
| 3278 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3279 | break; | |
| 3280 | } | |
| 3281 | } | |
| 3282 | break; | |
| 3283 | ||
| 3284 | case OP_NOT_HSPACE: | |
| 3285 | for (i = 1; i <= min; i++) | |
| 3286 | { | |
| 3287 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3288 | switch(*eptr++) | |
| 3289 | { | |
| 3290 | default: break; | |
| 3291 | case 0x09: /* HT */ | |
| 3292 | case 0x20: /* SPACE */ | |
| 3293 | case 0xa0: /* NBSP */ | |
| 3294 | RRETURN(MATCH_NOMATCH); | |
| 3295 | } | |
| 3296 | } | |
| 3297 | break; | |
| 3298 | ||
| 3299 | case OP_HSPACE: | |
| 3300 | for (i = 1; i <= min; i++) | |
| 3301 | { | |
| 3302 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3303 | switch(*eptr++) | |
| 3304 | { | |
| 3305 | default: RRETURN(MATCH_NOMATCH); | |
| 3306 | case 0x09: /* HT */ | |
| 3307 | case 0x20: /* SPACE */ | |
| 3308 | case 0xa0: /* NBSP */ | |
| 3309 | break; | |
| 3310 | } | |
| 3311 | } | |
| 3312 | break; | |
| 3313 | ||
| 3314 | case OP_NOT_VSPACE: | |
| 3315 | for (i = 1; i <= min; i++) | |
| 3316 | { | |
| 3317 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3318 | switch(*eptr++) | |
| 3319 | { | |
| 3320 | default: break; | |
| 3321 | case 0x0a: /* LF */ | |
| 3322 | case 0x0b: /* VT */ | |
| 3323 | case 0x0c: /* FF */ | |
| 3324 | case 0x0d: /* CR */ | |
| 3325 | case 0x85: /* NEL */ | |
| 3326 | RRETURN(MATCH_NOMATCH); | |
| 3327 | } | |
| 3328 | } | |
| 3329 | break; | |
| 3330 | ||
| 3331 | case OP_VSPACE: | |
| 3332 | for (i = 1; i <= min; i++) | |
| 3333 | { | |
| 3334 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3335 | switch(*eptr++) | |
| 3336 | { | |
| 3337 | default: RRETURN(MATCH_NOMATCH); | |
| 3338 | case 0x0a: /* LF */ | |
| 3339 | case 0x0b: /* VT */ | |
| 3340 | case 0x0c: /* FF */ | |
| 3341 | case 0x0d: /* CR */ | |
| 3342 | case 0x85: /* NEL */ | |
| 3343 | break; | |
| 3344 | } | |
| 3345 | } | |
| 3346 | break; | |
| 3347 | ||
| 3348 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 3349 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3350 | if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); | if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); |
| # | Line 2624 for (;;) | Line 3393 for (;;) |
| 3393 | if (minimize) | if (minimize) |
| 3394 | { | { |
| 3395 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 3396 | if (prop_type > 0) | if (prop_type >= 0) |
| 3397 | { | { |
| 3398 | for (fi = min;; fi++) | switch(prop_type) |
| 3399 | { | { |
| 3400 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | case PT_ANY: |
| 3401 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | for (fi = min;; fi++) |
| 3402 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | { |
| 3403 | GETCHARINC(c, eptr); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36); |
| 3404 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3405 | if ((*prop_test_variable == prop_test_against) == prop_fail_result) | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 3406 | RRETURN(MATCH_NOMATCH); | GETCHARINC(c, eptr); |
| 3407 | } | if (prop_fail_result) RRETURN(MATCH_NOMATCH); |
| 3408 | } | } |
| 3409 | /* Control never gets here */ | |
| 3410 | ||
| 3411 | /* Match extended Unicode sequences. We will get here only if the | case PT_LAMP: |
| 3412 | support is in the binary; otherwise a compile-time error occurs. */ | for (fi = min;; fi++) |
| 3413 | { | |
| 3414 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37); | |
| 3415 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 3416 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3417 | GETCHARINC(c, eptr); | |
| 3418 | prop_chartype = UCD_CHARTYPE(c); | |
| 3419 | if ((prop_chartype == ucp_Lu || | |
| 3420 | prop_chartype == ucp_Ll || | |
| 3421 | prop_chartype == ucp_Lt) == prop_fail_result) | |
| 3422 | RRETURN(MATCH_NOMATCH); | |
| 3423 | } | |
| 3424 | /* Control never gets here */ | |
| 3425 | ||
| 3426 | case PT_GC: | |
| 3427 | for (fi = min;; fi++) | |
| 3428 | { | |
| 3429 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38); | |
| 3430 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 3431 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3432 | GETCHARINC(c, eptr); | |
| 3433 | prop_category = UCD_CATEGORY(c); | |
| 3434 | if ((prop_category == prop_value) == prop_fail_result) | |
| 3435 | RRETURN(MATCH_NOMATCH); | |
| 3436 | } | |
| 3437 | /* Control never gets here */ | |
| 3438 | ||
| 3439 | case PT_PC: | |
| 3440 | for (fi = min;; fi++) | |
| 3441 | { | |
| 3442 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39); | |
| 3443 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 3444 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3445 | GETCHARINC(c, eptr); | |
| 3446 | prop_chartype = UCD_CHARTYPE(c); | |
| 3447 | if ((prop_chartype == prop_value) == prop_fail_result) | |
| 3448 | RRETURN(MATCH_NOMATCH); | |
| 3449 | } | |
| 3450 | /* Control never gets here */ | |
| 3451 | ||
| 3452 | case PT_SC: | |
| 3453 | for (fi = min;; fi++) | |
| 3454 | { | |
| 3455 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40); | |
| 3456 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 3457 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | |
| 3458 | GETCHARINC(c, eptr); | |
| 3459 | prop_script = UCD_SCRIPT(c); | |
| 3460 | if ((prop_script == prop_value) == prop_fail_result) | |
| 3461 | RRETURN(MATCH_NOMATCH); | |
| 3462 | } | |
| 3463 | /* Control never gets here */ | |
| 3464 | ||
| 3465 | default: | |
| 3466 | RRETURN(PCRE_ERROR_INTERNAL); | |
| 3467 | } | |
| 3468 | } | |
| 3469 | ||
| 3470 | /* Match extended Unicode sequences. We will get here only if the | |
| 3471 | support is in the binary; otherwise a compile-time error occurs. */ | |
| 3472 | ||
| 3473 | else if (ctype == OP_EXTUNI) | else if (ctype == OP_EXTUNI) |
| 3474 | { | { |
| 3475 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3476 | { | { |
| 3477 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41); |
| 3478 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3479 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
| 3480 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3481 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3482 | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 3483 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 3484 | { | { |
| # | Line 2658 for (;;) | Line 3487 for (;;) |
| 3487 | { | { |
| 3488 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 3489 | } | } |
| 3490 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3491 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 3492 | eptr += len; | eptr += len; |
| 3493 | } | } |
| # | Line 2674 for (;;) | Line 3503 for (;;) |
| 3503 | { | { |
| 3504 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3505 | { | { |
| 3506 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42); |
| 3507 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3508 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject || |
| 3509 | (ctype == OP_ANY && IS_NEWLINE(eptr))) | |
| 3510 | RRETURN(MATCH_NOMATCH); | |
| 3511 | ||
| 3512 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3513 | switch(ctype) | switch(ctype) |
| 3514 | { | { |
| 3515 | case OP_ANY: | case OP_ANY: /* This is the non-NL case */ |
| 3516 | if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH); | case OP_ALLANY: |
| 3517 | case OP_ANYBYTE: | |
| 3518 | break; | break; |
| 3519 | ||
| 3520 | case OP_ANYBYTE: | case OP_ANYNL: |
| 3521 | switch(c) | |
| 3522 | { | |
| 3523 | default: RRETURN(MATCH_NOMATCH); | |
| 3524 | case 0x000d: | |
| 3525 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3526 | break; | |
| 3527 | case 0x000a: | |
| 3528 | break; | |
| 3529 | ||
| 3530 | case 0x000b: | |
| 3531 | case 0x000c: | |
| 3532 | case 0x0085: | |
| 3533 | case 0x2028: | |
| 3534 | case 0x2029: | |
| 3535 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3536 | break; | |
| 3537 | } | |
| 3538 | break; | |
| 3539 | ||
| 3540 | case OP_NOT_HSPACE: | |
| 3541 | switch(c) | |
| 3542 | { | |
| 3543 | default: break; | |
| 3544 | case 0x09: /* HT */ | |
| 3545 | case 0x20: /* SPACE */ | |
| 3546 | case 0xa0: /* NBSP */ | |
| 3547 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3548 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3549 | case 0x2000: /* EN QUAD */ | |
| 3550 | case 0x2001: /* EM QUAD */ | |
| 3551 | case 0x2002: /* EN SPACE */ | |
| 3552 | case 0x2003: /* EM SPACE */ | |
| 3553 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3554 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3555 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3556 | case 0x2007: /* FIGURE SPACE */ | |
| 3557 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3558 | case 0x2009: /* THIN SPACE */ | |
| 3559 | case 0x200A: /* HAIR SPACE */ | |
| 3560 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3561 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3562 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3563 | RRETURN(MATCH_NOMATCH); | |
| 3564 | } | |
| 3565 | break; | |
| 3566 | ||
| 3567 | case OP_HSPACE: | |
| 3568 | switch(c) | |
| 3569 | { | |
| 3570 | default: RRETURN(MATCH_NOMATCH); | |
| 3571 | case 0x09: /* HT */ | |
| 3572 | case 0x20: /* SPACE */ | |
| 3573 | case 0xa0: /* NBSP */ | |
| 3574 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3575 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3576 | case 0x2000: /* EN QUAD */ | |
| 3577 | case 0x2001: /* EM QUAD */ | |
| 3578 | case 0x2002: /* EN SPACE */ | |
| 3579 | case 0x2003: /* EM SPACE */ | |
| 3580 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3581 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3582 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3583 | case 0x2007: /* FIGURE SPACE */ | |
| 3584 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3585 | case 0x2009: /* THIN SPACE */ | |
| 3586 | case 0x200A: /* HAIR SPACE */ | |
| 3587 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3588 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3589 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3590 | break; | |
| 3591 | } | |
| 3592 | break; | |
| 3593 | ||
| 3594 | case OP_NOT_VSPACE: | |
| 3595 | switch(c) | |
| 3596 | { | |
| 3597 | default: break; | |
| 3598 | case 0x0a: /* LF */ | |
| 3599 | case 0x0b: /* VT */ | |
| 3600 | case 0x0c: /* FF */ | |
| 3601 | case 0x0d: /* CR */ | |
| 3602 | case 0x85: /* NEL */ | |
| 3603 | case 0x2028: /* LINE SEPARATOR */ | |
| 3604 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3605 | RRETURN(MATCH_NOMATCH); | |
| 3606 | } | |
| 3607 | break; | |
| 3608 | ||
| 3609 | case OP_VSPACE: | |
| 3610 | switch(c) | |
| 3611 | { | |
| 3612 | default: RRETURN(MATCH_NOMATCH); | |
| 3613 | case 0x0a: /* LF */ | |
| 3614 | case 0x0b: /* VT */ | |
| 3615 | case 0x0c: /* FF */ | |
| 3616 | case 0x0d: /* CR */ | |
| 3617 | case 0x85: /* NEL */ | |
| 3618 | case 0x2028: /* LINE SEPARATOR */ | |
| 3619 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3620 | break; | |
| 3621 | } | |
| 3622 | break; | break; |
| 3623 | ||
| 3624 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| # | Line 2729 for (;;) | Line 3662 for (;;) |
| 3662 | { | { |
| 3663 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3664 | { | { |
| 3665 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43); |
| 3666 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3667 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max || eptr >= md->end_subject || |
| 3668 | (ctype == OP_ANY && IS_NEWLINE(eptr))) | |
| 3669 | RRETURN(MATCH_NOMATCH); | |
| 3670 | ||
| 3671 | c = *eptr++; | c = *eptr++; |
| 3672 | switch(ctype) | switch(ctype) |
| 3673 | { | { |
| 3674 | case OP_ANY: | case OP_ANY: /* This is the non-NL case */ |
| 3675 | if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH); | case OP_ALLANY: |
| 3676 | case OP_ANYBYTE: | |
| 3677 | break; | break; |
| 3678 | ||
| 3679 | case OP_ANYBYTE: | case OP_ANYNL: |
| 3680 | switch(c) | |
| 3681 | { | |
| 3682 | default: RRETURN(MATCH_NOMATCH); | |
| 3683 | case 0x000d: | |
| 3684 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3685 | break; | |
| 3686 | ||
| 3687 | case 0x000a: | |
| 3688 | break; | |
| 3689 | ||
| 3690 | case 0x000b: | |
| 3691 | case 0x000c: | |
| 3692 | case 0x0085: | |
| 3693 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3694 | break; | |
| 3695 | } | |
| 3696 | break; | |
| 3697 | ||
| 3698 | case OP_NOT_HSPACE: | |
| 3699 | switch(c) | |
| 3700 | { | |
| 3701 | default: break; | |
| 3702 | case 0x09: /* HT */ | |
| 3703 | case 0x20: /* SPACE */ | |
| 3704 | case 0xa0: /* NBSP */ | |
| 3705 | RRETURN(MATCH_NOMATCH); | |
| 3706 | } | |
| 3707 | break; | |
| 3708 | ||
| 3709 | case OP_HSPACE: | |
| 3710 | switch(c) | |
| 3711 | { | |
| 3712 | default: RRETURN(MATCH_NOMATCH); | |
| 3713 | case 0x09: /* HT */ | |
| 3714 | case 0x20: /* SPACE */ | |
| 3715 | case 0xa0: /* NBSP */ | |
| 3716 | break; | |
| 3717 | } | |
| 3718 | break; | |
| 3719 | ||
| 3720 | case OP_NOT_VSPACE: | |
| 3721 | switch(c) | |
| 3722 | { | |
| 3723 | default: break; | |
| 3724 | case 0x0a: /* LF */ | |
| 3725 | case 0x0b: /* VT */ | |
| 3726 | case 0x0c: /* FF */ | |
| 3727 | case 0x0d: /* CR */ | |
| 3728 | case 0x85: /* NEL */ | |
| 3729 | RRETURN(MATCH_NOMATCH); | |
| 3730 | } | |
| 3731 | break; | |
| 3732 | ||
| 3733 | case OP_VSPACE: | |
| 3734 | switch(c) | |
| 3735 | { | |
| 3736 | default: RRETURN(MATCH_NOMATCH); | |
| 3737 | case 0x0a: /* LF */ | |
| 3738 | case 0x0b: /* VT */ | |
| 3739 | case 0x0c: /* FF */ | |
| 3740 | case 0x0d: /* CR */ | |
| 3741 | case 0x85: /* NEL */ | |
| 3742 | break; | |
| 3743 | } | |
| 3744 | break; | break; |
| 3745 | ||
| 3746 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| # | Line 2774 for (;;) | Line 3775 for (;;) |
| 3775 | /* Control never gets here */ | /* Control never gets here */ |
| 3776 | } | } |
| 3777 | ||
| 3778 | /* 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 |
| 3779 | 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 |
| 3780 | UTF-8 and UCP stuff separate. */ | UTF-8 and UCP stuff separate. */ |
| 3781 | ||
| # | Line 2783 for (;;) | Line 3784 for (;;) |
| 3784 | pp = eptr; /* Remember where we started */ | pp = eptr; /* Remember where we started */ |
| 3785 | ||
| 3786 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 3787 | if (prop_type > 0) | if (prop_type >= 0) |
| 3788 | { | { |
| 3789 | for (i = min; i < max; i++) | switch(prop_type) |
| 3790 | { | { |
| 3791 | int len = 1; | case PT_ANY: |
| 3792 | if (eptr >= md->end_subject) break; | for (i = min; i < max; i++) |
| 3793 | GETCHARLEN(c, eptr, len); | { |
| 3794 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | int len = 1; |
| 3795 | if ((*prop_test_variable == prop_test_against) == prop_fail_result) | if (eptr >= md->end_subject) break; |
| 3796 | break; | GETCHARLEN(c, eptr, len); |
| 3797 | eptr+= len; | if (prop_fail_result) break; |
| 3798 | eptr+= len; | |
| 3799 | } | |
| 3800 | break; | |
| 3801 | ||
| 3802 | case PT_LAMP: | |
| 3803 | for (i = min; i < max; i++) | |
| 3804 | { | |
| 3805 | int len = 1; | |
| 3806 | if (eptr >= md->end_subject) break; | |
| 3807 | GETCHARLEN(c, eptr, len); | |
| 3808 | prop_chartype = UCD_CHARTYPE(c); | |
| 3809 | if ((prop_chartype == ucp_Lu || | |
| 3810 | prop_chartype == ucp_Ll || | |
| 3811 | prop_chartype == ucp_Lt) == prop_fail_result) | |
| 3812 | break; | |
| 3813 | eptr+= len; | |
| 3814 | } | |
| 3815 | break; | |
| 3816 | ||
| 3817 | case PT_GC: | |
| 3818 | for (i = min; i < max; i++) | |
| 3819 | { | |
| 3820 | int len = 1; | |
| 3821 | if (eptr >= md->end_subject) break; | |
| 3822 | GETCHARLEN(c, eptr, len); | |
| 3823 | prop_category = UCD_CATEGORY(c); | |
| 3824 | if ((prop_category == prop_value) == prop_fail_result) | |
| 3825 | break; | |
| 3826 | eptr+= len; | |
| 3827 | } | |
| 3828 | break; | |
| 3829 | ||
| 3830 | case PT_PC: | |
| 3831 | for (i = min; i < max; i++) | |
| 3832 | { | |
| 3833 | int len = 1; | |
| 3834 | if (eptr >= md->end_subject) break; | |
| 3835 | GETCHARLEN(c, eptr, len); | |
| 3836 | prop_chartype = UCD_CHARTYPE(c); | |
| 3837 | if ((prop_chartype == prop_value) == prop_fail_result) | |
| 3838 | break; | |
| 3839 | eptr+= len; | |
| 3840 | } | |
| 3841 | break; | |
| 3842 | ||
| 3843 | case PT_SC: | |
| 3844 | for (i = min; i < max; i++) | |
| 3845 | { | |
| 3846 | int len = 1; | |
| 3847 | if (eptr >= md->end_subject) break; | |
| 3848 | GETCHARLEN(c, eptr, len); | |
| 3849 | prop_script = UCD_SCRIPT(c); | |
| 3850 | if ((prop_script == prop_value) == prop_fail_result) | |
| 3851 | break; | |
| 3852 | eptr+= len; | |
| 3853 | } | |
| 3854 | break; | |
| 3855 | } | } |
| 3856 | ||
| 3857 | /* eptr is now past the end of the maximum run */ | /* eptr is now past the end of the maximum run */ |
| 3858 | ||
| 3859 | if (possessive) continue; | |
| 3860 | for(;;) | for(;;) |
| 3861 | { | { |
| 3862 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44); |
| 3863 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3864 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3865 | BACKCHAR(eptr); | if (utf8) BACKCHAR(eptr); |
| 3866 | } | } |
| 3867 | } | } |
| 3868 | ||
| # | Line 2816 for (;;) | Line 3875 for (;;) |
| 3875 | { | { |
| 3876 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) break; |
| 3877 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3878 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3879 | if (prop_category == ucp_M) break; | if (prop_category == ucp_M) break; |
| 3880 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 3881 | { | { |
| # | Line 2825 for (;;) | Line 3884 for (;;) |
| 3884 | { | { |
| 3885 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 3886 | } | } |
| 3887 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3888 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 3889 | eptr += len; | eptr += len; |
| 3890 | } | } |
| # | Line 2833 for (;;) | Line 3892 for (;;) |
| 3892 | ||
| 3893 | /* eptr is now past the end of the maximum run */ | /* eptr is now past the end of the maximum run */ |
| 3894 | ||
| 3895 | if (possessive) continue; | |
| 3896 | for(;;) | for(;;) |
| 3897 | { | { |
| 3898 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45); |
| 3899 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3900 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3901 | for (;;) /* Move back over one extended */ | for (;;) /* Move back over one extended */ |
| 3902 | { | { |
| 3903 | int len = 1; | int len = 1; |
| BACKCHAR(eptr); | ||
| 3904 | if (!utf8) c = *eptr; else | if (!utf8) c = *eptr; else |
| 3905 | { | { |
| 3906 | BACKCHAR(eptr); | |
| 3907 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 3908 | } | } |
| 3909 | prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase); | prop_category = UCD_CATEGORY(c); |
| 3910 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 3911 | eptr--; | eptr--; |
| 3912 | } | } |
| # | Line 2864 for (;;) | Line 3924 for (;;) |
| 3924 | switch(ctype) | switch(ctype) |
| 3925 | { | { |
| 3926 | 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. */ | ||
| 3927 | if (max < INT_MAX) | if (max < INT_MAX) |
| 3928 | { | { |
| 3929 | 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 | ||
| 3930 | { | { |
| 3931 | for (i = min; i < max; i++) | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; |
| 3932 | { | eptr++; |
| 3933 | eptr++; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
| } | ||
| 3934 | } | } |
| 3935 | } | } |
| 3936 | ||
| # | Line 2894 for (;;) | Line 3938 for (;;) |
| 3938 | ||
| 3939 | else | else |
| 3940 | { | { |
| 3941 | if ((ims & PCRE_DOTALL) == 0) | for (i = min; i < max; i++) |
| 3942 | { | { |
| 3943 | for (i = min; i < max; i++) | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; |
| 3944 | { | eptr++; |
| 3945 | if (eptr >= md->end_subject || *eptr == NEWLINE) break; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| eptr++; | ||
| } | ||
| break; | ||
| 3946 | } | } |
| 3947 | else | } |
| 3948 | break; | |
| 3949 | ||
| 3950 | case OP_ALLANY: | |
| 3951 | if (max < INT_MAX) | |
| 3952 | { | |
| 3953 | for (i = min; i < max; i++) | |
| 3954 | { | { |
| 3955 | c = max - min; | if (eptr >= md->end_subject) break; |
| 3956 | if (c > md->end_subject - eptr) c = md->end_subject - eptr; | eptr++; |
| 3957 | eptr += c; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| 3958 | } | } |
| 3959 | } | } |
| 3960 | else eptr = md->end_subject; /* Unlimited UTF-8 repeat */ | |
| 3961 | break; | break; |
| 3962 | ||
| 3963 | /* The byte case is the same as non-UTF8 */ | /* The byte case is the same as non-UTF8 */ |
| 3964 | ||
| 3965 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 3966 | c = max - min; | c = max - min; |
| 3967 | if (c > md->end_subject - eptr) c = md->end_subject - eptr; | if (c > (unsigned int)(md->end_subject - eptr)) |
| 3968 | c = md->end_subject - eptr; | |
| 3969 | eptr += c; | eptr += c; |
| 3970 | break; | break; |
| 3971 | ||
| 3972 | case OP_ANYNL: | |
| 3973 | for (i = min; i < max; i++) | |
| 3974 | { | |
| 3975 | int len = 1; | |
| 3976 | if (eptr >= md->end_subject) break; | |
| 3977 | GETCHARLEN(c, eptr, len); | |
| 3978 | if (c == 0x000d) | |
| 3979 | { | |
| 3980 | if (++eptr >= md->end_subject) break; | |
| 3981 | if (*eptr == 0x000a) eptr++; | |
| 3982 | } | |
| 3983 | else | |
| 3984 | { | |
| 3985 | if (c != 0x000a && | |
| 3986 | (md->bsr_anycrlf || | |
| 3987 | (c != 0x000b && c != 0x000c && | |
| 3988 | c != 0x0085 && c != 0x2028 && c != 0x2029))) | |
| 3989 | break; | |
| 3990 | eptr += len; | |
| 3991 | } | |
| 3992 | } | |
| 3993 | break; | |
| 3994 | ||
| 3995 | case OP_NOT_HSPACE: | |
| 3996 | case OP_HSPACE: | |
| 3997 | for (i = min; i < max; i++) | |
| 3998 | { | |
| 3999 | BOOL gotspace; | |
| 4000 | int len = 1; | |
| 4001 | if (eptr >= md->end_subject) break; | |
| 4002 | GETCHARLEN(c, eptr, len); | |
| 4003 | switch(c) | |
| 4004 | { | |
| 4005 | default: gotspace = FALSE; break; | |
| 4006 | case 0x09: /* HT */ | |
| 4007 | case 0x20: /* SPACE */ | |
| 4008 | case 0xa0: /* NBSP */ | |
| 4009 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 4010 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 4011 | case 0x2000: /* EN QUAD */ | |
| 4012 | case 0x2001: /* EM QUAD */ | |
| 4013 | case 0x2002: /* EN SPACE */ | |
| 4014 | case 0x2003: /* EM SPACE */ | |
| 4015 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 4016 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 4017 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 4018 | case 0x2007: /* FIGURE SPACE */ | |
| 4019 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 4020 | case 0x2009: /* THIN SPACE */ | |
| 4021 | case 0x200A: /* HAIR SPACE */ | |
| 4022 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 4023 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 4024 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 4025 | gotspace = TRUE; | |
| 4026 | break; | |
| 4027 | } | |
| 4028 | if (gotspace == (ctype == OP_NOT_HSPACE)) break; | |
| 4029 | eptr += len; | |
| 4030 | } | |
| 4031 | break; | |
| 4032 | ||
| 4033 | case OP_NOT_VSPACE: | |
| 4034 | case OP_VSPACE: | |
| 4035 | for (i = min; i < max; i++) | |
| 4036 | { | |
| 4037 | BOOL gotspace; | |
| 4038 | int len = 1; | |
| 4039 | if (eptr >= md->end_subject) break; | |
| 4040 | GETCHARLEN(c, eptr, len); | |
| 4041 | switch(c) | |
| 4042 | { | |
| 4043 | default: gotspace = FALSE; break; | |
| 4044 | case 0x0a: /* LF */ | |
| 4045 | case 0x0b: /* VT */ | |
| 4046 | case 0x0c: /* FF */ | |
| 4047 | case 0x0d: /* CR */ | |
| 4048 | case 0x85: /* NEL */ | |
| 4049 | case 0x2028: /* LINE SEPARATOR */ | |
| 4050 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 4051 | gotspace = TRUE; | |
| 4052 | break; | |
| 4053 | } | |
| 4054 | if (gotspace == (ctype == OP_NOT_VSPACE)) break; | |
| 4055 | eptr += len; | |
| 4056 | } | |
| 4057 | break; | |
| 4058 | ||
| 4059 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 4060 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 4061 | { | { |
| # | Line 2992 for (;;) | Line 4128 for (;;) |
| 4128 | ||
| 4129 | /* eptr is now past the end of the maximum run */ | /* eptr is now past the end of the maximum run */ |
| 4130 | ||
| 4131 | if (possessive) continue; | |
| 4132 | for(;;) | for(;;) |
| 4133 | { | { |
| 4134 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46); |
| 4135 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4136 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 4137 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| 4138 | } | } |
| 4139 | } | } |
| 4140 | else | else |
| 4141 | #endif | #endif /* SUPPORT_UTF8 */ |
| 4142 | ||
| 4143 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
| 4144 | { | { |
| 4145 | switch(ctype) | switch(ctype) |
| 4146 | { | { |
| 4147 | case OP_ANY: | case OP_ANY: |
| 4148 | if ((ims & PCRE_DOTALL) == 0) | for (i = min; i < max; i++) |
| 4149 | { | { |
| 4150 | for (i = min; i < max; i++) | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; |
| 4151 | { | eptr++; |
| if (eptr >= md->end_subject || *eptr == NEWLINE) break; | ||
| eptr++; | ||
| } | ||
| break; | ||
| 4152 | } | } |
| 4153 | /* For DOTALL case, fall through and treat as \C */ | break; |
| 4154 | ||
| 4155 | case OP_ALLANY: | |
| 4156 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 4157 | c = max - min; | c = max - min; |
| 4158 | if (c > md->end_subject - eptr) c = md->end_subject - eptr; | if (c > (unsigned int)(md->end_subject - eptr)) |
| 4159 | c = md->end_subject - eptr; | |
| 4160 | eptr += c; | eptr += c; |
| 4161 | break; | break; |
| 4162 | ||
| 4163 | case OP_ANYNL: | |
| 4164 | for (i = min; i < max; i++) | |
| 4165 | { | |
| 4166 | if (eptr >= md->end_subject) break; | |
| 4167 | c = *eptr; | |
| 4168 | if (c == 0x000d) | |
| 4169 | { | |
| 4170 | if (++eptr >= md->end_subject) break; | |
| 4171 | if (*eptr == 0x000a) eptr++; | |
| 4172 | } | |
| 4173 | else | |
| 4174 | { | |
| 4175 | if (c != 0x000a && | |
| 4176 | (md->bsr_anycrlf || | |
| 4177 | (c != 0x000b && c != 0x000c && c != 0x0085))) | |
| 4178 | break; | |
| 4179 | eptr++; | |
| 4180 | } | |
| 4181 | } | |
| 4182 | break; | |
| 4183 | ||
| 4184 | case OP_NOT_HSPACE: | |
| 4185 | for (i = min; i < max; i++) | |
| 4186 | { | |
| 4187 | if (eptr >= md->end_subject) break; | |
| 4188 | c = *eptr; | |
| 4189 | if (c == 0x09 || c == 0x20 || c == 0xa0) break; | |
| 4190 | eptr++; | |
| 4191 | } | |
| 4192 | break; | |
| 4193 | ||
| 4194 | case OP_HSPACE: | |
| 4195 | for (i = min; i < max; i++) | |
| 4196 | { | |
| 4197 | if (eptr >= md->end_subject) break; | |
| 4198 | c = *eptr; | |
| 4199 | if (c != 0x09 && c != 0x20 && c != 0xa0) break; | |
| 4200 | eptr++; | |
| 4201 | } | |
| 4202 | break; | |
| 4203 | ||
| 4204 | case OP_NOT_VSPACE: | |
| 4205 | for (i = min; i < max; i++) | |
| 4206 | { | |
| 4207 | if (eptr >= md->end_subject) break; | |
| 4208 | c = *eptr; | |
| 4209 | if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85) | |
| 4210 | break; | |
| 4211 | eptr++; | |
| 4212 | } | |
| 4213 | break; | |
| 4214 | ||
| 4215 | case OP_VSPACE: | |
| 4216 | for (i = min; i < max; i++) | |
| 4217 | { | |
| 4218 | if (eptr >= md->end_subject) break; | |
| 4219 | c = *eptr; | |
| 4220 | if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85) | |
| 4221 | break; | |
| 4222 | eptr++; | |
| 4223 | } | |
| 4224 | break; | |
| 4225 | ||
| 4226 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 4227 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 4228 | { | { |
| # | Line 3085 for (;;) | Line 4283 for (;;) |
| 4283 | ||
| 4284 | /* eptr is now past the end of the maximum run */ | /* eptr is now past the end of the maximum run */ |
| 4285 | ||
| 4286 | if (possessive) continue; | |
| 4287 | while (eptr >= pp) | while (eptr >= pp) |
| 4288 | { | { |
| 4289 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47); |
| 4290 | eptr--; | eptr--; |
| 4291 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4292 | } | } |
| # | Line 3099 for (;;) | Line 4298 for (;;) |
| 4298 | } | } |
| 4299 | /* Control never gets here */ | /* Control never gets here */ |
| 4300 | ||
| 4301 | /* 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 |
| 4302 | 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. */ | ||
| 4303 | ||
| 4304 | default: | default: |
| 4305 | DPRINTF(("Unknown opcode %d\n", *ecode)); | DPRINTF(("Unknown opcode %d\n", *ecode)); |
| 4306 | RRETURN(PCRE_ERROR_UNKNOWN_NODE); | RRETURN(PCRE_ERROR_UNKNOWN_OPCODE); |
| 4307 | } | } |
| 4308 | ||
| 4309 | /* 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 4312 for (;;) |
| 4312 | ||
| 4313 | } /* End of main loop */ | } /* End of main loop */ |
| 4314 | /* Control never reaches here */ | /* Control never reaches here */ |
| 4315 | ||
| 4316 | ||
| 4317 | /* When compiling to use the heap rather than the stack for recursive calls to | |
| 4318 | match(), the RRETURN() macro jumps here. The number that is saved in | |
| 4319 | frame->Xwhere indicates which label we actually want to return to. */ | |
| 4320 | ||
| 4321 | #ifdef NO_RECURSE | |
| 4322 | #define LBL(val) case val: goto L_RM##val; | |
| 4323 | HEAP_RETURN: | |
| 4324 | switch (frame->Xwhere) | |
| 4325 | { | |
| 4326 | LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8) | |
| 4327 | LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17) | |
| 4328 | LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33) | |
| 4329 | LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52) | |
| 4330 | LBL(53) LBL(54) | |
| 4331 | #ifdef SUPPORT_UTF8 | |
| 4332 | LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30) | |
| 4333 | LBL(32) LBL(34) LBL(42) LBL(46) | |
| 4334 | #ifdef SUPPORT_UCP | |
| 4335 | LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45) | |
| 4336 | #endif /* SUPPORT_UCP */ | |
| 4337 | #endif /* SUPPORT_UTF8 */ | |
| 4338 | default: | |
| 4339 | DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere)); | |
| 4340 | return PCRE_ERROR_INTERNAL; | |
| 4341 | } | |
| 4342 | #undef LBL | |
| 4343 | #endif /* NO_RECURSE */ | |
| 4344 | } | } |
| 4345 | ||
| 4346 | ||
| # | Line 3127 Undefine all the macros that were define | Line 4353 Undefine all the macros that were define |
| 4353 | #ifdef NO_RECURSE | #ifdef NO_RECURSE |
| 4354 | #undef eptr | #undef eptr |
| 4355 | #undef ecode | #undef ecode |
| 4356 | #undef mstart | |
| 4357 | #undef offset_top | #undef offset_top |
| 4358 | #undef ims | #undef ims |
| 4359 | #undef eptrb | #undef eptrb |
| # | Line 3144 Undefine all the macros that were define | Line 4371 Undefine all the macros that were define |
| 4371 | ||
| 4372 | #undef cur_is_word | #undef cur_is_word |
| 4373 | #undef condition | #undef condition |
| #undef minimize | ||
| 4374 | #undef prev_is_word | #undef prev_is_word |
| 4375 | ||
| 4376 | #undef original_ims | #undef original_ims |
| # | Line 3200 Returns: > 0 => success; value | Line 4426 Returns: > 0 => success; value |
| 4426 | < -1 => some kind of unexpected problem | < -1 => some kind of unexpected problem |
| 4427 | */ | */ |
| 4428 | ||
| 4429 | EXPORT int | PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
| 4430 | pcre_exec(const pcre *argument_re, const pcre_extra *extra_data, | pcre_exec(const pcre *argument_re, const pcre_extra *extra_data, |
| 4431 | const char *subject, int length, int start_offset, int options, int *offsets, | PCRE_SPTR subject, int length, int start_offset, int options, int *offsets, |
| 4432 | int offsetcount) | int offsetcount) |
| 4433 | { | { |
| 4434 | int rc, resetcount, ocount; | int rc, resetcount, ocount; |
| 4435 | int first_byte = -1; | int first_byte = -1; |
| 4436 | int req_byte = -1; | int req_byte = -1; |
| 4437 | int req_byte2 = -1; | int req_byte2 = -1; |
| 4438 | unsigned long int ims = 0; | int newline; |
| 4439 | unsigned long int ims; | |
| 4440 | BOOL using_temporary_offsets = FALSE; | BOOL using_temporary_offsets = FALSE; |
| 4441 | BOOL anchored; | BOOL anchored; |
| 4442 | BOOL startline; | BOOL startline; |
| 4443 | BOOL firstline; | BOOL firstline; |
| 4444 | BOOL first_byte_caseless = FALSE; | BOOL first_byte_caseless = FALSE; |
| 4445 | BOOL req_byte_caseless = FALSE; | BOOL req_byte_caseless = FALSE; |
| 4446 | BOOL utf8; | |
| 4447 | match_data match_block; | match_data match_block; |
| 4448 | match_data *md = &match_block; | |
| 4449 | const uschar *tables; | const uschar *tables; |
| 4450 | const uschar *start_bits = NULL; | const uschar *start_bits = NULL; |
| 4451 | const uschar *start_match = (const uschar *)subject + start_offset; | USPTR start_match = (USPTR)subject + start_offset; |
| 4452 | const uschar *end_subject; | USPTR end_subject; |
| 4453 | const uschar *req_byte_ptr = start_match - 1; | USPTR req_byte_ptr = start_match - 1; |
| 4454 | ||
| 4455 | pcre_study_data internal_study; | pcre_study_data internal_study; |
| 4456 | const pcre_study_data *study; | const pcre_study_data *study; |
| # | Line 3241 if (offsetcount < 0) return PCRE_ERROR_B | Line 4470 if (offsetcount < 0) return PCRE_ERROR_B |
| 4470 | the default values. */ | the default values. */ |
| 4471 | ||
| 4472 | study = NULL; | study = NULL; |
| 4473 | match_block.match_limit = MATCH_LIMIT; | md->match_limit = MATCH_LIMIT; |
| 4474 | match_block.callout_data = NULL; | md->match_limit_recursion = MATCH_LIMIT_RECURSION; |
| 4475 | md->callout_data = NULL; | |
| 4476 | ||
| 4477 | /* The table pointer is always in native byte order. */ | /* The table pointer is always in native byte order. */ |
| 4478 | ||
| # | Line 3254 if (extra_data != NULL) | Line 4484 if (extra_data != NULL) |
| 4484 | if ((flags & PCRE_EXTRA_STUDY_DATA) != 0) | if ((flags & PCRE_EXTRA_STUDY_DATA) != 0) |
| 4485 | study = (const pcre_study_data *)extra_data->study_data; | study = (const pcre_study_data *)extra_data->study_data; |
| 4486 | if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0) | if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0) |
| 4487 | match_block.match_limit = extra_data->match_limit; | md->match_limit = extra_data->match_limit; |
| 4488 | if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0) | |
| 4489 | md->match_limit_recursion = extra_data->match_limit_recursion; | |
| 4490 | if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0) | if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0) |
| 4491 | match_block.callout_data = extra_data->callout_data; | md->callout_data = extra_data->callout_data; |
| 4492 | if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables; | if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables; |
| 4493 | } | } |
| 4494 | ||
| # | Line 3281 if (re->magic_number != MAGIC_NUMBER) | Line 4513 if (re->magic_number != MAGIC_NUMBER) |
| 4513 | /* Set up other data */ | /* Set up other data */ |
| 4514 | ||
| 4515 | anchored = ((re->options | options) & PCRE_ANCHORED) != 0; | anchored = ((re->options | options) & PCRE_ANCHORED) != 0; |
| 4516 | startline = (re->options & PCRE_STARTLINE) != 0; | startline = (re->flags & PCRE_STARTLINE) != 0; |
| 4517 | firstline = (re->options & PCRE_FIRSTLINE) != 0; | firstline = (re->options & PCRE_FIRSTLINE) != 0; |
| 4518 | ||
| 4519 | /* 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. */ |
| 4520 | ||
| 4521 | match_block.start_code = (const uschar *)external_re + re->name_table_offset + | md->start_code = (const uschar *)external_re + re->name_table_offset + |
| 4522 | re->name_count * re->name_entry_size; | re->name_count * re->name_entry_size; |
| 4523 | ||
| 4524 | match_block.start_subject = (const uschar *)subject; | md->start_subject = (USPTR)subject; |
| 4525 | match_block.start_offset = start_offset; | md->start_offset = start_offset; |
| 4526 | match_block.end_subject = match_block.start_subject + length; | md->end_subject = md->start_subject + length; |
| 4527 | end_subject = match_block.end_subject; | end_subject = md->end_subject; |
| 4528 | ||
| 4529 | match_block.endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0; | md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0; |
| 4530 | match_block.utf8 = (re->options & PCRE_UTF8) != 0; | utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0; |
| 4531 | md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0; | |
| 4532 | match_block.notbol = (options & PCRE_NOTBOL) != 0; | |
| 4533 | match_block.noteol = (options & PCRE_NOTEOL) != 0; | md->notbol = (options & PCRE_NOTBOL) != 0; |
| 4534 | match_block.notempty = (options & PCRE_NOTEMPTY) != 0; | md->noteol = (options & PCRE_NOTEOL) != 0; |
| 4535 | match_block.partial = (options & PCRE_PARTIAL) != 0; | md->notempty = (options & PCRE_NOTEMPTY) != 0; |
| 4536 | match_block.hitend = FALSE; | md->partial = (options & PCRE_PARTIAL) != 0; |
| 4537 | md->hitend = FALSE; | |
| 4538 | ||
| 4539 | md->recursive = NULL; /* No recursion at top level */ | |
| 4540 | ||
| 4541 | md->lcc = tables + lcc_offset; | |
| 4542 | md->ctypes = tables + ctypes_offset; | |
| 4543 | ||
| 4544 | /* Handle different \R options. */ | |
| 4545 | ||
| 4546 | switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | |
| 4547 | { | |
| 4548 | case 0: | |
| 4549 | if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0) | |
| 4550 | md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0; | |
| 4551 | else | |
| 4552 | #ifdef BSR_ANYCRLF | |
| 4553 | md->bsr_anycrlf = TRUE; | |
| 4554 | #else | |
| 4555 | md->bsr_anycrlf = FALSE; | |
| 4556 | #endif | |
| 4557 | break; | |
| 4558 | ||
| 4559 | match_block.recursive = NULL; /* No recursion at top level */ | case PCRE_BSR_ANYCRLF: |
| 4560 | md->bsr_anycrlf = TRUE; | |
| 4561 | break; | |
| 4562 | ||
| 4563 | match_block.lcc = tables + lcc_offset; | case PCRE_BSR_UNICODE: |
| 4564 | match_block.ctypes = tables + ctypes_offset; | md->bsr_anycrlf = FALSE; |
| 4565 | break; | |
| 4566 | ||
| 4567 | default: return PCRE_ERROR_BADNEWLINE; | |
| 4568 | } | |
| 4569 | ||
| 4570 | /* Handle different types of newline. The three bits give eight cases. If | |
| 4571 | nothing is set at run time, whatever was used at compile time applies. */ | |
| 4572 | ||
| 4573 | switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : | |
| 4574 | (pcre_uint32)options) & PCRE_NEWLINE_BITS) | |
| 4575 | { | |
| 4576 | case 0: newline = NEWLINE; break; /* Compile-time default */ | |
| 4577 | case PCRE_NEWLINE_CR: newline = CHAR_CR; break; | |
| 4578 | case PCRE_NEWLINE_LF: newline = CHAR_NL; break; | |
| 4579 | case PCRE_NEWLINE_CR+ | |
| 4580 | PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break; | |
| 4581 | case PCRE_NEWLINE_ANY: newline = -1; break; | |
| 4582 | case PCRE_NEWLINE_ANYCRLF: newline = -2; break; | |
| 4583 | default: return PCRE_ERROR_BADNEWLINE; | |
| 4584 | } | |
| 4585 | ||
| 4586 | if (newline == -2) | |
| 4587 | { | |
| 4588 | md->nltype = NLTYPE_ANYCRLF; | |
| 4589 | } | |
| 4590 | else if (newline < 0) | |
| 4591 | { | |
| 4592 | md->nltype = NLTYPE_ANY; | |
| 4593 | } | |
| 4594 | else | |
| 4595 | { | |
| 4596 | md->nltype = NLTYPE_FIXED; | |
| 4597 | if (newline > 255) | |
| 4598 | { | |
| 4599 | md->nllen = 2; | |
| 4600 | md->nl[0] = (newline >> 8) & 255; | |
| 4601 | md->nl[1] = newline & 255; | |
| 4602 | } | |
| 4603 | else | |
| 4604 | { | |
| 4605 | md->nllen = 1; | |
| 4606 | md->nl[0] = newline; | |
| 4607 | } | |
| 4608 | } | |
| 4609 | ||
| 4610 | /* 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 |
| 4611 | moment. */ | moment. */ |
| 4612 | ||
| 4613 | if (match_block.partial && (re->options & PCRE_NOPARTIAL) != 0) | if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0) |
| 4614 | return PCRE_ERROR_BADPARTIAL; | return PCRE_ERROR_BADPARTIAL; |
| 4615 | ||
| 4616 | /* 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 |
| 4617 | back the character offset. */ | back the character offset. */ |
| 4618 | ||
| 4619 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 4620 | if (match_block.utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) | if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) |
| 4621 | { | { |
| 4622 | if (_pcre_valid_utf8((uschar *)subject, length) >= 0) | if (_pcre_valid_utf8((uschar *)subject, length) >= 0) |
| 4623 | return PCRE_ERROR_BADUTF8; | return PCRE_ERROR_BADUTF8; |
| # | Line 3350 ocount = offsetcount - (offsetcount % 3) | Line 4649 ocount = offsetcount - (offsetcount % 3) |
| 4649 | if (re->top_backref > 0 && re->top_backref >= ocount/3) | if (re->top_backref > 0 && re->top_backref >= ocount/3) |
| 4650 | { | { |
| 4651 | ocount = re->top_backref * 3 + 3; | ocount = re->top_backref * 3 + 3; |
| 4652 | match_block.offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int)); | md->offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int)); |
| 4653 | if (match_block.offset_vector == NULL) return PCRE_ERROR_NOMEMORY; | if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY; |
| 4654 | using_temporary_offsets = TRUE; | using_temporary_offsets = TRUE; |
| 4655 | DPRINTF(("Got memory to hold back references\n")); | DPRINTF(("Got memory to hold back references\n")); |
| 4656 | } | } |
| 4657 | else match_block.offset_vector = offsets; | else md->offset_vector = offsets; |
| 4658 | ||
| 4659 | match_block.offset_end = ocount; | md->offset_end = ocount; |
| 4660 | match_block.offset_max = (2*ocount)/3; | md->offset_max = (2*ocount)/3; |
| 4661 | match_block.offset_overflow = FALSE; | md->offset_overflow = FALSE; |
| 4662 | match_block.capture_last = -1; | md->capture_last = -1; |
| 4663 | ||
| 4664 | /* Compute the minimum number of offsets that we need to reset each time. Doing | /* Compute the minimum number of offsets that we need to reset each time. Doing |
| 4665 | this makes a huge difference to execution time when there aren't many brackets | this makes a huge difference to execution time when there aren't many brackets |
| # | Line 3373 if (resetcount > offsetcount) resetcount | Line 4672 if (resetcount > offsetcount) resetcount |
| 4672 | never be used unless previously set, but they get saved and restored, and so we | never be used unless previously set, but they get saved and restored, and so we |
| 4673 | initialize them to avoid reading uninitialized locations. */ | initialize them to avoid reading uninitialized locations. */ |
| 4674 | ||
| 4675 | if (match_block.offset_vector != NULL) | if (md->offset_vector != NULL) |
| 4676 | { | { |
| 4677 | register int *iptr = match_block.offset_vector + ocount; | register int *iptr = md->offset_vector + ocount; |
| 4678 | register int *iend = iptr - resetcount/2 + 1; | register int *iend = iptr - resetcount/2 + 1; |
| 4679 | while (--iptr >= iend) *iptr = -1; | while (--iptr >= iend) *iptr = -1; |
| 4680 | } | } |
| # | Line 3388 studied, there may be a bitmap of possib | Line 4687 studied, there may be a bitmap of possib |
| 4687 | ||
| 4688 | if (!anchored) | if (!anchored) |
| 4689 | { | { |
| 4690 | if ((re->options & PCRE_FIRSTSET) != 0) | if ((re->flags & PCRE_FIRSTSET) != 0) |
| 4691 | { | { |
| 4692 | first_byte = re->first_byte & 255; | first_byte = re->first_byte & 255; |
| 4693 | if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) | if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) |
| 4694 | first_byte = match_block.lcc[first_byte]; | first_byte = md->lcc[first_byte]; |
| 4695 | } | } |
| 4696 | else | else |
| 4697 | if (!startline && study != NULL && | if (!startline && study != NULL && |
| # | Line 3403 if (!anchored) | Line 4702 if (!anchored) |
| 4702 | /* For anchored or unanchored matches, there may be a "last known required | /* For anchored or unanchored matches, there may be a "last known required |
| 4703 | character" set. */ | character" set. */ |
| 4704 | ||
| 4705 | if ((re->options & PCRE_REQCHSET) != 0) | if ((re->flags & PCRE_REQCHSET) != 0) |
| 4706 | { | { |
| 4707 | req_byte = re->req_byte & 255; | req_byte = re->req_byte & 255; |
| 4708 | req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; | req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; |
| 4709 | req_byte2 = (tables + fcc_offset)[req_byte]; /* case flipped */ | req_byte2 = (tables + fcc_offset)[req_byte]; /* case flipped */ |
| 4710 | } | } |
| 4711 | ||
| 4712 | ||
| 4713 | /* ==========================================================================*/ | |
| 4714 | ||
| 4715 | /* Loop for handling unanchored repeated matching attempts; for anchored regexs | /* Loop for handling unanchored repeated matching attempts; for anchored regexs |
| 4716 | the loop runs just once. */ | the loop runs just once. */ |
| 4717 | ||
| 4718 | do | for(;;) |
| 4719 | { | { |
| 4720 | const uschar *save_end_subject = end_subject; | USPTR save_end_subject = end_subject; |
| 4721 | USPTR new_start_match; | |
| 4722 | ||
| 4723 | /* Reset the maximum number of extractions we might see. */ | /* Reset the maximum number of extractions we might see. */ |
| 4724 | ||
| 4725 | if (match_block.offset_vector != NULL) | if (md->offset_vector != NULL) |
| 4726 | { | { |
| 4727 | register int *iptr = match_block.offset_vector; | register int *iptr = md->offset_vector; |
| 4728 | register int *iend = iptr + resetcount; | register int *iend = iptr + resetcount; |
| 4729 | while (iptr < iend) *iptr++ = -1; | while (iptr < iend) *iptr++ = -1; |
| 4730 | } | } |
| 4731 | ||
| 4732 | /* Advance to a unique first char if possible. If firstline is TRUE, the | /* If firstline is TRUE, the start of the match is constrained to the first |
| 4733 | start of the match is constrained to the first line of a multiline string. | line of a multiline string. That is, the match must be before or at the first |
| 4734 | Implement this by temporarily adjusting end_subject so that we stop scanning | newline. Implement this by temporarily adjusting end_subject so that we stop |
| 4735 | at a newline. If the match fails at the newline, later code breaks this loop. | scanning at a newline. If the match fails at the newline, later code breaks |
| 4736 | */ | this loop. */ |
| 4737 | ||
| 4738 | if (firstline) | if (firstline) |
| 4739 | { | { |
| 4740 | const uschar *t = start_match; | USPTR t = start_match; |
| 4741 | while (t < save_end_subject && *t != '\n') t++; | #ifdef SUPPORT_UTF8 |
| 4742 | if (utf8) | |
| 4743 | { | |
| 4744 | while (t < md->end_subject && !IS_NEWLINE(t)) | |
| 4745 | { | |
| 4746 | t++; | |
| 4747 | while (t < end_subject && (*t & 0xc0) == 0x80) t++; | |
| 4748 | } | |
| 4749 | } | |
| 4750 | else | |
| 4751 | #endif | |
| 4752 | while (t < md->end_subject && !IS_NEWLINE(t)) t++; | |
| 4753 | end_subject = t; | end_subject = t; |
| 4754 | } | } |
| 4755 | ||
| 4756 | /* Now test for a unique first byte */ | /* There are some optimizations that avoid running the match if a known |
| 4757 | starting point is not found, or if a known later character is not present. | |
| 4758 | However, there is an option that disables these, for testing and for ensuring | |
| 4759 | that all callouts do actually occur. */ | |
| 4760 | ||
| 4761 | if (first_byte >= 0) | if ((options & PCRE_NO_START_OPTIMIZE) == 0) |
| 4762 | { | { |
| 4763 | if (first_byte_caseless) | /* Advance to a unique first byte if there is one. */ |
| while (start_match < end_subject && | ||
| match_block.lcc[*start_match] != first_byte) | ||
| start_match++; | ||
| else | ||
| while (start_match < end_subject && *start_match != first_byte) | ||
| start_match++; | ||
| } | ||
| 4764 | ||
| 4765 | /* Or to just after \n for a multiline match if possible */ | if (first_byte >= 0) |
| 4766 | { | |
| 4767 | if (first_byte_caseless) | |
| 4768 | while (start_match < end_subject && md->lcc[*start_match] != first_byte) | |
| 4769 | start_match++; | |
| 4770 | else | |
| 4771 | while (start_match < end_subject && *start_match != first_byte) | |
| 4772 | start_match++; | |
| 4773 | } | |
| 4774 | ||
| 4775 | else if (startline) | /* Or to just after a linebreak for a multiline match */ |
| 4776 | { | |
| 4777 | if (start_match > match_block.start_subject + start_offset) | else if (startline) |
| 4778 | { | { |
| 4779 | while (start_match < end_subject && start_match[-1] != NEWLINE) | if (start_match > md->start_subject + start_offset) |
| 4780 | start_match++; | { |
| 4781 | #ifdef SUPPORT_UTF8 | |
| 4782 | if (utf8) | |
| 4783 | { | |
| 4784 | while (start_match < end_subject && !WAS_NEWLINE(start_match)) | |
| 4785 | { | |
| 4786 | start_match++; | |
| 4787 | while(start_match < end_subject && (*start_match & 0xc0) == 0x80) | |
| 4788 | start_match++; | |
| 4789 | } | |
| 4790 | } | |
| 4791 | else | |
| 4792 | #endif | |
| 4793 | while (start_match < end_subject && !WAS_NEWLINE(start_match)) | |
| 4794 | start_match++; | |
| 4795 | ||
| 4796 | /* If we have just passed a CR and the newline option is ANY or ANYCRLF, | |
| 4797 | and we are now at a LF, advance the match position by one more character. | |
| 4798 | */ | |
| 4799 | ||
| 4800 | if (start_match[-1] == CHAR_CR && | |
| 4801 | (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) && | |
| 4802 | start_match < end_subject && | |
| 4803 | *start_match == CHAR_NL) | |
| 4804 | start_match++; | |
| 4805 | } | |
| 4806 | } | } |
| } | ||
| 4807 | ||
| 4808 | /* Or to a non-unique first char after study */ | /* Or to a non-unique first byte after study */ |
| 4809 | ||
| 4810 | else if (start_bits != NULL) | else if (start_bits != NULL) |
| { | ||
| while (start_match < end_subject) | ||
| 4811 | { | { |
| 4812 | register unsigned int c = *start_match; | while (start_match < end_subject) |
| 4813 | if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break; | { |
| 4814 | register unsigned int c = *start_match; | |
| 4815 | if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; | |
| 4816 | else break; | |
| 4817 | } | |
| 4818 | } | } |
| 4819 | } | } /* Starting optimizations */ |
| 4820 | ||
| 4821 | /* Restore fudged end_subject */ | /* Restore fudged end_subject */ |
| 4822 | ||
| # | Line 3480 do | Line 4824 do |
| 4824 | ||
| 4825 | #ifdef DEBUG /* Sigh. Some compilers never learn. */ | #ifdef DEBUG /* Sigh. Some compilers never learn. */ |
| 4826 | printf(">>>> Match against: "); | printf(">>>> Match against: "); |
| 4827 | pchars(start_match, end_subject - start_match, TRUE, &match_block); | pchars(start_match, end_subject - start_match, TRUE, md); |
| 4828 | printf("\n"); | printf("\n"); |
| 4829 | #endif | #endif |
| 4830 | ||
| 4831 | /* If req_byte is set, we know that that character must appear in the subject | /* If req_byte is set, we know that that character must appear in the |
| 4832 | for the match to succeed. If the first character is set, req_byte must be | subject for the match to succeed. If the first character is set, req_byte |
| 4833 | later in the subject; otherwise the test starts at the match point. This | must be later in the subject; otherwise the test starts at the match point. |
| 4834 | optimization can save a huge amount of backtracking in patterns with nested | This optimization can save a huge amount of backtracking in patterns with |
| 4835 | unlimited repeats that aren't going to match. Writing separate code for | nested unlimited repeats that aren't going to match. Writing separate code |
| 4836 | cased/caseless versions makes it go faster, as does using an autoincrement | for cased/caseless versions makes it go faster, as does using an |
| 4837 | and backing off on a match. | autoincrement and backing off on a match. |
| 4838 | ||
| 4839 | HOWEVER: when the subject string is very, very long, searching to its end can | HOWEVER: when the subject string is very, very long, searching to its end |
| 4840 | take a long time, and give bad performance on quite ordinary patterns. This | can take a long time, and give bad performance on quite ordinary patterns. |
| 4841 | showed up when somebody was matching /^C/ on a 32-megabyte string... so we | This showed up when somebody was matching something like /^\d+C/ on a |
| 4842 | don't do this when the string is sufficiently long. | 32-megabyte string... so we don't do this when the string is sufficiently |
| 4843 | long. | |
| 4844 | ||
| 4845 | ALSO: this processing is disabled when partial matching is requested. | ALSO: this processing is disabled when partial matching is requested, or if |
| 4846 | */ | disabling is explicitly requested. */ |
| 4847 | ||
| 4848 | if (req_byte >= 0 && | if ((options & PCRE_NO_START_OPTIMIZE) == 0 && |
| 4849 | req_byte >= 0 && | |
| 4850 | end_subject - start_match < REQ_BYTE_MAX && | end_subject - start_match < REQ_BYTE_MAX && |
| 4851 | !match_block.partial) | !md->partial) |
| 4852 | { | { |
| 4853 | register const uschar *p = start_match + ((first_byte >= 0)? 1 : 0); | register USPTR p = start_match + ((first_byte >= 0)? 1 : 0); |
| 4854 | ||
| 4855 | /* We don't need to repeat the search if we haven't yet reached the | /* We don't need to repeat the search if we haven't yet reached the |
| 4856 | place we found it at last time. */ | place we found it at last time. */ |
| # | Line 3527 do | Line 4873 do |
| 4873 | } | } |
| 4874 | } | } |
| 4875 | ||
| 4876 | /* If we can't find the required character, break the matching loop */ | /* If we can't find the required character, break the matching loop, |
| 4877 | forcing a match failure. */ | |
| 4878 | ||
| 4879 | if (p >= end_subject) break; | if (p >= end_subject) |
| 4880 | { | |
| 4881 | rc = MATCH_NOMATCH; | |
| 4882 | break; | |
| 4883 | } | |
| 4884 | ||
| 4885 | /* If we have found the required character, save the point where we | /* If we have found the required character, save the point where we |
| 4886 | found it, so that we don't search again next time round the loop if | found it, so that we don't search again next time round the loop if |
| # | Line 3539 do | Line 4890 do |
| 4890 | } | } |
| 4891 | } | } |
| 4892 | ||
| 4893 | /* When a match occurs, substrings will be set for all internal extractions; | /* OK, we can now run the match. */ |
| 4894 | we just need to set up the whole thing as substring 0 before returning. If | |
| 4895 | there were too many extractions, set the return code to zero. In the case | md->start_match_ptr = start_match; |
| 4896 | where we had to get some local store to hold offsets for backreferences, copy | md->match_call_count = 0; |
| 4897 | those back references that we can. In this case there need not be overflow | rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0); |
| if certain parts of the pattern were not used. */ | ||
| match_block.start_match = start_match; | ||
| match_block.match_call_count = 0; | ||
| rc = match(start_match, match_block.start_code, 2, &match_block, ims, NULL, | ||
| match_isgroup); | ||
| /* When the result is no match, if the subject's first character was a | ||
| newline and the PCRE_FIRSTLINE option is set, break (which will return | ||
| PCRE_ERROR_NOMATCH). The option requests that a match occur before the first | ||
| newline in the subject. Otherwise, advance the pointer to the next character | ||
| and continue - but the continuation will actually happen only when the | ||
| pattern is not anchored. */ | ||
| 4898 | ||
| 4899 | if (rc == MATCH_NOMATCH) | switch(rc) |
| 4900 |