Parent Directory
|
Revision Log
|
Patch
| revision 91 by nigel, Sat Feb 24 21:41:34 2007 UTC | revision 476 by ph10, Sun Jan 3 15:37:24 2010 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-2006 University of Cambridge | Copyright (c) 1997-2010 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 | #define NLBLOCK md /* The block containing newline information */ | #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; | ||
| USPTR 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 81 static const char rep_max[] = { 0, 0, 0, | Line 89 static const char rep_max[] = { 0, 0, 0, |
| 89 | ||
| 90 | ||
| 91 | ||
| 92 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
| 93 | /************************************************* | /************************************************* |
| 94 | * Debugging function to print chars * | * Debugging function to print chars * |
| 95 | *************************************************/ | *************************************************/ |
| # | 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 133 match_ref(int offset, register USPTR ept | Line 141 match_ref(int offset, register USPTR ept |
| 141 | { | { |
| 142 | USPTR p = md->start_subject + md->offset_vector[offset]; | USPTR p = md->start_subject + md->offset_vector[offset]; |
| 143 | ||
| 144 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
| 145 | if (eptr >= md->end_subject) | if (eptr >= md->end_subject) |
| 146 | printf("matching subject <null>"); | printf("matching subject <null>"); |
| 147 | else | else |
| # | 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 186 calls by keeping local variables that ne | Line 220 calls by keeping local variables that ne |
| 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 | 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 | /* These versions of the macros use the stack, as normal. There are debugging |
| 251 | versions and production versions. */ | 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 | #ifdef DEBUG | |
| 257 | #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \ | #ifdef PCRE_DEBUG |
| 258 | #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \ | |
| 259 | { \ | { \ |
| 260 | printf("match() called in line %d\n", __LINE__); \ | printf("match() called in line %d\n", __LINE__); \ |
| 261 | rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \ | rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \ |
| 262 | printf("to line %d\n", __LINE__); \ | printf("to line %d\n", __LINE__); \ |
| 263 | } | } |
| 264 | #define RRETURN(ra) \ | #define RRETURN(ra) \ |
| # | Line 208 versions and production versions. */ | Line 267 versions and production versions. */ |
| 267 | return ra; \ | return ra; \ |
| 268 | } | } |
| 269 | #else | #else |
| 270 | #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \ | #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \ |
| 271 | rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1) | 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 | #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->Xrdepth = frame->Xrdepth + 1;\ | newframe->Xrdepth = frame->Xrdepth + 1;\ |
| 296 | newframe->Xprevframe = frame;\ | newframe->Xprevframe = frame;\ |
| 297 | frame = newframe;\ | frame = newframe;\ |
| 298 | DPRINTF(("restarting from line %d\n", __LINE__));\ | DPRINTF(("restarting from line %d\n", __LINE__));\ |
| 299 | goto HEAP_RECURSE;\ | goto HEAP_RECURSE;\ |
| 300 | }\ | L_##rw:\ |
| 301 | else\ | 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 254 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 269 typedef struct heapframe { | Line 322 typedef struct heapframe { |
| 322 | ||
| 323 | /* Function arguments that may change */ | /* Function arguments that may change */ |
| 324 | ||
| 325 | const uschar *Xeptr; | USPTR Xeptr; |
| 326 | const uschar *Xecode; | const uschar *Xecode; |
| 327 | USPTR Xmstart; | |
| 328 | int Xoffset_top; | int Xoffset_top; |
| 329 | long int Xims; | long int Xims; |
| 330 | eptrblock *Xeptrb; | eptrblock *Xeptrb; |
| # | Line 279 typedef struct heapframe { | Line 333 typedef struct heapframe { |
| 333 | ||
| 334 | /* Function local variables */ | /* Function local variables */ |
| 335 | ||
| 336 | const uschar *Xcallpat; | USPTR Xcallpat; |
| 337 | const uschar *Xcharptr; | #ifdef SUPPORT_UTF8 |
| 338 | const uschar *Xdata; | USPTR Xcharptr; |
| 339 | const uschar *Xnext; | #endif |
| 340 | const uschar *Xpp; | USPTR Xdata; |
| 341 | const uschar *Xprev; | USPTR Xnext; |
| 342 | const uschar *Xsaved_eptr; | USPTR Xpp; |
| 343 | USPTR Xprev; | |
| 344 | USPTR Xsaved_eptr; | |
| 345 | ||
| 346 | recursion_info Xnew_recursive; | recursion_info Xnew_recursive; |
| 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; |
| # | Line 303 typedef struct heapframe { | Line 358 typedef struct heapframe { |
| 358 | int Xprop_category; | int Xprop_category; |
| 359 | int Xprop_chartype; | int Xprop_chartype; |
| 360 | int Xprop_script; | int Xprop_script; |
| 361 | int *Xprop_test_variable; | int Xoclength; |
| 362 | 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 321 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 340 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 | ||
| 403 | /* These macros pack up tests that are used for partial matching, and which | |
| 404 | appears several times in the code. We set the "hit end" flag if the pointer is | |
| 405 | at the end of the subject and also past the start of the subject (i.e. | |
| 406 | something has been matched). For hard partial matching, we then return | |
| 407 | immediately. The second one is used when we already know we are past the end of | |
| 408 | the subject. */ | |
| 409 | ||
| 410 | #define CHECK_PARTIAL()\ | |
| 411 | if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\ | |
| 412 | {\ | |
| 413 | md->hitend = TRUE;\ | |
| 414 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\ | |
| 415 | } | |
| 416 | ||
| 417 | #define SCHECK_PARTIAL()\ | |
| 418 | if (md->partial != 0 && eptr > mstart)\ | |
| 419 | {\ | |
| 420 | md->hitend = TRUE;\ | |
| 421 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\ | |
| 422 | } | |
| 423 | ||
| 424 | Performance note: It might be tempting to extract commonly used fields from the | |
| 425 | md structure (e.g. utf8, end_subject) into individual variables to improve | /* Performance note: It might be tempting to extract commonly used fields from |
| 426 | the md structure (e.g. utf8, end_subject) into individual variables to improve | |
| 427 | performance. Tests using gcc on a SPARC disproved this; in the first case, it | performance. Tests using gcc on a SPARC disproved this; in the first case, it |
| 428 | made performance worse. | made performance worse. |
| 429 | ||
| 430 | Arguments: | Arguments: |
| 431 | eptr pointer in subject | eptr pointer to current character in subject |
| 432 | ecode position in code | ecode pointer to current position in compiled code |
| 433 | mstart pointer to the current match start position (can be modified | |
| 434 | by encountering \K) | |
| 435 | offset_top current top pointer | offset_top current top pointer |
| 436 | md pointer to "static" info for the match | md pointer to "static" info for the match |
| 437 | ims current /i, /m, and /s options | ims current /i, /m, and /s options |
| # | Line 362 Arguments: | Line 439 Arguments: |
| 439 | brackets - for testing for empty matches | brackets - for testing for empty matches |
| 440 | flags can contain | flags can contain |
| 441 | match_condassert - this is an assertion condition | match_condassert - this is an assertion condition |
| 442 | match_isgroup - this is the start of a bracketed group | match_cbegroup - this is the start of an unlimited repeat |
| 443 | group that can match an empty string | |
| 444 | rdepth the recursion depth | rdepth the recursion depth |
| 445 | ||
| 446 | Returns: MATCH_MATCH if matched ) these values are >= 0 | Returns: MATCH_MATCH if matched ) these values are >= 0 |
| # | Line 372 Returns: MATCH_MATCH if matched | Line 450 Returns: MATCH_MATCH if matched |
| 450 | */ | */ |
| 451 | ||
| 452 | static int | static int |
| 453 | match(REGISTER USPTR eptr, REGISTER const uschar *ecode, | match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart, |
| 454 | int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, | int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, |
| 455 | int flags, unsigned int rdepth) | int flags, unsigned int rdepth) |
| 456 | { | { |
| 457 | /* 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, |
| 458 | 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 |
| 459 | because they are used a lot in loops. */ | "register" because they are used a lot in loops. */ |
| 460 | ||
| 461 | register int rrc; /* Returns from recursive calls */ | register int rrc; /* Returns from recursive calls */ |
| 462 | register int i; /* Used for loops not involving calls to RMATCH() */ | register int i; /* Used for loops not involving calls to RMATCH() */ |
| 463 | register unsigned int c; /* Character values not kept over RMATCH() calls */ | register unsigned int c; /* Character values not kept over RMATCH() calls */ |
| 464 | register BOOL utf8; /* Local copy of UTF-8 flag for speed */ | register BOOL utf8; /* Local copy of UTF-8 flag for speed */ |
| 465 | ||
| 466 | BOOL minimize, possessive; /* Quantifier options */ | |
| 467 | int condcode; | |
| 468 | ||
| 469 | /* 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 |
| 470 | 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 |
| 471 | heap storage. Set up the top-level frame here; others are obtained from the | heap storage. Set up the top-level frame here; others are obtained from the |
| # | Line 398 frame->Xprevframe = NULL; /* | Line 479 frame->Xprevframe = NULL; /* |
| 479 | ||
| 480 | frame->Xeptr = eptr; | frame->Xeptr = eptr; |
| 481 | frame->Xecode = ecode; | frame->Xecode = ecode; |
| 482 | frame->Xmstart = mstart; | |
| 483 | frame->Xoffset_top = offset_top; | frame->Xoffset_top = offset_top; |
| 484 | frame->Xims = ims; | frame->Xims = ims; |
| 485 | frame->Xeptrb = eptrb; | frame->Xeptrb = eptrb; |
| # | Line 412 HEAP_RECURSE: | Line 494 HEAP_RECURSE: |
| 494 | ||
| 495 | #define eptr frame->Xeptr | #define eptr frame->Xeptr |
| 496 | #define ecode frame->Xecode | #define ecode frame->Xecode |
| 497 | #define mstart frame->Xmstart | |
| 498 | #define offset_top frame->Xoffset_top | #define offset_top frame->Xoffset_top |
| 499 | #define ims frame->Xims | #define ims frame->Xims |
| 500 | #define eptrb frame->Xeptrb | #define eptrb frame->Xeptrb |
| # | Line 424 HEAP_RECURSE: | Line 507 HEAP_RECURSE: |
| 507 | #define charptr frame->Xcharptr | #define charptr frame->Xcharptr |
| 508 | #endif | #endif |
| 509 | #define callpat frame->Xcallpat | #define callpat frame->Xcallpat |
| 510 | #define codelink frame->Xcodelink | |
| 511 | #define data frame->Xdata | #define data frame->Xdata |
| 512 | #define next frame->Xnext | #define next frame->Xnext |
| 513 | #define pp frame->Xpp | #define pp frame->Xpp |
| # | Line 434 HEAP_RECURSE: | Line 518 HEAP_RECURSE: |
| 518 | ||
| 519 | #define cur_is_word frame->Xcur_is_word | #define cur_is_word frame->Xcur_is_word |
| 520 | #define condition frame->Xcondition | #define condition frame->Xcondition |
| #define minimize frame->Xminimize | ||
| 521 | #define prev_is_word frame->Xprev_is_word | #define prev_is_word frame->Xprev_is_word |
| 522 | ||
| 523 | #define original_ims frame->Xoriginal_ims | #define original_ims frame->Xoriginal_ims |
| # | Line 446 HEAP_RECURSE: | Line 529 HEAP_RECURSE: |
| 529 | #define prop_category frame->Xprop_category | #define prop_category frame->Xprop_category |
| 530 | #define prop_chartype frame->Xprop_chartype | #define prop_chartype frame->Xprop_chartype |
| 531 | #define prop_script frame->Xprop_script | #define prop_script frame->Xprop_script |
| 532 | #define prop_test_variable frame->Xprop_test_variable | #define oclength frame->Xoclength |
| 533 | #define occhars frame->Xocchars | |
| 534 | #endif | #endif |
| 535 | ||
| 536 | #define ctype frame->Xctype | #define ctype frame->Xctype |
| # | Line 470 HEAP_RECURSE: | Line 554 HEAP_RECURSE: |
| 554 | 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 |
| 555 | i, and fc and c, can be the same variables. */ | i, and fc and c, can be the same variables. */ |
| 556 | ||
| 557 | #else | #else /* NO_RECURSE not defined */ |
| 558 | #define fi i | #define fi i |
| 559 | #define fc c | #define fc c |
| 560 | ||
| # | Line 489 recursion_info new_recursive; /* wi | Line 573 recursion_info new_recursive; /* wi |
| 573 | /* that do not have to be preserved over */ | /* that do not have to be preserved over */ |
| 574 | BOOL cur_is_word; /* a recursive call to RMATCH(). */ | BOOL cur_is_word; /* a recursive call to RMATCH(). */ |
| 575 | BOOL condition; | BOOL condition; |
| BOOL minimize; | ||
| 576 | BOOL prev_is_word; | BOOL prev_is_word; |
| 577 | ||
| 578 | unsigned long int original_ims; | unsigned long int original_ims; |
| # | Line 501 int prop_fail_result; | Line 584 int prop_fail_result; |
| 584 | int prop_category; | int prop_category; |
| 585 | int prop_chartype; | int prop_chartype; |
| 586 | int prop_script; | int prop_script; |
| 587 | int *prop_test_variable; | int oclength; |
| 588 | uschar occhars[8]; | |
| 589 | #endif | #endif |
| 590 | ||
| 591 | int codelink; | |
| 592 | int ctype; | int ctype; |
| 593 | int length; | int length; |
| 594 | int max; | int max; |
| # | Line 516 int save_offset1, save_offset2, save_off | Line 601 int save_offset1, save_offset2, save_off |
| 601 | int stacksave[REC_STACK_SAVE_MAX]; | int stacksave[REC_STACK_SAVE_MAX]; |
| 602 | ||
| 603 | eptrblock newptrb; | eptrblock newptrb; |
| 604 | #endif | #endif /* NO_RECURSE */ |
| 605 | ||
| 606 | /* These statements are here to stop the compiler complaining about unitialized | /* These statements are here to stop the compiler complaining about unitialized |
| 607 | variables. */ | variables. */ |
| # | Line 524 variables. */ | Line 609 variables. */ |
| 609 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 610 | prop_value = 0; | prop_value = 0; |
| 611 | prop_fail_result = 0; | prop_fail_result = 0; |
| prop_test_variable = NULL; | ||
| 612 | #endif | #endif |
| 613 | ||
| 614 | ||
| 615 | /* This label is used for tail recursion, which is used in a few cases even | /* This label is used for tail recursion, which is used in a few cases even |
| 616 | when NO_RECURSE is not defined, in order to reduce the amount of stack that is | when NO_RECURSE is not defined, in order to reduce the amount of stack that is |
| 617 | used. Thanks to Ian Taylor for noticing this possibility and sending the | used. Thanks to Ian Taylor for noticing this possibility and sending the |
| # | Line 537 TAIL_RECURSE: | Line 622 TAIL_RECURSE: |
| 622 | /* OK, now we can get on with the real code of the function. Recursive calls | /* OK, now we can get on with the real code of the function. Recursive calls |
| 623 | are specified by the macro RMATCH and RRETURN is used to return. When | are specified by the macro RMATCH and RRETURN is used to return. When |
| 624 | NO_RECURSE is *not* defined, these just turn into a recursive call to match() | NO_RECURSE is *not* defined, these just turn into a recursive call to match() |
| 625 | and a "return", respectively (possibly with some debugging if DEBUG is | and a "return", respectively (possibly with some debugging if PCRE_DEBUG is |
| 626 | defined). However, RMATCH isn't like a function call because it's quite a | defined). However, RMATCH isn't like a function call because it's quite a |
| 627 | complicated macro. It has to be used in one particular way. This shouldn't, | complicated macro. It has to be used in one particular way. This shouldn't, |
| 628 | however, impact performance when true recursion is being used. */ | however, impact performance when true recursion is being used. */ |
| 629 | ||
| 630 | #ifdef SUPPORT_UTF8 | |
| 631 | utf8 = md->utf8; /* Local copy of the flag */ | |
| 632 | #else | |
| 633 | utf8 = FALSE; | |
| 634 | #endif | |
| 635 | ||
| 636 | /* First check that we haven't called match() too many times, or that we | /* First check that we haven't called match() too many times, or that we |
| 637 | haven't exceeded the recursive call limit. */ | haven't exceeded the recursive call limit. */ |
| 638 | ||
| # | Line 550 if (rdepth >= md->match_limit_recursion) | Line 641 if (rdepth >= md->match_limit_recursion) |
| 641 | ||
| 642 | original_ims = ims; /* Save for resetting on ')' */ | original_ims = ims; /* Save for resetting on ')' */ |
| 643 | ||
| 644 | #ifdef SUPPORT_UTF8 | /* At the start of a group with an unlimited repeat that may match an empty |
| 645 | utf8 = md->utf8; /* Local copy of the flag */ | string, the match_cbegroup flag is set. When this is the case, add the current |
| 646 | #else | subject pointer to the chain of such remembered pointers, to be checked when we |
| 647 | utf8 = FALSE; | hit the closing ket, in order to break infinite loops that match no characters. |
| 648 | #endif | When match() is called in other circumstances, don't add to the chain. The |
| 649 | match_cbegroup flag must NOT be used with tail recursion, because the memory | |
| 650 | /* At the start of a bracketed group, add the current subject pointer to the | block that is used is on the stack, so a new one may be required for each |
| 651 | stack of such pointers, to be re-instated at the end of the group when we hit | match(). */ |
| the closing ket. When match() is called in other circumstances, we don't add to | ||
| this stack. */ | ||
| 652 | ||
| 653 | if ((flags & match_isgroup) != 0) | if ((flags & match_cbegroup) != 0) |
| 654 | { | { |
| newptrb.epb_prev = eptrb; | ||
| 655 | newptrb.epb_saved_eptr = eptr; | newptrb.epb_saved_eptr = eptr; |
| 656 | newptrb.epb_prev = eptrb; | |
| 657 | eptrb = &newptrb; | eptrb = &newptrb; |
| 658 | } | } |
| 659 | ||
| 660 | /* Now start processing the operations. */ | /* Now start processing the opcodes. */ |
| 661 | ||
| 662 | for (;;) | for (;;) |
| 663 | { | { |
| 664 | minimize = possessive = FALSE; | |
| 665 | op = *ecode; | op = *ecode; |
| minimize = FALSE; | ||
| /* For partial matching, remember if we ever hit the end of the subject after | ||
| matching at least one subject character. */ | ||
| 666 | ||
| 667 | if (md->partial && | switch(op) |
| eptr >= md->end_subject && | ||
| eptr > md->start_match) | ||
| md->hitend = TRUE; | ||
| /* Opening capturing bracket. If there is space in the offset vector, save | ||
| 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) | ||
| 668 | { | { |
| 669 | number = op - OP_BRA; | case OP_FAIL: |
| 670 | RRETURN(MATCH_NOMATCH); | |
| 671 | ||
| 672 | /* For extended extraction brackets (large number), we have to fish out the | case OP_PRUNE: |
| 673 | number from a dummy opcode at the start. */ | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, |
| 674 | ims, eptrb, flags, RM51); | |
| 675 | if (number > EXTRACT_BASIC_MAX) | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 676 | number = GET2(ecode, 2+LINK_SIZE); | RRETURN(MATCH_PRUNE); |
| 677 | ||
| 678 | case OP_COMMIT: | |
| 679 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 680 | ims, eptrb, flags, RM52); | |
| 681 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 682 | RRETURN(MATCH_COMMIT); | |
| 683 | ||
| 684 | case OP_SKIP: | |
| 685 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 686 | ims, eptrb, flags, RM53); | |
| 687 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 688 | md->start_match_ptr = eptr; /* Pass back current position */ | |
| 689 | RRETURN(MATCH_SKIP); | |
| 690 | ||
| 691 | case OP_THEN: | |
| 692 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
| 693 | ims, eptrb, flags, RM54); | |
| 694 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 695 | RRETURN(MATCH_THEN); | |
| 696 | ||
| 697 | /* Handle a capturing bracket. If there is space in the offset vector, save | |
| 698 | the current subject position in the working slot at the top of the vector. | |
| 699 | We mustn't change the current values of the data slot, because they may be | |
| 700 | set from a previous iteration of this group, and be referred to by a | |
| 701 | reference inside the group. | |
| 702 | ||
| 703 | If the bracket fails to match, we need to restore this value and also the | |
| 704 | values of the final offsets, in case they were set by a previous iteration | |
| 705 | of the same bracket. | |
| 706 | ||
| 707 | If there isn't enough space in the offset vector, treat this as if it were | |
| 708 | a non-capturing bracket. Don't worry about setting the flag for the error | |
| 709 | case here; that is handled in the code for KET. */ | |
| 710 | ||
| 711 | case OP_CBRA: | |
| 712 | case OP_SCBRA: | |
| 713 | number = GET2(ecode, 1+LINK_SIZE); | |
| 714 | offset = number << 1; | offset = number << 1; |
| 715 | ||
| 716 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
| 717 | printf("start bracket %d subject=", number); | printf("start bracket %d\n", number); |
| 718 | printf("subject="); | |
| 719 | pchars(eptr, 16, TRUE, md); | pchars(eptr, 16, TRUE, md); |
| 720 | printf("\n"); | printf("\n"); |
| 721 | #endif | #endif |
| # | Line 624 for (;;) | Line 730 for (;;) |
| 730 | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); |
| 731 | md->offset_vector[md->offset_end - number] = eptr - md->start_subject; | md->offset_vector[md->offset_end - number] = eptr - md->start_subject; |
| 732 | ||
| 733 | flags = (op == OP_SCBRA)? match_cbegroup : 0; | |
| 734 | do | do |
| 735 | { | { |
| 736 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, |
| 737 | match_isgroup); | ims, eptrb, flags, RM1); |
| 738 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 739 | md->capture_last = save_capture_last; | md->capture_last = save_capture_last; |
| 740 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 741 | } | } |
| # | Line 643 for (;;) | Line 750 for (;;) |
| 750 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 751 | } | } |
| 752 | ||
| 753 | /* Insufficient room for saving captured contents */ | /* FALL THROUGH ... Insufficient room for saving captured contents. Treat |
| 754 | as a non-capturing bracket. */ | |
| else op = OP_BRA; | ||
| } | ||
| /* Other types of node can be handled by a switch */ | ||
| 755 | ||
| 756 | switch(op) | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 757 | { | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| case OP_BRA: /* Non-capturing bracket: optimized */ | ||
| DPRINTF(("start bracket 0\n")); | ||
| 758 | ||
| 759 | /* Loop for all the alternatives */ | DPRINTF(("insufficient capture room: treat as non-capturing\n")); |
| 760 | ||
| 761 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
| 762 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
| 763 | ||
| 764 | /* Non-capturing bracket. Loop for all the alternatives. When we get to the | |
| 765 | final alternative within the brackets, we would return the result of a | |
| 766 | recursive call to match() whatever happened. We can reduce stack usage by | |
| 767 | turning this into a tail recursion, except in the case when match_cbegroup | |
| 768 | is set.*/ | |
| 769 | ||
| 770 | case OP_BRA: | |
| 771 | case OP_SBRA: | |
| 772 | DPRINTF(("start non-capturing bracket\n")); | |
| 773 | flags = (op >= OP_SBRA)? match_cbegroup : 0; | |
| 774 | for (;;) | for (;;) |
| 775 | { | { |
| 776 | /* When we get to the final alternative within the brackets, we would | if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */ |
| 777 | return the result of a recursive call to match() whatever happened. We | { |
| 778 | can reduce stack usage by turning this into a tail recursion. */ | if (flags == 0) /* Not a possibly empty group */ |
| 779 | { | |
| 780 | if (ecode[GET(ecode, 1)] != OP_ALT) | ecode += _pcre_OP_lengths[*ecode]; |
| 781 | { | DPRINTF(("bracket 0 tail recursion\n")); |
| 782 | ecode += 1 + LINK_SIZE; | goto TAIL_RECURSE; |
| 783 | flags = match_isgroup; | } |
| 784 | DPRINTF(("bracket 0 tail recursion\n")); | |
| 785 | goto TAIL_RECURSE; | /* Possibly empty group; can't use tail recursion. */ |
| 786 | } | |
| 787 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, | |
| 788 | eptrb, flags, RM48); | |
| 789 | RRETURN(rrc); | |
| 790 | } | |
| 791 | ||
| 792 | /* For non-final alternatives, continue the loop for a NOMATCH result; | /* For non-final alternatives, continue the loop for a NOMATCH result; |
| 793 | otherwise return. */ | otherwise return. */ |
| 794 | ||
| 795 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, |
| 796 | match_isgroup); | eptrb, flags, RM2); |
| 797 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 798 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 799 | } | } |
| 800 | /* Control never reaches here. */ | /* Control never reaches here. */ |
| # | Line 688 for (;;) | Line 806 for (;;) |
| 806 | obeyed, we can use tail recursion to avoid using another stack frame. */ | obeyed, we can use tail recursion to avoid using another stack frame. */ |
| 807 | ||
| 808 | case OP_COND: | case OP_COND: |
| 809 | if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */ | case OP_SCOND: |
| 810 | codelink= GET(ecode, 1); | |
| 811 | ||
| 812 | /* Because of the way auto-callout works during compile, a callout item is | |
| 813 | inserted between OP_COND and an assertion condition. */ | |
| 814 | ||
| 815 | if (ecode[LINK_SIZE+1] == OP_CALLOUT) | |
| 816 | { | |
| 817 | if (pcre_callout != NULL) | |
| 818 | { | |
| 819 | pcre_callout_block cb; | |
| 820 | cb.version = 1; /* Version 1 of the callout block */ | |
| 821 | cb.callout_number = ecode[LINK_SIZE+2]; | |
| 822 | cb.offset_vector = md->offset_vector; | |
| 823 | cb.subject = (PCRE_SPTR)md->start_subject; | |
| 824 | cb.subject_length = md->end_subject - md->start_subject; | |
| 825 | cb.start_match = mstart - md->start_subject; | |
| 826 | cb.current_position = eptr - md->start_subject; | |
| 827 | cb.pattern_position = GET(ecode, LINK_SIZE + 3); | |
| 828 | cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE); | |
| 829 | cb.capture_top = offset_top/2; | |
| 830 | cb.capture_last = md->capture_last; | |
| 831 | cb.callout_data = md->callout_data; | |
| 832 | if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH); | |
| 833 | if (rrc < 0) RRETURN(rrc); | |
| 834 | } | |
| 835 | ecode += _pcre_OP_lengths[OP_CALLOUT]; | |
| 836 | } | |
| 837 | ||
| 838 | condcode = ecode[LINK_SIZE+1]; | |
| 839 | ||
| 840 | /* Now see what the actual condition is */ | |
| 841 | ||
| 842 | if (condcode == OP_RREF || condcode == OP_NRREF) /* Recursion test */ | |
| 843 | { | |
| 844 | if (md->recursive == NULL) /* Not recursing => FALSE */ | |
| 845 | { | |
| 846 | condition = FALSE; | |
| 847 | ecode += GET(ecode, 1); | |
| 848 | } | |
| 849 | else | |
| 850 | { | |
| 851 | int recno = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ | |
| 852 | condition = (recno == RREF_ANY || recno == md->recursive->group_num); | |
| 853 | ||
| 854 | /* If the test is for recursion into a specific subpattern, and it is | |
| 855 | false, but the test was set up by name, scan the table to see if the | |
| 856 | name refers to any other numbers, and test them. The condition is true | |
| 857 | if any one is set. */ | |
| 858 | ||
| 859 | if (!condition && condcode == OP_NRREF && recno != RREF_ANY) | |
| 860 | { | |
| 861 | uschar *slotA = md->name_table; | |
| 862 | for (i = 0; i < md->name_count; i++) | |
| 863 | { | |
| 864 | if (GET2(slotA, 0) == recno) break; | |
| 865 | slotA += md->name_entry_size; | |
| 866 | } | |
| 867 | ||
| 868 | /* Found a name for the number - there can be only one; duplicate | |
| 869 | names for different numbers are allowed, but not vice versa. First | |
| 870 | scan down for duplicates. */ | |
| 871 | ||
| 872 | if (i < md->name_count) | |
| 873 | { | |
| 874 | uschar *slotB = slotA; | |
| 875 | while (slotB > md->name_table) | |
| 876 | { | |
| 877 | slotB -= md->name_entry_size; | |
| 878 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
| 879 | { | |
| 880 | condition = GET2(slotB, 0) == md->recursive->group_num; | |
| 881 | if (condition) break; | |
| 882 | } | |
| 883 | else break; | |
| 884 | } | |
| 885 | ||
| 886 | /* Scan up for duplicates */ | |
| 887 | ||
| 888 | if (!condition) | |
| 889 | { | |
| 890 | slotB = slotA; | |
| 891 | for (i++; i < md->name_count; i++) | |
| 892 | { | |
| 893 | slotB += md->name_entry_size; | |
| 894 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
| 895 | { | |
| 896 | condition = GET2(slotB, 0) == md->recursive->group_num; | |
| 897 | if (condition) break; | |
| 898 | } | |
| 899 | else break; | |
| 900 | } | |
| 901 | } | |
| 902 | } | |
| 903 | } | |
| 904 | ||
| 905 | /* Chose branch according to the condition */ | |
| 906 | ||
| 907 | ecode += condition? 3 : GET(ecode, 1); | |
| 908 | } | |
| 909 | } | |
| 910 | ||
| 911 | else if (condcode == OP_CREF || condcode == OP_NCREF) /* Group used test */ | |
| 912 | { | { |
| 913 | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ |
| 914 | condition = (offset == CREF_RECURSE * 2)? | condition = offset < offset_top && md->offset_vector[offset] >= 0; |
| 915 | (md->recursive != NULL) : | |
| 916 | (offset < offset_top && md->offset_vector[offset] >= 0); | /* If the numbered capture is unset, but the reference was by name, |
| 917 | ecode += condition? (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1)); | scan the table to see if the name refers to any other numbers, and test |
| 918 | flags = match_isgroup; | them. The condition is true if any one is set. This is tediously similar |
| 919 | goto TAIL_RECURSE; | to the code above, but not close enough to try to amalgamate. */ |
| 920 | ||
| 921 | if (!condition && condcode == OP_NCREF) | |
| 922 | { | |
| 923 | int refno = offset >> 1; | |
| 924 | uschar *slotA = md->name_table; | |
| 925 | ||
| 926 | for (i = 0; i < md->name_count; i++) | |
| 927 | { | |
| 928 | if (GET2(slotA, 0) == refno) break; | |
| 929 | slotA += md->name_entry_size; | |
| 930 | } | |
| 931 | ||
| 932 | /* Found a name for the number - there can be only one; duplicate names | |
| 933 | for different numbers are allowed, but not vice versa. First scan down | |
| 934 | for duplicates. */ | |
| 935 | ||
| 936 | if (i < md->name_count) | |
| 937 | { | |
| 938 | uschar *slotB = slotA; | |
| 939 | while (slotB > md->name_table) | |
| 940 | { | |
| 941 | slotB -= md->name_entry_size; | |
| 942 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
| 943 | { | |
| 944 | offset = GET2(slotB, 0) << 1; | |
| 945 | condition = offset < offset_top && | |
| 946 | md->offset_vector[offset] >= 0; | |
| 947 | if (condition) break; | |
| 948 | } | |
| 949 | else break; | |
| 950 | } | |
| 951 | ||
| 952 | /* Scan up for duplicates */ | |
| 953 | ||
| 954 | if (!condition) | |
| 955 | { | |
| 956 | slotB = slotA; | |
| 957 | for (i++; i < md->name_count; i++) | |
| 958 | { | |
| 959 | slotB += md->name_entry_size; | |
| 960 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
| 961 | { | |
| 962 | offset = GET2(slotB, 0) << 1; | |
| 963 | condition = offset < offset_top && | |
| 964 | md->offset_vector[offset] >= 0; | |
| 965 | if (condition) break; | |
| 966 | } | |
| 967 | else break; | |
| 968 | } | |
| 969 | } | |
| 970 | } | |
| 971 | } | |
| 972 | ||
| 973 | /* Chose branch according to the condition */ | |
| 974 | ||
| 975 | ecode += condition? 3 : GET(ecode, 1); | |
| 976 | } | |
| 977 | ||
| 978 | else if (condcode == OP_DEF) /* DEFINE - always false */ | |
| 979 | { | |
| 980 | condition = FALSE; | |
| 981 | ecode += GET(ecode, 1); | |
| 982 | } | } |
| 983 | ||
| 984 | /* The condition is an assertion. Call match() to evaluate it - setting | /* The condition is an assertion. Call match() to evaluate it - setting |
| 985 | 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 |
| 986 | assertion. */ | |
| 987 | ||
| 988 | else | else |
| 989 | { | { |
| 990 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, |
| 991 | match_condassert | match_isgroup); | match_condassert, RM3); |
| 992 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
| 993 | { | { |
| 994 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2); | condition = TRUE; |
| 995 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); | |
| 996 | while (*ecode == OP_ALT) ecode += GET(ecode, 1); | while (*ecode == OP_ALT) ecode += GET(ecode, 1); |
| 997 | } | } |
| 998 | else if (rrc != MATCH_NOMATCH) | else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
| 999 | { | { |
| 1000 | RRETURN(rrc); /* Need braces because of following else */ | RRETURN(rrc); /* Need braces because of following else */ |
| 1001 | } | } |
| 1002 | else ecode += GET(ecode, 1); | else |
| 1003 | { | |
| 1004 | condition = FALSE; | |
| 1005 | ecode += codelink; | |
| 1006 | } | |
| 1007 | } | |
| 1008 | ||
| 1009 | /* We are now at the branch that is to be obeyed. As there is only one, | /* We are now at the branch that is to be obeyed. As there is only one, |
| 1010 | we can use tail recursion to avoid using another stack frame. */ | we can use tail recursion to avoid using another stack frame, except when |
| 1011 | match_cbegroup is required for an unlimited repeat of a possibly empty | |
| 1012 | group. If the second alternative doesn't exist, we can just plough on. */ | |
| 1013 | ||
| 1014 | if (condition || *ecode == OP_ALT) | |
| 1015 | { | |
| 1016 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1017 | flags = match_isgroup; | if (op == OP_SCOND) /* Possibly empty group */ |
| 1018 | goto TAIL_RECURSE; | { |
| 1019 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49); | |
| 1020 | RRETURN(rrc); | |
| 1021 | } | |
| 1022 | else /* Group must match something */ | |
| 1023 | { | |
| 1024 | flags = 0; | |
| 1025 | goto TAIL_RECURSE; | |
| 1026 | } | |
| 1027 | } | } |
| 1028 | /* Control never reaches here */ | else /* Condition false & no alternative */ |
| 1029 | { | |
| 1030 | ecode += 1 + LINK_SIZE; | |
| 1031 | } | |
| 1032 | break; | |
| 1033 | ||
| 1034 | ||
| 1035 | /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes, | |
| 1036 | to close any currently open capturing brackets. */ | |
| 1037 | ||
| 1038 | case OP_CLOSE: | |
| 1039 | number = GET2(ecode, 1); | |
| 1040 | offset = number << 1; | |
| 1041 | ||
| 1042 | /* Skip over conditional reference or large extraction number data if | #ifdef PCRE_DEBUG |
| 1043 | encountered. */ | printf("end bracket %d at *ACCEPT", number); |
| 1044 | printf("\n"); | |
| 1045 | #endif | |
| 1046 | ||
| 1047 | case OP_CREF: | md->capture_last = number; |
| 1048 | case OP_BRANUMBER: | if (offset >= md->offset_max) md->offset_overflow = TRUE; else |
| 1049 | { | |
| 1050 | md->offset_vector[offset] = | |
| 1051 | md->offset_vector[md->offset_end - number]; | |
| 1052 | md->offset_vector[offset+1] = eptr - md->start_subject; | |
| 1053 | if (offset_top <= offset) offset_top = offset + 2; | |
| 1054 | } | |
| 1055 | ecode += 3; | ecode += 3; |
| 1056 | break; | break; |
| 1057 | ||
| /* End of the pattern. If we are in a recursion, we should restore the | ||
| offsets appropriately and continue from after the call. */ | ||
| 1058 | ||
| 1059 | /* End of the pattern, either real or forced. If we are in a top-level | |
| 1060 | recursion, we should restore the offsets appropriately and continue from | |
| 1061 | after the call. */ | |
| 1062 | ||
| 1063 | case OP_ACCEPT: | |
| 1064 | case OP_END: | case OP_END: |
| 1065 | if (md->recursive != NULL && md->recursive->group_num == 0) | if (md->recursive != NULL && md->recursive->group_num == 0) |
| 1066 | { | { |
| # | Line 745 for (;;) | Line 1069 for (;;) |
| 1069 | md->recursive = rec->prevrec; | md->recursive = rec->prevrec; |
| 1070 | memmove(md->offset_vector, rec->offset_save, | memmove(md->offset_vector, rec->offset_save, |
| 1071 | rec->saved_max * sizeof(int)); | rec->saved_max * sizeof(int)); |
| 1072 | md->start_match = rec->save_start; | offset_top = rec->save_offset_top; |
| 1073 | mstart = rec->save_start; | |
| 1074 | ims = original_ims; | ims = original_ims; |
| 1075 | ecode = rec->after_call; | ecode = rec->after_call; |
| 1076 | break; | break; |
| 1077 | } | } |
| 1078 | ||
| 1079 | /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty | /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is |
| 1080 | string - backtracking will then try other alternatives, if any. */ | set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of |
| 1081 | the subject. In both cases, backtracking will then try other alternatives, | |
| 1082 | if any. */ | |
| 1083 | ||
| 1084 | if (eptr == mstart && | |
| 1085 | (md->notempty || | |
| 1086 | (md->notempty_atstart && | |
| 1087 | mstart == md->start_subject + md->start_offset))) | |
| 1088 | RRETURN(MATCH_NOMATCH); | |
| 1089 | ||
| 1090 | /* Otherwise, we have a match. */ | |
| 1091 | ||
| 1092 | if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH); | md->end_match_ptr = eptr; /* Record where we ended */ |
| 1093 | md->end_match_ptr = eptr; /* Record where we ended */ | md->end_offset_top = offset_top; /* and how many extracts were taken */ |
| 1094 | md->end_offset_top = offset_top; /* and how many extracts were taken */ | md->start_match_ptr = mstart; /* and the start (\K can modify) */ |
| 1095 | RRETURN(MATCH_MATCH); | RRETURN(MATCH_MATCH); |
| 1096 | ||
| 1097 | /* Change option settings */ | /* Change option settings */ |
| # | Line 777 for (;;) | Line 1112 for (;;) |
| 1112 | case OP_ASSERTBACK: | case OP_ASSERTBACK: |
| 1113 | do | do |
| 1114 | { | { |
| 1115 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, |
| 1116 | match_isgroup); | RM4); |
| 1117 | if (rrc == MATCH_MATCH) break; | if (rrc == MATCH_MATCH) break; |
| 1118 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 1119 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 1120 | } | } |
| 1121 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| # | Line 798 for (;;) | Line 1133 for (;;) |
| 1133 | offset_top = md->end_offset_top; | offset_top = md->end_offset_top; |
| 1134 | continue; | continue; |
| 1135 | ||
| 1136 | /* Negative assertion: all branches must fail to match */ | /* Negative assertion: all branches must fail to match. Encountering SKIP, |
| 1137 | PRUNE, or COMMIT means we must assume failure without checking subsequent | |
| 1138 | branches. */ | |
| 1139 | ||
| 1140 | case OP_ASSERT_NOT: | case OP_ASSERT_NOT: |
| 1141 | case OP_ASSERTBACK_NOT: | case OP_ASSERTBACK_NOT: |
| 1142 | do | do |
| 1143 | { | { |
| 1144 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, |
| 1145 | match_isgroup); | RM5); |
| 1146 | if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); | if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); |
| 1147 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT) |
| 1148 | { | |
| 1149 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | |
| 1150 | break; | |
| 1151 | } | |
| 1152 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); | |
| 1153 | ecode += GET(ecode,1); | ecode += GET(ecode,1); |
| 1154 | } | } |
| 1155 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| # | Line 826 for (;;) | Line 1168 for (;;) |
| 1168 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 1169 | if (utf8) | if (utf8) |
| 1170 | { | { |
| 1171 | c = GET(ecode,1); | i = GET(ecode, 1); |
| 1172 | for (i = 0; i < c; i++) | while (i-- > 0) |
| 1173 | { | { |
| 1174 | eptr--; | eptr--; |
| 1175 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1176 | BACKCHAR(eptr) | BACKCHAR(eptr); |
| 1177 | } | } |
| 1178 | } | } |
| 1179 | else | else |
| # | Line 840 for (;;) | Line 1182 for (;;) |
| 1182 | /* 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 */ |
| 1183 | ||
| 1184 | { | { |
| 1185 | eptr -= GET(ecode,1); | eptr -= GET(ecode, 1); |
| 1186 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1187 | } | } |
| 1188 | ||
| 1189 | /* Skip to next op code */ | /* Save the earliest consulted character, then skip to next op code */ |
| 1190 | ||
| 1191 | if (eptr < md->start_used_ptr) md->start_used_ptr = eptr; | |
| 1192 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1193 | break; | break; |
| 1194 | ||
| # | Line 862 for (;;) | Line 1205 for (;;) |
| 1205 | cb.offset_vector = md->offset_vector; | cb.offset_vector = md->offset_vector; |
| 1206 | cb.subject = (PCRE_SPTR)md->start_subject; | cb.subject = (PCRE_SPTR)md->start_subject; |
| 1207 | cb.subject_length = md->end_subject - md->start_subject; | cb.subject_length = md->end_subject - md->start_subject; |
| 1208 | cb.start_match = md->start_match - md->start_subject; | cb.start_match = mstart - md->start_subject; |
| 1209 | cb.current_position = eptr - md->start_subject; | cb.current_position = eptr - md->start_subject; |
| 1210 | cb.pattern_position = GET(ecode, 2); | cb.pattern_position = GET(ecode, 2); |
| 1211 | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); |
| # | Line 897 for (;;) | Line 1240 for (;;) |
| 1240 | case OP_RECURSE: | case OP_RECURSE: |
| 1241 | { | { |
| 1242 | callpat = md->start_code + GET(ecode, 1); | callpat = md->start_code + GET(ecode, 1); |
| 1243 | new_recursive.group_num = *callpat - OP_BRA; | new_recursive.group_num = (callpat == md->start_code)? 0 : |
| 1244 | 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); | ||
| 1245 | ||
| 1246 | /* Add to "recursing stack" */ | /* Add to "recursing stack" */ |
| 1247 | ||
| # | Line 929 for (;;) | Line 1267 for (;;) |
| 1267 | ||
| 1268 | memcpy(new_recursive.offset_save, md->offset_vector, | memcpy(new_recursive.offset_save, md->offset_vector, |
| 1269 | new_recursive.saved_max * sizeof(int)); | new_recursive.saved_max * sizeof(int)); |
| 1270 | new_recursive.save_start = md->start_match; | new_recursive.save_start = mstart; |
| 1271 | md->start_match = eptr; | new_recursive.save_offset_top = offset_top; |
| 1272 | mstart = eptr; | |
| 1273 | ||
| 1274 | /* 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 |
| 1275 | restore the offset and recursion data. */ | restore the offset and recursion data. */ |
| 1276 | ||
| 1277 | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); |
| 1278 | flags = (*callpat >= OP_SBRA)? match_cbegroup : 0; | |
| 1279 | do | do |
| 1280 | { | { |
| 1281 | RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims, | RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, |
| 1282 | eptrb, match_isgroup); | md, ims, eptrb, flags, RM6); |
| 1283 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
| 1284 | { | { |
| 1285 | DPRINTF(("Recursion matched\n")); | DPRINTF(("Recursion matched\n")); |
| # | Line 948 for (;;) | Line 1288 for (;;) |
| 1288 | (pcre_free)(new_recursive.offset_save); | (pcre_free)(new_recursive.offset_save); |
| 1289 | RRETURN(MATCH_MATCH); | RRETURN(MATCH_MATCH); |
| 1290 | } | } |
| 1291 | else if (rrc != MATCH_NOMATCH) | else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
| 1292 | { | { |
| 1293 | DPRINTF(("Recursion gave error %d\n", rrc)); | DPRINTF(("Recursion gave error %d\n", rrc)); |
| 1294 | if (new_recursive.offset_save != stacksave) | |
| 1295 | (pcre_free)(new_recursive.offset_save); | |
| 1296 | RRETURN(rrc); | RRETURN(rrc); |
| 1297 | } | } |
| 1298 | ||
| # | Line 982 for (;;) | Line 1324 for (;;) |
| 1324 | ||
| 1325 | do | do |
| 1326 | { | { |
| 1327 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7); |
| eptrb, match_isgroup); | ||
| 1328 | if (rrc == MATCH_MATCH) break; | if (rrc == MATCH_MATCH) break; |
| 1329 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 1330 | ecode += GET(ecode,1); | ecode += GET(ecode,1); |
| 1331 | } | } |
| 1332 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| # | Line 997 for (;;) | Line 1338 for (;;) |
| 1338 | /* Continue as from after the assertion, updating the offsets high water | /* Continue as from after the assertion, updating the offsets high water |
| 1339 | mark, since extracts may have been taken. */ | mark, since extracts may have been taken. */ |
| 1340 | ||
| 1341 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | do ecode += GET(ecode, 1); while (*ecode == OP_ALT); |
| 1342 | ||
| 1343 | offset_top = md->end_offset_top; | offset_top = md->end_offset_top; |
| 1344 | eptr = md->end_match_ptr; | eptr = md->end_match_ptr; |
| # | Line 1028 for (;;) | Line 1369 for (;;) |
| 1369 | ||
| 1370 | if (*ecode == OP_KETRMIN) | if (*ecode == OP_KETRMIN) |
| 1371 | { | { |
| 1372 | 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); |
| 1373 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1374 | ecode = prev; | ecode = prev; |
| 1375 | flags = match_isgroup; | flags = 0; |
| 1376 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
| 1377 | } | } |
| 1378 | else /* OP_KETRMAX */ | else /* OP_KETRMAX */ |
| 1379 | { | { |
| 1380 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9); |
| 1381 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1382 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1383 | flags = 0; | flags = 0; |
| # | Line 1051 for (;;) | Line 1392 for (;;) |
| 1392 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
| 1393 | break; | break; |
| 1394 | ||
| 1395 | /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating | /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group, |
| 1396 | 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 |
| 1397 | 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 |
| 1398 | 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 |
| 1399 | preceded by BRAZERO or BRAMINZERO. */ | optional ones preceded by BRAZERO or BRAMINZERO. */ |
| 1400 | ||
| 1401 | case OP_BRAZERO: | case OP_BRAZERO: |
| 1402 | { | { |
| 1403 | next = ecode+1; | next = ecode+1; |
| 1404 | RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10); |
| 1405 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1406 | do next += GET(next,1); while (*next == OP_ALT); | do next += GET(next,1); while (*next == OP_ALT); |
| 1407 | ecode = next + 1+LINK_SIZE; | ecode = next + 1 + LINK_SIZE; |
| 1408 | } | } |
| 1409 | break; | break; |
| 1410 | ||
| 1411 | case OP_BRAMINZERO: | case OP_BRAMINZERO: |
| 1412 | { | { |
| 1413 | next = ecode+1; | next = ecode+1; |
| 1414 | do next += GET(next,1); while (*next == OP_ALT); | do next += GET(next, 1); while (*next == OP_ALT); |
| 1415 | 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); | ||
| 1416 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1417 | ecode++; | ecode++; |
| 1418 | } | } |
| 1419 | break; | break; |
| 1420 | ||
| 1421 | /* End of a group, repeated or non-repeating. If we are at the end of | case OP_SKIPZERO: |
| 1422 | an assertion "group", stop matching and return MATCH_MATCH, but record the | { |
| 1423 | current high water mark for use by positive assertions. Do this also | next = ecode+1; |
| 1424 | for the "once" (not-backup up) groups. */ | do next += GET(next,1); while (*next == OP_ALT); |
| 1425 | ecode = next + 1 + LINK_SIZE; | |
| 1426 | } | |
| 1427 | break; | |
| 1428 | ||
| 1429 | /* End of a group, repeated or non-repeating. */ | |
| 1430 | ||
| 1431 | case OP_KET: | case OP_KET: |
| 1432 | case OP_KETRMIN: | case OP_KETRMIN: |
| 1433 | case OP_KETRMAX: | case OP_KETRMAX: |
| 1434 | prev = ecode - GET(ecode, 1); | prev = ecode - GET(ecode, 1); |
| saved_eptr = eptrb->epb_saved_eptr; | ||
| 1435 | ||
| 1436 | /* Back up the stack of bracket start pointers. */ | /* If this was a group that remembered the subject start, in order to break |
| 1437 | infinite repeats of empty string matches, retrieve the subject start from | |
| 1438 | the chain. Otherwise, set it NULL. */ | |
| 1439 | ||
| 1440 | eptrb = eptrb->epb_prev; | if (*prev >= OP_SBRA) |
| 1441 | { | |
| 1442 | saved_eptr = eptrb->epb_saved_eptr; /* Value at start of group */ | |
| 1443 | eptrb = eptrb->epb_prev; /* Backup to previous group */ | |
| 1444 | } | |
| 1445 | else saved_eptr = NULL; | |
| 1446 | ||
| 1447 | /* If we are at the end of an assertion group, stop matching and return | |
| 1448 | MATCH_MATCH, but record the current high water mark for use by positive | |
| 1449 | assertions. Do this also for the "once" (atomic) groups. */ | |
| 1450 | ||
| 1451 | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || |
| 1452 | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || |
| # | Line 1102 for (;;) | Line 1457 for (;;) |
| 1457 | RRETURN(MATCH_MATCH); | RRETURN(MATCH_MATCH); |
| 1458 | } | } |
| 1459 | ||
| 1460 | /* In all other cases except a conditional group we have to check the | /* For capturing groups we have to check the group number back at the start |
| 1461 | group number back at the start and if necessary complete handling an | and if necessary complete handling an extraction by setting the offsets and |
| 1462 | extraction by setting the offsets and bumping the high water mark. */ | bumping the high water mark. Note that whole-pattern recursion is coded as |
| 1463 | a recurse into group 0, so it won't be picked up here. Instead, we catch it | |
| 1464 | when the OP_END is reached. Other recursion is handled here. */ | |
| 1465 | ||
| 1466 | if (*prev != OP_COND) | if (*prev == OP_CBRA || *prev == OP_SCBRA) |
| 1467 | { | { |
| 1468 | number = *prev - OP_BRA; | number = GET2(prev, 1+LINK_SIZE); |
| /* For extended extraction brackets (large number), we have to fish out | ||
| the number from a dummy opcode at the start. */ | ||
| if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE); | ||
| 1469 | offset = number << 1; | offset = number << 1; |
| 1470 | ||
| 1471 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
| 1472 | printf("end bracket %d", number); | printf("end bracket %d", number); |
| 1473 | printf("\n"); | printf("\n"); |
| 1474 | #endif | #endif |
| 1475 | ||
| 1476 | /* Test for a numbered group. This includes groups called as a result | md->capture_last = number; |
| 1477 | of recursion. Note that whole-pattern recursion is coded as a recurse | if (offset >= md->offset_max) md->offset_overflow = TRUE; else |
| into group 0, so it won't be picked up here. Instead, we catch it when | ||
| the OP_END is reached. */ | ||
| if (number > 0) | ||
| 1478 | { | { |
| 1479 | md->capture_last = number; | md->offset_vector[offset] = |
| 1480 | if (offset >= md->offset_max) md->offset_overflow = TRUE; else | md->offset_vector[md->offset_end - number]; |
| 1481 | { | md->offset_vector[offset+1] = eptr - md->start_subject; |
| 1482 | md->offset_vector[offset] = | if (offset_top <= offset) offset_top = offset + 2; |
| 1483 | md->offset_vector[md->offset_end - number]; | } |
| 1484 | md->offset_vector[offset+1] = eptr - md->start_subject; | |
| 1485 | if (offset_top <= offset) offset_top = offset + 2; | /* Handle a recursively called group. Restore the offsets |
| 1486 | } | appropriately and continue from after the call. */ |
| 1487 | ||
| 1488 | /* Handle a recursively called group. Restore the offsets | if (md->recursive != NULL && md->recursive->group_num == number) |
| 1489 | appropriately and continue from after the call. */ | { |
| 1490 | recursion_info *rec = md->recursive; | |
| 1491 | if (md->recursive != NULL && md->recursive->group_num == number) | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); |
| 1492 | { | md->recursive = rec->prevrec; |
| 1493 | recursion_info *rec = md->recursive; | mstart = rec->save_start; |
| 1494 | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); | memcpy(md->offset_vector, rec->offset_save, |
| 1495 | md->recursive = rec->prevrec; | rec->saved_max * sizeof(int)); |
| 1496 | md->start_match = rec->save_start; | offset_top = rec->save_offset_top; |
| 1497 | memcpy(md->offset_vector, rec->offset_save, | ecode = rec->after_call; |
| 1498 | rec->saved_max * sizeof(int)); | ims = original_ims; |
| 1499 | ecode = rec->after_call; | break; |
| ims = original_ims; | ||
| break; | ||
| } | ||
| 1500 | } | } |
| 1501 | } | } |
| 1502 | ||
| 1503 | /* 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 |
| 1504 | the group. */ | flags, in case they got changed during the group. */ |
| 1505 | ||
| 1506 | ims = original_ims; | ims = original_ims; |
| 1507 | DPRINTF(("ims reset to %02lx\n", ims)); | DPRINTF(("ims reset to %02lx\n", ims)); |
| # | Line 1175 for (;;) | Line 1520 for (;;) |
| 1520 | ||
| 1521 | /* 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 |
| 1522 | preceding bracket, in the appropriate order. In the second case, we can use | preceding bracket, in the appropriate order. In the second case, we can use |
| 1523 | tail recursion to avoid using another stack frame. */ | tail recursion to avoid using another stack frame, unless we have an |
| 1524 | unlimited repeat of a group that can match an empty string. */ | |
| 1525 | ||
| 1526 | flags = (*prev >= OP_SBRA)? match_cbegroup : 0; | |
| 1527 | ||
| 1528 | if (*ecode == OP_KETRMIN) | if (*ecode == OP_KETRMIN) |
| 1529 | { | { |
| 1530 | 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, RM12); |
| 1531 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1532 | if (flags != 0) /* Could match an empty string */ | |
| 1533 | { | |
| 1534 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50); | |
| 1535 | RRETURN(rrc); | |
| 1536 | } | |
| 1537 | ecode = prev; | ecode = prev; |
| flags = match_isgroup; | ||
| 1538 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
| 1539 | } | } |
| 1540 | else /* OP_KETRMAX */ | else /* OP_KETRMAX */ |
| 1541 | { | { |
| 1542 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13); |
| 1543 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1544 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1545 | flags = 0; | flags = 0; |
| # | Line 1202 for (;;) | Line 1554 for (;;) |
| 1554 | if ((ims & PCRE_MULTILINE) != 0) | if ((ims & PCRE_MULTILINE) != 0) |
| 1555 | { | { |
| 1556 | if (eptr != md->start_subject && | if (eptr != md->start_subject && |
| 1557 | (eptr == md->end_subject || | (eptr == md->end_subject || !WAS_NEWLINE(eptr))) |
| eptr < md->start_subject + md->nllen || | ||
| !IS_NEWLINE(eptr - md->nllen))) | ||
| 1558 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1559 | ecode++; | ecode++; |
| 1560 | break; | break; |
| # | Line 1225 for (;;) | Line 1575 for (;;) |
| 1575 | ecode++; | ecode++; |
| 1576 | break; | break; |
| 1577 | ||
| 1578 | /* Reset the start of match point */ | |
| 1579 | ||
| 1580 | case OP_SET_SOM: | |
| 1581 | mstart = eptr; | |
| 1582 | ecode++; | |
| 1583 | break; | |
| 1584 | ||
| 1585 | /* Assert before internal newline if multiline, or before a terminating | /* Assert before internal newline if multiline, or before a terminating |
| 1586 | 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. */ |
| 1587 | ||
| # | Line 1244 for (;;) | Line 1601 for (;;) |
| 1601 | if (!md->endonly) | if (!md->endonly) |
| 1602 | { | { |
| 1603 | if (eptr != md->end_subject && | if (eptr != md->end_subject && |
| 1604 | (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr))) | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
| 1605 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1606 | ecode++; | ecode++; |
| 1607 | break; | break; |
| # | Line 1263 for (;;) | Line 1620 for (;;) |
| 1620 | ||
| 1621 | case OP_EODN: | case OP_EODN: |
| 1622 | if (eptr != md->end_subject && | if (eptr != md->end_subject && |
| 1623 | (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr))) | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
| 1624 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1625 | ecode++; | ecode++; |
| 1626 | break; | break; |
| # | Line 1276 for (;;) | Line 1633 for (;;) |
| 1633 | ||
| 1634 | /* Find out if the previous and current characters are "word" characters. | /* Find out if the previous and current characters are "word" characters. |
| 1635 | It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to | It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to |
| 1636 | be "non-word" characters. */ | be "non-word" characters. Remember the earliest consulted character for |
| 1637 | partial matching. */ | |
| 1638 | ||
| 1639 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 1640 | if (utf8) | if (utf8) |
| 1641 | { | { |
| 1642 | if (eptr == md->start_subject) prev_is_word = FALSE; else | if (eptr == md->start_subject) prev_is_word = FALSE; else |
| 1643 | { | { |
| 1644 | const uschar *lastptr = eptr - 1; | USPTR lastptr = eptr - 1; |
| 1645 | while((*lastptr & 0xc0) == 0x80) lastptr--; | while((*lastptr & 0xc0) == 0x80) lastptr--; |
| 1646 | if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr; | |
| 1647 | GETCHAR(c, lastptr); | GETCHAR(c, lastptr); |
| 1648 | prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; | prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
| 1649 | } | } |
| 1650 | if (eptr >= md->end_subject) cur_is_word = FALSE; else | if (eptr >= md->end_subject) |
| 1651 | { | |
| 1652 | SCHECK_PARTIAL(); | |
| 1653 | cur_is_word = FALSE; | |
| 1654 | } | |
| 1655 | else | |
| 1656 | { | { |
| 1657 | GETCHAR(c, eptr); | GETCHAR(c, eptr); |
| 1658 | cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; | cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
| # | Line 1297 for (;;) | Line 1661 for (;;) |
| 1661 | else | else |
| 1662 | #endif | #endif |
| 1663 | ||
| 1664 | /* More streamlined when not in UTF-8 mode */ | /* Not in UTF-8 mode */ |
| 1665 | ||
| 1666 | { | { |
| 1667 | prev_is_word = (eptr != md->start_subject) && | if (eptr == md->start_subject) prev_is_word = FALSE; else |
| 1668 | ((md->ctypes[eptr[-1]] & ctype_word) != 0); | { |
| 1669 | cur_is_word = (eptr < md->end_subject) && | if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1; |
| 1670 | ((md->ctypes[*eptr] & ctype_word) != 0); | prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0); |
| 1671 | } | |
| 1672 | if (eptr >= md->end_subject) | |
| 1673 | { | |
| 1674 | SCHECK_PARTIAL(); | |
| 1675 | cur_is_word = FALSE; | |
| 1676 | } | |
| 1677 | else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0); | |
| 1678 | } | } |
| 1679 | ||
| 1680 | /* Now see if the situation is what we want */ | /* Now see if the situation is what we want */ |
| # | Line 1317 for (;;) | Line 1688 for (;;) |
| 1688 | /* Match a single character type; inline for speed */ | /* Match a single character type; inline for speed */ |
| 1689 | ||
| 1690 | case OP_ANY: | case OP_ANY: |
| 1691 | if ((ims & PCRE_DOTALL) == 0) | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); |
| 1692 | /* Fall through */ | |
| 1693 | ||
| 1694 | case OP_ALLANY: | |
| 1695 | if (eptr++ >= md->end_subject) | |
| 1696 | { | { |
| 1697 | if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)) | SCHECK_PARTIAL(); |
| 1698 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1699 | } | } |
| 1700 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| if (utf8) | ||
| while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
| 1701 | ecode++; | ecode++; |
| 1702 | break; | break; |
| 1703 | ||
| # | Line 1332 for (;;) | Line 1705 for (;;) |
| 1705 | any byte, even newline, independent of the setting of PCRE_DOTALL. */ | any byte, even newline, independent of the setting of PCRE_DOTALL. */ |
| 1706 | ||
| 1707 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 1708 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr++ >= md->end_subject) |
| 1709 | { | |
| 1710 | SCHECK_PARTIAL(); | |
| 1711 | RRETURN(MATCH_NOMATCH); | |
| 1712 | } | |
| 1713 | ecode++; | ecode++; |
| 1714 | break; | break; |
| 1715 | ||
| 1716 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 1717 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1718 | { | |
| 1719 | SCHECK_PARTIAL(); | |
| 1720 | RRETURN(MATCH_NOMATCH); | |
| 1721 | } | |
| 1722 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1723 | if ( | if ( |
| 1724 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1350 for (;;) | Line 1731 for (;;) |
| 1731 | break; | break; |
| 1732 | ||
| 1733 | case OP_DIGIT: | case OP_DIGIT: |
| 1734 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1735 | { | |
| 1736 | SCHECK_PARTIAL(); | |
| 1737 | RRETURN(MATCH_NOMATCH); | |
| 1738 | } | |
| 1739 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1740 | if ( | if ( |
| 1741 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1363 for (;;) | Line 1748 for (;;) |
| 1748 | break; | break; |
| 1749 | ||
| 1750 | case OP_NOT_WHITESPACE: | case OP_NOT_WHITESPACE: |
| 1751 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1752 | { | |
| 1753 | SCHECK_PARTIAL(); | |
| 1754 | RRETURN(MATCH_NOMATCH); | |
| 1755 | } | |
| 1756 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1757 | if ( | if ( |
| 1758 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1376 for (;;) | Line 1765 for (;;) |
| 1765 | break; | break; |
| 1766 | ||
| 1767 | case OP_WHITESPACE: | case OP_WHITESPACE: |
| 1768 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1769 | { | |
| 1770 | SCHECK_PARTIAL(); | |
| 1771 | RRETURN(MATCH_NOMATCH); | |
| 1772 | } | |
| 1773 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1774 | if ( | if ( |
| 1775 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1389 for (;;) | Line 1782 for (;;) |
| 1782 | break; | break; |
| 1783 | ||
| 1784 | case OP_NOT_WORDCHAR: | case OP_NOT_WORDCHAR: |
| 1785 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1786 | { | |
| 1787 | SCHECK_PARTIAL(); | |
| 1788 | RRETURN(MATCH_NOMATCH); | |
| 1789 | } | |
| 1790 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1791 | if ( | if ( |
| 1792 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1402 for (;;) | Line 1799 for (;;) |
| 1799 | break; | break; |
| 1800 | ||
| 1801 | case OP_WORDCHAR: | case OP_WORDCHAR: |
| 1802 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1803 | { | |
| 1804 | SCHECK_PARTIAL(); | |
| 1805 | RRETURN(MATCH_NOMATCH); | |
| 1806 | } | |
| 1807 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1808 | if ( | if ( |
| 1809 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1414 for (;;) | Line 1815 for (;;) |
| 1815 | ecode++; | ecode++; |
| 1816 | break; | break; |
| 1817 | ||
| 1818 | #ifdef SUPPORT_UCP | case OP_ANYNL: |
| 1819 | /* Check the next character by Unicode property. We will get here only | if (eptr >= md->end_subject) |
| 1820 | if the support is in the binary; otherwise a compile-time error occurs. */ | { |
| 1821 | SCHECK_PARTIAL(); | |
| 1822 | case OP_PROP: | RRETURN(MATCH_NOMATCH); |
| 1823 | case OP_NOTPROP: | } |
| if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | ||
| 1824 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1825 | switch(c) | |
| 1826 | { | { |
| 1827 | int chartype, script; | default: RRETURN(MATCH_NOMATCH); |
| 1828 | int category = _pcre_ucp_findprop(c, &chartype, &script); | case 0x000d: |
| 1829 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 1830 | break; | |
| 1831 | ||
| 1832 | switch(ecode[1]) | case 0x000a: |
| 1833 | { | break; |
| case PT_ANY: | ||
| if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH); | ||
| break; | ||
| 1834 | ||
| 1835 | case PT_LAMP: | case 0x000b: |
| 1836 | if ((chartype == ucp_Lu || | case 0x000c: |
| 1837 | chartype == ucp_Ll || | case 0x0085: |
| 1838 | chartype == ucp_Lt) == (op == OP_NOTPROP)) | case 0x2028: |
| 1839 | RRETURN(MATCH_NOMATCH); | case 0x2029: |
| 1840 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 1841 | break; | |
| 1842 | } | |
| 1843 | ecode++; | |
| 1844 | break; | |
| 1845 | ||
| 1846 | case OP_NOT_HSPACE: | |
| 1847 | if (eptr >= md->end_subject) | |
| 1848 | { | |
| 1849 | SCHECK_PARTIAL(); | |
| 1850 | RRETURN(MATCH_NOMATCH); | |
| 1851 | } | |
| 1852 | GETCHARINCTEST(c, eptr); | |
| 1853 | switch(c) | |
| 1854 | { | |
| 1855 | default: break; | |
| 1856 | case 0x09: /* HT */ | |
| 1857 | case 0x20: /* SPACE */ | |
| 1858 | case 0xa0: /* NBSP */ | |
| 1859 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 1860 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 1861 | case 0x2000: /* EN QUAD */ | |
| 1862 | case 0x2001: /* EM QUAD */ | |
| 1863 | case 0x2002: /* EN SPACE */ | |
| 1864 | case 0x2003: /* EM SPACE */ | |
| 1865 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 1866 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 1867 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 1868 | case 0x2007: /* FIGURE SPACE */ | |
| 1869 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 1870 | case 0x2009: /* THIN SPACE */ | |
| 1871 | case 0x200A: /* HAIR SPACE */ | |
| 1872 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 1873 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 1874 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 1875 | RRETURN(MATCH_NOMATCH); | |
| 1876 | } | |
| 1877 | ecode++; | |
| 1878 | break; | |
| 1879 | ||
| 1880 | case OP_HSPACE: | |
| 1881 | if (eptr >= md->end_subject) | |
| 1882 | { | |
| 1883 | SCHECK_PARTIAL(); | |
| 1884 | RRETURN(MATCH_NOMATCH); | |
| 1885 | } | |
| 1886 | GETCHARINCTEST(c, eptr); | |
| 1887 | switch(c) | |
| 1888 | { | |
| 1889 | default: RRETURN(MATCH_NOMATCH); | |
| 1890 | case 0x09: /* HT */ | |
| 1891 | case 0x20: /* SPACE */ | |
| 1892 | case 0xa0: /* NBSP */ | |
| 1893 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 1894 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 1895 | case 0x2000: /* EN QUAD */ | |
| 1896 | case 0x2001: /* EM QUAD */ | |
| 1897 | case 0x2002: /* EN SPACE */ | |
| 1898 | case 0x2003: /* EM SPACE */ | |
| 1899 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 1900 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 1901 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 1902 | case 0x2007: /* FIGURE SPACE */ | |
| 1903 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 1904 | case 0x2009: /* THIN SPACE */ | |
| 1905 | case 0x200A: /* HAIR SPACE */ | |
| 1906 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 1907 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 1908 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 1909 | break; | |
| 1910 | } | |
| 1911 | ecode++; | |
| 1912 | break; | |
| 1913 | ||
| 1914 | case OP_NOT_VSPACE: | |
| 1915 | if (eptr >= md->end_subject) | |
| 1916 | { | |
| 1917 | SCHECK_PARTIAL(); | |
| 1918 | RRETURN(MATCH_NOMATCH); | |
| 1919 | } | |
| 1920 | GETCHARINCTEST(c, eptr); | |
| 1921 | switch(c) | |
| 1922 | { | |
| 1923 | default: break; | |
| 1924 | case 0x0a: /* LF */ | |
| 1925 | case 0x0b: /* VT */ | |
| 1926 | case 0x0c: /* FF */ | |
| 1927 | case 0x0d: /* CR */ | |
| 1928 | case 0x85: /* NEL */ | |
| 1929 | case 0x2028: /* LINE SEPARATOR */ | |
| 1930 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 1931 | RRETURN(MATCH_NOMATCH); | |
| 1932 | } | |
| 1933 | ecode++; | |
| 1934 | break; | |
| 1935 | ||
| 1936 | case OP_VSPACE: | |
| 1937 | if (eptr >= md->end_subject) | |
| 1938 | { | |
| 1939 | SCHECK_PARTIAL(); | |
| 1940 | RRETURN(MATCH_NOMATCH); | |
| 1941 | } | |
| 1942 | GETCHARINCTEST(c, eptr); | |
| 1943 | switch(c) | |
| 1944 | { | |
| 1945 | default: RRETURN(MATCH_NOMATCH); | |
| 1946 | case 0x0a: /* LF */ | |
| 1947 | case 0x0b: /* VT */ | |
| 1948 | case 0x0c: /* FF */ | |
| 1949 | case 0x0d: /* CR */ | |
| 1950 | case 0x85: /* NEL */ | |
| 1951 | case 0x2028: /* LINE SEPARATOR */ | |
| 1952 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 1953 | break; | |
| 1954 | } | |
| 1955 | ecode++; | |
| 1956 | break; | |
| 1957 | ||
| 1958 | #ifdef SUPPORT_UCP | |
| 1959 | /* Check the next character by Unicode property. We will get here only | |
| 1960 | if the support is in the binary; otherwise a compile-time error occurs. */ | |
| 1961 | ||
| 1962 | case OP_PROP: | |
| 1963 | case OP_NOTPROP: | |
| 1964 | if (eptr >= md->end_subject) | |
| 1965 | { | |
| 1966 | SCHECK_PARTIAL(); | |
| 1967 | RRETURN(MATCH_NOMATCH); | |
| 1968 | } | |
| 1969 | GETCHARINCTEST(c, eptr); | |
| 1970 | { | |
| 1971 | const ucd_record *prop = GET_UCD(c); | |
| 1972 | ||
| 1973 | switch(ecode[1]) | |
| 1974 | { | |
| 1975 | case PT_ANY: | |
| 1976 | if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH); | |
| 1977 | break; | |
| 1978 | ||
| 1979 | case PT_LAMP: | |
| 1980 | if ((prop->chartype == ucp_Lu || | |
| 1981 | prop->chartype == ucp_Ll || | |
| 1982 | prop->chartype == ucp_Lt) == (op == OP_NOTPROP)) | |
| 1983 | RRETURN(MATCH_NOMATCH); | |
| 1984 | break; | break; |
| 1985 | ||
| 1986 | case PT_GC: | case PT_GC: |
| 1987 | if ((ecode[2] != category) == (op == OP_PROP)) | if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP)) |
| 1988 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1989 | break; | break; |
| 1990 | ||
| 1991 | case PT_PC: | case PT_PC: |
| 1992 | if ((ecode[2] != chartype) == (op == OP_PROP)) | if ((ecode[2] != prop->chartype) == (op == OP_PROP)) |
| 1993 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1994 | break; | break; |
| 1995 | ||
| 1996 | case PT_SC: | case PT_SC: |
| 1997 | if ((ecode[2] != script) == (op == OP_PROP)) | if ((ecode[2] != prop->script) == (op == OP_PROP)) |
| 1998 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1999 | break; | break; |
| 2000 | ||
| 2001 | default: | default: |
| 2002 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
| break; | ||
| 2003 | } | } |
| 2004 | ||
| 2005 | ecode += 3; | ecode += 3; |
| # | Line 1467 for (;;) | Line 2010 for (;;) |
| 2010 | is in the binary; otherwise a compile-time error occurs. */ | is in the binary; otherwise a compile-time error occurs. */ |
| 2011 | ||
| 2012 | case OP_EXTUNI: | case OP_EXTUNI: |
| 2013 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2014 | { | |
| 2015 | SCHECK_PARTIAL(); | |
| 2016 | RRETURN(MATCH_NOMATCH); | |
| 2017 | } | |
| 2018 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2019 | { | { |
| 2020 | int chartype, script; | int category = UCD_CATEGORY(c); |
| int category = _pcre_ucp_findprop(c, &chartype, &script); | ||
| 2021 | if (category == ucp_M) RRETURN(MATCH_NOMATCH); | if (category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 2022 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 2023 | { | { |
| # | Line 1480 for (;;) | Line 2026 for (;;) |
| 2026 | { | { |
| 2027 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 2028 | } | } |
| 2029 | category = _pcre_ucp_findprop(c, &chartype, &script); | category = UCD_CATEGORY(c); |
| 2030 | if (category != ucp_M) break; | if (category != ucp_M) break; |
| 2031 | eptr += len; | eptr += len; |
| 2032 | } | } |
| # | Line 1501 for (;;) | Line 2047 for (;;) |
| 2047 | case OP_REF: | case OP_REF: |
| 2048 | { | { |
| 2049 | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ |
| 2050 | ecode += 3; /* Advance past item */ | ecode += 3; |
| 2051 | ||
| 2052 | /* If the reference is unset, there are two possibilities: | |
| 2053 | ||
| 2054 | (a) In the default, Perl-compatible state, set the length to be longer | |
| 2055 | than the amount of subject left; this ensures that every attempt at a | |
| 2056 | match fails. We can't just fail here, because of the possibility of | |
| 2057 | quantifiers with zero minima. | |
| 2058 | ||
| 2059 | /* If the reference is unset, set the length to be longer than the amount | (b) If the JavaScript compatibility flag is set, set the length to zero |
| 2060 | of subject left; this ensures that every attempt at a match fails. We | so that the back reference matches an empty string. |
| 2061 | can't just fail here, because of the possibility of quantifiers with zero | |
| 2062 | minima. */ | Otherwise, set the length to the length of what was matched by the |
| 2063 | referenced subpattern. */ | |
| 2064 | length = (offset >= offset_top || md->offset_vector[offset] < 0)? | |
| 2065 | md->end_subject - eptr + 1 : | if (offset >= offset_top || md->offset_vector[offset] < 0) |
| 2066 | md->offset_vector[offset+1] - md->offset_vector[offset]; | length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1; |
| 2067 | else | |
| 2068 | length = md->offset_vector[offset+1] - md->offset_vector[offset]; | |
| 2069 | ||
| 2070 | /* Set up for repetition, or handle the non-repeated case */ | /* Set up for repetition, or handle the non-repeated case */ |
| 2071 | ||
| # | Line 1539 for (;;) | Line 2094 for (;;) |
| 2094 | break; | break; |
| 2095 | ||
| 2096 | default: /* No repeat follows */ | default: /* No repeat follows */ |
| 2097 | if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH); | if (!match_ref(offset, eptr, length, md, ims)) |
| 2098 | { | |
| 2099 | CHECK_PARTIAL(); | |
| 2100 | RRETURN(MATCH_NOMATCH); | |
| 2101 | } | |
| 2102 | eptr += length; | eptr += length; |
| 2103 | continue; /* With the main loop */ | continue; /* With the main loop */ |
| 2104 | } | } |
| # | Line 1555 for (;;) | Line 2114 for (;;) |
| 2114 | ||
| 2115 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2116 | { | { |
| 2117 | if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH); | if (!match_ref(offset, eptr, length, md, ims)) |
| 2118 | { | |
| 2119 | CHECK_PARTIAL(); | |
| 2120 | RRETURN(MATCH_NOMATCH); | |
| 2121 | } | |
| 2122 | eptr += length; | eptr += length; |
| 2123 | } | } |
| 2124 | ||
| # | Line 1570 for (;;) | Line 2133 for (;;) |
| 2133 | { | { |
| 2134 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2135 | { | { |
| 2136 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14); |
| 2137 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2138 | if (fi >= max || !match_ref(offset, eptr, length, md, ims)) | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2139 | if (!match_ref(offset, eptr, length, md, ims)) | |
| 2140 | { | |
| 2141 | CHECK_PARTIAL(); | |
| 2142 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2143 | } | |
| 2144 | eptr += length; | eptr += length; |
| 2145 | } | } |
| 2146 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 1586 for (;;) | Line 2153 for (;;) |
| 2153 | pp = eptr; | pp = eptr; |
| 2154 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2155 | { | { |
| 2156 | if (!match_ref(offset, eptr, length, md, ims)) break; | if (!match_ref(offset, eptr, length, md, ims)) |
| 2157 | { | |
| 2158 | CHECK_PARTIAL(); | |
| 2159 | break; | |
| 2160 | } | |
| 2161 | eptr += length; | eptr += length; |
| 2162 | } | } |
| 2163 | while (eptr >= pp) | while (eptr >= pp) |
| 2164 | { | { |
| 2165 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15); |
| 2166 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2167 | eptr -= length; | eptr -= length; |
| 2168 | } | } |
| # | Line 1600 for (;;) | Line 2171 for (;;) |
| 2171 | } | } |
| 2172 | /* Control never gets here */ | /* Control never gets here */ |
| 2173 | ||
| 2174 | /* Match a bit-mapped character class, possibly repeatedly. This op code is | /* Match a bit-mapped character class, possibly repeatedly. This op code is |
| 2175 | used when all the characters in the class have values in the range 0-255, | used when all the characters in the class have values in the range 0-255, |
| 2176 | and either the matching is caseful, or the characters are in the range | and either the matching is caseful, or the characters are in the range |
| # | Line 1656 for (;;) | Line 2225 for (;;) |
| 2225 | { | { |
| 2226 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2227 | { | { |
| 2228 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2229 | { | |
| 2230 | SCHECK_PARTIAL(); | |
| 2231 | RRETURN(MATCH_NOMATCH); | |
| 2232 | } | |
| 2233 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 2234 | if (c > 255) | if (c > 255) |
| 2235 | { | { |
| # | Line 1674 for (;;) | Line 2247 for (;;) |
| 2247 | { | { |
| 2248 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2249 | { | { |
| 2250 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2251 | { | |
| 2252 | SCHECK_PARTIAL(); | |
| 2253 | RRETURN(MATCH_NOMATCH); | |
| 2254 | } | |
| 2255 | c = *eptr++; | c = *eptr++; |
| 2256 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); |
| 2257 | } | } |
| # | Line 1696 for (;;) | Line 2273 for (;;) |
| 2273 | { | { |
| 2274 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2275 | { | { |
| 2276 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16); |
| 2277 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2278 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2279 | if (eptr >= md->end_subject) | |
| 2280 | { | |
| 2281 | SCHECK_PARTIAL(); | |
| 2282 | RRETURN(MATCH_NOMATCH); | |
| 2283 | } | |
| 2284 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 2285 | if (c > 255) | if (c > 255) |
| 2286 | { | { |
| # | Line 1716 for (;;) | Line 2298 for (;;) |
| 2298 | { | { |
| 2299 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2300 | { | { |
| 2301 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17); |
| 2302 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2303 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2304 | if (eptr >= md->end_subject) | |
| 2305 | { | |
| 2306 | SCHECK_PARTIAL(); | |
| 2307 | RRETURN(MATCH_NOMATCH); | |
| 2308 | } | |
| 2309 | c = *eptr++; | c = *eptr++; |
| 2310 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); |
| 2311 | } | } |
| # | Line 1739 for (;;) | Line 2326 for (;;) |
| 2326 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2327 | { | { |
| 2328 | int len = 1; | int len = 1; |
| 2329 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
| 2330 | { | |
| 2331 | SCHECK_PARTIAL(); | |
| 2332 | break; | |
| 2333 | } | |
| 2334 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 2335 | if (c > 255) | if (c > 255) |
| 2336 | { | { |
| # | Line 1753 for (;;) | Line 2344 for (;;) |
| 2344 | } | } |
| 2345 | for (;;) | for (;;) |
| 2346 | { | { |
| 2347 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18); |
| 2348 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2349 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2350 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 1765 for (;;) | Line 2356 for (;;) |
| 2356 | { | { |
| 2357 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2358 | { | { |
| 2359 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
| 2360 | { | |
| 2361 | SCHECK_PARTIAL(); | |
| 2362 | break; | |
| 2363 | } | |
| 2364 | c = *eptr; | c = *eptr; |
| 2365 | if ((data[c/8] & (1 << (c&7))) == 0) break; | if ((data[c/8] & (1 << (c&7))) == 0) break; |
| 2366 | eptr++; | eptr++; |
| 2367 | } | } |
| 2368 | while (eptr >= pp) | while (eptr >= pp) |
| 2369 | { | { |
| 2370 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19); |
| 2371 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2372 | eptr--; | eptr--; |
| 2373 | } | } |
| # | Line 1785 for (;;) | Line 2380 for (;;) |
| 2380 | ||
| 2381 | ||
| 2382 | /* Match an extended character class. This opcode is encountered only | /* Match an extended character class. This opcode is encountered only |
| 2383 | 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 |
| 2384 | mode, because Unicode properties are supported in non-UTF-8 mode. */ | |
| 2385 | ||
| 2386 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 2387 | case OP_XCLASS: | case OP_XCLASS: |
| # | Line 1826 for (;;) | Line 2422 for (;;) |
| 2422 | ||
| 2423 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2424 | { | { |
| 2425 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2426 | GETCHARINC(c, eptr); | { |
| 2427 | SCHECK_PARTIAL(); | |
| 2428 | RRETURN(MATCH_NOMATCH); | |
| 2429 | } | |
| 2430 | GETCHARINCTEST(c, eptr); | |
| 2431 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
| 2432 | } | } |
| 2433 | ||
| # | Line 1843 for (;;) | Line 2443 for (;;) |
| 2443 | { | { |
| 2444 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2445 | { | { |
| 2446 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20); |
| 2447 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2448 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2449 | GETCHARINC(c, eptr); | if (eptr >= md->end_subject) |
| 2450 | { | |
| 2451 | SCHECK_PARTIAL(); | |
| 2452 | RRETURN(MATCH_NOMATCH); | |
| 2453 | } | |
| 2454 | GETCHARINCTEST(c, eptr); | |
| 2455 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
| 2456 | } | } |
| 2457 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 1860 for (;;) | Line 2465 for (;;) |
| 2465 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2466 | { | { |
| 2467 | int len = 1; | int len = 1; |
| 2468 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
| 2469 | GETCHARLEN(c, eptr, len); | { |
| 2470 | SCHECK_PARTIAL(); | |
| 2471 | break; | |
| 2472 | } | |
| 2473 | GETCHARLENTEST(c, eptr, len); | |
| 2474 | if (!_pcre_xclass(c, data)) break; | if (!_pcre_xclass(c, data)) break; |
| 2475 | eptr += len; | eptr += len; |
| 2476 | } | } |
| 2477 | for(;;) | for(;;) |
| 2478 | { | { |
| 2479 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21); |
| 2480 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2481 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2482 | BACKCHAR(eptr) | if (utf8) BACKCHAR(eptr); |
| 2483 | } | } |
| 2484 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2485 | } | } |
| # | Line 1888 for (;;) | Line 2497 for (;;) |
| 2497 | length = 1; | length = 1; |
| 2498 | ecode++; | ecode++; |
| 2499 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
| 2500 | if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | if (length > md->end_subject - eptr) |
| 2501 | { | |
| 2502 | CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */ | |
| 2503 | RRETURN(MATCH_NOMATCH); | |
| 2504 | } | |
| 2505 | while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH); | while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH); |
| 2506 | } | } |
| 2507 | else | else |
| # | Line 1896 for (;;) | Line 2509 for (;;) |
| 2509 | ||
| 2510 | /* Non-UTF-8 mode */ | /* Non-UTF-8 mode */ |
| 2511 | { | { |
| 2512 | if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH); | if (md->end_subject - eptr < 1) |
| 2513 | { | |
| 2514 | SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */ | |
| 2515 | RRETURN(MATCH_NOMATCH); | |
| 2516 | } | |
| 2517 | if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH); | if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH); |
| 2518 | ecode += 2; | ecode += 2; |
| 2519 | } | } |
| # | Line 1912 for (;;) | Line 2529 for (;;) |
| 2529 | ecode++; | ecode++; |
| 2530 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
| 2531 | ||
| 2532 | if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | if (length > md->end_subject - eptr) |
| 2533 | { | |
| 2534 | CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */ | |
| 2535 | RRETURN(MATCH_NOMATCH); | |
| 2536 | } | |
| 2537 | ||
| 2538 | /* If the pattern character's value is < 128, we have only one byte, and | /* If the pattern character's value is < 128, we have only one byte, and |
| 2539 | can use the fast lookup table. */ | can use the fast lookup table. */ |
| # | Line 1926 for (;;) | Line 2547 for (;;) |
| 2547 | ||
| 2548 | else | else |
| 2549 | { | { |
| 2550 | int dc; | unsigned int dc; |
| 2551 | GETCHARINC(dc, eptr); | GETCHARINC(dc, eptr); |
| 2552 | ecode += length; | ecode += length; |
| 2553 | ||
| # | Line 1936 for (;;) | Line 2557 for (;;) |
| 2557 | if (fc != dc) | if (fc != dc) |
| 2558 | { | { |
| 2559 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2560 | if (dc != _pcre_ucp_othercase(fc)) | if (dc != UCD_OTHERCASE(fc)) |
| 2561 | #endif | #endif |
| 2562 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2563 | } | } |
| # | Line 1947 for (;;) | Line 2568 for (;;) |
| 2568 | ||
| 2569 | /* Non-UTF-8 mode */ | /* Non-UTF-8 mode */ |
| 2570 | { | { |
| 2571 | if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH); | if (md->end_subject - eptr < 1) |
| 2572 | { | |
| 2573 | SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */ | |
| 2574 | RRETURN(MATCH_NOMATCH); | |
| 2575 | } | |
| 2576 | if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); |
| 2577 | ecode += 2; | ecode += 2; |
| 2578 | } | } |
| 2579 | break; | break; |
| 2580 | ||
| 2581 | /* Match a single character repeatedly; different opcodes share code. */ | /* Match a single character repeatedly. */ |
| 2582 | ||
| 2583 | case OP_EXACT: | case OP_EXACT: |
| 2584 | min = max = GET2(ecode, 1); | min = max = GET2(ecode, 1); |
| 2585 | ecode += 3; | ecode += 3; |
| 2586 | goto REPEATCHAR; | goto REPEATCHAR; |
| 2587 | ||
| 2588 | case OP_POSUPTO: | |
| 2589 | possessive = TRUE; | |
| 2590 | /* Fall through */ | |
| 2591 | ||
| 2592 | case OP_UPTO: | case OP_UPTO: |
| 2593 | case OP_MINUPTO: | case OP_MINUPTO: |
| 2594 | min = 0; | min = 0; |
| # | Line 1968 for (;;) | Line 2597 for (;;) |
| 2597 | ecode += 3; | ecode += 3; |
| 2598 | goto REPEATCHAR; | goto REPEATCHAR; |
| 2599 | ||
| 2600 | case OP_POSSTAR: | |
| 2601 | possessive = TRUE; | |
| 2602 | min = 0; | |
| 2603 | max = INT_MAX; | |
| 2604 | ecode++; | |
| 2605 | goto REPEATCHAR; | |
| 2606 | ||
| 2607 | case OP_POSPLUS: | |
| 2608 | possessive = TRUE; | |
| 2609 | min = 1; | |
| 2610 | max = INT_MAX; | |
| 2611 | ecode++; | |
| 2612 | goto REPEATCHAR; | |
| 2613 | ||
| 2614 | case OP_POSQUERY: | |
| 2615 | possessive = TRUE; | |
| 2616 | min = 0; | |
| 2617 | max = 1; | |
| 2618 | ecode++; | |
| 2619 | goto REPEATCHAR; | |
| 2620 | ||
| 2621 | case OP_STAR: | case OP_STAR: |
| 2622 | case OP_MINSTAR: | case OP_MINSTAR: |
| 2623 | case OP_PLUS: | case OP_PLUS: |
| # | Line 1976 for (;;) | Line 2626 for (;;) |
| 2626 | case OP_MINQUERY: | case OP_MINQUERY: |
| 2627 | c = *ecode++ - OP_STAR; | c = *ecode++ - OP_STAR; |
| 2628 | minimize = (c & 1) != 0; | minimize = (c & 1) != 0; |
| 2629 | ||
| 2630 | min = rep_min[c]; /* Pick up values from tables; */ | min = rep_min[c]; /* Pick up values from tables; */ |
| 2631 | max = rep_max[c]; /* zero for max => infinity */ | max = rep_max[c]; /* zero for max => infinity */ |
| 2632 | if (max == 0) max = INT_MAX; | if (max == 0) max = INT_MAX; |
| 2633 | ||
| 2634 | /* Common code for all repeated single-character matches. We can give | /* Common code for all repeated single-character matches. */ |
| up quickly if there are fewer than the minimum number of characters left in | ||
| the subject. */ | ||
| 2635 | ||
| 2636 | REPEATCHAR: | REPEATCHAR: |
| 2637 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1991 for (;;) | Line 2640 for (;;) |
| 2640 | length = 1; | length = 1; |
| 2641 | charptr = ecode; | charptr = ecode; |
| 2642 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
| if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
| 2643 | ecode += length; | ecode += length; |
| 2644 | ||
| 2645 | /* Handle multibyte character matching specially here. There is | /* Handle multibyte character matching specially here. There is |
| # | Line 1999 for (;;) | Line 2647 for (;;) |
| 2647 | ||
| 2648 | if (length > 1) | if (length > 1) |
| 2649 | { | { |
| int oclength = 0; | ||
| uschar occhars[8]; | ||
| 2650 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2651 | int othercase; | unsigned int othercase; |
| 2652 | if ((ims & PCRE_CASELESS) != 0 && | if ((ims & PCRE_CASELESS) != 0 && |
| 2653 | (othercase = _pcre_ucp_othercase(fc)) >= 0 && | (othercase = UCD_OTHERCASE(fc)) != fc) |
| othercase >= 0) | ||
| 2654 | oclength = _pcre_ord2utf8(othercase, occhars); | oclength = _pcre_ord2utf8(othercase, occhars); |
| 2655 | else oclength = 0; | |
| 2656 | #endif /* SUPPORT_UCP */ | #endif /* SUPPORT_UCP */ |
| 2657 | ||
| 2658 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2659 | { | { |
| 2660 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (eptr <= md->end_subject - length && |
| 2661 | /* Need braces because of following else */ | memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2662 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | #ifdef SUPPORT_UCP |
| 2663 | else if (oclength > 0 && | |
| 2664 | eptr <= md->end_subject - oclength && | |
| 2665 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
| 2666 | #endif /* SUPPORT_UCP */ | |
| 2667 | else | else |
| 2668 | { | { |
| 2669 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | CHECK_PARTIAL(); |
| 2670 | eptr += oclength; | RRETURN(MATCH_NOMATCH); |
| 2671 | } | } |
| 2672 | } | } |
| 2673 | ||
| # | Line 2028 for (;;) | Line 2677 for (;;) |
| 2677 | { | { |
| 2678 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2679 | { | { |
| 2680 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22); |
| 2681 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2682 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2683 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (eptr <= md->end_subject - length && |
| 2684 | /* Need braces because of following else */ | memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2685 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | #ifdef SUPPORT_UCP |
| 2686 | else if (oclength > 0 && | |
| 2687 | eptr <= md->end_subject - oclength && | |
| 2688 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
| 2689 | #endif /* SUPPORT_UCP */ | |
| 2690 | else | else |
| 2691 | { | { |
| 2692 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | CHECK_PARTIAL(); |
| 2693 | eptr += oclength; | RRETURN(MATCH_NOMATCH); |
| 2694 | } | } |
| 2695 | } | } |
| 2696 | /* Control never gets here */ | /* Control never gets here */ |
| 2697 | } | } |
| 2698 | else | |
| 2699 | else /* Maximize */ | |
| 2700 | { | { |
| 2701 | pp = eptr; | pp = eptr; |
| 2702 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2703 | { | { |
| 2704 | if (eptr > md->end_subject - length) break; | if (eptr <= md->end_subject - length && |
| 2705 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2706 | else if (oclength == 0) break; | #ifdef SUPPORT_UCP |
| 2707 | else if (oclength > 0 && | |
| 2708 | eptr <= md->end_subject - oclength && | |
| 2709 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
| 2710 | #endif /* SUPPORT_UCP */ | |
| 2711 | else | else |
| 2712 | { | { |
| 2713 | if (memcmp(eptr, occhars, oclength) != 0) break; | CHECK_PARTIAL(); |
| 2714 | eptr += oclength; | break; |
| 2715 | } | } |
| 2716 | } | } |
| 2717 | while (eptr >= pp) | |
| 2718 | { | if (possessive) continue; |
| 2719 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | |
| 2720 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | for(;;) |
| 2721 | eptr -= length; | { |
| 2722 | } | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23); |
| 2723 | RRETURN(MATCH_NOMATCH); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2724 | if (eptr == pp) { RRETURN(MATCH_NOMATCH); } | |
| 2725 | #ifdef SUPPORT_UCP | |
| 2726 | eptr--; | |
| 2727 | BACKCHAR(eptr); | |
| 2728 | #else /* without SUPPORT_UCP */ | |
| 2729 | eptr -= length; | |
| 2730 | #endif /* SUPPORT_UCP */ | |
| 2731 | } | |
| 2732 | } | } |
| 2733 | /* Control never gets here */ | /* Control never gets here */ |
| 2734 | } | } |
| # | Line 2075 for (;;) | Line 2741 for (;;) |
| 2741 | #endif /* SUPPORT_UTF8 */ | #endif /* SUPPORT_UTF8 */ |
| 2742 | ||
| 2743 | /* When not in UTF-8 mode, load a single-byte character. */ | /* When not in UTF-8 mode, load a single-byte character. */ |
| 2744 | { | |
| 2745 | if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | fc = *ecode++; |
| fc = *ecode++; | ||
| } | ||
| 2746 | ||
| 2747 | /* The value of fc at this point is always less than 256, though we may or | /* The value of fc at this point is always less than 256, though we may or |
| 2748 | may not be in UTF-8 mode. The code is duplicated for the caseless and | may not be in UTF-8 mode. The code is duplicated for the caseless and |
| # | Line 2096 for (;;) | Line 2760 for (;;) |
| 2760 | { | { |
| 2761 | fc = md->lcc[fc]; | fc = md->lcc[fc]; |
| 2762 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2763 | { | |
| 2764 | if (eptr >= md->end_subject) | |
| 2765 | { | |
| 2766 | SCHECK_PARTIAL(); | |
| 2767 | RRETURN(MATCH_NOMATCH); | |
| 2768 | } | |
| 2769 | if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); |
| 2770 | } | |
| 2771 | if (min == max) continue; | if (min == max) continue; |
| 2772 | if (minimize) | if (minimize) |
| 2773 | { | { |
| 2774 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2775 | { | { |
| 2776 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24); |
| 2777 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2778 | if (fi >= max || eptr >= md->end_subject || | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2779 | fc != md->lcc[*eptr++]) | if (eptr >= md->end_subject) |
| 2780 | { | |
| 2781 | SCHECK_PARTIAL(); | |
| 2782 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2783 | } | |
| 2784 | if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | |
| 2785 | } | } |
| 2786 | /* Control never gets here */ | /* Control never gets here */ |
| 2787 | } | } |
| 2788 | else | else /* Maximize */ |
| 2789 | { | { |
| 2790 | pp = eptr; | pp = eptr; |
| 2791 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2792 | { | { |
| 2793 | if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break; | if (eptr >= md->end_subject) |
| 2794 | { | |
| 2795 | SCHECK_PARTIAL(); | |
| 2796 | break; | |
| 2797 | } | |
| 2798 | if (fc != md->lcc[*eptr]) break; | |
| 2799 | eptr++; | eptr++; |
| 2800 | } | } |
| 2801 | ||
| 2802 | if (possessive) continue; | |
| 2803 | ||
| 2804 | while (eptr >= pp) | while (eptr >= pp) |
| 2805 | { | { |
| 2806 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25); |
| 2807 | eptr--; | eptr--; |
| 2808 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2809 | } | } |
| # | Line 2133 for (;;) | Line 2816 for (;;) |
| 2816 | ||
| 2817 | else | else |
| 2818 | { | { |
| 2819 | for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH); | for (i = 1; i <= min; i++) |
| 2820 | { | |
| 2821 | if (eptr >= md->end_subject) | |
| 2822 | { | |
| 2823 | SCHECK_PARTIAL(); | |
| 2824 | RRETURN(MATCH_NOMATCH); | |
| 2825 | } | |
| 2826 | if (fc != *eptr++) RRETURN(MATCH_NOMATCH); | |
| 2827 | } | |
| 2828 | ||
| 2829 | if (min == max) continue; | if (min == max) continue; |
| 2830 | ||
| 2831 | if (minimize) | if (minimize) |
| 2832 | { | { |
| 2833 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2834 | { | { |
| 2835 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26); |
| 2836 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2837 | if (fi >= max || eptr >= md->end_subject || fc != *eptr++) | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2838 | if (eptr >= md->end_subject) | |
| 2839 | { | |
| 2840 | SCHECK_PARTIAL(); | |
| 2841 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2842 | } | |
| 2843 | if (fc != *eptr++) RRETURN(MATCH_NOMATCH); | |
| 2844 | } | } |
| 2845 | /* Control never gets here */ | /* Control never gets here */ |
| 2846 | } | } |
| 2847 | else | else /* Maximize */ |
| 2848 | { | { |
| 2849 | pp = eptr; | pp = eptr; |
| 2850 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2851 | { | { |
| 2852 | if (eptr >= md->end_subject || fc != *eptr) break; | if (eptr >= md->end_subject) |
| 2853 | { | |
| 2854 | SCHECK_PARTIAL(); | |
| 2855 | break; | |
| 2856 | } | |
| 2857 | if (fc != *eptr) break; | |
| 2858 | eptr++; | eptr++; |
| 2859 | } | } |
| 2860 | if (possessive) continue; | |
| 2861 | ||
| 2862 | while (eptr >= pp) | while (eptr >= pp) |
| 2863 | { | { |
| 2864 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27); |
| 2865 | eptr--; | eptr--; |
| 2866 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2867 | } | } |
| # | Line 2169 for (;;) | Line 2874 for (;;) |
| 2874 | checking can be multibyte. */ | checking can be multibyte. */ |
| 2875 | ||
| 2876 | case OP_NOT: | case OP_NOT: |
| 2877 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2878 | { | |
| 2879 | SCHECK_PARTIAL(); | |
| 2880 | RRETURN(MATCH_NOMATCH); | |
| 2881 | } | |
| 2882 | ecode++; | ecode++; |
| 2883 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2884 | if ((ims & PCRE_CASELESS) != 0) | if ((ims & PCRE_CASELESS) != 0) |
| # | Line 2206 for (;;) | Line 2915 for (;;) |
| 2915 | ecode += 3; | ecode += 3; |
| 2916 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
| 2917 | ||
| 2918 | case OP_NOTPOSSTAR: | |
| 2919 | possessive = TRUE; | |
| 2920 | min = 0; | |
| 2921 | max = INT_MAX; | |
| 2922 | ecode++; | |
| 2923 | goto REPEATNOTCHAR; | |
| 2924 | ||
| 2925 | case OP_NOTPOSPLUS: | |
| 2926 | possessive = TRUE; | |
| 2927 | min = 1; | |
| 2928 | max = INT_MAX; | |
| 2929 | ecode++; | |
| 2930 | goto REPEATNOTCHAR; | |
| 2931 | ||
| 2932 | case OP_NOTPOSQUERY: | |
| 2933 | possessive = TRUE; | |
| 2934 | min = 0; | |
| 2935 | max = 1; | |
| 2936 | ecode++; | |
| 2937 | goto REPEATNOTCHAR; | |
| 2938 | ||
| 2939 | case OP_NOTPOSUPTO: | |
| 2940 | possessive = TRUE; | |
| 2941 | min = 0; | |
| 2942 | max = GET2(ecode, 1); | |
| 2943 | ecode += 3; | |
| 2944 | goto REPEATNOTCHAR; | |
| 2945 | ||
| 2946 | case OP_NOTSTAR: | case OP_NOTSTAR: |
| 2947 | case OP_NOTMINSTAR: | case OP_NOTMINSTAR: |
| 2948 | case OP_NOTPLUS: | case OP_NOTPLUS: |
| # | Line 2218 for (;;) | Line 2955 for (;;) |
| 2955 | max = rep_max[c]; /* zero for max => infinity */ | max = rep_max[c]; /* zero for max => infinity */ |
| 2956 | if (max == 0) max = INT_MAX; | if (max == 0) max = INT_MAX; |
| 2957 | ||
| 2958 | /* Common code for all repeated single-byte matches. We can give up quickly | /* Common code for all repeated single-byte matches. */ |
| if there are fewer than the minimum number of bytes left in the | ||
| subject. */ | ||
| 2959 | ||
| 2960 | REPEATNOTCHAR: | REPEATNOTCHAR: |
| if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
| 2961 | fc = *ecode++; | fc = *ecode++; |
| 2962 | ||
| 2963 | /* The code is duplicated for the caseless and caseful cases, for speed, | /* The code is duplicated for the caseless and caseful cases, for speed, |
| # | Line 2245 for (;;) | Line 2979 for (;;) |
| 2979 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2980 | if (utf8) | if (utf8) |
| 2981 | { | { |
| 2982 | register int d; | register unsigned int d; |
| 2983 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2984 | { | { |
| 2985 | if (eptr >= md->end_subject) | |
| 2986 | { | |
| 2987 | SCHECK_PARTIAL(); | |
| 2988 | RRETURN(MATCH_NOMATCH); | |
| 2989 | } | |
| 2990 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 2991 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
| 2992 | if (fc == d) RRETURN(MATCH_NOMATCH); | if (fc == d) RRETURN(MATCH_NOMATCH); |
| # | Line 2259 for (;;) | Line 2998 for (;;) |
| 2998 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
| 2999 | { | { |
| 3000 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3001 | { | |
| 3002 | if (eptr >= md->end_subject) | |
| 3003 | { | |
| 3004 | SCHECK_PARTIAL(); | |
| 3005 | RRETURN(MATCH_NOMATCH); | |
| 3006 | } | |
| 3007 | if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); |
| 3008 | } | |
| 3009 | } | } |
| 3010 | ||
| 3011 | if (min == max) continue; | if (min == max) continue; |
| # | Line 2270 for (;;) | Line 3016 for (;;) |
| 3016 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 3017 | if (utf8) | if (utf8) |
| 3018 | { | { |
| 3019 | register int d; | register unsigned int d; |
| 3020 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3021 | { | { |
| 3022 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28); |
| 3023 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3024 | if (fi >= max) RRETURN(MATCH_NOMATCH); | |
| 3025 | if (eptr >= md->end_subject) | |
| 3026 | { | |
| 3027 | SCHECK_PARTIAL(); | |
| 3028 | RRETURN(MATCH_NOMATCH); | |
| 3029 | } | |
| 3030 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 3031 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
| 3032 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (fc == d) RRETURN(MATCH_NOMATCH); |
| RRETURN(MATCH_NOMATCH); | ||
| 3033 | } | } |
| 3034 | } | } |
| 3035 | else | else |
| # | Line 2287 for (;;) | Line 3038 for (;;) |
| 3038 | { | { |
| 3039 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3040 | { | { |
| 3041 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29); |
| 3042 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3043 | if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++]) | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3044 | if (eptr >= md->end_subject) | |
| 3045 | { | |
| 3046 | SCHECK_PARTIAL(); | |
| 3047 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3048 | } | |
| 3049 | if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | |
| 3050 | } | } |
| 3051 | } | } |
| 3052 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 2306 for (;;) | Line 3062 for (;;) |
| 3062 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 3063 | if (utf8) | if (utf8) |
| 3064 | { | { |
| 3065 | register int d; | register unsigned int d; |
| 3066 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3067 | { | { |
| 3068 | int len = 1; | int len = 1; |
| 3069 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
| 3070 | { | |
| 3071 | SCHECK_PARTIAL(); | |
| 3072 | break; | |
| 3073 | } | |
| 3074 | GETCHARLEN(d, eptr, len); | GETCHARLEN(d, eptr, len); |
| 3075 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
| 3076 | if (fc == d) break; | if (fc == d) break; |
| 3077 | eptr += len; | eptr += len; |
| 3078 | } | } |
| 3079 | for(;;) | if (possessive) continue; |
| 3080 | for(;;) | |
| 3081 | { | { |
| 3082 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30); |
| 3083 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3084 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3085 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 2330 for (;;) | Line 3091 for (;;) |
| 3091 | { | { |
| 3092 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3093 | { | { |
| 3094 | if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break; | if (eptr >= md->end_subject) |
| 3095 | { | |
| 3096 | SCHECK_PARTIAL(); | |
| 3097 | break; | |
| 3098 | } | |
| 3099 | if (fc == md->lcc[*eptr]) break; | |
| 3100 | eptr++; | eptr++; |
| 3101 | } | } |
| 3102 | if (possessive) continue; | |
| 3103 | while (eptr >= pp) | while (eptr >= pp) |
| 3104 | { | { |
| 3105 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31); |
| 3106 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3107 | eptr--; | eptr--; |
| 3108 | } | } |
| # | Line 2354 for (;;) | Line 3121 for (;;) |
| 3121 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 3122 | if (utf8) | if (utf8) |
| 3123 | { | { |
| 3124 | register int d; | register unsigned int d; |
| 3125 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3126 | { | { |
| 3127 | if (eptr >= md->end_subject) | |
| 3128 | { | |
| 3129 | SCHECK_PARTIAL(); | |
| 3130 | RRETURN(MATCH_NOMATCH); | |
| 3131 | } | |
| 3132 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 3133 | if (fc == d) RRETURN(MATCH_NOMATCH); | if (fc == d) RRETURN(MATCH_NOMATCH); |
| 3134 | } | } |
| # | Line 2366 for (;;) | Line 3138 for (;;) |
| 3138 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
| 3139 | { | { |
| 3140 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3141 | { | |
| 3142 | if (eptr >= md->end_subject) | |
| 3143 | { | |
| 3144 | SCHECK_PARTIAL(); | |
| 3145 | RRETURN(MATCH_NOMATCH); | |
| 3146 | } | |
| 3147 | if (fc == *eptr++) RRETURN(MATCH_NOMATCH); | if (fc == *eptr++) RRETURN(MATCH_NOMATCH); |
| 3148 | } | |
| 3149 | } | } |
| 3150 | ||
| 3151 | if (min == max) continue; | if (min == max) continue; |
| # | Line 2377 for (;;) | Line 3156 for (;;) |
| 3156 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 3157 | if (utf8) | if (utf8) |
| 3158 | { | { |
| 3159 | register int d; | register unsigned int d; |
| 3160 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3161 | { | { |
| 3162 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32); |
| 3163 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3164 | GETCHARINC(d, eptr); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3165 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (eptr >= md->end_subject) |
| 3166 | { | |
| 3167 | SCHECK_PARTIAL(); | |
| 3168 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3169 | } | |
| 3170 | GETCHARINC(d, eptr); | |
| 3171 | if (fc == d) RRETURN(MATCH_NOMATCH); | |
| 3172 | } | } |
| 3173 | } | } |
| 3174 | else | else |
| # | Line 2393 for (;;) | Line 3177 for (;;) |
| 3177 | { | { |
| 3178 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3179 | { | { |
| 3180 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33); |
| 3181 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3182 | if (fi >= max || eptr >= md->end_subject || fc == *eptr++) | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3183 | if (eptr >= md->end_subject) | |
| 3184 | { | |
| 3185 | SCHECK_PARTIAL(); | |
| 3186 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3187 | } | |
| 3188 | if (fc == *eptr++) RRETURN(MATCH_NOMATCH); | |
| 3189 | } | } |
| 3190 | } | } |
| 3191 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 2412 for (;;) | Line 3201 for (;;) |
| 3201 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 3202 | if (utf8) | if (utf8) |
| 3203 | { | { |
| 3204 | register int d; | register unsigned int d; |
| 3205 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3206 | { | { |
| 3207 | int len = 1; | int len = 1; |
| 3208 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
| 3209 | GETCHARLEN(d, eptr, len); | { |
| 3210 | if (fc == d) break; | SCHECK_PARTIAL(); |
| 3211 | break; | |
| 3212 | } | |
| 3213 | GETCHARLEN(d, eptr, len); | |
| 3214 | if (fc == d) break; | |
| 3215 | eptr += len; | eptr += len; |
| 3216 | } | } |
| 3217 | if (possessive) continue; | |
| 3218 | for(;;) | for(;;) |
| 3219 | { | { |
| 3220 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34); |
| 3221 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3222 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3223 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 2435 for (;;) | Line 3229 for (;;) |
| 3229 | { | { |
| 3230 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3231 | { | { |
| 3232 | if (eptr >= md->end_subject || fc == *eptr) break; | if (eptr >= md->end_subject) |
| 3233 | { | |
| 3234 | SCHECK_PARTIAL(); | |
| 3235 | break; | |
| 3236 | } | |
| 3237 | if (fc == *eptr) break; | |
| 3238 | eptr++; | eptr++; |
| 3239 | } | } |
| 3240 | if (possessive) continue; | |
| 3241 | while (eptr >= pp) | while (eptr >= pp) |
| 3242 | { | { |
| 3243 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35); |
| 3244 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3245 | eptr--; | eptr--; |
| 3246 | } | } |
| # | Line 2469 for (;;) | Line 3269 for (;;) |
| 3269 | ecode += 3; | ecode += 3; |
| 3270 | goto REPEATTYPE; | goto REPEATTYPE; |
| 3271 | ||
| 3272 | case OP_TYPEPOSSTAR: | |
| 3273 | possessive = TRUE; | |
| 3274 | min = 0; | |
| 3275 | max = INT_MAX; | |
| 3276 | ecode++; | |
| 3277 | goto REPEATTYPE; | |
| 3278 | ||
| 3279 | case OP_TYPEPOSPLUS: | |
| 3280 | possessive = TRUE; | |
| 3281 | min = 1; | |
| 3282 | max = INT_MAX; | |
| 3283 | ecode++; | |
| 3284 | goto REPEATTYPE; | |
| 3285 | ||
| 3286 | case OP_TYPEPOSQUERY: | |
| 3287 | possessive = TRUE; | |
| 3288 | min = 0; | |
| 3289 | max = 1; | |
| 3290 | ecode++; | |
| 3291 | goto REPEATTYPE; | |
| 3292 | ||
| 3293 | case OP_TYPEPOSUPTO: | |
| 3294 | possessive = TRUE; | |
| 3295 | min = 0; | |
| 3296 | max = GET2(ecode, 1); | |
| 3297 | ecode += 3; | |
| 3298 | goto REPEATTYPE; | |
| 3299 | ||
| 3300 | case OP_TYPESTAR: | case OP_TYPESTAR: |
| 3301 | case OP_TYPEMINSTAR: | case OP_TYPEMINSTAR: |
| 3302 | case OP_TYPEPLUS: | case OP_TYPEPLUS: |
| # | Line 2500 for (;;) | Line 3328 for (;;) |
| 3328 | ||
| 3329 | /* First, ensure the minimum number of matches are present. Use inline | /* First, ensure the minimum number of matches are present. Use inline |
| 3330 | code for maximizing the speed, and do the type test once at the start | code for maximizing the speed, and do the type test once at the start |
| 3331 | (i.e. keep it out of the loop). Also we can test that there are at least | (i.e. keep it out of the loop). Separate the UTF-8 code completely as that |
| the minimum number of bytes before we start. This isn't as effective in | ||
| UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that | ||
| 3332 | is tidier. Also separate the UCP code, which can be the same for both UTF-8 | is tidier. Also separate the UCP code, which can be the same for both UTF-8 |
| 3333 | and single-bytes. */ | and single-bytes. */ |
| 3334 | ||
| if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
| 3335 | if (min > 0) | if (min > 0) |
| 3336 | { | { |
| 3337 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| # | Line 2518 for (;;) | Line 3343 for (;;) |
| 3343 | if (prop_fail_result) RRETURN(MATCH_NOMATCH); | if (prop_fail_result) RRETURN(MATCH_NOMATCH); |
| 3344 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3345 | { | { |
| 3346 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3347 | GETCHARINC(c, eptr); | { |
| 3348 | SCHECK_PARTIAL(); | |
| 3349 | RRETURN(MATCH_NOMATCH); | |
| 3350 | } | |
| 3351 | GETCHARINCTEST(c, eptr); | |
| 3352 | } | } |
| 3353 | break; | break; |
| 3354 | ||
| 3355 | case PT_LAMP: | case PT_LAMP: |
| 3356 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3357 | { | { |
| 3358 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3359 | GETCHARINC(c, eptr); | { |
| 3360 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
| 3361 | RRETURN(MATCH_NOMATCH); | |
| 3362 | } | |
| 3363 | GETCHARINCTEST(c, eptr); | |
| 3364 | prop_chartype = UCD_CHARTYPE(c); | |
| 3365 | if ((prop_chartype == ucp_Lu || | if ((prop_chartype == ucp_Lu || |
| 3366 | prop_chartype == ucp_Ll || | prop_chartype == ucp_Ll || |
| 3367 | prop_chartype == ucp_Lt) == prop_fail_result) | prop_chartype == ucp_Lt) == prop_fail_result) |
| # | Line 2539 for (;;) | Line 3372 for (;;) |
| 3372 | case PT_GC: | case PT_GC: |
| 3373 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3374 | { | { |
| 3375 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3376 | GETCHARINC(c, eptr); | { |
| 3377 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
| 3378 | RRETURN(MATCH_NOMATCH); | |
| 3379 | } | |
| 3380 | GETCHARINCTEST(c, eptr); | |
| 3381 | prop_category = UCD_CATEGORY(c); | |
| 3382 | if ((prop_category == prop_value) == prop_fail_result) | if ((prop_category == prop_value) == prop_fail_result) |
| 3383 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3384 | } | } |
| # | Line 2550 for (;;) | Line 3387 for (;;) |
| 3387 | case PT_PC: | case PT_PC: |
| 3388 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3389 | { | { |
| 3390 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3391 | GETCHARINC(c, eptr); | { |
| 3392 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
| 3393 | RRETURN(MATCH_NOMATCH); | |
| 3394 | } | |
| 3395 | GETCHARINCTEST(c, eptr); | |
| 3396 | prop_chartype = UCD_CHARTYPE(c); | |
| 3397 | if ((prop_chartype == prop_value) == prop_fail_result) | if ((prop_chartype == prop_value) == prop_fail_result) |
| 3398 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3399 | } | } |
| # | Line 2561 for (;;) | Line 3402 for (;;) |
| 3402 | case PT_SC: | case PT_SC: |
| 3403 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3404 | { | { |
| 3405 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3406 | GETCHARINC(c, eptr); | { |
| 3407 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
| 3408 | RRETURN(MATCH_NOMATCH); | |
| 3409 | } | |
| 3410 | GETCHARINCTEST(c, eptr); | |
| 3411 | prop_script = UCD_SCRIPT(c); | |
| 3412 | if ((prop_script == prop_value) == prop_fail_result) | if ((prop_script == prop_value) == prop_fail_result) |
| 3413 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3414 | } | } |
| # | Line 2571 for (;;) | Line 3416 for (;;) |
| 3416 | ||
| 3417 | default: | default: |
| 3418 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
| break; | ||
| 3419 | } | } |
| 3420 | } | } |
| 3421 | ||
| # | Line 2582 for (;;) | Line 3426 for (;;) |
| 3426 | { | { |
| 3427 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3428 | { | { |
| 3429 | if (eptr >= md->end_subject) | |
| 3430 | { | |
| 3431 | SCHECK_PARTIAL(); | |
| 3432 | RRETURN(MATCH_NOMATCH); | |
| 3433 | } | |
| 3434 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3435 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
| 3436 | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 3437 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 3438 | { | { |
| 3439 | int len = 1; | int len = 1; |
| 3440 | if (!utf8) c = *eptr; else | if (!utf8) c = *eptr; |
| 3441 | { | else { GETCHARLEN(c, eptr, len); } |
| 3442 | GETCHARLEN(c, eptr, len); | prop_category = UCD_CATEGORY(c); |
| } | ||
| prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | ||
| 3443 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 3444 | eptr += len; | eptr += len; |
| 3445 | } | } |
| # | Line 2610 for (;;) | Line 3457 for (;;) |
| 3457 | case OP_ANY: | case OP_ANY: |
| 3458 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3459 | { | { |
| 3460 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
| 3461 | ((ims & PCRE_DOTALL) == 0 && | { |
| 3462 | eptr <= md->end_subject - md->nllen && | SCHECK_PARTIAL(); |
| IS_NEWLINE(eptr))) | ||
| 3463 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3464 | } | |
| 3465 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); | |
| 3466 | eptr++; | |
| 3467 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | |
| 3468 | } | |
| 3469 | break; | |
| 3470 | ||
| 3471 | case OP_ALLANY: | |
| 3472 | for (i = 1; i <= min; i++) | |
| 3473 | { | |
| 3474 | if (eptr >= md->end_subject) | |
| 3475 | { | |
| 3476 | SCHECK_PARTIAL(); | |
| 3477 | RRETURN(MATCH_NOMATCH); | |
| 3478 | } | |
| 3479 | eptr++; | eptr++; |
| 3480 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| 3481 | } | } |
| 3482 | break; | break; |
| 3483 | ||
| 3484 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 3485 | if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH); | |
| 3486 | eptr += min; | eptr += min; |
| 3487 | break; | break; |
| 3488 | ||
| 3489 | case OP_ANYNL: | |
| 3490 | for (i = 1; i <= min; i++) | |
| 3491 | { | |
| 3492 | if (eptr >= md->end_subject) | |
| 3493 | { | |
| 3494 | SCHECK_PARTIAL(); | |
| 3495 | RRETURN(MATCH_NOMATCH); | |
| 3496 | } | |
| 3497 | GETCHARINC(c, eptr); | |
| 3498 | switch(c) | |
| 3499 | { | |
| 3500 | default: RRETURN(MATCH_NOMATCH); | |
| 3501 | case 0x000d: | |
| 3502 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3503 | break; | |
| 3504 | ||
| 3505 | case 0x000a: | |
| 3506 | break; | |
| 3507 | ||
| 3508 | case 0x000b: | |
| 3509 | case 0x000c: | |
| 3510 | case 0x0085: | |
| 3511 | case 0x2028: | |
| 3512 | case 0x2029: | |
| 3513 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3514 | break; | |
| 3515 | } | |
| 3516 | } | |
| 3517 | break; | |
| 3518 | ||
| 3519 | case OP_NOT_HSPACE: | |
| 3520 | for (i = 1; i <= min; i++) | |
| 3521 | { | |
| 3522 | if (eptr >= md->end_subject) | |
| 3523 | { | |
| 3524 | SCHECK_PARTIAL(); | |
| 3525 | RRETURN(MATCH_NOMATCH); | |
| 3526 | } | |
| 3527 | GETCHARINC(c, eptr); | |
| 3528 | switch(c) | |
| 3529 | { | |
| 3530 | default: break; | |
| 3531 | case 0x09: /* HT */ | |
| 3532 | case 0x20: /* SPACE */ | |
| 3533 | case 0xa0: /* NBSP */ | |
| 3534 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3535 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3536 | case 0x2000: /* EN QUAD */ | |
| 3537 | case 0x2001: /* EM QUAD */ | |
| 3538 | case 0x2002: /* EN SPACE */ | |
| 3539 | case 0x2003: /* EM SPACE */ | |
| 3540 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3541 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3542 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3543 | case 0x2007: /* FIGURE SPACE */ | |
| 3544 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3545 | case 0x2009: /* THIN SPACE */ | |
| 3546 | case 0x200A: /* HAIR SPACE */ | |
| 3547 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3548 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3549 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3550 | RRETURN(MATCH_NOMATCH); | |
| 3551 | } | |
| 3552 | } | |
| 3553 | break; | |
| 3554 | ||
| 3555 | case OP_HSPACE: | |
| 3556 | for (i = 1; i <= min; i++) | |
| 3557 | { | |
| 3558 | if (eptr >= md->end_subject) | |
| 3559 | { | |
| 3560 | SCHECK_PARTIAL(); | |
| 3561 | RRETURN(MATCH_NOMATCH); | |
| 3562 | } | |
| 3563 | GETCHARINC(c, eptr); | |
| 3564 | switch(c) | |
| 3565 | { | |
| 3566 | default: RRETURN(MATCH_NOMATCH); | |
| 3567 | case 0x09: /* HT */ | |
| 3568 | case 0x20: /* SPACE */ | |
| 3569 | case 0xa0: /* NBSP */ | |
| 3570 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3571 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3572 | case 0x2000: /* EN QUAD */ | |
| 3573 | case 0x2001: /* EM QUAD */ | |
| 3574 | case 0x2002: /* EN SPACE */ | |
| 3575 | case 0x2003: /* EM SPACE */ | |
| 3576 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3577 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3578 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3579 | case 0x2007: /* FIGURE SPACE */ | |
| 3580 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3581 | case 0x2009: /* THIN SPACE */ | |
| 3582 | case 0x200A: /* HAIR SPACE */ | |
| 3583 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3584 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3585 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3586 | break; | |
| 3587 | } | |
| 3588 | } | |
| 3589 | break; | |
| 3590 | ||
| 3591 | case OP_NOT_VSPACE: | |
| 3592 | for (i = 1; i <= min; i++) | |
| 3593 | { | |
| 3594 | if (eptr >= md->end_subject) | |
| 3595 | { | |
| 3596 | SCHECK_PARTIAL(); | |
| 3597 | RRETURN(MATCH_NOMATCH); | |
| 3598 | } | |
| 3599 | GETCHARINC(c, eptr); | |
| 3600 | switch(c) | |
| 3601 | { | |
| 3602 | default: break; | |
| 3603 | case 0x0a: /* LF */ | |
| 3604 | case 0x0b: /* VT */ | |
| 3605 | case 0x0c: /* FF */ | |
| 3606 | case 0x0d: /* CR */ | |
| 3607 | case 0x85: /* NEL */ | |
| 3608 | case 0x2028: /* LINE SEPARATOR */ | |
| 3609 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3610 | RRETURN(MATCH_NOMATCH); | |
| 3611 | } | |
| 3612 | } | |
| 3613 | break; | |
| 3614 | ||
| 3615 | case OP_VSPACE: | |
| 3616 | for (i = 1; i <= min; i++) | |
| 3617 | { | |
| 3618 | if (eptr >= md->end_subject) | |
| 3619 | { | |
| 3620 | SCHECK_PARTIAL(); | |
| 3621 | RRETURN(MATCH_NOMATCH); | |
| 3622 | } | |
| 3623 | GETCHARINC(c, eptr); | |
| 3624 | switch(c) | |
| 3625 | { | |
| 3626 | default: RRETURN(MATCH_NOMATCH); | |
| 3627 | case 0x0a: /* LF */ | |
| 3628 | case 0x0b: /* VT */ | |
| 3629 | case 0x0c: /* FF */ | |
| 3630 | case 0x0d: /* CR */ | |
| 3631 | case 0x85: /* NEL */ | |
| 3632 | case 0x2028: /* LINE SEPARATOR */ | |
| 3633 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3634 | break; | |
| 3635 | } | |
| 3636 | } | |
| 3637 | break; | |
| 3638 | ||
| 3639 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 3640 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3641 | { | { |
| 3642 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3643 | { | |
| 3644 | SCHECK_PARTIAL(); | |
| 3645 | RRETURN(MATCH_NOMATCH); | |
| 3646 | } | |
| 3647 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3648 | if (c < 128 && (md->ctypes[c] & ctype_digit) != 0) | if (c < 128 && (md->ctypes[c] & ctype_digit) != 0) |
| 3649 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| # | Line 2637 for (;;) | Line 3653 for (;;) |
| 3653 | case OP_DIGIT: | case OP_DIGIT: |
| 3654 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3655 | { | { |
| 3656 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
| 3657 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0) | { |
| 3658 | SCHECK_PARTIAL(); | |
| 3659 | RRETURN(MATCH_NOMATCH); | |
| 3660 | } | |
| 3661 | if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0) | |
| 3662 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3663 | /* No need to skip more bytes - we know it's a 1-byte character */ | /* No need to skip more bytes - we know it's a 1-byte character */ |
| 3664 | } | } |
| # | Line 2647 for (;;) | Line 3667 for (;;) |
| 3667 | case OP_NOT_WHITESPACE: | case OP_NOT_WHITESPACE: |
| 3668 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3669 | { | { |
| 3670 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
| 3671 | (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0)) | { |
| 3672 | SCHECK_PARTIAL(); | |
| 3673 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3674 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | } |
| 3675 | if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0) | |
| 3676 | RRETURN(MATCH_NOMATCH); | |
| 3677 | while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); | |
| 3678 | } | } |
| 3679 | break; | break; |
| 3680 | ||
| 3681 | case OP_WHITESPACE: | case OP_WHITESPACE: |
| 3682 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3683 | { | { |
| 3684 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
| 3685 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0) | { |
| 3686 | SCHECK_PARTIAL(); | |
| 3687 | RRETURN(MATCH_NOMATCH); | |
| 3688 | } | |
| 3689 | if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0) | |
| 3690 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3691 | /* No need to skip more bytes - we know it's a 1-byte character */ | /* No need to skip more bytes - we know it's a 1-byte character */ |
| 3692 | } | } |
| # | Line 2668 for (;;) | Line 3696 for (;;) |
| 3696 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3697 | { | { |
| 3698 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject || |
| 3699 | (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0)) | (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)) |
| 3700 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3701 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); |
| 3702 | } | } |
| 3703 | break; | break; |
| 3704 | ||
| 3705 | case OP_WORDCHAR: | case OP_WORDCHAR: |
| 3706 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3707 | { | { |
| 3708 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
| 3709 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0) | { |
| 3710 | SCHECK_PARTIAL(); | |
| 3711 | RRETURN(MATCH_NOMATCH); | |
| 3712 | } | |
| 3713 | if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0) | |
| 3714 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3715 | /* No need to skip more bytes - we know it's a 1-byte character */ | /* No need to skip more bytes - we know it's a 1-byte character */ |
| 3716 | } | } |
| # | Line 2697 for (;;) | Line 3729 for (;;) |
| 3729 | switch(ctype) | switch(ctype) |
| 3730 | { | { |
| 3731 | case OP_ANY: | case OP_ANY: |
| 3732 | if ((ims & PCRE_DOTALL) == 0) | for (i = 1; i <= min; i++) |
| 3733 | { | { |
| 3734 | for (i = 1; i <= min; i++) | if (eptr >= md->end_subject) |
| 3735 | { | { |
| 3736 | if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)) | SCHECK_PARTIAL(); |
| 3737 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| eptr++; | ||
| 3738 | } | } |
| 3739 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); | |
| 3740 | eptr++; | |
| 3741 | } | } |
| 3742 | else eptr += min; | break; |
| 3743 | ||
| 3744 | case OP_ALLANY: | |
| 3745 | if (eptr > md->end_subject - min) | |
| 3746 | { | |
| 3747 | SCHECK_PARTIAL(); | |
| 3748 | RRETURN(MATCH_NOMATCH); | |
| 3749 | } | |
| 3750 | eptr += min; | |
| 3751 | break; | break; |
| 3752 | ||
| 3753 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 3754 | if (eptr > md->end_subject - min) | |
| 3755 | { | |
| 3756 | SCHECK_PARTIAL(); | |
| 3757 | RRETURN(MATCH_NOMATCH); | |
| 3758 | } | |
| 3759 | eptr += min; | eptr += min; |
| 3760 | break; | break; |
| 3761 | ||
| 3762 | case OP_ANYNL: | |
| 3763 | for (i = 1; i <= min; i++) | |
| 3764 | { | |
| 3765 | if (eptr >= md->end_subject) | |
| 3766 | { | |
| 3767 | SCHECK_PARTIAL(); | |
| 3768 | RRETURN(MATCH_NOMATCH); | |
| 3769 | } | |
| 3770 | switch(*eptr++) | |
| 3771 | { | |
| 3772 | default: RRETURN(MATCH_NOMATCH); | |
| 3773 | case 0x000d: | |
| 3774 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3775 | break; | |
| 3776 | case 0x000a: | |
| 3777 | break; | |
| 3778 | ||
| 3779 | case 0x000b: | |
| 3780 | case 0x000c: | |
| 3781 | case 0x0085: | |
| 3782 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3783 | break; | |
| 3784 | } | |
| 3785 | } | |
| 3786 | break; | |
| 3787 | ||
| 3788 | case OP_NOT_HSPACE: | |
| 3789 | for (i = 1; i <= min; i++) | |
| 3790 | { | |
| 3791 | if (eptr >= md->end_subject) | |
| 3792 | { | |
| 3793 | SCHECK_PARTIAL(); | |
| 3794 | RRETURN(MATCH_NOMATCH); | |
| 3795 | } | |
| 3796 | switch(*eptr++) | |
| 3797 | { | |
| 3798 | default: break; | |
| 3799 | case 0x09: /* HT */ | |
| 3800 | case 0x20: /* SPACE */ | |
| 3801 | case 0xa0: /* NBSP */ | |
| 3802 | RRETURN(MATCH_NOMATCH); | |
| 3803 | } | |
| 3804 | } | |
| 3805 | break; | |
| 3806 | ||
| 3807 | case OP_HSPACE: | |
| 3808 | for (i = 1; i <= min; i++) | |
| 3809 | { | |
| 3810 | if (eptr >= md->end_subject) | |
| 3811 | { | |
| 3812 | SCHECK_PARTIAL(); | |
| 3813 | RRETURN(MATCH_NOMATCH); | |
| 3814 | } | |
| 3815 | switch(*eptr++) | |
| 3816 | { | |
| 3817 | default: RRETURN(MATCH_NOMATCH); | |
| 3818 | case 0x09: /* HT */ | |
| 3819 | case 0x20: /* SPACE */ | |
| 3820 | case 0xa0: /* NBSP */ | |
| 3821 | break; | |
| 3822 | } | |
| 3823 | } | |
| 3824 | break; | |
| 3825 | ||
| 3826 | case OP_NOT_VSPACE: | |
| 3827 | for (i = 1; i <= min; i++) | |
| 3828 | { | |
| 3829 | if (eptr >= md->end_subject) | |
| 3830 | { | |
| 3831 | SCHECK_PARTIAL(); | |
| 3832 | RRETURN(MATCH_NOMATCH); | |
| 3833 | } | |
| 3834 | switch(*eptr++) | |
| 3835 | { | |
| 3836 | default: break; | |
| 3837 | case 0x0a: /* LF */ | |
| 3838 | case 0x0b: /* VT */ | |
| 3839 | case 0x0c: /* FF */ | |
| 3840 | case 0x0d: /* CR */ | |
| 3841 | case 0x85: /* NEL */ | |
| 3842 | RRETURN(MATCH_NOMATCH); | |
| 3843 | } | |
| 3844 | } | |
| 3845 | break; | |
| 3846 | ||
| 3847 | case OP_VSPACE: | |
| 3848 | for (i = 1; i <= min; i++) | |
| 3849 | { | |
| 3850 | if (eptr >= md->end_subject) | |
| 3851 | { | |
| 3852 | SCHECK_PARTIAL(); | |
| 3853 | RRETURN(MATCH_NOMATCH); | |
| 3854 | } | |
| 3855 | switch(*eptr++) | |
| 3856 | { | |
| 3857 | default: RRETURN(MATCH_NOMATCH); | |
| 3858 | case 0x0a: /* LF */ | |
| 3859 | case 0x0b: /* VT */ | |
| 3860 | case 0x0c: /* FF */ | |
| 3861 | case 0x0d: /* CR */ | |
| 3862 | case 0x85: /* NEL */ | |
| 3863 | break; | |
| 3864 | } | |
| 3865 | } | |
| 3866 | break; | |
| 3867 | ||
| 3868 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 3869 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3870 | { | |
| 3871 | if (eptr >= md->end_subject) | |
| 3872 | { | |
| 3873 | SCHECK_PARTIAL(); | |
| 3874 | RRETURN(MATCH_NOMATCH); | |
| 3875 | } | |
| 3876 | if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); | if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); |
| 3877 | } | |
| 3878 | break; | break; |
| 3879 | ||
| 3880 | case OP_DIGIT: | case OP_DIGIT: |
| 3881 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3882 | { | |
| 3883 | if (eptr >= md->end_subject) | |
| 3884 | { | |
| 3885 | SCHECK_PARTIAL(); | |
| 3886 | RRETURN(MATCH_NOMATCH); | |
| 3887 | } | |
| 3888 | if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH); | if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH); |
| 3889 | } | |
| 3890 | break; | break; |
| 3891 | ||
| 3892 | case OP_NOT_WHITESPACE: | case OP_NOT_WHITESPACE: |
| 3893 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3894 | { | |
| 3895 | if (eptr >= md->end_subject) | |
| 3896 | { | |
| 3897 | SCHECK_PARTIAL(); | |
| 3898 | RRETURN(MATCH_NOMATCH); | |
| 3899 | } | |
| 3900 | if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH); | if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH); |
| 3901 | } | |
| 3902 | break; | break; |
| 3903 | ||
| 3904 | case OP_WHITESPACE: | case OP_WHITESPACE: |
| 3905 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3906 | { | |
| 3907 | if (eptr >= md->end_subject) | |
| 3908 | { | |
| 3909 | SCHECK_PARTIAL(); | |
| 3910 | RRETURN(MATCH_NOMATCH); | |
| 3911 | } | |
| 3912 | if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH); | if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH); |
| 3913 | } | |
| 3914 | break; | break; |
| 3915 | ||
| 3916 | case OP_NOT_WORDCHAR: | case OP_NOT_WORDCHAR: |
| 3917 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3918 | { | |
| 3919 | if (eptr >= md->end_subject) | |
| 3920 | { | |
| 3921 | SCHECK_PARTIAL(); | |
| 3922 | RRETURN(MATCH_NOMATCH); | |
| 3923 | } | |
| 3924 | if ((md->ctypes[*eptr++] & ctype_word) != 0) | if ((md->ctypes[*eptr++] & ctype_word) != 0) |
| 3925 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3926 | } | |
| 3927 | break; | break; |
| 3928 | ||
| 3929 | case OP_WORDCHAR: | case OP_WORDCHAR: |
| 3930 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3931 | { | |
| 3932 | if (eptr >= md->end_subject) | |
| 3933 | { | |
| 3934 | SCHECK_PARTIAL(); | |
| 3935 | RRETURN(MATCH_NOMATCH); | |
| 3936 | } | |
| 3937 | if ((md->ctypes[*eptr++] & ctype_word) == 0) | if ((md->ctypes[*eptr++] & ctype_word) == 0) |
| 3938 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3939 | } | |
| 3940 | break; | break; |
| 3941 | ||
| 3942 | default: | default: |
| # | Line 2768 for (;;) | Line 3962 for (;;) |
| 3962 | case PT_ANY: | case PT_ANY: |
| 3963 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3964 | { | { |
| 3965 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36); |
| 3966 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3967 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3968 | if (eptr >= md->end_subject) | |
| 3969 | { | |
| 3970 | SCHECK_PARTIAL(); | |
| 3971 | RRETURN(MATCH_NOMATCH); | |
| 3972 | } | |
| 3973 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3974 | if (prop_fail_result) RRETURN(MATCH_NOMATCH); | if (prop_fail_result) RRETURN(MATCH_NOMATCH); |
| 3975 | } | } |
| 3976 | break; | /* Control never gets here */ |
| 3977 | ||
| 3978 | case PT_LAMP: | case PT_LAMP: |
| 3979 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3980 | { | { |
| 3981 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37); |
| 3982 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3983 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3984 | if (eptr >= md->end_subject) | |
| 3985 | { | |
| 3986 | SCHECK_PARTIAL(); | |
| 3987 | RRETURN(MATCH_NOMATCH); | |
| 3988 | } | |
| 3989 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3990 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_chartype = UCD_CHARTYPE(c); |
| 3991 | if ((prop_chartype == ucp_Lu || | if ((prop_chartype == ucp_Lu || |
| 3992 | prop_chartype == ucp_Ll || | prop_chartype == ucp_Ll || |
| 3993 | prop_chartype == ucp_Lt) == prop_fail_result) | prop_chartype == ucp_Lt) == prop_fail_result) |
| 3994 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3995 | } | } |
| 3996 | break; | /* Control never gets here */ |
| 3997 | ||
| 3998 | case PT_GC: | case PT_GC: |
| 3999 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 4000 | { | { |
| 4001 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38); |
| 4002 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4003 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4004 | if (eptr >= md->end_subject) | |
| 4005 | { | |
| 4006 | SCHECK_PARTIAL(); | |
| 4007 | RRETURN(MATCH_NOMATCH); | |
| 4008 | } | |
| 4009 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 4010 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
| 4011 | if ((prop_category == prop_value) == prop_fail_result) | if ((prop_category == prop_value) == prop_fail_result) |
| 4012 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 4013 | } | } |
| 4014 | break; | /* Control never gets here */ |
| 4015 | ||
| 4016 | case PT_PC: | case PT_PC: |
| 4017 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 4018 | { | { |
| 4019 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39); |
| 4020 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4021 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4022 | if (eptr >= md->end_subject) | |
| 4023 | { | |
| 4024 | SCHECK_PARTIAL(); | |
| 4025 | RRETURN(MATCH_NOMATCH); | |
| 4026 | } | |
| 4027 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 4028 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_chartype = UCD_CHARTYPE(c); |
| 4029 | if ((prop_chartype == prop_value) == prop_fail_result) | if ((prop_chartype == prop_value) == prop_fail_result) |
| 4030 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 4031 | } | } |
| 4032 | break; | /* Control never gets here */ |
| 4033 | ||
| 4034 | case PT_SC: | case PT_SC: |
| 4035 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 4036 | { | { |
| 4037 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40); |
| 4038 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4039 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4040 | if (eptr >= md->end_subject) | |
| 4041 | { | |
| 4042 | SCHECK_PARTIAL(); | |
| 4043 | RRETURN(MATCH_NOMATCH); | |
| 4044 | } | |
| 4045 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 4046 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_script = UCD_SCRIPT(c); |
| 4047 | if ((prop_script == prop_value) == prop_fail_result) | if ((prop_script == prop_value) == prop_fail_result) |
| 4048 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 4049 | } | } |
| 4050 | break; | /* Control never gets here */ |
| 4051 | ||
| 4052 | default: | default: |
| 4053 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
| break; | ||
| 4054 | } | } |
| 4055 | } | } |
| 4056 | ||
| # | Line 2843 for (;;) | Line 4061 for (;;) |
| 4061 | { | { |
| 4062 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 4063 | { | { |
| 4064 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41); |
| 4065 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4066 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4067 | if (eptr >= md->end_subject) | |
| 4068 | { | |
| 4069 | SCHECK_PARTIAL(); | |
| 4070 | RRETURN(MATCH_NOMATCH); | |
| 4071 | } | |
| 4072 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 4073 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
| 4074 | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 4075 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 4076 | { | { |
| 4077 | int len = 1; | int len = 1; |
| 4078 | if (!utf8) c = *eptr; else | if (!utf8) c = *eptr; |
| 4079 | { | else { GETCHARLEN(c, eptr, len); } |
| 4080 | GETCHARLEN(c, eptr, len); | prop_category = UCD_CATEGORY(c); |
| } | ||
| prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | ||
| 4081 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 4082 | eptr += len; | eptr += len; |
| 4083 | } | } |
| # | Line 2872 for (;;) | Line 4093 for (;;) |
| 4093 | { | { |
| 4094 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 4095 | { | { |
| 4096 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42); |
| 4097 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4098 | if (fi >= max || eptr >= md->end_subject || | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4099 | (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 && | if (eptr >= md->end_subject) |
| 4100 | eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) | { |
| 4101 | SCHECK_PARTIAL(); | |
| 4102 | RRETURN(MATCH_NOMATCH); | |
| 4103 | } | |
| 4104 | if (ctype == OP_ANY && IS_NEWLINE(eptr)) | |
| 4105 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 4106 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 4107 | switch(ctype) | switch(ctype) |
| 4108 | { | { |
| 4109 | case OP_ANY: /* This is the DOTALL case */ | case OP_ANY: /* This is the non-NL case */ |
| 4110 | case OP_ALLANY: | |
| 4111 | case OP_ANYBYTE: | |
| 4112 | break; | break; |
| 4113 | ||
| 4114 | case OP_ANYBYTE: | case OP_ANYNL: |
| 4115 | switch(c) | |
| 4116 | { | |
| 4117 | default: RRETURN(MATCH_NOMATCH); | |
| 4118 | case 0x000d: | |
| 4119 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 4120 | break; | |
| 4121 | case 0x000a: | |
| 4122 | break; | |
| 4123 | ||
| 4124 | case 0x000b: | |
| 4125 | case 0x000c: | |
| 4126 | case 0x0085: | |
| 4127 | case 0x2028: | |
| 4128 | case 0x2029: | |
| 4129 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 4130 | break; | |
| 4131 | } | |
| 4132 | break; | |
| 4133 | ||
| 4134 | case OP_NOT_HSPACE: | |
| 4135 | switch(c) | |
| 4136 | { | |
| 4137 | default: break; | |
| 4138 | case 0x09: /* HT */ | |
| 4139 | case 0x20: /* SPACE */ | |
| 4140 | case 0xa0: /* NBSP */ | |
| 4141 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 4142 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 4143 | case 0x2000: /* EN QUAD */ | |
| 4144 | case 0x2001: /* EM QUAD */ | |
| 4145 | case 0x2002: /* EN SPACE */ | |
| 4146 | case 0x2003: /* EM SPACE */ | |
| 4147 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 4148 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 4149 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 4150 | case 0x2007: /* FIGURE SPACE */ | |
| 4151 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 4152 | case 0x2009: /* THIN SPACE */ | |
| 4153 | case 0x200A: /* HAIR SPACE */ | |
| 4154 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 4155 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 4156 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 4157 | RRETURN(MATCH_NOMATCH); | |
| 4158 | } | |
| 4159 | break; | |
| 4160 | ||
| 4161 | case OP_HSPACE: | |
| 4162 | switch(c) | |
| 4163 | { | |
| 4164 | default: RRETURN(MATCH_NOMATCH); | |
| 4165 | case 0x09: /* HT */ | |
| 4166 | case 0x20: /* SPACE */ | |
| 4167 | case 0xa0: /* NBSP */ | |
| 4168 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 4169 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 4170 | case 0x2000: /* EN QUAD */ | |
| 4171 | case 0x2001: /* EM QUAD */ | |
| 4172 | case 0x2002: /* EN SPACE */ | |
| 4173 | case 0x2003: /* EM SPACE */ | |
| 4174 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 4175 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 4176 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 4177 | case 0x2007: /* FIGURE SPACE */ | |
| 4178 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 4179 | case 0x2009: /* THIN SPACE */ | |