Parent Directory
|
Revision Log
|
Patch
| revision 87 by nigel, Sat Feb 24 21:41:21 2007 UTC | revision 443 by ph10, Sun Sep 13 16:00:08 2009 UTC | |
|---|---|---|
| # | Line 6 | Line 6 |
| 6 | and semantics are as close as possible to those of the Perl 5 language. | and semantics are as close as possible to those of the Perl 5 language. |
| 7 | ||
| 8 | Written by Philip Hazel | Written by Philip Hazel |
| 9 | Copyright (c) 1997-2006 University of Cambridge | Copyright (c) 1997-2009 University of Cambridge |
| 10 | ||
| 11 | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| 12 | Redistribution and use in source and binary forms, with or without | Redistribution and use in source and binary forms, with or without |
| # | Line 42 POSSIBILITY OF SUCH DAMAGE. | Line 42 POSSIBILITY OF SUCH DAMAGE. |
| 42 | pattern matching using an NFA algorithm, trying to mimic Perl as closely as | pattern matching using an NFA algorithm, trying to mimic Perl as closely as |
| 43 | possible. There are also some static supporting functions. */ | possible. There are also some static supporting functions. */ |
| 44 | ||
| 45 | #ifdef HAVE_CONFIG_H | |
| 46 | #include "config.h" | |
| 47 | #endif | |
| 48 | ||
| 49 | #define NLBLOCK md /* Block containing newline information */ | |
| 50 | #define PSSTART start_subject /* Field containing processed string start */ | |
| 51 | #define PSEND end_subject /* Field containing processed string end */ | |
| 52 | ||
| 53 | #include "pcre_internal.h" | #include "pcre_internal.h" |
| 54 | ||
| 55 | /* Undefine some potentially clashing cpp symbols */ | |
| 56 | ||
| 57 | /* Structure for building a chain of data that actually lives on the | #undef min |
| 58 | stack, for holding the values of the subject pointer at the start of each | #undef max |
| subpattern, so as to detect when an empty string has been matched by a | ||
| subpattern - to break infinite loops. When NO_RECURSE is set, these blocks | ||
| are on the heap, not on the stack. */ | ||
| typedef struct eptrblock { | ||
| struct eptrblock *epb_prev; | ||
| 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 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 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 | ||
| 257 | #ifdef DEBUG | #ifdef DEBUG |
| 258 | #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \ | #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; |
| 331 | int Xflags; | int Xflags; |
| 332 | int Xrdepth; | unsigned int Xrdepth; |
| 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 | Performance note: It might be tempting to extract commonly used fields from the | #define SCHECK_PARTIAL()\ |
| 418 | md structure (e.g. utf8, end_subject) into individual variables to improve | if (md->partial && eptr > mstart)\ |
| 419 | {\ | |
| 420 | md->hitend = TRUE;\ | |
| 421 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\ | |
| 422 | } | |
| 423 | ||
| 424 | ||
| 425 | /* 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, 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 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 |
| # | 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 | |
| 616 | 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 | |
| 618 | original patch. */ | |
| 619 | ||
| 620 | TAIL_RECURSE: | |
| 621 | ||
| 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() |
| # | Line 535 defined). However, RMATCH isn't like a f | Line 627 defined). However, RMATCH isn't like a f |
| 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 542 if (md->match_call_count++ >= md->match_ | Line 640 if (md->match_call_count++ >= md->match_ |
| 640 | if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); | if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); |
| 641 | ||
| 642 | original_ims = ims; /* Save for resetting on ')' */ | original_ims = ims; /* Save for resetting on ')' */ |
| utf8 = md->utf8; /* Local copy of the flag */ | ||
| 643 | ||
| 644 | /* At the start of a bracketed group, add the current subject pointer to the | /* At the start of a group with an unlimited repeat that may match an empty |
| 645 | stack of such pointers, to be re-instated at the end of the group when we hit | string, the match_cbegroup flag is set. When this is the case, add the current |
| 646 | the closing ket. When match() is called in other circumstances, we don't add to | subject pointer to the chain of such remembered pointers, to be checked when we |
| 647 | this stack. */ | hit the closing ket, in order to break infinite loops that match no characters. |
| 648 | 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 | block that is used is on the stack, so a new one may be required for each | |
| 651 | match(). */ | |
| 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. */ | ||
| if (md->partial && | ||
| 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. */ | ||
| 666 | ||
| 667 | if (op > OP_BRA) | switch(op) |
| 668 | { | { |
| 669 | number = op - OP_BRA; | case OP_FAIL: |
| 670 | RRETURN(MATCH_NOMATCH); | |
| /* For extended extraction brackets (large number), we have to fish out the | ||
| number from a dummy opcode at the start. */ | ||
| 671 | ||
| 672 | if (number > EXTRACT_BASIC_MAX) | case OP_PRUNE: |
| 673 | number = GET2(ecode, 2+LINK_SIZE); | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, |
| 674 | ims, eptrb, flags, RM51); | |
| 675 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 676 | 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 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 612 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 631 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. */ | |
| 755 | ||
| 756 | else op = OP_BRA; | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 757 | } | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 758 | ||
| 759 | /* Other types of node can be handled by a switch */ | DPRINTF(("insufficient capture room: treat as non-capturing\n")); |
| 760 | ||
| 761 | switch(op) | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 762 | { | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 763 | case OP_BRA: /* Non-capturing bracket: optimized */ | |
| 764 | DPRINTF(("start bracket 0\n")); | /* Non-capturing bracket. Loop for all the alternatives. When we get to the |
| 765 | do | 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 (;;) | |
| 775 | { | { |
| 776 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, | if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */ |
| 777 | match_isgroup); | { |
| 778 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (flags == 0) /* Not a possibly empty group */ |
| 779 | { | |
| 780 | ecode += _pcre_OP_lengths[*ecode]; | |
| 781 | DPRINTF(("bracket 0 tail recursion\n")); | |
| 782 | goto TAIL_RECURSE; | |
| 783 | } | |
| 784 | ||
| 785 | /* 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; | |
| 793 | otherwise return. */ | |
| 794 | ||
| 795 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, | |
| 796 | eptrb, flags, RM2); | |
| 797 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); | |
| 798 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 799 | } | } |
| 800 | while (*ecode == OP_ALT); | /* Control never reaches here. */ |
| DPRINTF(("bracket 0 failed\n")); | ||
| RRETURN(MATCH_NOMATCH); | ||
| 801 | ||
| 802 | /* Conditional group: compilation checked that there are no more than | /* Conditional group: compilation checked that there are no more than |
| 803 | two branches. If the condition is false, skipping the first branch takes us | two branches. If the condition is false, skipping the first branch takes us |
| 804 | past the end if there is only one branch, but that's OK because that is | past the end if there is only one branch, but that's OK because that is |
| 805 | exactly what going to the ket would do. */ | exactly what going to the ket would do. As there is only one branch to be |
| 806 | 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) /* Recursion test */ | |
| 843 | { | |
| 844 | offset = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ | |
| 845 | condition = md->recursive != NULL && | |
| 846 | (offset == RREF_ANY || offset == md->recursive->group_num); | |
| 847 | ecode += condition? 3 : GET(ecode, 1); | |
| 848 | } | |
| 849 | ||
| 850 | else if (condcode == OP_CREF) /* Group used test */ | |
| 851 | { | { |
| 852 | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ |
| 853 | condition = (offset == CREF_RECURSE * 2)? | condition = offset < offset_top && md->offset_vector[offset] >= 0; |
| 854 | (md->recursive != NULL) : | ecode += condition? 3 : GET(ecode, 1); |
| 855 | (offset < offset_top && md->offset_vector[offset] >= 0); | } |
| 856 | RMATCH(rrc, eptr, ecode + (condition? | |
| 857 | (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1))), | else if (condcode == OP_DEF) /* DEFINE - always false */ |
| 858 | offset_top, md, ims, eptrb, match_isgroup); | { |
| 859 | RRETURN(rrc); | condition = FALSE; |
| 860 | ecode += GET(ecode, 1); | |
| 861 | } | } |
| 862 | ||
| 863 | /* The condition is an assertion. Call match() to evaluate it - setting | /* The condition is an assertion. Call match() to evaluate it - setting |
| 864 | 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 |
| 865 | assertion. */ | |
| 866 | ||
| 867 | else | else |
| 868 | { | { |
| 869 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, |
| 870 | match_condassert | match_isgroup); | match_condassert, RM3); |
| 871 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
| 872 | { | { |
| 873 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2); | condition = TRUE; |
| 874 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); | |
| 875 | while (*ecode == OP_ALT) ecode += GET(ecode, 1); | while (*ecode == OP_ALT) ecode += GET(ecode, 1); |
| 876 | } | } |
| 877 | else if (rrc != MATCH_NOMATCH) | else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
| 878 | { | { |
| 879 | RRETURN(rrc); /* Need braces because of following else */ | RRETURN(rrc); /* Need braces because of following else */ |
| 880 | } | } |
| 881 | else ecode += GET(ecode, 1); | else |
| 882 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, | { |
| 883 | match_isgroup); | condition = FALSE; |
| 884 | RRETURN(rrc); | ecode += codelink; |
| 885 | } | |
| 886 | } | } |
| /* Control never reaches here */ | ||
| 887 | ||
| 888 | /* Skip over conditional reference or large extraction number data if | /* We are now at the branch that is to be obeyed. As there is only one, |
| 889 | encountered. */ | we can use tail recursion to avoid using another stack frame, except when |
| 890 | match_cbegroup is required for an unlimited repeat of a possibly empty | |
| 891 | group. If the second alternative doesn't exist, we can just plough on. */ | |
| 892 | ||
| 893 | case OP_CREF: | if (condition || *ecode == OP_ALT) |
| 894 | case OP_BRANUMBER: | { |
| 895 | ecode += 3; | ecode += 1 + LINK_SIZE; |
| 896 | if (op == OP_SCOND) /* Possibly empty group */ | |
| 897 | { | |
| 898 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49); | |
| 899 | RRETURN(rrc); | |
| 900 | } | |
| 901 | else /* Group must match something */ | |
| 902 | { | |
| 903 | flags = 0; | |
| 904 | goto TAIL_RECURSE; | |
| 905 | } | |
| 906 | } | |
| 907 | else /* Condition false & no alternative */ | |
| 908 | { | |
| 909 | ecode += 1 + LINK_SIZE; | |
| 910 | } | |
| 911 | break; | break; |
| 912 | ||
| /* End of the pattern. If we are in a recursion, we should restore the | ||
| offsets appropriately and continue from after the call. */ | ||
| 913 | ||
| 914 | /* End of the pattern, either real or forced. If we are in a top-level | |
| 915 | recursion, we should restore the offsets appropriately and continue from | |
| 916 | after the call. */ | |
| 917 | ||
| 918 | case OP_ACCEPT: | |
| 919 | case OP_END: | case OP_END: |
| 920 | if (md->recursive != NULL && md->recursive->group_num == 0) | if (md->recursive != NULL && md->recursive->group_num == 0) |
| 921 | { | { |
| # | Line 713 for (;;) | Line 924 for (;;) |
| 924 | md->recursive = rec->prevrec; | md->recursive = rec->prevrec; |
| 925 | memmove(md->offset_vector, rec->offset_save, | memmove(md->offset_vector, rec->offset_save, |
| 926 | rec->saved_max * sizeof(int)); | rec->saved_max * sizeof(int)); |
| 927 | md->start_match = rec->save_start; | mstart = rec->save_start; |
| 928 | ims = original_ims; | ims = original_ims; |
| 929 | ecode = rec->after_call; | ecode = rec->after_call; |
| 930 | break; | break; |
| 931 | } | } |
| 932 | ||
| 933 | /* 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 |
| 934 | 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 |
| 935 | the subject. In both cases, backtracking will then try other alternatives, | |
| 936 | if any. */ | |
| 937 | ||
| 938 | if (eptr == mstart && | |
| 939 | (md->notempty || | |
| 940 | (md->notempty_atstart && | |
| 941 | mstart == md->start_subject + md->start_offset))) | |
| 942 | RRETURN(MATCH_NOMATCH); | |
| 943 | ||
| 944 | /* Otherwise, we have a match. */ | |
| 945 | ||
| 946 | if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH); | md->end_match_ptr = eptr; /* Record where we ended */ |
| 947 | md->end_match_ptr = eptr; /* Record where we ended */ | md->end_offset_top = offset_top; /* and how many extracts were taken */ |
| 948 | md->end_offset_top = offset_top; /* and how many extracts were taken */ | md->start_match_ptr = mstart; /* and the start (\K can modify) */ |
| 949 | RRETURN(MATCH_MATCH); | RRETURN(MATCH_MATCH); |
| 950 | ||
| 951 | /* Change option settings */ | /* Change option settings */ |
| # | Line 745 for (;;) | Line 966 for (;;) |
| 966 | case OP_ASSERTBACK: | case OP_ASSERTBACK: |
| 967 | do | do |
| 968 | { | { |
| 969 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, |
| 970 | match_isgroup); | RM4); |
| 971 | if (rrc == MATCH_MATCH) break; | if (rrc == MATCH_MATCH) break; |
| 972 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 973 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
| 974 | } | } |
| 975 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| # | Line 772 for (;;) | Line 993 for (;;) |
| 993 | case OP_ASSERTBACK_NOT: | case OP_ASSERTBACK_NOT: |
| 994 | do | do |
| 995 | { | { |
| 996 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, |
| 997 | match_isgroup); | RM5); |
| 998 | if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); | if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); |
| 999 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 1000 | ecode += GET(ecode,1); | ecode += GET(ecode,1); |
| 1001 | } | } |
| 1002 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
| # | Line 794 for (;;) | Line 1015 for (;;) |
| 1015 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 1016 | if (utf8) | if (utf8) |
| 1017 | { | { |
| 1018 | c = GET(ecode,1); | i = GET(ecode, 1); |
| 1019 | for (i = 0; i < c; i++) | while (i-- > 0) |
| 1020 | { | { |
| 1021 | eptr--; | eptr--; |
| 1022 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1023 | BACKCHAR(eptr) | BACKCHAR(eptr); |
| 1024 | } | } |
| 1025 | } | } |
| 1026 | else | else |
| # | Line 808 for (;;) | Line 1029 for (;;) |
| 1029 | /* 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 */ |
| 1030 | ||
| 1031 | { | { |
| 1032 | eptr -= GET(ecode,1); | eptr -= GET(ecode, 1); |
| 1033 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1034 | } | } |
| 1035 | ||
| 1036 | /* Skip to next op code */ | /* Save the earliest consulted character, then skip to next op code */ |
| 1037 | ||
| 1038 | if (eptr < md->start_used_ptr) md->start_used_ptr = eptr; | |
| 1039 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1040 | break; | break; |
| 1041 | ||
| # | Line 830 for (;;) | Line 1052 for (;;) |
| 1052 | cb.offset_vector = md->offset_vector; | cb.offset_vector = md->offset_vector; |
| 1053 | cb.subject = (PCRE_SPTR)md->start_subject; | cb.subject = (PCRE_SPTR)md->start_subject; |
| 1054 | cb.subject_length = md->end_subject - md->start_subject; | cb.subject_length = md->end_subject - md->start_subject; |
| 1055 | cb.start_match = md->start_match - md->start_subject; | cb.start_match = mstart - md->start_subject; |
| 1056 | cb.current_position = eptr - md->start_subject; | cb.current_position = eptr - md->start_subject; |
| 1057 | cb.pattern_position = GET(ecode, 2); | cb.pattern_position = GET(ecode, 2); |
| 1058 | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); |
| # | Line 865 for (;;) | Line 1087 for (;;) |
| 1087 | case OP_RECURSE: | case OP_RECURSE: |
| 1088 | { | { |
| 1089 | callpat = md->start_code + GET(ecode, 1); | callpat = md->start_code + GET(ecode, 1); |
| 1090 | new_recursive.group_num = *callpat - OP_BRA; | new_recursive.group_num = (callpat == md->start_code)? 0 : |
| 1091 | 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); | ||
| 1092 | ||
| 1093 | /* Add to "recursing stack" */ | /* Add to "recursing stack" */ |
| 1094 | ||
| # | Line 897 for (;;) | Line 1114 for (;;) |
| 1114 | ||
| 1115 | memcpy(new_recursive.offset_save, md->offset_vector, | memcpy(new_recursive.offset_save, md->offset_vector, |
| 1116 | new_recursive.saved_max * sizeof(int)); | new_recursive.saved_max * sizeof(int)); |
| 1117 | new_recursive.save_start = md->start_match; | new_recursive.save_start = mstart; |
| 1118 | md->start_match = eptr; | mstart = eptr; |
| 1119 | ||
| 1120 | /* 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 |
| 1121 | restore the offset and recursion data. */ | restore the offset and recursion data. */ |
| 1122 | ||
| 1123 | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); |
| 1124 | flags = (*callpat >= OP_SBRA)? match_cbegroup : 0; | |
| 1125 | do | do |
| 1126 | { | { |
| 1127 | RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims, | RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, |
| 1128 | eptrb, match_isgroup); | md, ims, eptrb, flags, RM6); |
| 1129 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
| 1130 | { | { |
| 1131 | DPRINTF(("Recursion matched\n")); | DPRINTF(("Recursion matched\n")); |
| # | Line 916 for (;;) | Line 1134 for (;;) |
| 1134 | (pcre_free)(new_recursive.offset_save); | (pcre_free)(new_recursive.offset_save); |
| 1135 | RRETURN(MATCH_MATCH); | RRETURN(MATCH_MATCH); |
| 1136 | } | } |
| 1137 | else if (rrc != MATCH_NOMATCH) | else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
| 1138 | { | { |
| 1139 | DPRINTF(("Recursion gave error %d\n", rrc)); | DPRINTF(("Recursion gave error %d\n", rrc)); |
| 1140 | if (new_recursive.offset_save != stacksave) | |
| 1141 | (pcre_free)(new_recursive.offset_save); | |
| 1142 | RRETURN(rrc); | RRETURN(rrc); |
| 1143 | } | } |
| 1144 | ||
| # | Line 945 for (;;) | Line 1165 for (;;) |
| 1165 | the end of a normal bracket, leaving the subject pointer. */ | the end of a normal bracket, leaving the subject pointer. */ |
| 1166 | ||
| 1167 | case OP_ONCE: | case OP_ONCE: |
| 1168 | { | prev = ecode; |
| 1169 | prev = ecode; | saved_eptr = eptr; |
| saved_eptr = eptr; | ||
| 1170 | ||
| 1171 | do | do |
| 1172 | { | { |
| 1173 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7); |
| 1174 | eptrb, match_isgroup); | if (rrc == MATCH_MATCH) break; |
| 1175 | if (rrc == MATCH_MATCH) break; | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 1176 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ecode += GET(ecode,1); |
| 1177 | ecode += GET(ecode,1); | } |
| 1178 | } | while (*ecode == OP_ALT); |
| while (*ecode == OP_ALT); | ||
| 1179 | ||
| 1180 | /* If hit the end of the group (which could be repeated), fail */ | /* If hit the end of the group (which could be repeated), fail */ |
| 1181 | ||
| 1182 | if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); | if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); |
| 1183 | ||
| 1184 | /* Continue as from after the assertion, updating the offsets high water | /* Continue as from after the assertion, updating the offsets high water |
| 1185 | mark, since extracts may have been taken. */ | mark, since extracts may have been taken. */ |
| 1186 | ||
| 1187 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | do ecode += GET(ecode, 1); while (*ecode == OP_ALT); |
| 1188 | ||
| 1189 | offset_top = md->end_offset_top; | offset_top = md->end_offset_top; |
| 1190 | eptr = md->end_match_ptr; | eptr = md->end_match_ptr; |
| 1191 | ||
| 1192 | /* For a non-repeating ket, just continue at this level. This also | /* For a non-repeating ket, just continue at this level. This also |
| 1193 | happens for a repeating ket if no characters were matched in the group. | happens for a repeating ket if no characters were matched in the group. |
| 1194 | This is the forcible breaking of infinite loops as implemented in Perl | This is the forcible breaking of infinite loops as implemented in Perl |
| 1195 | 5.005. If there is an options reset, it will get obeyed in the normal | 5.005. If there is an options reset, it will get obeyed in the normal |
| 1196 | course of events. */ | course of events. */ |
| 1197 | ||
| 1198 | if (*ecode == OP_KET || eptr == saved_eptr) | if (*ecode == OP_KET || eptr == saved_eptr) |
| 1199 | { | { |
| 1200 | ecode += 1+LINK_SIZE; | ecode += 1+LINK_SIZE; |
| 1201 | break; | break; |
| 1202 | } | } |
| 1203 | ||
| 1204 | /* 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 |
| 1205 | preceding bracket, in the appropriate order. We need to reset any options | preceding bracket, in the appropriate order. The second "call" of match() |
| 1206 | that changed within the bracket before re-running it, so check the next | uses tail recursion, to avoid using another stack frame. We need to reset |
| 1207 | opcode. */ | any options that changed within the bracket before re-running it, so |
| 1208 | check the next opcode. */ | |
| 1209 | ||
| 1210 | if (ecode[1+LINK_SIZE] == OP_OPT) | if (ecode[1+LINK_SIZE] == OP_OPT) |
| 1211 | { | { |
| 1212 | ims = (ims & ~PCRE_IMS) | ecode[4]; | ims = (ims & ~PCRE_IMS) | ecode[4]; |
| 1213 | DPRINTF(("ims set to %02lx at group repeat\n", ims)); | DPRINTF(("ims set to %02lx at group repeat\n", ims)); |
| 1214 | } | } |
| 1215 | ||
| 1216 | if (*ecode == OP_KETRMIN) | if (*ecode == OP_KETRMIN) |
| 1217 | { | { |
| 1218 | 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); |
| 1219 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1220 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | ecode = prev; |
| 1221 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | flags = 0; |
| 1222 | } | goto TAIL_RECURSE; |
| else /* OP_KETRMAX */ | ||
| { | ||
| RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | ||
| if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ||
| RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); | ||
| if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ||
| } | ||
| 1223 | } | } |
| 1224 | RRETURN(MATCH_NOMATCH); | else /* OP_KETRMAX */ |
| 1225 | { | |
| 1226 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9); | |
| 1227 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 1228 | ecode += 1 + LINK_SIZE; | |
| 1229 | flags = 0; | |
| 1230 | goto TAIL_RECURSE; | |
| 1231 | } | |
| 1232 | /* Control never gets here */ | |
| 1233 | ||
| 1234 | /* An alternation is the end of a branch; scan along to find the end of the | /* An alternation is the end of a branch; scan along to find the end of the |
| 1235 | bracketed group and go to there. */ | bracketed group and go to there. */ |
| # | Line 1018 for (;;) | Line 1238 for (;;) |
| 1238 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
| 1239 | break; | break; |
| 1240 | ||
| 1241 | /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating | /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group, |
| 1242 | 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 |
| 1243 | 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 |
| 1244 | 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 |
| 1245 | preceded by BRAZERO or BRAMINZERO. */ | optional ones preceded by BRAZERO or BRAMINZERO. */ |
| 1246 | ||
| 1247 | case OP_BRAZERO: | case OP_BRAZERO: |
| 1248 | { | { |
| 1249 | next = ecode+1; | next = ecode+1; |
| 1250 | RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10); |
| 1251 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1252 | do next += GET(next,1); while (*next == OP_ALT); | do next += GET(next,1); while (*next == OP_ALT); |
| 1253 | ecode = next + 1+LINK_SIZE; | ecode = next + 1 + LINK_SIZE; |
| 1254 | } | } |
| 1255 | break; | break; |
| 1256 | ||
| 1257 | case OP_BRAMINZERO: | case OP_BRAMINZERO: |
| 1258 | { | { |
| 1259 | next = ecode+1; | next = ecode+1; |
| 1260 | do next += GET(next,1); while (*next == OP_ALT); | do next += GET(next, 1); while (*next == OP_ALT); |
| 1261 | 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); | ||
| 1262 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1263 | ecode++; | ecode++; |
| 1264 | } | } |
| 1265 | break; | break; |
| 1266 | ||
| 1267 | /* End of a group, repeated or non-repeating. If we are at the end of | case OP_SKIPZERO: |
| 1268 | an assertion "group", stop matching and return MATCH_MATCH, but record the | { |
| 1269 | current high water mark for use by positive assertions. Do this also | next = ecode+1; |
| 1270 | for the "once" (not-backup up) groups. */ | do next += GET(next,1); while (*next == OP_ALT); |
| 1271 | ecode = next + 1 + LINK_SIZE; | |
| 1272 | } | |
| 1273 | break; | |
| 1274 | ||
| 1275 | /* End of a group, repeated or non-repeating. */ | |
| 1276 | ||
| 1277 | case OP_KET: | case OP_KET: |
| 1278 | case OP_KETRMIN: | case OP_KETRMIN: |
| 1279 | case OP_KETRMAX: | case OP_KETRMAX: |
| 1280 | { | prev = ecode - GET(ecode, 1); |
| prev = ecode - GET(ecode, 1); | ||
| saved_eptr = eptrb->epb_saved_eptr; | ||
| 1281 | ||
| 1282 | /* Back up the stack of bracket start pointers. */ | /* If this was a group that remembered the subject start, in order to break |
| 1283 | infinite repeats of empty string matches, retrieve the subject start from | |
| 1284 | the chain. Otherwise, set it NULL. */ | |
| 1285 | ||
| 1286 | eptrb = eptrb->epb_prev; | if (*prev >= OP_SBRA) |
| 1287 | { | |
| 1288 | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || | saved_eptr = eptrb->epb_saved_eptr; /* Value at start of group */ |
| 1289 | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || | eptrb = eptrb->epb_prev; /* Backup to previous group */ |
| 1290 | *prev == OP_ONCE) | } |
| 1291 | { | else saved_eptr = NULL; |
| md->end_match_ptr = eptr; /* For ONCE */ | ||
| md->end_offset_top = offset_top; | ||
| RRETURN(MATCH_MATCH); | ||
| } | ||
| 1292 | ||
| 1293 | /* In all other cases except a conditional group we have to check the | /* If we are at the end of an assertion group, stop matching and return |
| 1294 | group number back at the start and if necessary complete handling an | MATCH_MATCH, but record the current high water mark for use by positive |
| 1295 | extraction by setting the offsets and bumping the high water mark. */ | assertions. Do this also for the "once" (atomic) groups. */ |
| 1296 | ||
| 1297 | if (*prev != OP_COND) | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || |
| 1298 | { | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || |
| 1299 | number = *prev - OP_BRA; | *prev == OP_ONCE) |
| 1300 | { | |
| 1301 | md->end_match_ptr = eptr; /* For ONCE */ | |
| 1302 | md->end_offset_top = offset_top; | |
| 1303 | RRETURN(MATCH_MATCH); | |
| 1304 | } | |
| 1305 | ||
| 1306 | /* For extended extraction brackets (large number), we have to fish out | /* For capturing groups we have to check the group number back at the start |
| 1307 | the number from a dummy opcode at the start. */ | and if necessary complete handling an extraction by setting the offsets and |
| 1308 | bumping the high water mark. Note that whole-pattern recursion is coded as | |
| 1309 | a recurse into group 0, so it won't be picked up here. Instead, we catch it | |
| 1310 | when the OP_END is reached. Other recursion is handled here. */ | |
| 1311 | ||
| 1312 | if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE); | if (*prev == OP_CBRA || *prev == OP_SCBRA) |
| 1313 | offset = number << 1; | { |
| 1314 | number = GET2(prev, 1+LINK_SIZE); | |
| 1315 | offset = number << 1; | |
| 1316 | ||
| 1317 | #ifdef DEBUG | #ifdef DEBUG |
| 1318 | printf("end bracket %d", number); | printf("end bracket %d", number); |
| 1319 | printf("\n"); | printf("\n"); |
| 1320 | #endif | #endif |
| 1321 | ||
| 1322 | /* Test for a numbered group. This includes groups called as a result | md->capture_last = number; |
| 1323 | of recursion. Note that whole-pattern recursion is coded as a recurse | if (offset >= md->offset_max) md->offset_overflow = TRUE; else |
| 1324 | into group 0, so it won't be picked up here. Instead, we catch it when | { |
| 1325 | the OP_END is reached. */ | md->offset_vector[offset] = |
| 1326 | md->offset_vector[md->offset_end - number]; | |
| 1327 | if (number > 0) | md->offset_vector[offset+1] = eptr - md->start_subject; |
| 1328 | { | if (offset_top <= offset) offset_top = offset + 2; |
| 1329 | md->capture_last = number; | } |
| if (offset >= md->offset_max) md->offset_overflow = TRUE; else | ||
| { | ||
| md->offset_vector[offset] = | ||
| md->offset_vector[md->offset_end - number]; | ||
| md->offset_vector[offset+1] = eptr - md->start_subject; | ||
| if (offset_top <= offset) offset_top = offset + 2; | ||
| } | ||
| 1330 | ||
| 1331 | /* Handle a recursively called group. Restore the offsets | /* Handle a recursively called group. Restore the offsets |
| 1332 | appropriately and continue from after the call. */ | appropriately and continue from after the call. */ |
| 1333 | ||
| 1334 | if (md->recursive != NULL && md->recursive->group_num == number) | if (md->recursive != NULL && md->recursive->group_num == number) |
| 1335 | { | { |
| 1336 | recursion_info *rec = md->recursive; | recursion_info *rec = md->recursive; |
| 1337 | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); |
| 1338 | md->recursive = rec->prevrec; | md->recursive = rec->prevrec; |
| 1339 | md->start_match = rec->save_start; | mstart = rec->save_start; |
| 1340 | memcpy(md->offset_vector, rec->offset_save, | memcpy(md->offset_vector, rec->offset_save, |
| 1341 | rec->saved_max * sizeof(int)); | rec->saved_max * sizeof(int)); |
| 1342 | ecode = rec->after_call; | ecode = rec->after_call; |
| 1343 | ims = original_ims; | ims = original_ims; |
| 1344 | break; | break; |
| } | ||
| } | ||
| 1345 | } | } |
| 1346 | } | |
| 1347 | ||
| 1348 | /* 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 |
| 1349 | the group. */ | flags, in case they got changed during the group. */ |
| 1350 | ||
| 1351 | ims = original_ims; | ims = original_ims; |
| 1352 | DPRINTF(("ims reset to %02lx\n", ims)); | DPRINTF(("ims reset to %02lx\n", ims)); |
| 1353 | ||
| 1354 | /* For a non-repeating ket, just continue at this level. This also | /* For a non-repeating ket, just continue at this level. This also |
| 1355 | happens for a repeating ket if no characters were matched in the group. | happens for a repeating ket if no characters were matched in the group. |
| 1356 | This is the forcible breaking of infinite loops as implemented in Perl | This is the forcible breaking of infinite loops as implemented in Perl |
| 1357 | 5.005. If there is an options reset, it will get obeyed in the normal | 5.005. If there is an options reset, it will get obeyed in the normal |
| 1358 | course of events. */ | course of events. */ |
| 1359 | ||
| 1360 | if (*ecode == OP_KET || eptr == saved_eptr) | if (*ecode == OP_KET || eptr == saved_eptr) |
| 1361 | { | { |
| 1362 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
| 1363 | break; | break; |
| 1364 | } | } |
| 1365 | ||
| 1366 | /* 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 |
| 1367 | preceding bracket, in the appropriate order. */ | preceding bracket, in the appropriate order. In the second case, we can use |
| 1368 | tail recursion to avoid using another stack frame, unless we have an | |
| 1369 | unlimited repeat of a group that can match an empty string. */ | |
| 1370 | ||
| 1371 | if (*ecode == OP_KETRMIN) | flags = (*prev >= OP_SBRA)? match_cbegroup : 0; |
| 1372 | { | |
| 1373 | RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); | if (*ecode == OP_KETRMIN) |
| 1374 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | { |
| 1375 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12); |
| 1376 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1377 | } | if (flags != 0) /* Could match an empty string */ |
| else /* OP_KETRMAX */ | ||
| 1378 | { | { |
| 1379 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50); |
| 1380 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | RRETURN(rrc); |
| RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); | ||
| if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ||
| 1381 | } | } |
| 1382 | ecode = prev; | |
| 1383 | goto TAIL_RECURSE; | |
| 1384 | } | } |
| 1385 | else /* OP_KETRMAX */ | |
| 1386 | RRETURN(MATCH_NOMATCH); | { |
| 1387 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13); | |
| 1388 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 1389 | ecode += 1 + LINK_SIZE; | |
| 1390 | flags = 0; | |
| 1391 | goto TAIL_RECURSE; | |
| 1392 | } | |
| 1393 | /* Control never gets here */ | |
| 1394 | ||
| 1395 | /* Start of subject unless notbol, or after internal newline if multiline */ | /* Start of subject unless notbol, or after internal newline if multiline */ |
| 1396 | ||
| # | Line 1168 for (;;) | Line 1398 for (;;) |
| 1398 | if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); | if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1399 | if ((ims & PCRE_MULTILINE) != 0) | if ((ims & PCRE_MULTILINE) != 0) |
| 1400 | { | { |
| 1401 | if (eptr != md->start_subject && eptr[-1] != NEWLINE) | if (eptr != md->start_subject && |
| 1402 | (eptr == md->end_subject || !WAS_NEWLINE(eptr))) | |
| 1403 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1404 | ecode++; | ecode++; |
| 1405 | break; | break; |
| # | Line 1189 for (;;) | Line 1420 for (;;) |
| 1420 | ecode++; | ecode++; |
| 1421 | break; | break; |
| 1422 | ||
| 1423 | /* Reset the start of match point */ | |
| 1424 | ||
| 1425 | case OP_SET_SOM: | |
| 1426 | mstart = eptr; | |
| 1427 | ecode++; | |
| 1428 | break; | |
| 1429 | ||
| 1430 | /* Assert before internal newline if multiline, or before a terminating | /* Assert before internal newline if multiline, or before a terminating |
| 1431 | 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. */ |
| 1432 | ||
| # | Line 1196 for (;;) | Line 1434 for (;;) |
| 1434 | if ((ims & PCRE_MULTILINE) != 0) | if ((ims & PCRE_MULTILINE) != 0) |
| 1435 | { | { |
| 1436 | if (eptr < md->end_subject) | if (eptr < md->end_subject) |
| 1437 | { if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); } | { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); } |
| 1438 | else | else |
| 1439 | { if (md->noteol) RRETURN(MATCH_NOMATCH); } | { if (md->noteol) RRETURN(MATCH_NOMATCH); } |
| 1440 | ecode++; | ecode++; |
| # | Line 1207 for (;;) | Line 1445 for (;;) |
| 1445 | if (md->noteol) RRETURN(MATCH_NOMATCH); | if (md->noteol) RRETURN(MATCH_NOMATCH); |
| 1446 | if (!md->endonly) | if (!md->endonly) |
| 1447 | { | { |
| 1448 | if (eptr < md->end_subject - 1 || | if (eptr != md->end_subject && |
| 1449 | (eptr == md->end_subject - 1 && *eptr != NEWLINE)) | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
| 1450 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1451 | ecode++; | ecode++; |
| 1452 | break; | break; |
| 1453 | } | } |
| 1454 | } | } |
| 1455 | /* ... else fall through */ | /* ... else fall through for endonly */ |
| 1456 | ||
| 1457 | /* End of subject assertion (\z) */ | /* End of subject assertion (\z) */ |
| 1458 | ||
| # | Line 1226 for (;;) | Line 1464 for (;;) |
| 1464 | /* End of subject or ending \n assertion (\Z) */ | /* End of subject or ending \n assertion (\Z) */ |
| 1465 | ||
| 1466 | case OP_EODN: | case OP_EODN: |
| 1467 | if (eptr < md->end_subject - 1 || | if (eptr != md->end_subject && |
| 1468 | (eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH); | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
| 1469 | RRETURN(MATCH_NOMATCH); | |
| 1470 | ecode++; | ecode++; |
| 1471 | break; | break; |
| 1472 | ||
| # | Line 1239 for (;;) | Line 1478 for (;;) |
| 1478 | ||
| 1479 | /* Find out if the previous and current characters are "word" characters. | /* Find out if the previous and current characters are "word" characters. |
| 1480 | 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 |
| 1481 | be "non-word" characters. */ | be "non-word" characters. Remember the earliest consulted character for |
| 1482 | partial matching. */ | |
| 1483 | ||
| 1484 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 1485 | if (utf8) | if (utf8) |
| 1486 | { | { |
| 1487 | if (eptr == md->start_subject) prev_is_word = FALSE; else | if (eptr == md->start_subject) prev_is_word = FALSE; else |
| 1488 | { | { |
| 1489 | const uschar *lastptr = eptr - 1; | USPTR lastptr = eptr - 1; |
| 1490 | while((*lastptr & 0xc0) == 0x80) lastptr--; | while((*lastptr & 0xc0) == 0x80) lastptr--; |
| 1491 | if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr; | |
| 1492 | GETCHAR(c, lastptr); | GETCHAR(c, lastptr); |
| 1493 | prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; | prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
| 1494 | } | } |
| 1495 | if (eptr >= md->end_subject) cur_is_word = FALSE; else | if (eptr >= md->end_subject) |
| 1496 | { | |
| 1497 | SCHECK_PARTIAL(); | |
| 1498 | cur_is_word = FALSE; | |
| 1499 | } | |
| 1500 | else | |
| 1501 | { | { |
| 1502 | GETCHAR(c, eptr); | GETCHAR(c, eptr); |
| 1503 | cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; | cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
| # | Line 1260 for (;;) | Line 1506 for (;;) |
| 1506 | else | else |
| 1507 | #endif | #endif |
| 1508 | ||
| 1509 | /* More streamlined when not in UTF-8 mode */ | /* Not in UTF-8 mode */ |
| 1510 | ||
| 1511 | { | { |
| 1512 | prev_is_word = (eptr != md->start_subject) && | if (eptr == md->start_subject) prev_is_word = FALSE; else |
| 1513 | ((md->ctypes[eptr[-1]] & ctype_word) != 0); | { |
| 1514 | cur_is_word = (eptr < md->end_subject) && | if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1; |
| 1515 | ((md->ctypes[*eptr] & ctype_word) != 0); | prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0); |
| 1516 | } | |
| 1517 | if (eptr >= md->end_subject) | |
| 1518 | { | |
| 1519 | SCHECK_PARTIAL(); | |
| 1520 | cur_is_word = FALSE; | |
| 1521 | } | |
| 1522 | else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0); | |
| 1523 | } | } |
| 1524 | ||
| 1525 | /* Now see if the situation is what we want */ | /* Now see if the situation is what we want */ |
| # | Line 1280 for (;;) | Line 1533 for (;;) |
| 1533 | /* Match a single character type; inline for speed */ | /* Match a single character type; inline for speed */ |
| 1534 | ||
| 1535 | case OP_ANY: | case OP_ANY: |
| 1536 | if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE) | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); |
| 1537 | /* Fall through */ | |
| 1538 | ||
| 1539 | case OP_ALLANY: | |
| 1540 | if (eptr++ >= md->end_subject) | |
| 1541 | { | |
| 1542 | SCHECK_PARTIAL(); | |
| 1543 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1544 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | } |
| 1545 | #ifdef SUPPORT_UTF8 | if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| if (utf8) | ||
| while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
| #endif | ||
| 1546 | ecode++; | ecode++; |
| 1547 | break; | break; |
| 1548 | ||
| # | Line 1294 for (;;) | Line 1550 for (;;) |
| 1550 | any byte, even newline, independent of the setting of PCRE_DOTALL. */ | any byte, even newline, independent of the setting of PCRE_DOTALL. */ |
| 1551 | ||
| 1552 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 1553 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr++ >= md->end_subject) |
| 1554 | { | |
| 1555 | SCHECK_PARTIAL(); | |
| 1556 | RRETURN(MATCH_NOMATCH); | |
| 1557 | } | |
| 1558 | ecode++; | ecode++; |
| 1559 | break; | break; |
| 1560 | ||
| 1561 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 1562 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1563 | { | |
| 1564 | SCHECK_PARTIAL(); | |
| 1565 | RRETURN(MATCH_NOMATCH); | |
| 1566 | } | |
| 1567 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1568 | if ( | if ( |
| 1569 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1312 for (;;) | Line 1576 for (;;) |
| 1576 | break; | break; |
| 1577 | ||
| 1578 | case OP_DIGIT: | case OP_DIGIT: |
| 1579 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1580 | { | |
| 1581 | SCHECK_PARTIAL(); | |
| 1582 | RRETURN(MATCH_NOMATCH); | |
| 1583 | } | |
| 1584 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1585 | if ( | if ( |
| 1586 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1325 for (;;) | Line 1593 for (;;) |
| 1593 | break; | break; |
| 1594 | ||
| 1595 | case OP_NOT_WHITESPACE: | case OP_NOT_WHITESPACE: |
| 1596 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1597 | { | |
| 1598 | SCHECK_PARTIAL(); | |
| 1599 | RRETURN(MATCH_NOMATCH); | |
| 1600 | } | |
| 1601 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1602 | if ( | if ( |
| 1603 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1338 for (;;) | Line 1610 for (;;) |
| 1610 | break; | break; |
| 1611 | ||
| 1612 | case OP_WHITESPACE: | case OP_WHITESPACE: |
| 1613 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1614 | { | |
| 1615 | SCHECK_PARTIAL(); | |
| 1616 | RRETURN(MATCH_NOMATCH); | |
| 1617 | } | |
| 1618 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1619 | if ( | if ( |
| 1620 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1351 for (;;) | Line 1627 for (;;) |
| 1627 | break; | break; |
| 1628 | ||
| 1629 | case OP_NOT_WORDCHAR: | case OP_NOT_WORDCHAR: |
| 1630 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1631 | { | |
| 1632 | SCHECK_PARTIAL(); | |
| 1633 | RRETURN(MATCH_NOMATCH); | |
| 1634 | } | |
| 1635 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1636 | if ( | if ( |
| 1637 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1364 for (;;) | Line 1644 for (;;) |
| 1644 | break; | break; |
| 1645 | ||
| 1646 | case OP_WORDCHAR: | case OP_WORDCHAR: |
| 1647 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1648 | { | |
| 1649 | SCHECK_PARTIAL(); | |
| 1650 | RRETURN(MATCH_NOMATCH); | |
| 1651 | } | |
| 1652 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1653 | if ( | if ( |
| 1654 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1376 for (;;) | Line 1660 for (;;) |
| 1660 | ecode++; | ecode++; |
| 1661 | break; | break; |
| 1662 | ||
| 1663 | #ifdef SUPPORT_UCP | case OP_ANYNL: |
| 1664 | /* Check the next character by Unicode property. We will get here only | if (eptr >= md->end_subject) |
| 1665 | if the support is in the binary; otherwise a compile-time error occurs. */ | { |
| 1666 | SCHECK_PARTIAL(); | |
| 1667 | case OP_PROP: | RRETURN(MATCH_NOMATCH); |
| 1668 | case OP_NOTPROP: | } |
| if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | ||
| 1669 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1670 | switch(c) | |
| 1671 | { | { |
| 1672 | int chartype, script; | default: RRETURN(MATCH_NOMATCH); |
| 1673 | int category = _pcre_ucp_findprop(c, &chartype, &script); | case 0x000d: |
| 1674 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 1675 | break; | |
| 1676 | ||
| 1677 | switch(ecode[1]) | case 0x000a: |
| 1678 | { | break; |
| case PT_ANY: | ||
| if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH); | ||
| break; | ||
| 1679 | ||
| 1680 | case PT_LAMP: | case 0x000b: |
| 1681 | if ((chartype == ucp_Lu || | case 0x000c: |
| 1682 | chartype == ucp_Ll || | case 0x0085: |
| 1683 | chartype == ucp_Lt) == (op == OP_NOTPROP)) | case 0x2028: |
| 1684 | RRETURN(MATCH_NOMATCH); | case 0x2029: |
| 1685 | break; | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); |
| 1686 | break; | |
| 1687 | } | |
| 1688 | ecode++; | |
| 1689 | break; | |
| 1690 | ||
| 1691 | case OP_NOT_HSPACE: | |
| 1692 | if (eptr >= md->end_subject) | |
| 1693 | { | |
| 1694 | SCHECK_PARTIAL(); | |
| 1695 | RRETURN(MATCH_NOMATCH); | |
| 1696 | } | |
| 1697 | GETCHARINCTEST(c, eptr); | |
| 1698 | switch(c) | |
| 1699 | { | |
| 1700 | default: break; | |
| 1701 | case 0x09: /* HT */ | |
| 1702 | case 0x20: /* SPACE */ | |
| 1703 | case 0xa0: /* NBSP */ | |
| 1704 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 1705 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 1706 | case 0x2000: /* EN QUAD */ | |
| 1707 | case 0x2001: /* EM QUAD */ | |
| 1708 | case 0x2002: /* EN SPACE */ | |
| 1709 | case 0x2003: /* EM SPACE */ | |
| 1710 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 1711 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 1712 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 1713 | case 0x2007: /* FIGURE SPACE */ | |
| 1714 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 1715 | case 0x2009: /* THIN SPACE */ | |
| 1716 | case 0x200A: /* HAIR SPACE */ | |
| 1717 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 1718 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 1719 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 1720 | RRETURN(MATCH_NOMATCH); | |
| 1721 | } | |
| 1722 | ecode++; | |
| 1723 | break; | |
| 1724 | ||
| 1725 | case OP_HSPACE: | |
| 1726 | if (eptr >= md->end_subject) | |
| 1727 | { | |
| 1728 | SCHECK_PARTIAL(); | |
| 1729 | RRETURN(MATCH_NOMATCH); | |
| 1730 | } | |
| 1731 | GETCHARINCTEST(c, eptr); | |
| 1732 | switch(c) | |
| 1733 | { | |
| 1734 | default: RRETURN(MATCH_NOMATCH); | |
| 1735 | case 0x09: /* HT */ | |
| 1736 | case 0x20: /* SPACE */ | |
| 1737 | case 0xa0: /* NBSP */ | |
| 1738 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 1739 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 1740 | case 0x2000: /* EN QUAD */ | |
| 1741 | case 0x2001: /* EM QUAD */ | |
| 1742 | case 0x2002: /* EN SPACE */ | |
| 1743 | case 0x2003: /* EM SPACE */ | |
| 1744 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 1745 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 1746 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 1747 | case 0x2007: /* FIGURE SPACE */ | |
| 1748 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 1749 | case 0x2009: /* THIN SPACE */ | |
| 1750 | case 0x200A: /* HAIR SPACE */ | |
| 1751 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 1752 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 1753 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 1754 | break; | |
| 1755 | } | |
| 1756 | ecode++; | |
| 1757 | break; | |
| 1758 | ||
| 1759 | case OP_NOT_VSPACE: | |
| 1760 | if (eptr >= md->end_subject) | |
| 1761 | { | |
| 1762 | SCHECK_PARTIAL(); | |
| 1763 | RRETURN(MATCH_NOMATCH); | |
| 1764 | } | |
| 1765 | GETCHARINCTEST(c, eptr); | |
| 1766 | switch(c) | |
| 1767 | { | |
| 1768 | default: break; | |
| 1769 | case 0x0a: /* LF */ | |
| 1770 | case 0x0b: /* VT */ | |
| 1771 | case 0x0c: /* FF */ | |
| 1772 | case 0x0d: /* CR */ | |
| 1773 | case 0x85: /* NEL */ | |
| 1774 | case 0x2028: /* LINE SEPARATOR */ | |
| 1775 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 1776 | RRETURN(MATCH_NOMATCH); | |
| 1777 | } | |
| 1778 | ecode++; | |
| 1779 | break; | |
| 1780 | ||
| 1781 | case OP_VSPACE: | |
| 1782 | if (eptr >= md->end_subject) | |
| 1783 | { | |
| 1784 | SCHECK_PARTIAL(); | |
| 1785 | RRETURN(MATCH_NOMATCH); | |
| 1786 | } | |
| 1787 | GETCHARINCTEST(c, eptr); | |
| 1788 | switch(c) | |
| 1789 | { | |
| 1790 | default: RRETURN(MATCH_NOMATCH); | |
| 1791 | case 0x0a: /* LF */ | |
| 1792 | case 0x0b: /* VT */ | |
| 1793 | case 0x0c: /* FF */ | |
| 1794 | case 0x0d: /* CR */ | |
| 1795 | case 0x85: /* NEL */ | |
| 1796 | case 0x2028: /* LINE SEPARATOR */ | |
| 1797 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 1798 | break; | |
| 1799 | } | |
| 1800 | ecode++; | |
| 1801 | break; | |
| 1802 | ||
| 1803 | #ifdef SUPPORT_UCP | |
| 1804 | /* Check the next character by Unicode property. We will get here only | |
| 1805 | if the support is in the binary; otherwise a compile-time error occurs. */ | |
| 1806 | ||
| 1807 | case OP_PROP: | |
| 1808 | case OP_NOTPROP: | |
| 1809 | if (eptr >= md->end_subject) | |
| 1810 | { | |
| 1811 | SCHECK_PARTIAL(); | |
| 1812 | RRETURN(MATCH_NOMATCH); | |
| 1813 | } | |
| 1814 | GETCHARINCTEST(c, eptr); | |
| 1815 | { | |
| 1816 | const ucd_record *prop = GET_UCD(c); | |
| 1817 | ||
| 1818 | switch(ecode[1]) | |
| 1819 | { | |
| 1820 | case PT_ANY: | |
| 1821 | if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH); | |
| 1822 | break; | |
| 1823 | ||
| 1824 | case PT_LAMP: | |
| 1825 | if ((prop->chartype == ucp_Lu || | |
| 1826 | prop->chartype == ucp_Ll || | |
| 1827 | prop->chartype == ucp_Lt) == (op == OP_NOTPROP)) | |
| 1828 | RRETURN(MATCH_NOMATCH); | |
| 1829 | break; | |
| 1830 | ||
| 1831 | case PT_GC: | case PT_GC: |
| 1832 | if ((ecode[2] != category) == (op == OP_PROP)) | if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP)) |
| 1833 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1834 | break; | break; |
| 1835 | ||
| 1836 | case PT_PC: | case PT_PC: |
| 1837 | if ((ecode[2] != chartype) == (op == OP_PROP)) | if ((ecode[2] != prop->chartype) == (op == OP_PROP)) |
| 1838 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1839 | break; | break; |
| 1840 | ||
| 1841 | case PT_SC: | case PT_SC: |
| 1842 | if ((ecode[2] != script) == (op == OP_PROP)) | if ((ecode[2] != prop->script) == (op == OP_PROP)) |
| 1843 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1844 | break; | break; |
| 1845 | ||
| 1846 | default: | default: |
| 1847 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
| break; | ||
| 1848 | } | } |
| 1849 | ||
| 1850 | ecode += 3; | ecode += 3; |
| # | Line 1429 for (;;) | Line 1855 for (;;) |
| 1855 | is in the binary; otherwise a compile-time error occurs. */ | is in the binary; otherwise a compile-time error occurs. */ |
| 1856 | ||
| 1857 | case OP_EXTUNI: | case OP_EXTUNI: |
| 1858 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 1859 | { | |
| 1860 | SCHECK_PARTIAL(); | |
| 1861 | RRETURN(MATCH_NOMATCH); | |
| 1862 | } | |
| 1863 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 1864 | { | { |
| 1865 | int chartype, script; | int category = UCD_CATEGORY(c); |
| int category = _pcre_ucp_findprop(c, &chartype, &script); | ||
| 1866 | if (category == ucp_M) RRETURN(MATCH_NOMATCH); | if (category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 1867 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 1868 | { | { |
| # | Line 1442 for (;;) | Line 1871 for (;;) |
| 1871 | { | { |
| 1872 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
| 1873 | } | } |
| 1874 | category = _pcre_ucp_findprop(c, &chartype, &script); | category = UCD_CATEGORY(c); |
| 1875 | if (category != ucp_M) break; | if (category != ucp_M) break; |
| 1876 | eptr += len; | eptr += len; |
| 1877 | } | } |
| # | Line 1463 for (;;) | Line 1892 for (;;) |
| 1892 | case OP_REF: | case OP_REF: |
| 1893 | { | { |
| 1894 | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ |
| 1895 | ecode += 3; /* Advance past item */ | ecode += 3; |
| 1896 | ||
| 1897 | /* If the reference is unset, there are two possibilities: | |
| 1898 | ||
| 1899 | /* If the reference is unset, set the length to be longer than the amount | (a) In the default, Perl-compatible state, set the length to be longer |
| 1900 | of subject left; this ensures that every attempt at a match fails. We | than the amount of subject left; this ensures that every attempt at a |
| 1901 | can't just fail here, because of the possibility of quantifiers with zero | match fails. We can't just fail here, because of the possibility of |
| 1902 | minima. */ | quantifiers with zero minima. |
| 1903 | ||
| 1904 | length = (offset >= offset_top || md->offset_vector[offset] < 0)? | (b) If the JavaScript compatibility flag is set, set the length to zero |
| 1905 | md->end_subject - eptr + 1 : | so that the back reference matches an empty string. |
| 1906 | md->offset_vector[offset+1] - md->offset_vector[offset]; | |
| 1907 | Otherwise, set the length to the length of what was matched by the | |
| 1908 | referenced subpattern. */ | |
| 1909 | ||
| 1910 | if (offset >= offset_top || md->offset_vector[offset] < 0) | |
| 1911 | length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1; | |
| 1912 | else | |
| 1913 | length = md->offset_vector[offset+1] - md->offset_vector[offset]; | |
| 1914 | ||
| 1915 | /* Set up for repetition, or handle the non-repeated case */ | /* Set up for repetition, or handle the non-repeated case */ |
| 1916 | ||
| # | Line 1501 for (;;) | Line 1939 for (;;) |
| 1939 | break; | break; |
| 1940 | ||
| 1941 | default: /* No repeat follows */ | default: /* No repeat follows */ |
| 1942 | if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH); | if (!match_ref(offset, eptr, length, md, ims)) |
| 1943 | { | |
| 1944 | CHECK_PARTIAL(); | |
| 1945 | RRETURN(MATCH_NOMATCH); | |
| 1946 | } | |
| 1947 | eptr += length; | eptr += length; |
| 1948 | continue; /* With the main loop */ | continue; /* With the main loop */ |
| 1949 | } | } |
| # | Line 1517 for (;;) | Line 1959 for (;;) |
| 1959 | ||
| 1960 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 1961 | { | { |
| 1962 | if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH); | if (!match_ref(offset, eptr, length, md, ims)) |
| 1963 | { | |
| 1964 | CHECK_PARTIAL(); | |
| 1965 | RRETURN(MATCH_NOMATCH); | |
| 1966 | } | |
| 1967 | eptr += length; | eptr += length; |
| 1968 | } | } |
| 1969 | ||
| # | Line 1532 for (;;) | Line 1978 for (;;) |
| 1978 | { | { |
| 1979 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 1980 | { | { |
| 1981 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14); |
| 1982 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1983 | if (fi >= max || !match_ref(offset, eptr, length, md, ims)) | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 1984 | if (!match_ref(offset, eptr, length, md, ims)) | |
| 1985 | { | |
| 1986 | CHECK_PARTIAL(); | |
| 1987 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 1988 | } | |
| 1989 | eptr += length; | eptr += length; |
| 1990 | } | } |
| 1991 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 1553 for (;;) | Line 2003 for (;;) |
| 2003 | } | } |
| 2004 | while (eptr >= pp) | while (eptr >= pp) |
| 2005 | { | { |
| 2006 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15); |
| 2007 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2008 | eptr -= length; | eptr -= length; |
| 2009 | } | } |
| # | Line 1562 for (;;) | Line 2012 for (;;) |
| 2012 | } | } |
| 2013 | /* Control never gets here */ | /* Control never gets here */ |
| 2014 | ||
| 2015 | /* Match a bit-mapped character class, possibly repeatedly. This op code is | /* Match a bit-mapped character class, possibly repeatedly. This op code is |
| 2016 | 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, |
| 2017 | 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 1618 for (;;) | Line 2066 for (;;) |
| 2066 | { | { |
| 2067 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2068 | { | { |
| 2069 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2070 | { | |
| 2071 | SCHECK_PARTIAL(); | |
| 2072 | RRETURN(MATCH_NOMATCH); | |
| 2073 | } | |
| 2074 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 2075 | if (c > 255) | if (c > 255) |
| 2076 | { | { |
| # | Line 1636 for (;;) | Line 2088 for (;;) |
| 2088 | { | { |
| 2089 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2090 | { | { |
| 2091 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2092 | { | |
| 2093 | SCHECK_PARTIAL(); | |
| 2094 | RRETURN(MATCH_NOMATCH); | |
| 2095 | } | |
| 2096 | c = *eptr++; | c = *eptr++; |
| 2097 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); |
| 2098 | } | } |
| # | Line 1658 for (;;) | Line 2114 for (;;) |
| 2114 | { | { |
| 2115 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2116 | { | { |
| 2117 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16); |
| 2118 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2119 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2120 | if (eptr >= md->end_subject) | |
| 2121 | { | |
| 2122 | SCHECK_PARTIAL(); | |
| 2123 | RRETURN(MATCH_NOMATCH); | |
| 2124 | } | |
| 2125 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 2126 | if (c > 255) | if (c > 255) |
| 2127 | { | { |
| # | Line 1678 for (;;) | Line 2139 for (;;) |
| 2139 | { | { |
| 2140 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2141 | { | { |
| 2142 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17); |
| 2143 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2144 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2145 | if (eptr >= md->end_subject) | |
| 2146 | { | |
| 2147 | SCHECK_PARTIAL(); | |
| 2148 | RRETURN(MATCH_NOMATCH); | |
| 2149 | } | |
| 2150 | c = *eptr++; | c = *eptr++; |
| 2151 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); |
| 2152 | } | } |
| # | Line 1715 for (;;) | Line 2181 for (;;) |
| 2181 | } | } |
| 2182 | for (;;) | for (;;) |
| 2183 | { | { |
| 2184 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18); |
| 2185 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2186 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2187 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 1734 for (;;) | Line 2200 for (;;) |
| 2200 | } | } |
| 2201 | while (eptr >= pp) | while (eptr >= pp) |
| 2202 | { | { |
| 2203 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19); |
| 2204 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2205 | eptr--; | eptr--; |
| 2206 | } | } |
| # | Line 1747 for (;;) | Line 2213 for (;;) |
| 2213 | ||
| 2214 | ||
| 2215 | /* Match an extended character class. This opcode is encountered only | /* Match an extended character class. This opcode is encountered only |
| 2216 | 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 |
| 2217 | mode, because Unicode properties are supported in non-UTF-8 mode. */ | |
| 2218 | ||
| 2219 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| 2220 | case OP_XCLASS: | case OP_XCLASS: |
| # | Line 1788 for (;;) | Line 2255 for (;;) |
| 2255 | ||
| 2256 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2257 | { | { |
| 2258 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2259 | GETCHARINC(c, eptr); | { |
| 2260 | SCHECK_PARTIAL(); | |
| 2261 | RRETURN(MATCH_NOMATCH); | |
| 2262 | } | |
| 2263 | GETCHARINCTEST(c, eptr); | |
| 2264 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
| 2265 | } | } |
| 2266 | ||
| # | Line 1805 for (;;) | Line 2276 for (;;) |
| 2276 | { | { |
| 2277 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2278 | { | { |
| 2279 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20); |
| 2280 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2281 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2282 | GETCHARINC(c, eptr); | if (eptr >= md->end_subject) |
| 2283 | { | |
| 2284 | SCHECK_PARTIAL(); | |
| 2285 | RRETURN(MATCH_NOMATCH); | |
| 2286 | } | |
| 2287 | GETCHARINCTEST(c, eptr); | |
| 2288 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
| 2289 | } | } |
| 2290 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 1823 for (;;) | Line 2299 for (;;) |
| 2299 | { | { |
| 2300 | int len = 1; | int len = 1; |
| 2301 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) break; |
| 2302 | GETCHARLEN(c, eptr, len); | GETCHARLENTEST(c, eptr, len); |
| 2303 | if (!_pcre_xclass(c, data)) break; | if (!_pcre_xclass(c, data)) break; |
| 2304 | eptr += len; | eptr += len; |
| 2305 | } | } |
| 2306 | for(;;) | for(;;) |
| 2307 | { | { |
| 2308 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21); |
| 2309 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2310 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2311 | BACKCHAR(eptr) | if (utf8) BACKCHAR(eptr); |
| 2312 | } | } |
| 2313 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2314 | } | } |
| # | Line 1850 for (;;) | Line 2326 for (;;) |
| 2326 | length = 1; | length = 1; |
| 2327 | ecode++; | ecode++; |
| 2328 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
| 2329 | if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | if (length > md->end_subject - eptr) |
| 2330 | { | |
| 2331 | CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */ | |
| 2332 | RRETURN(MATCH_NOMATCH); | |
| 2333 | } | |
| 2334 | while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH); | while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH); |
| 2335 | } | } |
| 2336 | else | else |
| # | Line 1858 for (;;) | Line 2338 for (;;) |
| 2338 | ||
| 2339 | /* Non-UTF-8 mode */ | /* Non-UTF-8 mode */ |
| 2340 | { | { |
| 2341 | if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH); | if (md->end_subject - eptr < 1) |
| 2342 | { | |
| 2343 | SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */ | |
| 2344 | RRETURN(MATCH_NOMATCH); | |
| 2345 | } | |
| 2346 | if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH); | if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH); |
| 2347 | ecode += 2; | ecode += 2; |
| 2348 | } | } |
| # | Line 1874 for (;;) | Line 2358 for (;;) |
| 2358 | ecode++; | ecode++; |
| 2359 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
| 2360 | ||
| 2361 | if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | if (length > md->end_subject - eptr) |
| 2362 | { | |
| 2363 | CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */ | |
| 2364 | RRETURN(MATCH_NOMATCH); | |
| 2365 | } | |
| 2366 | ||
| 2367 | /* 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 |
| 2368 | can use the fast lookup table. */ | can use the fast lookup table. */ |
| # | Line 1888 for (;;) | Line 2376 for (;;) |
| 2376 | ||
| 2377 | else | else |
| 2378 | { | { |
| 2379 | int dc; | unsigned int dc; |
| 2380 | GETCHARINC(dc, eptr); | GETCHARINC(dc, eptr); |
| 2381 | ecode += length; | ecode += length; |
| 2382 | ||
| # | Line 1898 for (;;) | Line 2386 for (;;) |
| 2386 | if (fc != dc) | if (fc != dc) |
| 2387 | { | { |
| 2388 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2389 | if (dc != _pcre_ucp_othercase(fc)) | if (dc != UCD_OTHERCASE(fc)) |
| 2390 | #endif | #endif |
| 2391 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2392 | } | } |
| # | Line 1909 for (;;) | Line 2397 for (;;) |
| 2397 | ||
| 2398 | /* Non-UTF-8 mode */ | /* Non-UTF-8 mode */ |
| 2399 | { | { |
| 2400 | if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH); | if (md->end_subject - eptr < 1) |
| 2401 | { | |
| 2402 | SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */ | |
| 2403 | RRETURN(MATCH_NOMATCH); | |
| 2404 | } | |
| 2405 | if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); |
| 2406 | ecode += 2; | ecode += 2; |
| 2407 | } | } |
| 2408 | break; | break; |
| 2409 | ||
| 2410 | /* Match a single character repeatedly; different opcodes share code. */ | /* Match a single character repeatedly. */ |
| 2411 | ||
| 2412 | case OP_EXACT: | case OP_EXACT: |
| 2413 | min = max = GET2(ecode, 1); | min = max = GET2(ecode, 1); |
| 2414 | ecode += 3; | ecode += 3; |
| 2415 | goto REPEATCHAR; | goto REPEATCHAR; |
| 2416 | ||
| 2417 | case OP_POSUPTO: | |
| 2418 | possessive = TRUE; | |
| 2419 | /* Fall through */ | |
| 2420 | ||
| 2421 | case OP_UPTO: | case OP_UPTO: |
| 2422 | case OP_MINUPTO: | case OP_MINUPTO: |
| 2423 | min = 0; | min = 0; |
| # | Line 1930 for (;;) | Line 2426 for (;;) |
| 2426 | ecode += 3; | ecode += 3; |
| 2427 | goto REPEATCHAR; | goto REPEATCHAR; |
| 2428 | ||
| 2429 | case OP_POSSTAR: | |
| 2430 | possessive = TRUE; | |
| 2431 | min = 0; | |
| 2432 | max = INT_MAX; | |
| 2433 | ecode++; | |
| 2434 | goto REPEATCHAR; | |
| 2435 | ||
| 2436 | case OP_POSPLUS: | |
| 2437 | possessive = TRUE; | |
| 2438 | min = 1; | |
| 2439 | max = INT_MAX; | |
| 2440 | ecode++; | |
| 2441 | goto REPEATCHAR; | |
| 2442 | ||
| 2443 | case OP_POSQUERY: | |
| 2444 | possessive = TRUE; | |
| 2445 | min = 0; | |
| 2446 | max = 1; | |
| 2447 | ecode++; | |
| 2448 | goto REPEATCHAR; | |
| 2449 | ||
| 2450 | case OP_STAR: | case OP_STAR: |
| 2451 | case OP_MINSTAR: | case OP_MINSTAR: |
| 2452 | case OP_PLUS: | case OP_PLUS: |
| # | Line 1938 for (;;) | Line 2455 for (;;) |
| 2455 | case OP_MINQUERY: | case OP_MINQUERY: |
| 2456 | c = *ecode++ - OP_STAR; | c = *ecode++ - OP_STAR; |
| 2457 | minimize = (c & 1) != 0; | minimize = (c & 1) != 0; |
| 2458 | ||
| 2459 | min = rep_min[c]; /* Pick up values from tables; */ | min = rep_min[c]; /* Pick up values from tables; */ |
| 2460 | max = rep_max[c]; /* zero for max => infinity */ | max = rep_max[c]; /* zero for max => infinity */ |
| 2461 | if (max == 0) max = INT_MAX; | if (max == 0) max = INT_MAX; |
| 2462 | ||
| 2463 | /* 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. */ | ||
| 2464 | ||
| 2465 | REPEATCHAR: | REPEATCHAR: |
| 2466 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
| # | Line 1953 for (;;) | Line 2469 for (;;) |
| 2469 | length = 1; | length = 1; |
| 2470 | charptr = ecode; | charptr = ecode; |
| 2471 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
| if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
| 2472 | ecode += length; | ecode += length; |
| 2473 | ||
| 2474 | /* Handle multibyte character matching specially here. There is | /* Handle multibyte character matching specially here. There is |
| # | Line 1961 for (;;) | Line 2476 for (;;) |
| 2476 | ||
| 2477 | if (length > 1) | if (length > 1) |
| 2478 | { | { |
| int oclength = 0; | ||
| uschar occhars[8]; | ||
| 2479 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| 2480 | int othercase; | unsigned int othercase; |
| 2481 | if ((ims & PCRE_CASELESS) != 0 && | if ((ims & PCRE_CASELESS) != 0 && |
| 2482 | (othercase = _pcre_ucp_othercase(fc)) >= 0 && | (othercase = UCD_OTHERCASE(fc)) != fc) |
| othercase >= 0) | ||
| 2483 | oclength = _pcre_ord2utf8(othercase, occhars); | oclength = _pcre_ord2utf8(othercase, occhars); |
| 2484 | else oclength = 0; | |
| 2485 | #endif /* SUPPORT_UCP */ | #endif /* SUPPORT_UCP */ |
| 2486 | ||
| 2487 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2488 | { | { |
| 2489 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (eptr <= md->end_subject - length && |
| 2490 | /* Need braces because of following else */ | memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2491 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | #ifdef SUPPORT_UCP |
| 2492 | else if (oclength > 0 && | |
| 2493 | eptr <= md->end_subject - oclength && | |
| 2494 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
| 2495 | #endif /* SUPPORT_UCP */ | |
| 2496 | else | else |
| 2497 | { | { |
| 2498 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | CHECK_PARTIAL(); |
| 2499 | eptr += oclength; | RRETURN(MATCH_NOMATCH); |
| 2500 | } | } |
| 2501 | } | } |
| 2502 | ||
| # | Line 1990 for (;;) | Line 2506 for (;;) |
| 2506 | { | { |
| 2507 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2508 | { | { |
| 2509 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22); |
| 2510 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2511 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2512 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (eptr <= md->end_subject - length && |
| 2513 | /* Need braces because of following else */ | memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2514 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | #ifdef SUPPORT_UCP |
| 2515 | else if (oclength > 0 && | |
| 2516 | eptr <= md->end_subject - oclength && | |
| 2517 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
| 2518 | #endif /* SUPPORT_UCP */ | |
| 2519 | else | else |
| 2520 | { | { |
| 2521 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | CHECK_PARTIAL(); |
| 2522 | eptr += oclength; | RRETURN(MATCH_NOMATCH); |
| 2523 | } | } |
| 2524 | } | } |
| 2525 | /* Control never gets here */ | /* Control never gets here */ |
| 2526 | } | } |
| 2527 | else | |
| 2528 | else /* Maximize */ | |
| 2529 | { | { |
| 2530 | pp = eptr; | pp = eptr; |
| 2531 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2532 | { | { |
| 2533 | if (eptr > md->end_subject - length) break; | if (eptr <= md->end_subject - length && |
| 2534 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | memcmp(eptr, charptr, length) == 0) eptr += length; |
| 2535 | else if (oclength == 0) break; | #ifdef SUPPORT_UCP |
| 2536 | else | else if (oclength > 0 && |
| 2537 | { | eptr <= md->end_subject - oclength && |
| 2538 | if (memcmp(eptr, occhars, oclength) != 0) break; | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; |
| 2539 | eptr += oclength; | #endif /* SUPPORT_UCP */ |
| 2540 | } | else break; |
| 2541 | } | |
| 2542 | ||
| 2543 | if (possessive) continue; | |
| 2544 | ||
| 2545 | for(;;) | |
| 2546 | { | |
| 2547 | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23); | |
| 2548 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
| 2549 | if (eptr == pp) { RRETURN(MATCH_NOMATCH); } | |
| 2550 | #ifdef SUPPORT_UCP | |
| 2551 | eptr--; | |
| 2552 | BACKCHAR(eptr); | |
| 2553 | #else /* without SUPPORT_UCP */ | |
| 2554 | eptr -= length; | |
| 2555 | #endif /* SUPPORT_UCP */ | |
| 2556 | } | } |
| while (eptr >= pp) | ||
| { | ||
| RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | ||
| if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ||
| eptr -= length; | ||
| } | ||
| RRETURN(MATCH_NOMATCH); | ||
| 2557 | } | } |
| 2558 | /* Control never gets here */ | /* Control never gets here */ |
| 2559 | } | } |
| # | Line 2037 for (;;) | Line 2566 for (;;) |
| 2566 | #endif /* SUPPORT_UTF8 */ | #endif /* SUPPORT_UTF8 */ |
| 2567 | ||
| 2568 | /* When not in UTF-8 mode, load a single-byte character. */ | /* When not in UTF-8 mode, load a single-byte character. */ |
| 2569 | { | |
| 2570 | if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | fc = *ecode++; |
| fc = *ecode++; | ||
| } | ||
| 2571 | ||
| 2572 | /* 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 |
| 2573 | 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 2058 for (;;) | Line 2585 for (;;) |
| 2585 | { | { |
| 2586 | fc = md->lcc[fc]; | fc = md->lcc[fc]; |
| 2587 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2588 | { | |
| 2589 | if (eptr >= md->end_subject) | |
| 2590 | { | |
| 2591 | SCHECK_PARTIAL(); | |
| 2592 | RRETURN(MATCH_NOMATCH); | |
| 2593 | } | |
| 2594 | if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); |
| 2595 | } | |
| 2596 | if (min == max) continue; | if (min == max) continue; |
| 2597 | if (minimize) | if (minimize) |
| 2598 | { | { |
| 2599 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2600 | { | { |
| 2601 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24); |
| 2602 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2603 | if (fi >= max || eptr >= md->end_subject || | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2604 | fc != md->lcc[*eptr++]) | if (eptr >= md->end_subject) |
| 2605 | { | |
| 2606 | SCHECK_PARTIAL(); | |
| 2607 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2608 | } | |
| 2609 | if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | |
| 2610 | } | } |
| 2611 | /* Control never gets here */ | /* Control never gets here */ |
| 2612 | } | } |
| 2613 | else | else /* Maximize */ |
| 2614 | { | { |
| 2615 | pp = eptr; | pp = eptr; |
| 2616 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| # | Line 2080 for (;;) | Line 2618 for (;;) |
| 2618 | if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break; | if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break; |
| 2619 | eptr++; | eptr++; |
| 2620 | } | } |
| 2621 | ||
| 2622 | if (possessive) continue; | |
| 2623 | ||
| 2624 | while (eptr >= pp) | while (eptr >= pp) |
| 2625 | { | { |
| 2626 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25); |
| 2627 | eptr--; | eptr--; |
| 2628 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2629 | } | } |
| # | Line 2095 for (;;) | Line 2636 for (;;) |
| 2636 | ||
| 2637 | else | else |
| 2638 | { | { |
| 2639 | for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH); | for (i = 1; i <= min; i++) |
| 2640 | { | |
| 2641 | if (eptr >= md->end_subject) | |
| 2642 | { | |
| 2643 | SCHECK_PARTIAL(); | |
| 2644 | RRETURN(MATCH_NOMATCH); | |
| 2645 | } | |
| 2646 | if (fc != *eptr++) RRETURN(MATCH_NOMATCH); | |
| 2647 | } | |
| 2648 | ||
| 2649 | if (min == max) continue; | if (min == max) continue; |
| 2650 | ||
| 2651 | if (minimize) | if (minimize) |
| 2652 | { | { |
| 2653 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2654 | { | { |
| 2655 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26); |
| 2656 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2657 | if (fi >= max || eptr >= md->end_subject || fc != *eptr++) | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2658 | if (eptr >= md->end_subject) | |
| 2659 | { | |
| 2660 | SCHECK_PARTIAL(); | |
| 2661 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2662 | } | |
| 2663 | if (fc != *eptr++) RRETURN(MATCH_NOMATCH); | |
| 2664 | } | } |
| 2665 | /* Control never gets here */ | /* Control never gets here */ |
| 2666 | } | } |
| 2667 | else | else /* Maximize */ |
| 2668 | { | { |
| 2669 | pp = eptr; | pp = eptr; |
| 2670 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| # | Line 2116 for (;;) | Line 2672 for (;;) |
| 2672 | if (eptr >= md->end_subject || fc != *eptr) break; | if (eptr >= md->end_subject || fc != *eptr) break; |
| 2673 | eptr++; | eptr++; |
| 2674 | } | } |
| 2675 | if (possessive) continue; | |
| 2676 | ||
| 2677 | while (eptr >= pp) | while (eptr >= pp) |
| 2678 | { | { |
| 2679 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27); |
| 2680 | eptr--; | eptr--; |
| 2681 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2682 | } | } |
| # | Line 2131 for (;;) | Line 2689 for (;;) |
| 2689 | checking can be multibyte. */ | checking can be multibyte. */ |
| 2690 | ||
| 2691 | case OP_NOT: | case OP_NOT: |
| 2692 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 2693 | { | |
| 2694 | SCHECK_PARTIAL(); | |
| 2695 | RRETURN(MATCH_NOMATCH); | |
| 2696 | } | |
| 2697 | ecode++; | ecode++; |
| 2698 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 2699 | if ((ims & PCRE_CASELESS) != 0) | if ((ims & PCRE_CASELESS) != 0) |
| # | Line 2168 for (;;) | Line 2730 for (;;) |
| 2730 | ecode += 3; | ecode += 3; |
| 2731 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
| 2732 | ||
| 2733 | case OP_NOTPOSSTAR: | |
| 2734 | possessive = TRUE; | |
| 2735 | min = 0; | |
| 2736 | max = INT_MAX; | |
| 2737 | ecode++; | |
| 2738 | goto REPEATNOTCHAR; | |
| 2739 | ||
| 2740 | case OP_NOTPOSPLUS: | |
| 2741 | possessive = TRUE; | |
| 2742 | min = 1; | |
| 2743 | max = INT_MAX; | |
| 2744 | ecode++; | |
| 2745 | goto REPEATNOTCHAR; | |
| 2746 | ||
| 2747 | case OP_NOTPOSQUERY: | |
| 2748 | possessive = TRUE; | |
| 2749 | min = 0; | |
| 2750 | max = 1; | |
| 2751 | ecode++; | |
| 2752 | goto REPEATNOTCHAR; | |
| 2753 | ||
| 2754 | case OP_NOTPOSUPTO: | |
| 2755 | possessive = TRUE; | |
| 2756 | min = 0; | |
| 2757 | max = GET2(ecode, 1); | |
| 2758 | ecode += 3; | |
| 2759 | goto REPEATNOTCHAR; | |
| 2760 | ||
| 2761 | case OP_NOTSTAR: | case OP_NOTSTAR: |
| 2762 | case OP_NOTMINSTAR: | case OP_NOTMINSTAR: |
| 2763 | case OP_NOTPLUS: | case OP_NOTPLUS: |
| # | Line 2180 for (;;) | Line 2770 for (;;) |
| 2770 | max = rep_max[c]; /* zero for max => infinity */ | max = rep_max[c]; /* zero for max => infinity */ |
| 2771 | if (max == 0) max = INT_MAX; | if (max == 0) max = INT_MAX; |
| 2772 | ||
| 2773 | /* 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. */ | ||
| 2774 | ||
| 2775 | REPEATNOTCHAR: | REPEATNOTCHAR: |
| if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
| 2776 | fc = *ecode++; | fc = *ecode++; |
| 2777 | ||
| 2778 | /* 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 2207 for (;;) | Line 2794 for (;;) |
| 2794 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2795 | if (utf8) | if (utf8) |
| 2796 | { | { |
| 2797 | register int d; | register unsigned int d; |
| 2798 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2799 | { | { |
| 2800 | if (eptr >= md->end_subject) | |
| 2801 | { | |
| 2802 | SCHECK_PARTIAL(); | |
| 2803 | RRETURN(MATCH_NOMATCH); | |
| 2804 | } | |
| 2805 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 2806 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
| 2807 | if (fc == d) RRETURN(MATCH_NOMATCH); | if (fc == d) RRETURN(MATCH_NOMATCH); |
| # | Line 2221 for (;;) | Line 2813 for (;;) |
| 2813 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
| 2814 | { | { |
| 2815 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2816 | { | |
| 2817 | if (eptr >= md->end_subject) | |
| 2818 | { | |
| 2819 | SCHECK_PARTIAL(); | |
| 2820 | RRETURN(MATCH_NOMATCH); | |
| 2821 | } | |
| 2822 | if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); |
| 2823 | } | |
| 2824 | } | } |
| 2825 | ||
| 2826 | if (min == max) continue; | if (min == max) continue; |
| # | Line 2232 for (;;) | Line 2831 for (;;) |
| 2831 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2832 | if (utf8) | if (utf8) |
| 2833 | { | { |
| 2834 | register int d; | register unsigned int d; |
| 2835 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2836 | { | { |
| 2837 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28); |
| 2838 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2839 | if (fi >= max) RRETURN(MATCH_NOMATCH); | |
| 2840 | if (eptr >= md->end_subject) | |
| 2841 | { | |
| 2842 | SCHECK_PARTIAL(); | |
| 2843 | RRETURN(MATCH_NOMATCH); | |
| 2844 | } | |
| 2845 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 2846 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
| 2847 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (fc == d) RRETURN(MATCH_NOMATCH); |
| RRETURN(MATCH_NOMATCH); | ||
| 2848 | } | } |
| 2849 | } | } |
| 2850 | else | else |
| # | Line 2249 for (;;) | Line 2853 for (;;) |
| 2853 | { | { |
| 2854 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2855 | { | { |
| 2856 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29); |
| 2857 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2858 | if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++]) | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2859 | if (eptr >= md->end_subject) | |
| 2860 | { | |
| 2861 | SCHECK_PARTIAL(); | |
| 2862 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2863 | } | |
| 2864 | if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | |
| 2865 | } | } |
| 2866 | } | } |
| 2867 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 2268 for (;;) | Line 2877 for (;;) |
| 2877 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2878 | if (utf8) | if (utf8) |
| 2879 | { | { |
| 2880 | register int d; | register unsigned int d; |
| 2881 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 2882 | { | { |
| 2883 | int len = 1; | int len = 1; |
| # | Line 2278 for (;;) | Line 2887 for (;;) |
| 2887 | if (fc == d) break; | if (fc == d) break; |
| 2888 | eptr += len; | eptr += len; |
| 2889 | } | } |
| 2890 | for(;;) | if (possessive) continue; |
| 2891 | for(;;) | |
| 2892 | { | { |
| 2893 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30); |
| 2894 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2895 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2896 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 2295 for (;;) | Line 2905 for (;;) |
| 2905 | if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break; | if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break; |
| 2906 | eptr++; | eptr++; |
| 2907 | } | } |
| 2908 | if (possessive) continue; | |
| 2909 | while (eptr >= pp) | while (eptr >= pp) |
| 2910 | { | { |
| 2911 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31); |
| 2912 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2913 | eptr--; | eptr--; |
| 2914 | } | } |
| # | Line 2316 for (;;) | Line 2927 for (;;) |
| 2927 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2928 | if (utf8) | if (utf8) |
| 2929 | { | { |
| 2930 | register int d; | register unsigned int d; |
| 2931 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2932 | { | { |
| 2933 | if (eptr >= md->end_subject) | |
| 2934 | { | |
| 2935 | SCHECK_PARTIAL(); | |
| 2936 | RRETURN(MATCH_NOMATCH); | |
| 2937 | } | |
| 2938 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
| 2939 | if (fc == d) RRETURN(MATCH_NOMATCH); | if (fc == d) RRETURN(MATCH_NOMATCH); |
| 2940 | } | } |
| # | Line 2328 for (;;) | Line 2944 for (;;) |
| 2944 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
| 2945 | { | { |
| 2946 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 2947 | { | |
| 2948 | if (eptr >= md->end_subject) | |
| 2949 | { | |
| 2950 | SCHECK_PARTIAL(); | |
| 2951 | RRETURN(MATCH_NOMATCH); | |
| 2952 | } | |
| 2953 | if (fc == *eptr++) RRETURN(MATCH_NOMATCH); | if (fc == *eptr++) RRETURN(MATCH_NOMATCH); |
| 2954 | } | |
| 2955 | } | } |
| 2956 | ||
| 2957 | if (min == max) continue; | if (min == max) continue; |
| # | Line 2339 for (;;) | Line 2962 for (;;) |
| 2962 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 2963 | if (utf8) | if (utf8) |
| 2964 | { | { |
| 2965 | register int d; | register unsigned int d; |
| 2966 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2967 | { | { |
| 2968 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32); |
| 2969 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2970 | GETCHARINC(d, eptr); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2971 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (eptr >= md->end_subject) |
| 2972 | { | |
| 2973 | SCHECK_PARTIAL(); | |
| 2974 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2975 | } | |
| 2976 | GETCHARINC(d, eptr); | |
| 2977 | if (fc == d) RRETURN(MATCH_NOMATCH); | |
| 2978 | } | } |
| 2979 | } | } |
| 2980 | else | else |
| # | Line 2355 for (;;) | Line 2983 for (;;) |
| 2983 | { | { |
| 2984 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 2985 | { | { |
| 2986 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33); |
| 2987 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2988 | if (fi >= max || eptr >= md->end_subject || fc == *eptr++) | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2989 | if (eptr >= md->end_subject) | |
| 2990 | { | |
| 2991 | SCHECK_PARTIAL(); | |
| 2992 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 2993 | } | |
| 2994 | if (fc == *eptr++) RRETURN(MATCH_NOMATCH); | |
| 2995 | } | } |
| 2996 | } | } |
| 2997 | /* Control never gets here */ | /* Control never gets here */ |
| # | Line 2374 for (;;) | Line 3007 for (;;) |
| 3007 | /* UTF-8 mode */ | /* UTF-8 mode */ |
| 3008 | if (utf8) | if (utf8) |
| 3009 | { | { |
| 3010 | register int d; | register unsigned int d; |
| 3011 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
| 3012 | { | { |
| 3013 | int len = 1; | int len = 1; |
| # | Line 2383 for (;;) | Line 3016 for (;;) |
| 3016 | if (fc == d) break; | if (fc == d) break; |
| 3017 | eptr += len; | eptr += len; |
| 3018 | } | } |
| 3019 | if (possessive) continue; | |
| 3020 | for(;;) | for(;;) |
| 3021 | { | { |
| 3022 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34); |
| 3023 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3024 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3025 | BACKCHAR(eptr); | BACKCHAR(eptr); |
| # | Line 2400 for (;;) | Line 3034 for (;;) |
| 3034 | if (eptr >= md->end_subject || fc == *eptr) break; | if (eptr >= md->end_subject || fc == *eptr) break; |
| 3035 | eptr++; | eptr++; |
| 3036 | } | } |
| 3037 | if (possessive) continue; | |
| 3038 | while (eptr >= pp) | while (eptr >= pp) |
| 3039 | { | { |
| 3040 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35); |
| 3041 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3042 | eptr--; | eptr--; |
| 3043 | } | } |
| # | Line 2431 for (;;) | Line 3066 for (;;) |
| 3066 | ecode += 3; | ecode += 3; |
| 3067 | goto REPEATTYPE; | goto REPEATTYPE; |
| 3068 | ||
| 3069 | case OP_TYPEPOSSTAR: | |
| 3070 | possessive = TRUE; | |
| 3071 | min = 0; | |
| 3072 | max = INT_MAX; | |
| 3073 | ecode++; | |
| 3074 | goto REPEATTYPE; | |
| 3075 | ||
| 3076 | case OP_TYPEPOSPLUS: | |
| 3077 | possessive = TRUE; | |
| 3078 | min = 1; | |
| 3079 | max = INT_MAX; | |
| 3080 | ecode++; | |
| 3081 | goto REPEATTYPE; | |
| 3082 | ||
| 3083 | case OP_TYPEPOSQUERY: | |
| 3084 | possessive = TRUE; | |
| 3085 | min = 0; | |
| 3086 | max = 1; | |
| 3087 | ecode++; | |
| 3088 | goto REPEATTYPE; | |
| 3089 | ||
| 3090 | case OP_TYPEPOSUPTO: | |
| 3091 | possessive = TRUE; | |
| 3092 | min = 0; | |
| 3093 | max = GET2(ecode, 1); | |
| 3094 | ecode += 3; | |
| 3095 | goto REPEATTYPE; | |
| 3096 | ||
| 3097 | case OP_TYPESTAR: | case OP_TYPESTAR: |
| 3098 | case OP_TYPEMINSTAR: | case OP_TYPEMINSTAR: |
| 3099 | case OP_TYPEPLUS: | case OP_TYPEPLUS: |
| # | Line 2462 for (;;) | Line 3125 for (;;) |
| 3125 | ||
| 3126 | /* First, ensure the minimum number of matches are present. Use inline | /* First, ensure the minimum number of matches are present. Use inline |
| 3127 | 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 |
| 3128 | (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 | ||
| 3129 | 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 |
| 3130 | and single-bytes. */ | and single-bytes. */ |
| 3131 | ||
| if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
| 3132 | if (min > 0) | if (min > 0) |
| 3133 | { | { |
| 3134 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
| # | Line 2480 for (;;) | Line 3140 for (;;) |
| 3140 | if (prop_fail_result) RRETURN(MATCH_NOMATCH); | if (prop_fail_result) RRETURN(MATCH_NOMATCH); |
| 3141 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3142 | { | { |
| 3143 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3144 | GETCHARINC(c, eptr); | { |
| 3145 | SCHECK_PARTIAL(); | |
| 3146 | RRETURN(MATCH_NOMATCH); | |
| 3147 | } | |
| 3148 | GETCHARINCTEST(c, eptr); | |
| 3149 | } | } |
| 3150 | break; | break; |
| 3151 | ||
| 3152 | case PT_LAMP: | case PT_LAMP: |
| 3153 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3154 | { | { |
| 3155 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3156 | GETCHARINC(c, eptr); | { |
| 3157 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
| 3158 | if ((prop_chartype == ucp_Lu || | RRETURN(MATCH_NOMATCH); |
| 3159 | prop_chartype == ucp_Ll || | } |
| 3160 | GETCHARINCTEST(c, eptr); | |
| 3161 | prop_chartype = UCD_CHARTYPE(c); | |
| 3162 | if ((prop_chartype == ucp_Lu || | |
| 3163 | prop_chartype == ucp_Ll || | |
| 3164 | prop_chartype == ucp_Lt) == prop_fail_result) | prop_chartype == ucp_Lt) == prop_fail_result) |
| 3165 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3166 | } | } |
| # | Line 2501 for (;;) | Line 3169 for (;;) |
| 3169 | case PT_GC: | case PT_GC: |
| 3170 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3171 | { | { |
| 3172 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3173 | GETCHARINC(c, eptr); | { |
| 3174 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
| 3175 | RRETURN(MATCH_NOMATCH); | |
| 3176 | } | |
| 3177 | GETCHARINCTEST(c, eptr); | |
| 3178 | prop_category = UCD_CATEGORY(c); | |
| 3179 | if ((prop_category == prop_value) == prop_fail_result) | if ((prop_category == prop_value) == prop_fail_result) |
| 3180 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3181 | } | } |
| # | Line 2512 for (;;) | Line 3184 for (;;) |
| 3184 | case PT_PC: | case PT_PC: |
| 3185 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3186 | { | { |
| 3187 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3188 | GETCHARINC(c, eptr); | { |
| 3189 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
| 3190 | RRETURN(MATCH_NOMATCH); | |
| 3191 | } | |
| 3192 | GETCHARINCTEST(c, eptr); | |
| 3193 | prop_chartype = UCD_CHARTYPE(c); | |
| 3194 | if ((prop_chartype == prop_value) == prop_fail_result) | if ((prop_chartype == prop_value) == prop_fail_result) |
| 3195 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3196 | } | } |
| # | Line 2523 for (;;) | Line 3199 for (;;) |
| 3199 | case PT_SC: | case PT_SC: |
| 3200 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3201 | { | { |
| 3202 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3203 | GETCHARINC(c, eptr); | { |
| 3204 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
| 3205 | RRETURN(MATCH_NOMATCH); | |
| 3206 | } | |
| 3207 | GETCHARINCTEST(c, eptr); | |
| 3208 | prop_script = UCD_SCRIPT(c); | |
| 3209 | if ((prop_script == prop_value) == prop_fail_result) | if ((prop_script == prop_value) == prop_fail_result) |
| 3210 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3211 | } | } |
| # | Line 2533 for (;;) | Line 3213 for (;;) |
| 3213 | ||
| 3214 | default: | default: |
| 3215 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
| break; | ||
| 3216 | } | } |
| 3217 | } | } |
| 3218 | ||
| # | Line 2544 for (;;) | Line 3223 for (;;) |
| 3223 | { | { |
| 3224 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3225 | { | { |
| 3226 | if (eptr >= md->end_subject) | |
| 3227 | { | |
| 3228 | SCHECK_PARTIAL(); | |
| 3229 | RRETURN(MATCH_NOMATCH); | |
| 3230 | } | |
| 3231 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3232 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
| 3233 | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 3234 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 3235 | { | { |
| 3236 | int len = 1; | int len = 1; |
| 3237 | if (!utf8) c = *eptr; else | if (!utf8) c = *eptr; |
| 3238 | { | else { GETCHARLEN(c, eptr, len); } |
| 3239 | GETCHARLEN(c, eptr, len); | prop_category = UCD_CATEGORY(c); |
| } | ||
| prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | ||
| 3240 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 3241 | eptr += len; | eptr += len; |
| 3242 | } | } |
| # | Line 2572 for (;;) | Line 3254 for (;;) |
| 3254 | case OP_ANY: | case OP_ANY: |
| 3255 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3256 | { | { |
| 3257 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
| 3258 | (*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0)) | { |
| 3259 | SCHECK_PARTIAL(); | |
| 3260 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3261 | } | |
| 3262 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); | |
| 3263 | eptr++; | |
| 3264 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | |
| 3265 | } | |
| 3266 | break; | |
| 3267 | ||
| 3268 | case OP_ALLANY: | |
| 3269 | for (i = 1; i <= min; i++) | |
| 3270 | { | |
| 3271 | if (eptr >= md->end_subject) | |
| 3272 | { | |
| 3273 | SCHECK_PARTIAL(); | |
| 3274 | RRETURN(MATCH_NOMATCH); | |
| 3275 | } | |
| 3276 | eptr++; | |
| 3277 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
| 3278 | } | } |
| 3279 | break; | break; |
| 3280 | ||
| 3281 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 3282 | if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH); | |
| 3283 | eptr += min; | eptr += min; |
| 3284 | break; | break; |
| 3285 | ||
| 3286 | case OP_ANYNL: | |
| 3287 | for (i = 1; i <= min; i++) | |
| 3288 | { | |
| 3289 | if (eptr >= md->end_subject) | |
| 3290 | { | |
| 3291 | SCHECK_PARTIAL(); | |
| 3292 | RRETURN(MATCH_NOMATCH); | |
| 3293 | } | |
| 3294 | GETCHARINC(c, eptr); | |
| 3295 | switch(c) | |
| 3296 | { | |
| 3297 | default: RRETURN(MATCH_NOMATCH); | |
| 3298 | case 0x000d: | |
| 3299 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3300 | break; | |
| 3301 | ||
| 3302 | case 0x000a: | |
| 3303 | break; | |
| 3304 | ||
| 3305 | case 0x000b: | |
| 3306 | case 0x000c: | |
| 3307 | case 0x0085: | |
| 3308 | case 0x2028: | |
| 3309 | case 0x2029: | |
| 3310 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3311 | break; | |
| 3312 | } | |
| 3313 | } | |
| 3314 | break; | |
| 3315 | ||
| 3316 | case OP_NOT_HSPACE: | |
| 3317 | for (i = 1; i <= min; i++) | |
| 3318 | { | |
| 3319 | if (eptr >= md->end_subject) | |
| 3320 | { | |
| 3321 | SCHECK_PARTIAL(); | |
| 3322 | RRETURN(MATCH_NOMATCH); | |
| 3323 | } | |
| 3324 | GETCHARINC(c, eptr); | |
| 3325 | switch(c) | |
| 3326 | { | |
| 3327 | default: break; | |
| 3328 | case 0x09: /* HT */ | |
| 3329 | case 0x20: /* SPACE */ | |
| 3330 | case 0xa0: /* NBSP */ | |
| 3331 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3332 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3333 | case 0x2000: /* EN QUAD */ | |
| 3334 | case 0x2001: /* EM QUAD */ | |
| 3335 | case 0x2002: /* EN SPACE */ | |
| 3336 | case 0x2003: /* EM SPACE */ | |
| 3337 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3338 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3339 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3340 | case 0x2007: /* FIGURE SPACE */ | |
| 3341 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3342 | case 0x2009: /* THIN SPACE */ | |
| 3343 | case 0x200A: /* HAIR SPACE */ | |
| 3344 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3345 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3346 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3347 | RRETURN(MATCH_NOMATCH); | |
| 3348 | } | |
| 3349 | } | |
| 3350 | break; | |
| 3351 | ||
| 3352 | case OP_HSPACE: | |
| 3353 | for (i = 1; i <= min; i++) | |
| 3354 | { | |
| 3355 | if (eptr >= md->end_subject) | |
| 3356 | { | |
| 3357 | SCHECK_PARTIAL(); | |
| 3358 | RRETURN(MATCH_NOMATCH); | |
| 3359 | } | |
| 3360 | GETCHARINC(c, eptr); | |
| 3361 | switch(c) | |
| 3362 | { | |
| 3363 | default: RRETURN(MATCH_NOMATCH); | |
| 3364 | case 0x09: /* HT */ | |
| 3365 | case 0x20: /* SPACE */ | |
| 3366 | case 0xa0: /* NBSP */ | |
| 3367 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3368 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3369 | case 0x2000: /* EN QUAD */ | |
| 3370 | case 0x2001: /* EM QUAD */ | |
| 3371 | case 0x2002: /* EN SPACE */ | |
| 3372 | case 0x2003: /* EM SPACE */ | |
| 3373 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3374 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3375 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3376 | case 0x2007: /* FIGURE SPACE */ | |
| 3377 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3378 | case 0x2009: /* THIN SPACE */ | |
| 3379 | case 0x200A: /* HAIR SPACE */ | |
| 3380 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3381 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3382 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3383 | break; | |
| 3384 | } | |
| 3385 | } | |
| 3386 | break; | |
| 3387 | ||
| 3388 | case OP_NOT_VSPACE: | |
| 3389 | for (i = 1; i <= min; i++) | |
| 3390 | { | |
| 3391 | if (eptr >= md->end_subject) | |
| 3392 | { | |
| 3393 | SCHECK_PARTIAL(); | |
| 3394 | RRETURN(MATCH_NOMATCH); | |
| 3395 | } | |
| 3396 | GETCHARINC(c, eptr); | |
| 3397 | switch(c) | |
| 3398 | { | |
| 3399 | default: break; | |
| 3400 | case 0x0a: /* LF */ | |
| 3401 | case 0x0b: /* VT */ | |
| 3402 | case 0x0c: /* FF */ | |
| 3403 | case 0x0d: /* CR */ | |
| 3404 | case 0x85: /* NEL */ | |
| 3405 | case 0x2028: /* LINE SEPARATOR */ | |
| 3406 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3407 | RRETURN(MATCH_NOMATCH); | |
| 3408 | } | |
| 3409 | } | |
| 3410 | break; | |
| 3411 | ||
| 3412 | case OP_VSPACE: | |
| 3413 | for (i = 1; i <= min; i++) | |
| 3414 | { | |
| 3415 | if (eptr >= md->end_subject) | |
| 3416 | { | |
| 3417 | SCHECK_PARTIAL(); | |
| 3418 | RRETURN(MATCH_NOMATCH); | |
| 3419 | } | |
| 3420 | GETCHARINC(c, eptr); | |
| 3421 | switch(c) | |
| 3422 | { | |
| 3423 | default: RRETURN(MATCH_NOMATCH); | |
| 3424 | case 0x0a: /* LF */ | |
| 3425 | case 0x0b: /* VT */ | |
| 3426 | case 0x0c: /* FF */ | |
| 3427 | case 0x0d: /* CR */ | |
| 3428 | case 0x85: /* NEL */ | |
| 3429 | case 0x2028: /* LINE SEPARATOR */ | |
| 3430 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3431 | break; | |
| 3432 | } | |
| 3433 | } | |
| 3434 | break; | |
| 3435 | ||
| 3436 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 3437 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3438 | { | { |
| 3439 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
| 3440 | { | |
| 3441 | SCHECK_PARTIAL(); | |
| 3442 | RRETURN(MATCH_NOMATCH); | |
| 3443 | } | |
| 3444 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3445 | if (c < 128 && (md->ctypes[c] & ctype_digit) != 0) | if (c < 128 && (md->ctypes[c] & ctype_digit) != 0) |
| 3446 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| # | Line 2596 for (;;) | Line 3450 for (;;) |
| 3450 | case OP_DIGIT: | case OP_DIGIT: |
| 3451 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3452 | { | { |
| 3453 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
| 3454 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0) | { |
| 3455 | SCHECK_PARTIAL(); | |
| 3456 | RRETURN(MATCH_NOMATCH); | |
| 3457 | } | |
| 3458 | if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0) | |
| 3459 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3460 | /* 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 */ |
| 3461 | } | } |
| # | Line 2606 for (;;) | Line 3464 for (;;) |
| 3464 | case OP_NOT_WHITESPACE: | case OP_NOT_WHITESPACE: |
| 3465 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3466 | { | { |
| 3467 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
| 3468 | (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0)) | { |
| 3469 | SCHECK_PARTIAL(); | |
| 3470 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3471 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | } |
| 3472 | if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0) | |
| 3473 | RRETURN(MATCH_NOMATCH); | |
| 3474 | while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); | |
| 3475 | } | } |
| 3476 | break; | break; |
| 3477 | ||
| 3478 | case OP_WHITESPACE: | case OP_WHITESPACE: |
| 3479 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3480 | { | { |
| 3481 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
| 3482 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0) | { |
| 3483 | SCHECK_PARTIAL(); | |
| 3484 | RRETURN(MATCH_NOMATCH); | |
| 3485 | } | |
| 3486 | if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0) | |
| 3487 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3488 | /* 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 */ |
| 3489 | } | } |
| # | Line 2627 for (;;) | Line 3493 for (;;) |
| 3493 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3494 | { | { |
| 3495 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject || |
| 3496 | (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0)) | (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)) |
| 3497 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3498 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); |
| 3499 | } | } |
| 3500 | break; | break; |
| 3501 | ||
| 3502 | case OP_WORDCHAR: | case OP_WORDCHAR: |
| 3503 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3504 | { | { |
| 3505 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
| 3506 | *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0) | { |
| 3507 | SCHECK_PARTIAL(); | |
| 3508 | RRETURN(MATCH_NOMATCH); | |
| 3509 | } | |
| 3510 | if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0) | |
| 3511 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3512 | /* 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 */ |
| 3513 | } | } |
| # | Line 2656 for (;;) | Line 3526 for (;;) |
| 3526 | switch(ctype) | switch(ctype) |
| 3527 | { | { |
| 3528 | case OP_ANY: | case OP_ANY: |
| 3529 | if ((ims & PCRE_DOTALL) == 0) | for (i = 1; i <= min; i++) |
| 3530 | { | { |
| 3531 | for (i = 1; i <= min; i++) | if (eptr >= md->end_subject) |
| 3532 | if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH); | { |
| 3533 | SCHECK_PARTIAL(); | |
| 3534 | RRETURN(MATCH_NOMATCH); | |
| 3535 | } | |
| 3536 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); | |
| 3537 | eptr++; | |
| 3538 | } | } |
| 3539 | else eptr += min; | break; |
| 3540 | ||
| 3541 | case OP_ALLANY: | |
| 3542 | if (eptr > md->end_subject - min) | |
| 3543 | { | |
| 3544 | SCHECK_PARTIAL(); | |
| 3545 | RRETURN(MATCH_NOMATCH); | |
| 3546 | } | |
| 3547 | eptr += min; | |
| 3548 | break; | break; |
| 3549 | ||
| 3550 | case OP_ANYBYTE: | case OP_ANYBYTE: |
| 3551 | if (eptr > md->end_subject - min) | |
| 3552 | { | |
| 3553 | SCHECK_PARTIAL(); | |
| 3554 | RRETURN(MATCH_NOMATCH); | |
| 3555 | } | |
| 3556 | eptr += min; | eptr += min; |
| 3557 | break; | break; |
| 3558 | ||
| 3559 | case OP_ANYNL: | |
| 3560 | for (i = 1; i <= min; i++) | |
| 3561 | { | |
| 3562 | if (eptr >= md->end_subject) | |
| 3563 | { | |
| 3564 | SCHECK_PARTIAL(); | |
| 3565 | RRETURN(MATCH_NOMATCH); | |
| 3566 | } | |
| 3567 | switch(*eptr++) | |
| 3568 | { | |
| 3569 | default: RRETURN(MATCH_NOMATCH); | |
| 3570 | case 0x000d: | |
| 3571 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3572 | break; | |
| 3573 | case 0x000a: | |
| 3574 | break; | |
| 3575 | ||
| 3576 | case 0x000b: | |
| 3577 | case 0x000c: | |
| 3578 | case 0x0085: | |
| 3579 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3580 | break; | |
| 3581 | } | |
| 3582 | } | |
| 3583 | break; | |
| 3584 | ||
| 3585 | case OP_NOT_HSPACE: | |
| 3586 | for (i = 1; i <= min; i++) | |
| 3587 | { | |
| 3588 | if (eptr >= md->end_subject) | |
| 3589 | { | |
| 3590 | SCHECK_PARTIAL(); | |
| 3591 | RRETURN(MATCH_NOMATCH); | |
| 3592 | } | |
| 3593 | switch(*eptr++) | |
| 3594 | { | |
| 3595 | default: break; | |
| 3596 | case 0x09: /* HT */ | |
| 3597 | case 0x20: /* SPACE */ | |
| 3598 | case 0xa0: /* NBSP */ | |
| 3599 | RRETURN(MATCH_NOMATCH); | |
| 3600 | } | |
| 3601 | } | |
| 3602 | break; | |
| 3603 | ||
| 3604 | case OP_HSPACE: | |
| 3605 | for (i = 1; i <= min; i++) | |
| 3606 | { | |
| 3607 | if (eptr >= md->end_subject) | |
| 3608 | { | |
| 3609 | SCHECK_PARTIAL(); | |
| 3610 | RRETURN(MATCH_NOMATCH); | |
| 3611 | } | |
| 3612 | switch(*eptr++) | |
| 3613 | { | |
| 3614 | default: RRETURN(MATCH_NOMATCH); | |
| 3615 | case 0x09: /* HT */ | |
| 3616 | case 0x20: /* SPACE */ | |
| 3617 | case 0xa0: /* NBSP */ | |
| 3618 | break; | |
| 3619 | } | |
| 3620 | } | |
| 3621 | break; | |
| 3622 | ||
| 3623 | case OP_NOT_VSPACE: | |
| 3624 | for (i = 1; i <= min; i++) | |
| 3625 | { | |
| 3626 | if (eptr >= md->end_subject) | |
| 3627 | { | |
| 3628 | SCHECK_PARTIAL(); | |
| 3629 | RRETURN(MATCH_NOMATCH); | |
| 3630 | } | |
| 3631 | switch(*eptr++) | |
| 3632 | { | |
| 3633 | default: break; | |
| 3634 | case 0x0a: /* LF */ | |
| 3635 | case 0x0b: /* VT */ | |
| 3636 | case 0x0c: /* FF */ | |
| 3637 | case 0x0d: /* CR */ | |
| 3638 | case 0x85: /* NEL */ | |
| 3639 | RRETURN(MATCH_NOMATCH); | |
| 3640 | } | |
| 3641 | } | |
| 3642 | break; | |
| 3643 | ||
| 3644 | case OP_VSPACE: | |
| 3645 | for (i = 1; i <= min; i++) | |
| 3646 | { | |
| 3647 | if (eptr >= md->end_subject) | |
| 3648 | { | |
| 3649 | SCHECK_PARTIAL(); | |
| 3650 | RRETURN(MATCH_NOMATCH); | |
| 3651 | } | |
| 3652 | switch(*eptr++) | |
| 3653 | { | |
| 3654 | default: RRETURN(MATCH_NOMATCH); | |
| 3655 | case 0x0a: /* LF */ | |
| 3656 | case 0x0b: /* VT */ | |
| 3657 | case 0x0c: /* FF */ | |
| 3658 | case 0x0d: /* CR */ | |
| 3659 | case 0x85: /* NEL */ | |
| 3660 | break; | |
| 3661 | } | |
| 3662 | } | |
| 3663 | break; | |
| 3664 | ||
| 3665 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
| 3666 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3667 | { | |
| 3668 | if (eptr >= md->end_subject) | |
| 3669 | { | |
| 3670 | SCHECK_PARTIAL(); | |
| 3671 | RRETURN(MATCH_NOMATCH); | |
| 3672 | } | |
| 3673 | if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); | if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); |
| 3674 | } | |
| 3675 | break; | break; |
| 3676 | ||
| 3677 | case OP_DIGIT: | case OP_DIGIT: |
| 3678 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3679 | { | |
| 3680 | if (eptr >= md->end_subject) | |
| 3681 | { | |
| 3682 | SCHECK_PARTIAL(); | |
| 3683 | RRETURN(MATCH_NOMATCH); | |
| 3684 | } | |
| 3685 | if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH); | if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH); |
| 3686 | } | |
| 3687 | break; | break; |
| 3688 | ||
| 3689 | case OP_NOT_WHITESPACE: | case OP_NOT_WHITESPACE: |
| 3690 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3691 | { | |
| 3692 | if (eptr >= md->end_subject) | |
| 3693 | { | |
| 3694 | SCHECK_PARTIAL(); | |
| 3695 | RRETURN(MATCH_NOMATCH); | |
| 3696 | } | |
| 3697 | if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH); | if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH); |
| 3698 | } | |
| 3699 | break; | break; |
| 3700 | ||
| 3701 | case OP_WHITESPACE: | case OP_WHITESPACE: |
| 3702 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3703 | { | |
| 3704 | if (eptr >= md->end_subject) | |
| 3705 | { | |
| 3706 | SCHECK_PARTIAL(); | |
| 3707 | RRETURN(MATCH_NOMATCH); | |
| 3708 | } | |
| 3709 | if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH); | if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH); |
| 3710 | } | |
| 3711 | break; | break; |
| 3712 | ||
| 3713 | case OP_NOT_WORDCHAR: | case OP_NOT_WORDCHAR: |
| 3714 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3715 | { | |
| 3716 | if (eptr >= md->end_subject) | |
| 3717 | { | |
| 3718 | SCHECK_PARTIAL(); | |
| 3719 | RRETURN(MATCH_NOMATCH); | |
| 3720 | } | |
| 3721 | if ((md->ctypes[*eptr++] & ctype_word) != 0) | if ((md->ctypes[*eptr++] & ctype_word) != 0) |
| 3722 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3723 | } | |
| 3724 | break; | break; |
| 3725 | ||
| 3726 | case OP_WORDCHAR: | case OP_WORDCHAR: |
| 3727 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
| 3728 | { | |
| 3729 | if (eptr >= md->end_subject) | |
| 3730 | { | |
| 3731 | SCHECK_PARTIAL(); | |
| 3732 | RRETURN(MATCH_NOMATCH); | |
| 3733 | } | |
| 3734 | if ((md->ctypes[*eptr++] & ctype_word) == 0) | if ((md->ctypes[*eptr++] & ctype_word) == 0) |
| 3735 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3736 | } | |
| 3737 | break; | break; |
| 3738 | ||
| 3739 | default: | default: |
| # | Line 2723 for (;;) | Line 3759 for (;;) |
| 3759 | case PT_ANY: | case PT_ANY: |
| 3760 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3761 | { | { |
| 3762 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36); |
| 3763 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3764 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3765 | if (eptr >= md->end_subject) | |
| 3766 | { | |
| 3767 | SCHECK_PARTIAL(); | |
| 3768 | RRETURN(MATCH_NOMATCH); | |
| 3769 | } | |
| 3770 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3771 | if (prop_fail_result) RRETURN(MATCH_NOMATCH); | if (prop_fail_result) RRETURN(MATCH_NOMATCH); |
| 3772 | } | } |
| 3773 | break; | /* Control never gets here */ |
| 3774 | ||
| 3775 | case PT_LAMP: | case PT_LAMP: |
| 3776 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3777 | { | { |
| 3778 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37); |
| 3779 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3780 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3781 | if (eptr >= md->end_subject) | |
| 3782 | { | |
| 3783 | SCHECK_PARTIAL(); | |
| 3784 | RRETURN(MATCH_NOMATCH); | |
| 3785 | } | |
| 3786 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3787 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_chartype = UCD_CHARTYPE(c); |
| 3788 | if ((prop_chartype == ucp_Lu || | if ((prop_chartype == ucp_Lu || |
| 3789 | prop_chartype == ucp_Ll || | prop_chartype == ucp_Ll || |
| 3790 | prop_chartype == ucp_Lt) == prop_fail_result) | prop_chartype == ucp_Lt) == prop_fail_result) |
| 3791 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3792 | } | } |
| 3793 | break; | /* Control never gets here */ |
| 3794 | ||
| 3795 | case PT_GC: | case PT_GC: |
| 3796 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3797 | { | { |
| 3798 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38); |
| 3799 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3800 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3801 | if (eptr >= md->end_subject) | |
| 3802 | { | |
| 3803 | SCHECK_PARTIAL(); | |
| 3804 | RRETURN(MATCH_NOMATCH); | |
| 3805 | } | |
| 3806 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3807 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
| 3808 | if ((prop_category == prop_value) == prop_fail_result) | if ((prop_category == prop_value) == prop_fail_result) |
| 3809 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3810 | } | } |
| 3811 | break; | /* Control never gets here */ |
| 3812 | ||
| 3813 | case PT_PC: | case PT_PC: |
| 3814 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3815 | { | { |
| 3816 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39); |
| 3817 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3818 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3819 | if (eptr >= md->end_subject) | |
| 3820 | { | |
| 3821 | SCHECK_PARTIAL(); | |
| 3822 | RRETURN(MATCH_NOMATCH); | |
| 3823 | } | |
| 3824 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3825 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_chartype = UCD_CHARTYPE(c); |
| 3826 | if ((prop_chartype == prop_value) == prop_fail_result) | if ((prop_chartype == prop_value) == prop_fail_result) |
| 3827 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3828 | } | } |
| 3829 | break; | /* Control never gets here */ |
| 3830 | ||
| 3831 | case PT_SC: | case PT_SC: |
| 3832 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3833 | { | { |
| 3834 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40); |
| 3835 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3836 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3837 | if (eptr >= md->end_subject) | |
| 3838 | { | |
| 3839 | SCHECK_PARTIAL(); | |
| 3840 | RRETURN(MATCH_NOMATCH); | |
| 3841 | } | |
| 3842 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3843 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_script = UCD_SCRIPT(c); |
| 3844 | if ((prop_script == prop_value) == prop_fail_result) | if ((prop_script == prop_value) == prop_fail_result) |
| 3845 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
| 3846 | } | } |
| 3847 | break; | /* Control never gets here */ |
| 3848 | ||
| 3849 | default: | default: |
| 3850 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
| break; | ||
| 3851 | } | } |
| 3852 | } | } |
| 3853 | ||
| # | Line 2798 for (;;) | Line 3858 for (;;) |
| 3858 | { | { |
| 3859 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3860 | { | { |
| 3861 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41); |
| 3862 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3863 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3864 | if (eptr >= md->end_subject) | |
| 3865 | { | |
| 3866 | SCHECK_PARTIAL(); | |
| 3867 | RRETURN(MATCH_NOMATCH); | |
| 3868 | } | |
| 3869 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
| 3870 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
| 3871 | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); |
| 3872 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
| 3873 | { | { |
| 3874 | int len = 1; | int len = 1; |
| 3875 | if (!utf8) c = *eptr; else | if (!utf8) c = *eptr; |
| 3876 | { | else { GETCHARLEN(c, eptr, len); } |
| 3877 | GETCHARLEN(c, eptr, len); | prop_category = UCD_CATEGORY(c); |
| } | ||
| prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | ||
| 3878 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
| 3879 | eptr += len; | eptr += len; |
| 3880 | } | } |
| # | Line 2827 for (;;) | Line 3890 for (;;) |
| 3890 | { | { |
| 3891 | for (fi = min;; fi++) | for (fi = min;; fi++) |
| 3892 | { | { |
| 3893 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42); |
| 3894 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3895 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3896 | if (eptr >= md->end_subject) | |
| 3897 | { | |
| 3898 | SCHECK_PARTIAL(); | |
| 3899 | RRETURN(MATCH_NOMATCH); | |
| 3900 | } | |
| 3901 | if (ctype == OP_ANY && IS_NEWLINE(eptr)) | |
| 3902 | RRETURN(MATCH_NOMATCH); | |
| 3903 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
| 3904 | switch(ctype) | switch(ctype) |
| 3905 | { | { |
| 3906 | case OP_ANY: | case OP_ANY: /* This is the non-NL case */ |
| 3907 | if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH); | case OP_ALLANY: |
| 3908 | case OP_ANYBYTE: | |
| 3909 | break; | break; |
| 3910 | ||
| 3911 | case OP_ANYBYTE: | case OP_ANYNL: |
| 3912 | switch(c) | |
| 3913 | { | |
| 3914 | default: RRETURN(MATCH_NOMATCH); | |
| 3915 | case 0x000d: | |
| 3916 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | |
| 3917 | break; | |
| 3918 | case 0x000a: | |
| 3919 | break; | |
| 3920 | ||
| 3921 | case 0x000b: | |
| 3922 | case 0x000c: | |
| 3923 | case 0x0085: | |
| 3924 | case 0x2028: | |
| 3925 | case 0x2029: | |
| 3926 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
| 3927 | break; | |
| 3928 | } | |
| 3929 | break; | |
| 3930 | ||
| 3931 | case OP_NOT_HSPACE: | |
| 3932 | switch(c) | |
| 3933 | { | |
| 3934 | default: break; | |
| 3935 | case 0x09: /* HT */ | |
| 3936 | case 0x20: /* SPACE */ | |
| 3937 | case 0xa0: /* NBSP */ | |
| 3938 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3939 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3940 | case 0x2000: /* EN QUAD */ | |
| 3941 | case 0x2001: /* EM QUAD */ | |
| 3942 | case 0x2002: /* EN SPACE */ | |
| 3943 | case 0x2003: /* EM SPACE */ | |
| 3944 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3945 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3946 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3947 | case 0x2007: /* FIGURE SPACE */ | |
| 3948 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3949 | case 0x2009: /* THIN SPACE */ | |
| 3950 | case 0x200A: /* HAIR SPACE */ | |
| 3951 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3952 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3953 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3954 | RRETURN(MATCH_NOMATCH); | |
| 3955 | } | |
| 3956 | break; | |
| 3957 | ||
| 3958 | case OP_HSPACE: | |
| 3959 | switch(c) | |
| 3960 | { | |
| 3961 | default: RRETURN(MATCH_NOMATCH); | |
| 3962 | case 0x09: /* HT */ | |
| 3963 | case 0x20: /* SPACE */ | |
| 3964 | case 0xa0: /* NBSP */ | |
| 3965 | case 0x1680: /* OGHAM SPACE MARK */ | |
| 3966 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
| 3967 | case 0x2000: /* EN QUAD */ | |
| 3968 | case 0x2001: /* EM QUAD */ | |
| 3969 | case 0x2002: /* EN SPACE */ | |
| 3970 | case 0x2003: /* EM SPACE */ | |
| 3971 | case 0x2004: /* THREE-PER-EM SPACE */ | |
| 3972 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
| 3973 | case 0x2006: /* SIX-PER-EM SPACE */ | |
| 3974 | case 0x2007: /* FIGURE SPACE */ | |
| 3975 | case 0x2008: /* PUNCTUATION SPACE */ | |
| 3976 | case 0x2009: /* THIN SPACE */ | |
| 3977 | case 0x200A: /* HAIR SPACE */ | |
| 3978 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
| 3979 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
| 3980 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
| 3981 | break; | |
| 3982 | } | |
| 3983 | break; | |
| 3984 | ||
| 3985 | case OP_NOT_VSPACE: | |
| 3986 | switch(c) | |
| 3987 | { | |
| 3988 | default: break; | |
| 3989 | case 0x0a: /* LF */ | |
| 3990 | case 0x0b: /* VT */ | |
| 3991 | case 0x0c: /* FF */ | |
| 3992 | case 0x0d: /* CR */ | |
| 3993 | case 0x85: /* NEL */ | |
| 3994 | case 0x2028: /* LINE SEPARATOR */ | |
| 3995 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
| 3996 | RRETURN(MATCH_NOMATCH); | |
| 3997 | } | |
| 3998 | break; | |
| 3999 | ||
| 4000 | case OP_VSPACE: | |
| 4001 | switch(c) | |
| 4002 | { | |
| 4003 | default: RRETURN(MATCH_NOMATCH); | |
| 4004 | case 0x0a: /* LF */ | |