Parent Directory
|
Revision Log
|
Patch
revision 123 by ph10, Mon Mar 12 15:19:06 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-2007 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 */ | #define NLBLOCK md /* Block containing newline information */ |
50 | #define PSSTART start_subject /* Field containing processed string start */ | #define PSSTART start_subject /* Field containing processed string start */ |
51 | #define PSEND end_subject /* Field containing processed string end */ | #define PSEND end_subject /* Field containing processed string end */ |
52 | ||
53 | #include "pcre_internal.h" | #include "pcre_internal.h" |
54 | ||
55 | /* The chain of eptrblocks for tail recursions uses memory in stack workspace, | /* Undefine some potentially clashing cpp symbols */ |
obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */ | ||
56 | ||
57 | #define EPTR_WORK_SIZE (1000) | #undef min |
58 | #undef max | |
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_cbegroup 0x02 /* Could-be-empty unlimited repeat group */ | #define match_cbegroup 0x02 /* Could-be-empty unlimited repeat group */ |
#define match_tail_recursed 0x04 /* Tail recursive call */ | ||
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 65 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 147 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 183 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 205 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 251 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 266 typedef struct heapframe { | Line 322 typedef struct heapframe { |
322 | ||
323 | /* Function arguments that may change */ | /* Function arguments that may change */ |
324 | ||
325 | const uschar *Xeptr; | USPTR Xeptr; |
326 | const uschar *Xecode; | const uschar *Xecode; |
327 | USPTR Xmstart; | |
328 | int Xoffset_top; | int Xoffset_top; |
329 | long int Xims; | long int Xims; |
330 | eptrblock *Xeptrb; | eptrblock *Xeptrb; |
# | Line 276 typedef struct heapframe { | Line 333 typedef struct heapframe { |
333 | ||
334 | /* Function local variables */ | /* Function local variables */ |
335 | ||
336 | const uschar *Xcallpat; | USPTR Xcallpat; |
337 | const uschar *Xcharptr; | #ifdef SUPPORT_UTF8 |
338 | const uschar *Xdata; | USPTR Xcharptr; |
339 | const uschar *Xnext; | #endif |
340 | const uschar *Xpp; | USPTR Xdata; |
341 | const uschar *Xprev; | USPTR Xnext; |
342 | const uschar *Xsaved_eptr; | USPTR Xpp; |
343 | USPTR Xprev; | |
344 | USPTR Xsaved_eptr; | |
345 | ||
346 | recursion_info Xnew_recursive; | recursion_info Xnew_recursive; |
347 | ||
# | Line 303 typedef struct heapframe { | Line 362 typedef struct heapframe { |
362 | uschar Xocchars[8]; | uschar Xocchars[8]; |
363 | #endif | #endif |
364 | ||
365 | int Xcodelink; | |
366 | int Xctype; | int Xctype; |
367 | unsigned int Xfc; | unsigned int Xfc; |
368 | int Xfi; | int Xfi; |
# | Line 318 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 339 typedef struct heapframe { | Line 398 typedef struct heapframe { |
398 | ||
399 | /* This function is called recursively in many circumstances. Whenever it | /* 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 to current character in subject | eptr pointer to current character in subject |
432 | ecode pointer to current position in compiled 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 358 Arguments: | Line 441 Arguments: |
441 | match_condassert - this is an assertion condition | match_condassert - this is an assertion condition |
442 | match_cbegroup - this is the start of an unlimited repeat | match_cbegroup - this is the start of an unlimited repeat |
443 | group that can match an empty string | group that can match an empty string |
match_tail_recursed - this is a tail_recursed group | ||
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 368 Returns: MATCH_MATCH if matched | Line 450 Returns: MATCH_MATCH if matched |
450 | */ | */ |
451 | ||
452 | static int | static int |
453 | match(REGISTER USPTR eptr, REGISTER const uschar *ecode, | match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart, |
454 | int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, | int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, |
455 | int flags, unsigned int rdepth) | int flags, unsigned int rdepth) |
456 | { | { |
# | Line 382 register unsigned int c; /* Character | Line 464 register unsigned int c; /* Character |
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 */ | 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 396 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 410 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 422 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 502 int oclength; | Line 588 int oclength; |
588 | uschar occhars[8]; | 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 540 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 548 if (rdepth >= md->match_limit_recursion) | Line 641 if (rdepth >= md->match_limit_recursion) |
641 | ||
642 | original_ims = ims; /* Save for resetting on ')' */ | original_ims = ims; /* Save for resetting on ')' */ |
643 | ||
#ifdef SUPPORT_UTF8 | ||
utf8 = md->utf8; /* Local copy of the flag */ | ||
#else | ||
utf8 = FALSE; | ||
#endif | ||
644 | /* At the start of a group with an unlimited repeat that may match an empty | /* At the start of a group with an unlimited repeat that may match an empty |
645 | string, the match_cbegroup flag is set. When this is the case, add the current | string, the match_cbegroup flag is set. When this is the case, add the current |
646 | subject pointer to the chain of such remembered pointers, to be checked when we | subject pointer to the chain of such remembered pointers, to be checked when we |
647 | hit the closing ket, in order to break infinite loops that match no characters. | 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. If this | When match() is called in other circumstances, don't add to the chain. The |
649 | is a tail recursion, use a block from the workspace, as the one on the stack is | match_cbegroup flag must NOT be used with tail recursion, because the memory |
650 | already used. */ | block that is used is on the stack, so a new one may be required for each |
651 | match(). */ | |
652 | ||
653 | if ((flags & match_cbegroup) != 0) | if ((flags & match_cbegroup) != 0) |
654 | { | { |
655 | eptrblock *p; | newptrb.epb_saved_eptr = eptr; |
656 | if ((flags & match_tail_recursed) != 0) | newptrb.epb_prev = eptrb; |
657 | { | eptrb = &newptrb; |
if (md->eptrn >= EPTR_WORK_SIZE) RRETURN(PCRE_ERROR_NULLWSLIMIT); | ||
p = md->eptrchain + md->eptrn++; | ||
} | ||
else p = &newptrb; | ||
p->epb_saved_eptr = eptr; | ||
p->epb_prev = eptrb; | ||
eptrb = p; | ||
658 | } | } |
659 | ||
660 | /* Now start processing the opcodes. */ | /* Now start processing the opcodes. */ |
# | Line 583 for (;;) | Line 664 for (;;) |
664 | minimize = possessive = FALSE; | minimize = possessive = FALSE; |
665 | op = *ecode; | op = *ecode; |
666 | ||
/* 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; | ||
667 | switch(op) | switch(op) |
668 | { | { |
669 | case OP_FAIL: | |
670 | RRETURN(MATCH_NOMATCH); | |
671 | ||
672 | case OP_PRUNE: | |
673 | 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 | /* 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. | 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 | We mustn't change the current values of the data slot, because they may be |
# | Line 632 for (;;) | Line 733 for (;;) |
733 | flags = (op == OP_SCBRA)? match_cbegroup : 0; | flags = (op == OP_SCBRA)? match_cbegroup : 0; |
734 | do | do |
735 | { | { |
736 | RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, |
737 | ims, eptrb, flags); | 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 649 for (;;) | Line 750 for (;;) |
750 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
751 | } | } |
752 | ||
753 | /* Insufficient room for saving captured contents. Treat as a non-capturing | /* FALL THROUGH ... Insufficient room for saving captured contents. Treat |
754 | bracket. */ | as a non-capturing bracket. */ |
755 | ||
756 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
757 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
758 | ||
759 | DPRINTF(("insufficient capture room: treat as non-capturing\n")); | DPRINTF(("insufficient capture room: treat as non-capturing\n")); |
760 | ||
761 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
762 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
763 | ||
764 | /* Non-capturing bracket. Loop for all the alternatives. When we get to the | /* Non-capturing bracket. Loop for all the alternatives. When we get to the |
765 | final alternative within the brackets, we would return the result of a | 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 | recursive call to match() whatever happened. We can reduce stack usage by |
767 | turning this into a tail recursion. */ | turning this into a tail recursion, except in the case when match_cbegroup |
768 | is set.*/ | |
769 | ||
770 | case OP_BRA: | case OP_BRA: |
771 | case OP_SBRA: | case OP_SBRA: |
# | Line 665 for (;;) | Line 773 for (;;) |
773 | flags = (op >= OP_SBRA)? match_cbegroup : 0; | flags = (op >= OP_SBRA)? match_cbegroup : 0; |
774 | for (;;) | for (;;) |
775 | { | { |
776 | if (ecode[GET(ecode, 1)] != OP_ALT) | if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */ |
777 | { | { |
778 | ecode += _pcre_OP_lengths[*ecode]; | if (flags == 0) /* Not a possibly empty group */ |
779 | flags |= match_tail_recursed; | { |
780 | DPRINTF(("bracket 0 tail recursion\n")); | ecode += _pcre_OP_lengths[*ecode]; |
781 | goto TAIL_RECURSE; | 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; | /* For non-final alternatives, continue the loop for a NOMATCH result; |
793 | otherwise return. */ | otherwise return. */ |
794 | ||
795 | RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, |
796 | eptrb, flags); | eptrb, flags, RM2); |
797 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
798 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
799 | } | } |
800 | /* Control never reaches here. */ | /* Control never reaches here. */ |
# | Line 691 for (;;) | Line 807 for (;;) |
807 | ||
808 | case OP_COND: | case OP_COND: |
809 | case OP_SCOND: | case OP_SCOND: |
810 | if (ecode[LINK_SIZE+1] == OP_RREF) /* Recursion test */ | 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*/ | offset = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ |
845 | condition = md->recursive != NULL && | condition = md->recursive != NULL && |
# | Line 699 for (;;) | Line 847 for (;;) |
847 | ecode += condition? 3 : GET(ecode, 1); | ecode += condition? 3 : GET(ecode, 1); |
848 | } | } |
849 | ||
850 | else if (ecode[LINK_SIZE+1] == OP_CREF) /* Group used test */ | 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 < offset_top && md->offset_vector[offset] >= 0; | condition = offset < offset_top && md->offset_vector[offset] >= 0; |
854 | ecode += condition? 3 : GET(ecode, 1); | ecode += condition? 3 : GET(ecode, 1); |
855 | } | } |
856 | ||
857 | else if (ecode[LINK_SIZE+1] == OP_DEF) /* DEFINE - always false */ | else if (condcode == OP_DEF) /* DEFINE - always false */ |
858 | { | { |
859 | condition = FALSE; | condition = FALSE; |
860 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
# | Line 718 for (;;) | Line 866 for (;;) |
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_condassert, RM3); |
871 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
872 | { | { |
873 | condition = TRUE; | condition = TRUE; |
874 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); | 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 | else |
882 | { | { |
883 | condition = FALSE; | condition = FALSE; |
884 | ecode += GET(ecode, 1); | ecode += codelink; |
885 | } | } |
886 | } | } |
887 | ||
888 | /* We are now at the branch that is to be obeyed. As there is only one, | /* We are now at the branch that is to be obeyed. As there is only one, |
889 | we can use tail recursion to avoid using another stack frame. If the second | we can use tail recursion to avoid using another stack frame, except when |
890 | alternative doesn't exist, we can just plough on. */ | 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 | if (condition || *ecode == OP_ALT) | if (condition || *ecode == OP_ALT) |
894 | { | { |
895 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
896 | flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0); | if (op == OP_SCOND) /* Possibly empty group */ |
897 | goto TAIL_RECURSE; | { |
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 | else /* Condition false & no alternative */ |
908 | { | { |
909 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
910 | } | } |
911 | break; | break; |
912 | ||
913 | ||
914 | /* End of the pattern. If we are in a top-level recursion, we should | /* End of the pattern, either real or forced. If we are in a top-level |
915 | restore the offsets appropriately and continue from after the call. */ | 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 765 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 797 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, 0); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, |
970 | 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 823 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, 0); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, |
997 | 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 849 for (;;) | Line 1020 for (;;) |
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 862 for (;;) | Line 1033 for (;;) |
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 880 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 942 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. */ |
# | Line 952 for (;;) | Line 1124 for (;;) |
1124 | flags = (*callpat >= OP_SBRA)? match_cbegroup : 0; | flags = (*callpat >= OP_SBRA)? match_cbegroup : 0; |
1125 | do | do |
1126 | { | { |
1127 | RMATCH(rrc, eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, | RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, |
1128 | md, ims, eptrb, flags); | 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 962 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 996 for (;;) | Line 1170 for (;;) |
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); |
eptrb, 0); | ||
1174 | if (rrc == MATCH_MATCH) break; | if (rrc == MATCH_MATCH) break; |
1175 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
1176 | ecode += GET(ecode,1); | ecode += GET(ecode,1); |
1177 | } | } |
1178 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
# | Line 1042 for (;;) | Line 1215 for (;;) |
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 | ecode = prev; | ecode = prev; |
1221 | flags = match_tail_recursed; | flags = 0; |
1222 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
1223 | } | } |
1224 | else /* OP_KETRMAX */ | else /* OP_KETRMAX */ |
1225 | { | { |
1226 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_cbegroup); | RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9); |
1227 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1228 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
1229 | flags = match_tail_recursed; | flags = 0; |
1230 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
1231 | } | } |
1232 | /* Control never gets here */ | /* Control never gets here */ |
# | Line 1065 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, 0); | 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; |
# | Line 1085 for (;;) | Line 1258 for (;;) |
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, 0); | RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11); |
1262 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1263 | ecode++; | ecode++; |
1264 | } | } |
1265 | break; | break; |
1266 | ||
1267 | case OP_SKIPZERO: | |
1268 | { | |
1269 | next = ecode+1; | |
1270 | 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. */ | /* End of a group, repeated or non-repeating. */ |
1276 | ||
1277 | case OP_KET: | case OP_KET: |
# | Line 1155 for (;;) | Line 1336 for (;;) |
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; |
# | Line 1184 for (;;) | Line 1365 for (;;) |
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. In the second case, we can use | preceding bracket, in the appropriate order. In the second case, we can use |
1368 | tail recursion to avoid using another stack frame. */ | 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 | flags = (*prev >= OP_SBRA)? match_cbegroup : 0; | flags = (*prev >= OP_SBRA)? match_cbegroup : 0; |
1372 | ||
1373 | if (*ecode == OP_KETRMIN) | if (*ecode == OP_KETRMIN) |
1374 | { | { |
1375 | RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12); |
1376 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1377 | if (flags != 0) /* Could match an empty string */ | |
1378 | { | |
1379 | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50); | |
1380 | RRETURN(rrc); | |
1381 | } | |
1382 | ecode = prev; | ecode = prev; |
flags |= match_tail_recursed; | ||
1383 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
1384 | } | } |
1385 | else /* OP_KETRMAX */ | else /* OP_KETRMAX */ |
1386 | { | { |
1387 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, flags); | RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13); |
1388 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1389 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
1390 | flags = match_tail_recursed; | flags = 0; |
1391 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
1392 | } | } |
1393 | /* Control never gets here */ | /* Control never gets here */ |
# | Line 1234 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 1285 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 1306 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 1326 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) | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); |
1537 | /* Fall through */ | |
1538 | ||
1539 | case OP_ALLANY: | |
1540 | if (eptr++ >= md->end_subject) | |
1541 | { | { |
1542 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); | SCHECK_PARTIAL(); |
1543 | RRETURN(MATCH_NOMATCH); | |
1544 | } | } |
1545 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
if (utf8) | ||
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
1546 | ecode++; | ecode++; |
1547 | break; | break; |
1548 | ||
# | Line 1340 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 1358 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 1371 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 1384 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 1397 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 1410 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 1423 for (;;) | Line 1661 for (;;) |
1661 | break; | break; |
1662 | ||
1663 | case OP_ANYNL: | case OP_ANYNL: |
1664 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
1665 | { | |
1666 | SCHECK_PARTIAL(); | |
1667 | RRETURN(MATCH_NOMATCH); | |
1668 | } | |
1669 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
1670 | switch(c) | switch(c) |
1671 | { | { |
# | Line 1431 for (;;) | Line 1673 for (;;) |
1673 | case 0x000d: | case 0x000d: |
1674 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
1675 | break; | break; |
1676 | ||
1677 | case 0x000a: | case 0x000a: |
1678 | break; | |
1679 | ||
1680 | case 0x000b: | case 0x000b: |
1681 | case 0x000c: | case 0x000c: |
1682 | case 0x0085: | case 0x0085: |
1683 | case 0x2028: | case 0x2028: |
1684 | case 0x2029: | case 0x2029: |
1685 | 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; | break; |
1799 | } | } |
1800 | ecode++; | ecode++; |
# | Line 1448 for (;;) | Line 1806 for (;;) |
1806 | ||
1807 | case OP_PROP: | case OP_PROP: |
1808 | case OP_NOTPROP: | case OP_NOTPROP: |
1809 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
1810 | { | |
1811 | SCHECK_PARTIAL(); | |
1812 | RRETURN(MATCH_NOMATCH); | |
1813 | } | |
1814 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
1815 | { | { |
1816 | int chartype, script; | const ucd_record *prop = GET_UCD(c); |
int category = _pcre_ucp_findprop(c, &chartype, &script); | ||
1817 | ||
1818 | switch(ecode[1]) | switch(ecode[1]) |
1819 | { | { |
# | Line 1461 for (;;) | Line 1822 for (;;) |
1822 | break; | break; |
1823 | ||
1824 | case PT_LAMP: | case PT_LAMP: |
1825 | if ((chartype == ucp_Lu || | if ((prop->chartype == ucp_Lu || |
1826 | chartype == ucp_Ll || | prop->chartype == ucp_Ll || |
1827 | chartype == ucp_Lt) == (op == OP_NOTPROP)) | prop->chartype == ucp_Lt) == (op == OP_NOTPROP)) |
1828 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
1829 | break; | 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 | ||
# | Line 1494 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 1507 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 1528 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 1566 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 1582 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 1597 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 1618 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 1627 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 1683 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 1701 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 1723 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 1743 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 1780 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 1799 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 1812 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 1853 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 1870 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 1888 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 1915 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 1923 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 1939 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 1963 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 1974 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 | } | } |
# | Line 2028 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 2043 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 2054 for (;;) | Line 2479 for (;;) |
2479 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
2480 | unsigned int othercase; | unsigned int othercase; |
2481 | if ((ims & PCRE_CASELESS) != 0 && | if ((ims & PCRE_CASELESS) != 0 && |
2482 | (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR) | (othercase = UCD_OTHERCASE(fc)) != fc) |
2483 | oclength = _pcre_ord2utf8(othercase, occhars); | oclength = _pcre_ord2utf8(othercase, occhars); |
2484 | else oclength = 0; | 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 | memcmp(eptr, charptr, length) == 0) eptr += length; | |
2491 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
2492 | /* Need braces because of following else */ | else if (oclength > 0 && |
2493 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | 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 | } | } |
#else /* without SUPPORT_UCP */ | ||
else { RRETURN(MATCH_NOMATCH); } | ||
#endif /* SUPPORT_UCP */ | ||
2501 | } | } |
2502 | ||
2503 | if (min == max) continue; | if (min == max) continue; |
# | Line 2081 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 | memcmp(eptr, charptr, length) == 0) eptr += length; | |
2514 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
2515 | /* Need braces because of following else */ | else if (oclength > 0 && |
2516 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | 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 | } | } |
#else /* without SUPPORT_UCP */ | ||
else { RRETURN (MATCH_NOMATCH); } | ||
#endif /* SUPPORT_UCP */ | ||
2524 | } | } |
2525 | /* Control never gets here */ | /* Control never gets here */ |
2526 | } | } |
# | Line 2105 for (;;) | Line 2530 for (;;) |
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 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
2536 | else if (oclength == 0) break; | else if (oclength > 0 && |
2537 | else | eptr <= md->end_subject - oclength && |
2538 | { | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; |
if (memcmp(eptr, occhars, oclength) != 0) break; | ||
eptr += oclength; | ||
} | ||
#else /* without SUPPORT_UCP */ | ||
else break; | ||
2539 | #endif /* SUPPORT_UCP */ | #endif /* SUPPORT_UCP */ |
2540 | else break; | |
2541 | } | } |
2542 | ||
2543 | if (possessive) continue; | if (possessive) continue; |
2544 | ||
2545 | for(;;) | for(;;) |
2546 | { | { |
2547 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23); |
2548 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2549 | if (eptr == pp) RRETURN(MATCH_NOMATCH); | if (eptr == pp) { RRETURN(MATCH_NOMATCH); } |
2550 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
2551 | eptr--; | eptr--; |
2552 | BACKCHAR(eptr); | BACKCHAR(eptr); |
2553 | #else /* without SUPPORT_UCP */ | #else /* without SUPPORT_UCP */ |
2554 | eptr -= length; | eptr -= length; |
2555 | #endif /* SUPPORT_UCP */ | #endif /* SUPPORT_UCP */ |
2556 | } | } |
2557 | } | } |
2558 | /* Control never gets here */ | /* Control never gets here */ |
2559 | } | } |
# | Line 2144 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 2165 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 | } | } |
# | Line 2187 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; | 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 2203 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 | } | } |
# | Line 2225 for (;;) | Line 2673 for (;;) |
2673 | eptr++; | eptr++; |
2674 | } | } |
2675 | if (possessive) continue; | 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 2240 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 2317 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 2347 for (;;) | Line 2797 for (;;) |
2797 | register unsigned 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 2358 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 2372 for (;;) | Line 2834 for (;;) |
2834 | register unsigned 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 2386 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 2418 for (;;) | Line 2890 for (;;) |
2890 | if (possessive) continue; | if (possessive) continue; |
2891 | for(;;) | 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 2436 for (;;) | Line 2908 for (;;) |
2908 | if (possessive) continue; | 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 2458 for (;;) | Line 2930 for (;;) |
2930 | register unsigned 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 2467 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 2481 for (;;) | Line 2965 for (;;) |
2965 | register unsigned 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 2494 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 2525 for (;;) | Line 3019 for (;;) |
3019 | if (possessive) continue; | 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 2543 for (;;) | Line 3037 for (;;) |
3037 | if (possessive) continue; | 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 2631 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 2649 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 | RRETURN(MATCH_NOMATCH); | |
3159 | } | |
3160 | GETCHARINCTEST(c, eptr); | |
3161 | prop_chartype = UCD_CHARTYPE(c); | |
3162 | if ((prop_chartype == ucp_Lu || | if ((prop_chartype == ucp_Lu || |
3163 | prop_chartype == ucp_Ll || | prop_chartype == ucp_Ll || |
3164 | prop_chartype == ucp_Lt) == prop_fail_result) | prop_chartype == ucp_Lt) == prop_fail_result) |
# | Line 2670 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 2681 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 2692 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 2712 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 2740 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 | ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr))) | { |
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++; | 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: | case OP_ANYNL: |
3287 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3288 | { | { |
3289 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3290 | { | |
3291 | SCHECK_PARTIAL(); | |
3292 | RRETURN(MATCH_NOMATCH); | |
3293 | } | |
3294 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
3295 | switch(c) | switch(c) |
3296 | { | { |
# | Line 2763 for (;;) | Line 3298 for (;;) |
3298 | case 0x000d: | case 0x000d: |
3299 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
3300 | break; | break; |
3301 | ||
3302 | case 0x000a: | case 0x000a: |
3303 | break; | |
3304 | ||
3305 | case 0x000b: | case 0x000b: |
3306 | case 0x000c: | case 0x000c: |
3307 | case 0x0085: | case 0x0085: |
3308 | case 0x2028: | case 0x2028: |
3309 | case 0x2029: | 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; | break; |
3432 | } | } |
3433 | } | } |
# | Line 2777 for (;;) | Line 3436 for (;;) |
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 2787 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 2797 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 2818 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 2842 for (;;) | Line 3521 for (;;) |
3521 | #endif /* SUPPORT_UTF8 */ | #endif /* SUPPORT_UTF8 */ |
3522 | ||
3523 | /* Code for the non-UTF-8 case for minimum matching of operators other | /* Code for the non-UTF-8 case for minimum matching of operators other |
3524 | than OP_PROP and OP_NOTPROP. We can assume that there are the minimum | than OP_PROP and OP_NOTPROP. */ |
number of bytes present, as this was tested above. */ | ||
3525 | ||
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 | { | { |
3533 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); | SCHECK_PARTIAL(); |
3534 | eptr++; | RRETURN(MATCH_NOMATCH); |
3535 | } | } |
3536 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); | |
3537 | eptr++; | |
3538 | } | } |
else eptr += min; | ||
3539 | break; | break; |
3540 | ||
3541 | case OP_ANYBYTE: | case OP_ALLANY: |
3542 | if (eptr > md->end_subject - min) | |
3543 | { | |
3544 | SCHECK_PARTIAL(); | |
3545 | RRETURN(MATCH_NOMATCH); | |
3546 | } | |
3547 | eptr += min; | eptr += min; |
3548 | break; | break; |
3549 | ||
3550 | /* Because of the CRLF case, we can't assume the minimum number of | case OP_ANYBYTE: |
3551 | bytes are present in this case. */ | if (eptr > md->end_subject - min) |
3552 | { | |
3553 | SCHECK_PARTIAL(); | |
3554 | RRETURN(MATCH_NOMATCH); | |
3555 | } | |
3556 | eptr += min; | |
3557 | break; | |
3558 | ||
3559 | case OP_ANYNL: | case OP_ANYNL: |
3560 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3561 | { | { |
3562 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3563 | { | |
3564 | SCHECK_PARTIAL(); | |
3565 | RRETURN(MATCH_NOMATCH); | |
3566 | } | |
3567 | switch(*eptr++) | switch(*eptr++) |
3568 | { | { |
3569 | default: RRETURN(MATCH_NOMATCH); | default: RRETURN(MATCH_NOMATCH); |
# | Line 2877 for (;;) | Line 3571 for (;;) |
3571 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
3572 | break; | break; |
3573 | case 0x000a: | case 0x000a: |
3574 | break; | |
3575 | ||
3576 | case 0x000b: | case 0x000b: |
3577 | case 0x000c: | case 0x000c: |
3578 | case 0x0085: | 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; | break; |
3661 | } | } |
3662 | } | } |
# | Line 2887 for (;;) | Line 3664 for (;;) |
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 2940 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 | } | } |
# | Line 2951 for (;;) | Line 3775 for (;;) |
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) |
# | Line 2966 for (;;) | Line 3795 for (;;) |
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 | } | } |
# | Line 2979 for (;;) | Line 3813 for (;;) |
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 | } | } |
# | Line 2992 for (;;) | Line 3831 for (;;) |
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 | } | } |
# | Line 3014 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 3043 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 || | if (fi >= max) RRETURN(MATCH_NOMATCH); |
3896 | (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 && | if (eptr >= md->end_subject) |
3897 | IS_NEWLINE(eptr))) | { |
3898 | SCHECK_PARTIAL(); | |
3899 | RRETURN(MATCH_NOMATCH); | |
3900 | } | |
3901 | if (ctype == OP_ANY && IS_NEWLINE(eptr)) | |
3902 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
3903 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
3904 | switch(ctype) | switch(ctype) |
3905 | { | { |
3906 | case OP_ANY: /* This is the DOTALL case */ | case OP_ANY: /* This is the non-NL case */ |
3907 | break; | case OP_ALLANY: |
3908 | case OP_ANYBYTE: | case OP_ANYBYTE: |
3909 | break; | break; |
3910 | ||
# | Line 3067 for (;;) | Line 3916 for (;;) |
3916 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
3917 | break; | break; |
3918 | case 0x000a: | case 0x000a: |
3919 | break; | |
3920 | ||
3921 | case 0x000b: | case 0x000b: |
3922 | case 0x000c: | case 0x000c: |
3923 | case 0x0085: | case 0x0085: |
3924 | case 0x2028: | case 0x2028: |
3925 | case 0x2029: | 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 */ | |
4005 | case 0x0b: /* VT */ | |
4006 | case 0x0c: /* FF */ | |
4007 | case 0x0d: /* CR */ | |
4008 | case 0x85: /* NEL */ | |
4009 | case 0x2028: /* LINE SEPARATOR */ | |
4010 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
4011 | break; | break; |
4012 | } | } |
4013 | break; | break; |
# | Line 3117 for (;;) | Line 4053 for (;;) |
4053 | { | { |
4054 | for (fi = min;; fi++) | for (fi = min;; fi++) |
4055 | { | { |
4056 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43); |
4057 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
4058 | if (fi >= max || eptr >= md->end_subject || | if (fi >= max) RRETURN(MATCH_NOMATCH); |
4059 | ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr))) | if (eptr >= md->end_subject) |
4060 | { | |
4061 | SCHECK_PARTIAL(); | |
4062 | RRETURN(MATCH_NOMATCH); | |
4063 | } | |
4064 | if (ctype == OP_ANY && IS_NEWLINE(eptr)) | |
4065 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
4066 | c = *eptr++; | c = *eptr++; |
4067 | switch(ctype) | switch(ctype) |
4068 | { | { |
4069 | case OP_ANY: /* This is the DOTALL case */ | case OP_ANY: /* This is the non-NL case */ |
4070 | break; | case OP_ALLANY: |
4071 | case OP_ANYBYTE: | case OP_ANYBYTE: |
4072 | break; | break; |
4073 | ||
# | Line 3139 for (;;) | Line 4078 for (;;) |
4078 | case 0x000d: | case 0x000d: |
4079 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
4080 | break; | break; |
4081 | ||
4082 | case 0x000a: | case 0x000a: |
4083 | break; | |
4084 | ||
4085 | case 0x000b: | case 0x000b: |
4086 | case 0x000c: | case 0x000c: |
4087 | case 0x0085: | case 0x0085: |
4088 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); | |
4089 | break; | |
4090 | } | |
4091 | break; | |
4092 | ||
4093 | case OP_NOT_HSPACE: | |
4094 | switch(c) | |
4095 | { | |
4096 | default: break; | |
4097 | case 0x09: /* HT */ | |
4098 | case 0x20: /* SPACE */ | |
4099 | case 0xa0: /* NBSP */ | |
4100 | RRETURN(MATCH_NOMATCH); | |
4101 | } | |
4102 | break; | |
4103 | ||
4104 | case OP_HSPACE: | |
4105 | switch(c) | |
4106 | { | |
4107 | default: RRETURN(MATCH_NOMATCH); | |
4108 | case 0x09: /* HT */ | |
4109 | case 0x20: /* SPACE */ | |
4110 | case 0xa0: /* NBSP */ | |
4111 | break; | |
4112 | } | |
4113 | break; | |
4114 | ||
4115 | case OP_NOT_VSPACE: | |
4116 | switch(c) | |
4117 | { | |
4118 | default: break; | |
4119 | case 0x0a: /* LF */ | |
4120 | case 0x0b: /* VT */ | |
4121 | case 0x0c: /* FF */ | |
4122 | case 0x0d: /* CR */ | |
4123 | case 0x85: /* NEL */ | |
4124 | RRETURN(MATCH_NOMATCH); | |
4125 | } | |
4126 | break; | |
4127 | ||
4128 | case OP_VSPACE: | |
4129 | switch(c) | |
4130 | { | |
4131 | default: RRETURN(MATCH_NOMATCH); | |
4132 | case 0x0a: /* LF */ | |
4133 | case 0x0b: /* VT */ | |
4134 | case 0x0c: /* FF */ | |
4135 | case 0x0d: /* CR */ | |
4136 | case 0x85: /* NEL */ | |
4137 | break; | break; |
4138 | } | } |
4139 | break; | break; |
# | Line 3209 for (;;) | Line 4200 for (;;) |
4200 | int len = 1; | int len = 1; |
4201 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) break; |
4202 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
4203 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_chartype = UCD_CHARTYPE(c); |
4204 | if ((prop_chartype == ucp_Lu || | if ((prop_chartype == ucp_Lu || |
4205 | prop_chartype == ucp_Ll || | prop_chartype == ucp_Ll || |
4206 | prop_chartype == ucp_Lt) == prop_fail_result) | prop_chartype == ucp_Lt) == prop_fail_result) |
# | Line 3224 for (;;) | Line 4215 for (;;) |
4215 | int len = 1; | int len = 1; |
4216 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) break; |
4217 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
4218 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
4219 | if ((prop_category == prop_value) == prop_fail_result) | if ((prop_category == prop_value) == prop_fail_result) |
4220 | break; | break; |
4221 | eptr+= len; | eptr+= len; |
# | Line 3237 for (;;) | Line 4228 for (;;) |
4228 | int len = 1; | int len = 1; |
4229 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) break; |
4230 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
4231 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_chartype = UCD_CHARTYPE(c); |
4232 | if ((prop_chartype == prop_value) == prop_fail_result) | if ((prop_chartype == prop_value) == prop_fail_result) |
4233 | break; | break; |
4234 | eptr+= len; | eptr+= len; |
# | Line 3250 for (;;) | Line 4241 for (;;) |
4241 | int len = 1; | int len = 1; |
4242 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) break; |
4243 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
4244 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_script = UCD_SCRIPT(c); |
4245 | if ((prop_script == prop_value) == prop_fail_result) | if ((prop_script == prop_value) == prop_fail_result) |
4246 | break; | break; |
4247 | eptr+= len; | eptr+= len; |
# | Line 3263 for (;;) | Line 4254 for (;;) |
4254 | if (possessive) continue; | if (possessive) continue; |
4255 | for(;;) | for(;;) |
4256 | { | { |
4257 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44); |
4258 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
4259 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
4260 | BACKCHAR(eptr); | if (utf8) BACKCHAR(eptr); |
4261 | } | } |
4262 | } | } |
4263 | ||
# | Line 3279 for (;;) | Line 4270 for (;;) |
4270 | { | { |
4271 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) break; |
4272 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
4273 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
4274 | if (prop_category == ucp_M) break; | if (prop_category == ucp_M) break; |
4275 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
4276 | { | { |
# | Line 3288 for (;;) | Line 4279 for (;;) |
4279 | { | { |
4280 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
4281 | } | } |
4282 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
4283 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
4284 | eptr += len; | eptr += len; |
4285 | } | } |
# | Line 3299 for (;;) | Line 4290 for (;;) |
4290 | if (possessive) continue; | if (possessive) continue; |
4291 | for(;;) | for(;;) |
4292 | { | { |
4293 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45); |
4294 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
4295 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
4296 | for (;;) /* Move back over one extended */ | for (;;) /* Move back over one extended */ |
4297 | { | { |
4298 | int len = 1; | int len = 1; |
BACKCHAR(eptr); | ||
4299 | if (!utf8) c = *eptr; else | if (!utf8) c = *eptr; else |
4300 | { | { |
4301 | BACKCHAR(eptr); | |
4302 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
4303 | } | } |
4304 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
4305 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
4306 | eptr--; | eptr--; |
4307 | } | } |
# | Line 3328 for (;;) | Line 4319 for (;;) |
4319 | switch(ctype) | switch(ctype) |
4320 | { | { |
4321 | case OP_ANY: | case OP_ANY: |
/* Special code is required for UTF8, but when the maximum is | ||
unlimited we don't need it, so we repeat the non-UTF8 code. This is | ||
probably worth it, because .* is quite a common idiom. */ | ||
4322 | if (max < INT_MAX) | if (max < INT_MAX) |
4323 | { | { |
4324 | if ((ims & PCRE_DOTALL) == 0) | for (i = min; i < max; i++) |
{ | ||
for (i = min; i < max; i++) | ||
{ | ||
if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; | ||
eptr++; | ||
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
} | ||
} | ||
else | ||
4325 | { | { |
4326 | for (i = min; i < max; i++) | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; |
4327 | { | eptr++; |
4328 | if (eptr >= md->end_subject) break; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
eptr++; | ||
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
} | ||
4329 | } | } |
4330 | } | } |
4331 | ||
# | Line 3359 for (;;) | Line 4333 for (;;) |
4333 | ||
4334 | else | else |
4335 | { | { |
4336 | if ((ims & PCRE_DOTALL) == 0) | for (i = min; i < max; i++) |
4337 | { | { |
4338 | for (i = min; i < max; i++) | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; |
4339 | { | eptr++; |
4340 | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
eptr++; | ||
} | ||
break; | ||
4341 | } | } |
4342 | else | } |
4343 | break; | |
4344 | ||
4345 | case OP_ALLANY: | |
4346 | if (max < INT_MAX) | |
4347 | { | |
4348 | for (i = min; i < max; i++) | |
4349 | { | { |
4350 | c = max - min; | if (eptr >= md->end_subject) break; |
4351 | if (c > (unsigned int)(md->end_subject - eptr)) | eptr++; |
4352 | c = md->end_subject - eptr; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
eptr += c; | ||
4353 | } | } |
4354 | } | } |
4355 | else eptr = md->end_subject; /* Unlimited UTF-8 repeat */ | |
4356 | break; | break; |
4357 | ||
4358 | /* The byte case is the same as non-UTF8 */ | /* The byte case is the same as non-UTF8 */ |
# | Line 3400 for (;;) | Line 4377 for (;;) |
4377 | } | } |
4378 | else | else |
4379 | { | { |
4380 | if (c != 0x000a && c != 0x000b && c != 0x000c && | if (c != 0x000a && |
4381 | c != 0x0085 && c != 0x2028 && c != 0x2029) | (md->bsr_anycrlf || |
4382 | (c != 0x000b && c != 0x000c && | |
4383 | c != 0x0085 && c != 0x2028 && c != 0x2029))) | |
4384 | break; | break; |
4385 | eptr += len; | eptr += len; |
4386 | } | } |
4387 | } | } |
4388 | break; | break; |
4389 | ||
4390 | case OP_NOT_HSPACE: | |
4391 | case OP_HSPACE: | |
4392 | for (i = min; i < max; i++) | |
4393 | { | |
4394 | BOOL gotspace; | |
4395 | int len = 1; | |
4396 | if (eptr >= md->end_subject) break; | |
4397 | GETCHARLEN(c, eptr, len); | |
4398 | switch(c) | |
4399 | { | |
4400 | default: gotspace = FALSE; break; | |
4401 | case 0x09: /* HT */ | |
4402 | case 0x20: /* SPACE */ | |
4403 | case 0xa0: /* NBSP */ | |
4404 | case 0x1680: /* OGHAM SPACE MARK */ | |
4405 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
4406 | case 0x2000: /* EN QUAD */ | |
4407 | case 0x2001: /* EM QUAD */ | |
4408 | case 0x2002: /* EN SPACE */ | |
4409 | case 0x2003: /* EM SPACE */ | |
4410 | case 0x2004: /* THREE-PER-EM SPACE */ | |
4411 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
4412 | case 0x2006: /* SIX-PER-EM SPACE */ | |
4413 | case 0x2007: /* FIGURE SPACE */ | |
4414 | case 0x2008: /* PUNCTUATION SPACE */ | |
4415 | case 0x2009: /* THIN SPACE */ | |
4416 | case 0x200A: /* HAIR SPACE */ | |
4417 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
4418 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
4419 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
4420 | gotspace = TRUE; | |
4421 | break; | |
4422 | } | |
4423 | if (gotspace == (ctype == OP_NOT_HSPACE)) break; | |
4424 | eptr += len; | |
4425 | } | |
4426 | break; | |
4427 | ||
4428 | case OP_NOT_VSPACE: | |
4429 | case OP_VSPACE: | |
4430 | for (i = min; i < max; i++) | |
4431 | { | |
4432 | BOOL gotspace; | |
4433 | int len = 1; | |
4434 | if (eptr >= md->end_subject) break; | |
4435 | GETCHARLEN(c, eptr, len); | |
4436 | switch(c) | |
4437 | { | |
4438 | default: gotspace = FALSE; break; | |
4439 | case 0x0a: /* LF */ | |
4440 | case 0x0b: /* VT */ | |
4441 | case 0x0c: /* FF */ | |
4442 | case 0x0d: /* CR */ | |
4443 | case 0x85: /* NEL */ | |
4444 | case 0x2028: /* LINE SEPARATOR */ | |
4445 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
4446 | gotspace = TRUE; | |
4447 | break; | |
4448 | } | |
4449 | if (gotspace == (ctype == OP_NOT_VSPACE)) break; | |
4450 | eptr += len; | |
4451 | } | |
4452 | break; | |
4453 | ||
4454 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
4455 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
4456 | { | { |
# | Line 3483 for (;;) | Line 4526 for (;;) |
4526 | if (possessive) continue; | if (possessive) continue; |
4527 | for(;;) | for(;;) |
4528 | { | { |
4529 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46); |
4530 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
4531 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
4532 | BACKCHAR(eptr); | BACKCHAR(eptr); |
4533 | } | } |
4534 | } | } |
4535 | else | else |
4536 | #endif | #endif /* SUPPORT_UTF8 */ |
4537 | ||
4538 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
4539 | { | { |
4540 | switch(ctype) | switch(ctype) |
4541 | { | { |
4542 | case OP_ANY: | case OP_ANY: |
4543 | if ((ims & PCRE_DOTALL) == 0) | for (i = min; i < max; i++) |
4544 | { | { |
4545 | for (i = min; i < max; i++) | if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; |
4546 | { | eptr++; |
if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; | ||
eptr++; | ||
} | ||
break; | ||
4547 | } | } |
4548 | /* For DOTALL case, fall through and treat as \C */ | break; |
4549 | ||
4550 | case OP_ALLANY: | |
4551 | case OP_ANYBYTE: | case OP_ANYBYTE: |
4552 | c = max - min; | c = max - min; |
4553 | if (c > (unsigned int)(md->end_subject - eptr)) | if (c > (unsigned int)(md->end_subject - eptr)) |
# | Line 3527 for (;;) | Line 4567 for (;;) |
4567 | } | } |
4568 | else | else |
4569 | { | { |
4570 | if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085) | if (c != 0x000a && |
4571 | (md->bsr_anycrlf || | |
4572 | (c != 0x000b && c != 0x000c && c != 0x0085))) | |
4573 | break; | break; |
4574 | eptr++; | eptr++; |
4575 | } | } |
4576 | } | } |
4577 | break; | break; |
4578 | ||
4579 | case OP_NOT_HSPACE: | |
4580 | for (i = min; i < max; i++) | |
4581 | { | |
4582 | if (eptr >= md->end_subject) break; | |
4583 | c = *eptr; | |
4584 | if (c == 0x09 || c == 0x20 || c == 0xa0) break; | |
4585 | eptr++; | |
4586 | } | |
4587 | break; | |
4588 | ||
4589 | case OP_HSPACE: | |
4590 | for (i = min; i < max; i++) | |
4591 | { | |
4592 | if (eptr >= md->end_subject) break; | |
4593 | c = *eptr; | |
4594 | if (c != 0x09 && c != 0x20 && c != 0xa0) break; | |
4595 | eptr++; | |
4596 | } | |
4597 | break; | |
4598 | ||
4599 | case OP_NOT_VSPACE: | |
4600 | for (i = min; i < max; i++) | |
4601 | { | |
4602 | if (eptr >= md->end_subject) break; | |
4603 | c = *eptr; | |
4604 | if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85) | |
4605 | break; | |
4606 | eptr++; | |
4607 | } | |
4608 | break; | |
4609 | ||
4610 | case OP_VSPACE: | |
4611 | for (i = min; i < max; i++) | |
4612 | { | |
4613 | if (eptr >= md->end_subject) break; | |
4614 | c = *eptr; | |
4615 | if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85) | |
4616 | break; | |
4617 | eptr++; | |
4618 | } | |
4619 | break; | |
4620 | ||
4621 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
4622 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
4623 | { | { |
# | Line 3597 for (;;) | Line 4681 for (;;) |
4681 | if (possessive) continue; | if (possessive) continue; |
4682 | while (eptr >= pp) | while (eptr >= pp) |
4683 | { | { |
4684 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47); |
4685 | eptr--; | eptr--; |
4686 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
4687 | } | } |
# | Line 3623 for (;;) | Line 4707 for (;;) |
4707 | ||
4708 | } /* End of main loop */ | } /* End of main loop */ |
4709 | /* Control never reaches here */ | /* Control never reaches here */ |
4710 | ||
4711 | ||
4712 | /* When compiling to use the heap rather than the stack for recursive calls to | |
4713 | match(), the RRETURN() macro jumps here. The number that is saved in | |
4714 | frame->Xwhere indicates which label we actually want to return to. */ | |
4715 | ||
4716 | #ifdef NO_RECURSE | |
4717 | #define LBL(val) case val: goto L_RM##val; | |
4718 | HEAP_RETURN: | |
4719 | switch (frame->Xwhere) | |
4720 | { | |
4721 | LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8) | |
4722 | LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17) | |
4723 | LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33) | |
4724 | LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52) | |
4725 | LBL(53) LBL(54) | |
4726 | #ifdef SUPPORT_UTF8 | |
4727 | LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30) | |
4728 | LBL(32) LBL(34) LBL(42) LBL(46) | |
4729 | #ifdef SUPPORT_UCP | |
4730 | LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45) | |
4731 | #endif /* SUPPORT_UCP */ | |
4732 | #endif /* SUPPORT_UTF8 */ | |
4733 | default: | |
4734 | DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere)); | |
4735 | return PCRE_ERROR_INTERNAL; | |
4736 | } | |
4737 | #undef LBL | |
4738 | #endif /* NO_RECURSE */ | |
4739 | } | } |
4740 | ||
4741 | ||
# | Line 3635 Undefine all the macros that were define | Line 4748 Undefine all the macros that were define |
4748 | #ifdef NO_RECURSE | #ifdef NO_RECURSE |
4749 | #undef eptr | #undef eptr |
4750 | #undef ecode | #undef ecode |
4751 | #undef mstart | |
4752 | #undef offset_top | #undef offset_top |
4753 | #undef ims | #undef ims |
4754 | #undef eptrb | #undef eptrb |
# | Line 3707 Returns: > 0 => success; value | Line 4821 Returns: > 0 => success; value |
4821 | < -1 => some kind of unexpected problem | < -1 => some kind of unexpected problem |
4822 | */ | */ |
4823 | ||
4824 | PCRE_DATA_SCOPE int | PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
4825 | pcre_exec(const pcre *argument_re, const pcre_extra *extra_data, | pcre_exec(const pcre *argument_re, const pcre_extra *extra_data, |
4826 | PCRE_SPTR subject, int length, int start_offset, int options, int *offsets, | PCRE_SPTR subject, int length, int start_offset, int options, int *offsets, |
4827 | int offsetcount) | int offsetcount) |
# | Line 3731 const uschar *tables; | Line 4845 const uschar *tables; |
4845 | const uschar *start_bits = NULL; | const uschar *start_bits = NULL; |
4846 | USPTR start_match = (USPTR)subject + start_offset; | USPTR start_match = (USPTR)subject + start_offset; |
4847 | USPTR end_subject; | USPTR end_subject; |
4848 | USPTR start_partial = NULL; | |
4849 | USPTR req_byte_ptr = start_match - 1; | USPTR req_byte_ptr = start_match - 1; |
eptrblock eptrchain[EPTR_WORK_SIZE]; | ||
4850 | ||
4851 | pcre_study_data internal_study; | pcre_study_data internal_study; |
4852 | const pcre_study_data *study; | const pcre_study_data *study; |
# | Line 3795 if (re->magic_number != MAGIC_NUMBER) | Line 4909 if (re->magic_number != MAGIC_NUMBER) |
4909 | /* Set up other data */ | /* Set up other data */ |
4910 | ||
4911 | anchored = ((re->options | options) & PCRE_ANCHORED) != 0; | anchored = ((re->options | options) & PCRE_ANCHORED) != 0; |
4912 | startline = (re->options & PCRE_STARTLINE) != 0; | startline = (re->flags & PCRE_STARTLINE) != 0; |
4913 | firstline = (re->options & PCRE_FIRSTLINE) != 0; | firstline = (re->options & PCRE_FIRSTLINE) != 0; |
4914 | ||
4915 | /* The code starts after the real_pcre block and the capture name table. */ | /* The code starts after the real_pcre block and the capture name table. */ |
# | Line 3810 end_subject = md->end_subject; | Line 4924 end_subject = md->end_subject; |
4924 | ||
4925 | md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0; | md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0; |
4926 | utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0; | utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0; |
4927 | md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0; | |
4928 | ||
4929 | md->notbol = (options & PCRE_NOTBOL) != 0; | md->notbol = (options & PCRE_NOTBOL) != 0; |
4930 | md->noteol = (options & PCRE_NOTEOL) != 0; | md->noteol = (options & PCRE_NOTEOL) != 0; |
4931 | md->notempty = (options & PCRE_NOTEMPTY) != 0; | md->notempty = (options & PCRE_NOTEMPTY) != 0; |
4932 | md->partial = (options & PCRE_PARTIAL) != 0; | md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0; |
4933 | md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 : | |
4934 | ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0; | |
4935 | md->hitend = FALSE; | md->hitend = FALSE; |
4936 | ||
4937 | md->recursive = NULL; /* No recursion at top level */ | md->recursive = NULL; /* No recursion at top level */ |
md->eptrchain = eptrchain; /* Make workspace generally available */ | ||
4938 | ||
4939 | md->lcc = tables + lcc_offset; | md->lcc = tables + lcc_offset; |
4940 | md->ctypes = tables + ctypes_offset; | md->ctypes = tables + ctypes_offset; |
4941 | ||
4942 | /* Handle different \R options. */ | |
4943 | ||
4944 | switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | |
4945 | { | |
4946 | case 0: | |
4947 | if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0) | |
4948 | md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0; | |
4949 | else | |
4950 | #ifdef BSR_ANYCRLF | |
4951 | md->bsr_anycrlf = TRUE; | |
4952 | #else | |
4953 | md->bsr_anycrlf = FALSE; | |
4954 | #endif | |
4955 | break; | |
4956 | ||
4957 | case PCRE_BSR_ANYCRLF: | |
4958 | md->bsr_anycrlf = TRUE; | |
4959 | break; | |
4960 | ||
4961 | case PCRE_BSR_UNICODE: | |
4962 | md->bsr_anycrlf = FALSE; | |
4963 | break; | |
4964 | ||
4965 | default: return PCRE_ERROR_BADNEWLINE; | |
4966 | } | |
4967 | ||
4968 | /* Handle different types of newline. The three bits give eight cases. If | /* Handle different types of newline. The three bits give eight cases. If |
4969 | nothing is set at run time, whatever was used at compile time applies. */ | nothing is set at run time, whatever was used at compile time applies. */ |
4970 | ||
4971 | switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) & | switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : |
4972 | PCRE_NEWLINE_BITS) | (pcre_uint32)options) & PCRE_NEWLINE_BITS) |
4973 | { | { |
4974 | case 0: newline = NEWLINE; break; /* Compile-time default */ | case 0: newline = NEWLINE; break; /* Compile-time default */ |
4975 | case PCRE_NEWLINE_CR: newline = '\r'; break; | case PCRE_NEWLINE_CR: newline = CHAR_CR; break; |
4976 | case PCRE_NEWLINE_LF: newline = '\n'; break; | case PCRE_NEWLINE_LF: newline = CHAR_NL; break; |
4977 | case PCRE_NEWLINE_CR+ | case PCRE_NEWLINE_CR+ |
4978 | PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break; | PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break; |
4979 | case PCRE_NEWLINE_ANY: newline = -1; break; | case PCRE_NEWLINE_ANY: newline = -1; break; |
4980 | case PCRE_NEWLINE_ANYCRLF: newline = -2; break; | |
4981 | default: return PCRE_ERROR_BADNEWLINE; | default: return PCRE_ERROR_BADNEWLINE; |
4982 | } | } |
4983 | ||
4984 | if (newline < 0) | if (newline == -2) |
4985 | { | |
4986 | md->nltype = NLTYPE_ANYCRLF; | |
4987 | } | |
4988 | else if (newline < 0) | |
4989 | { | { |
4990 | md->nltype = NLTYPE_ANY; | md->nltype = NLTYPE_ANY; |
4991 | } | } |
# | Line 3858 else | Line 5005 else |
5005 | } | } |
5006 | } | } |
5007 | ||
5008 | /* Partial matching is supported only for a restricted set of regexes at the | /* Partial matching was originally supported only for a restricted set of |
5009 | moment. */ | regexes; from release 8.00 there are no restrictions, but the bits are still |
5010 | defined (though never set). So there's no harm in leaving this code. */ | |
5011 | ||
5012 | if (md->partial && (re->options & PCRE_NOPARTIAL) != 0) | if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0) |
5013 | return PCRE_ERROR_BADPARTIAL; | return PCRE_ERROR_BADPARTIAL; |
5014 | ||
5015 | /* Check a UTF-8 string if required. Unfortunately there's no way of passing | /* Check a UTF-8 string if required. Unfortunately there's no way of passing |
# | Line 3870 back the character offset. */ | Line 5018 back the character offset. */ |
5018 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
5019 | if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) | if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) |
5020 | { | { |
5021 | if (_pcre_valid_utf8((uschar *)subject, length) >= 0) | if (_pcre_valid_utf8((USPTR)subject, length) >= 0) |
5022 | return PCRE_ERROR_BADUTF8; | return PCRE_ERROR_BADUTF8; |
5023 | if (start_offset > 0 && start_offset < length) | if (start_offset > 0 && start_offset < length) |
5024 | { | { |
5025 | int tb = ((uschar *)subject)[start_offset]; | int tb = ((USPTR)subject)[start_offset]; |
5026 | if (tb > 127) | if (tb > 127) |
5027 | { | { |
5028 | tb &= 0xc0; | tb &= 0xc0; |
# | Line 3938 studied, there may be a bitmap of possib | Line 5086 studied, there may be a bitmap of possib |
5086 | ||
5087 | if (!anchored) | if (!anchored) |
5088 | { | { |
5089 | if ((re->options & PCRE_FIRSTSET) != 0) | if ((re->flags & PCRE_FIRSTSET) != 0) |
5090 | { | { |
5091 | first_byte = re->first_byte & 255; | first_byte = re->first_byte & 255; |
5092 | if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) | if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) |
# | Line 3953 if (!anchored) | Line 5101 if (!anchored) |
5101 | /* For anchored or unanchored matches, there may be a "last known required | /* For anchored or unanchored matches, there may be a "last known required |
5102 | character" set. */ | character" set. */ |
5103 | ||
5104 | if ((re->options & PCRE_REQCHSET) != 0) | if ((re->flags & PCRE_REQCHSET) != 0) |
5105 | { | { |
5106 | req_byte = re->req_byte & 255; | req_byte = re->req_byte & 255; |
5107 | req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; | req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; |
# | Line 3969 the loop runs just once. */ | Line 5117 the loop runs just once. */ |
5117 | for(;;) | for(;;) |
5118 | { | { |
5119 | USPTR save_end_subject = end_subject; | USPTR save_end_subject = end_subject; |
5120 | USPTR new_start_match; | |
5121 | ||
5122 | /* Reset the maximum number of extractions we might see. */ | /* Reset the maximum number of extractions we might see. */ |
5123 | ||
# | Line 3979 for(;;) | Line 5128 for(;;) |
5128 | while (iptr < iend) *iptr++ = -1; | while (iptr < iend) *iptr++ = -1; |
5129 | } | } |
5130 | ||
5131 | /* Advance to a unique first char if possible. If firstline is TRUE, the | /* If firstline is TRUE, the start of the match is constrained to the first |
5132 | start of the match is constrained to the first line of a multiline string. | line of a multiline string. That is, the match must be before or at the first |
5133 | That is, the match must be before or at the first newline. Implement this by | newline. Implement this by temporarily adjusting end_subject so that we stop |
5134 | temporarily adjusting end_subject so that we stop scanning at a newline. If | scanning at a newline. If the match fails at the newline, later code breaks |
5135 | the match fails at the newline, later code breaks this loop. */ | this loop. */ |
5136 | ||
5137 | if (firstline) | if (firstline) |
5138 | { | { |
5139 | USPTR t = start_match; | USPTR t = start_match; |
5140 | #ifdef SUPPORT_UTF8 | |
5141 | if (utf8) | |
5142 | { | |
5143 | while (t < md->end_subject && !IS_NEWLINE(t)) | |
5144 | { | |
5145 | t++; | |
5146 | while (t < end_subject && (*t & 0xc0) == 0x80) t++; | |
5147 | } | |
5148 | } | |
5149 | else | |
5150 | #endif | |
5151 | while (t < md->end_subject && !IS_NEWLINE(t)) t++; | while (t < md->end_subject && !IS_NEWLINE(t)) t++; |
5152 | end_subject = t; | end_subject = t; |
5153 | } | } |
5154 | ||
5155 | /* Now test for a unique first byte */ | /* There are some optimizations that avoid running the match if a known |
5156 | starting point is not found, or if a known later character is not present. | |
5157 | However, there is an option that disables these, for testing and for ensuring | |
5158 | that all callouts do actually occur. */ | |
5159 | ||
5160 | if (first_byte >= 0) | if ((options & PCRE_NO_START_OPTIMIZE) == 0) |
5161 | { | { |
5162 | if (first_byte_caseless) | /* Advance to a unique first byte if there is one. */ |
while (start_match < end_subject && | ||
md->lcc[*start_match] != first_byte) | ||
start_match++; | ||
else | ||
while (start_match < end_subject && *start_match != first_byte) | ||
start_match++; | ||
} | ||
5163 | ||
5164 | /* Or to just after a linebreak for a multiline match if possible */ | if (first_byte >= 0) |
5165 | { | |
5166 | if (first_byte_caseless) | |
5167 | while (start_match < end_subject && md->lcc[*start_match] != first_byte) | |
5168 | start_match++; | |
5169 | else | |
5170 | while (start_match < end_subject && *start_match != first_byte) | |
5171 | start_match++; | |
5172 | } | |
5173 | ||
5174 | else if (startline) | /* Or to just after a linebreak for a multiline match */ |
5175 | { | |
5176 | if (start_match > md->start_subject + start_offset) | else if (startline) |
5177 | { | { |
5178 | while (start_match <= end_subject && !WAS_NEWLINE(start_match)) | if (start_match > md->start_subject + start_offset) |
5179 | start_match++; | { |
5180 | #ifdef SUPPORT_UTF8 | |
5181 | if (utf8) | |
5182 | { | |
5183 | while (start_match < end_subject && !WAS_NEWLINE(start_match)) | |
5184 | { | |
5185 | start_match++; | |
5186 | while(start_match < end_subject && (*start_match & 0xc0) == 0x80) | |
5187 | start_match++; | |
5188 | } | |
5189 | } | |
5190 | else | |
5191 | #endif | |
5192 | while (start_match < end_subject && !WAS_NEWLINE(start_match)) | |
5193 | start_match++; | |
5194 | ||
5195 | /* If we have just passed a CR and the newline option is ANY or ANYCRLF, | |
5196 | and we are now at a LF, advance the match position by one more character. | |
5197 | */ | |
5198 | ||
5199 | if (start_match[-1] == CHAR_CR && | |
5200 | (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) && | |
5201 | start_match < end_subject && | |
5202 | *start_match == CHAR_NL) | |
5203 | start_match++; | |
5204 | } | |
5205 | } | } |
} | ||
5206 | ||
5207 | /* Or to a non-unique first char after study */ | /* Or to a non-unique first byte after study */ |
5208 | ||
5209 | else if (start_bits != NULL) | else if (start_bits != NULL) |
{ | ||
while (start_match < end_subject) | ||
5210 | { | { |
5211 | register unsigned int c = *start_match; | while (start_match < end_subject) |
5212 | if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break; | { |
5213 | register unsigned int c = *start_match; | |
5214 | if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; | |
5215 | else break; | |
5216 | } | |
5217 | } | } |
5218 | } | } /* Starting optimizations */ |
5219 | ||
5220 | /* Restore fudged end_subject */ | /* Restore fudged end_subject */ |
5221 | ||
# | Line 4037 for(;;) | Line 5227 for(;;) |
5227 | printf("\n"); | printf("\n"); |
5228 | #endif | #endif |
5229 | ||
5230 | /* If req_byte is set, we know that that character must appear in the subject | /* If req_byte is set, we know that that character must appear in the |
5231 | for the match to succeed. If the first character is set, req_byte must be | subject for the match to succeed. If the first character is set, req_byte |
5232 | later in the subject; otherwise the test starts at the match point. This | must be later in the subject; otherwise the test starts at the match point. |
5233 | optimization can save a huge amount of backtracking in patterns with nested | This optimization can save a huge amount of backtracking in patterns with |
5234 | unlimited repeats that aren't going to match. Writing separate code for | nested unlimited repeats that aren't going to match. Writing separate code |
5235 | cased/caseless versions makes it go faster, as does using an autoincrement | for cased/caseless versions makes it go faster, as does using an |
5236 | and backing off on a match. | autoincrement and backing off on a match. |
5237 | ||
5238 | HOWEVER: when the subject string is very, very long, searching to its end can | HOWEVER: when the subject string is very, very long, searching to its end |
5239 | take a long time, and give bad performance on quite ordinary patterns. This | can take a long time, and give bad performance on quite ordinary patterns. |
5240 | showed up when somebody was matching something like /^\d+C/ on a 32-megabyte | This showed up when somebody was matching something like /^\d+C/ on a |
5241 | string... so we don't do this when the string is sufficiently long. | 32-megabyte string... so we don't do this when the string is sufficiently |
5242 | long. | |
5243 | ||
5244 | ALSO: this processing is disabled when partial matching is requested. | ALSO: this processing is disabled when partial matching is requested, or if |
5245 | */ | disabling is explicitly requested. */ |
5246 | ||
5247 | if (req_byte >= 0 && | if ((options & PCRE_NO_START_OPTIMIZE) == 0 && |
5248 | req_byte >= 0 && | |
5249 | end_subject - start_match < REQ_BYTE_MAX && | end_subject - start_match < REQ_BYTE_MAX && |
5250 | !md->partial) | !md->partial) |
5251 | { | { |
# | Line 4097 for(;;) | Line 5289 for(;;) |
5289 | } | } |
5290 | } | } |
5291 | ||
5292 | /* OK, we can now run the match. */ | /* OK, we can now run the match. If "hitend" is set afterwards, remember the |
5293 | first starting point for which a partial match was found. */ | |
5294 | ||
5295 | md->start_match = start_match; | md->start_match_ptr = start_match; |
5296 | md->start_used_ptr = start_match; | |
5297 | md->match_call_count = 0; | md->match_call_count = 0; |
5298 | md->eptrn = 0; /* Next free eptrchain slot */ | rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0); |
5299 | rc = match(start_match, md->start_code, 2, md, ims, NULL, 0, 0); | if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr; |
5300 | ||
5301 | switch(rc) | |
5302 | { | |
5303 | /* NOMATCH a |