1 /*************************************************
2 * Perl-Compatible Regular Expressions *
3 *************************************************/
5 /* PCRE is a library of functions to support regular expressions whose syntax
6 and semantics are as close as possible to those of the Perl 5 language.
8 Written by Philip Hazel
9 Copyright (c) 1997-2012 University of Cambridge
11 -----------------------------------------------------------------------------
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright notice,
16 this list of conditions and the following disclaimer.
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
22 * Neither the name of the University of Cambridge nor the names of its
23 contributors may be used to endorse or promote products derived from
24 this software without specific prior written permission.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37 -----------------------------------------------------------------------------
40 /* This module contains pcre_exec(), the externally visible function that does
41 pattern matching using an NFA algorithm, trying to mimic Perl as closely as
42 possible. There are also some static supporting functions. */
46 #define NLBLOCK md /* Block containing newline information */
47 #define PSSTART start_subject /* Field containing processed string start */
48 #define PSEND end_subject /* Field containing processed string end */
50 #include "pcre_internal.h"
52 /* Undefine some potentially clashing cpp symbols */
57 /* Values for setting in md->match_function_type to indicate two special types
58 of call to match(). We do it this way to save on using another stack variable,
59 as stack usage is to be discouraged. */
61 #define MATCH_CONDASSERT 1 /* Called to check a condition assertion */
62 #define MATCH_CBEGROUP 2 /* Could-be-empty unlimited repeat group */
64 /* Non-error returns from the match() function. Error returns are externally
65 defined PCRE_ERROR_xxx codes, which are all negative. */
68 #define MATCH_NOMATCH 0
70 /* Special internal returns from the match() function. Make them sufficiently
71 negative to avoid the external error codes. */
73 #define MATCH_ACCEPT (-999)
74 #define MATCH_COMMIT (-998)
75 #define MATCH_KETRPOS (-997)
76 #define MATCH_ONCE (-996)
77 #define MATCH_PRUNE (-995)
78 #define MATCH_SKIP (-994)
79 #define MATCH_SKIP_ARG (-993)
80 #define MATCH_THEN (-992)
82 /* Maximum number of ints of offset to save on the stack for recursive calls.
83 If the offset vector is bigger, malloc is used. This should be a multiple of 3,
84 because the offset vector is always a multiple of 3 long. */
86 #define REC_STACK_SAVE_MAX 30
88 /* Min and max values for the common repeats; for the maxima, 0 => infinity */
90 static const char rep_min
[] = { 0, 0, 1, 1, 0, 0 };
91 static const char rep_max
[] = { 0, 0, 0, 0, 1, 1 };
96 /*************************************************
97 * Debugging function to print chars *
98 *************************************************/
100 /* Print a sequence of chars in printable format, stopping at the end of the
101 subject if the requested.
104 p points to characters
105 length number to print
106 is_subject TRUE if printing from within md->start_subject
107 md pointer to matching data block, if is_subject is TRUE
113 pchars(const pcre_uchar
*p
, int length
, BOOL is_subject
, match_data
*md
)
116 if (is_subject
&& length
> md
->end_subject
- p
) length
= md
->end_subject
- p
;
118 if (isprint(c
= *(p
++))) printf("%c", c
); else printf("\\x%02x", c
);
124 /*************************************************
125 * Match a back-reference *
126 *************************************************/
128 /* Normally, if a back reference hasn't been set, the length that is passed is
129 negative, so the match always fails. However, in JavaScript compatibility mode,
130 the length passed is zero. Note that in caseless UTF-8 mode, the number of
131 subject bytes matched may be different to the number of reference bytes.
134 offset index into the offset vector
135 eptr pointer into the subject
136 length length of reference to be matched (number of bytes)
137 md points to match data block
138 caseless TRUE if caseless
140 Returns: >= 0 the number of subject bytes matched
142 -2 partial match; always given if at end subject
146 match_ref(int offset
, PCRE_PUCHAR eptr
, int length
, match_data
*md
,
149 PCRE_PUCHAR eptr_start
= eptr
;
150 PCRE_PUCHAR p
= md
->start_subject
+ md
->offset_vector
[offset
];
153 if (eptr
>= md
->end_subject
)
154 printf("matching subject <null>");
157 printf("matching subject ");
158 pchars(eptr
, length
, TRUE
, md
);
160 printf(" against backref ");
161 pchars(p
, length
, FALSE
, md
);
165 /* Always fail if reference not set (and not JavaScript compatible - in that
166 case the length is passed as zero). */
168 if (length
< 0) return -1;
170 /* Separate the caseless case for speed. In UTF-8 mode we can only do this
171 properly if Unicode properties are supported. Otherwise, we can check only
180 /* Match characters up to the end of the reference. NOTE: the number of
181 bytes matched may differ, because there are some characters whose upper and
182 lower case versions code as different numbers of bytes. For example, U+023A
183 (2 bytes in UTF-8) is the upper case version of U+2C65 (3 bytes in UTF-8);
184 a sequence of 3 of the former uses 6 bytes, as does a sequence of two of
185 the latter. It is important, therefore, to check the length along the
186 reference, not along the subject (earlier code did this wrong). */
188 PCRE_PUCHAR endptr
= p
+ length
;
192 if (eptr
>= md
->end_subject
) return -2; /* Partial match */
195 if (c
!= d
&& c
!= UCD_OTHERCASE(d
)) return -1;
202 /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
203 is no UCP support. */
207 if (eptr
>= md
->end_subject
) return -2; /* Partial match */
208 if (TABLE_GET(*p
, md
->lcc
, *p
) != TABLE_GET(*eptr
, md
->lcc
, *eptr
)) return -1;
215 /* In the caseful case, we can just compare the bytes, whether or not we
216 are in UTF-8 mode. */
222 if (eptr
>= md
->end_subject
) return -2; /* Partial match */
223 if (*p
++ != *eptr
++) return -1;
227 return (int)(eptr
- eptr_start
);
232 /***************************************************************************
233 ****************************************************************************
234 RECURSION IN THE match() FUNCTION
236 The match() function is highly recursive, though not every recursive call
237 increases the recursive depth. Nevertheless, some regular expressions can cause
238 it to recurse to a great depth. I was writing for Unix, so I just let it call
239 itself recursively. This uses the stack for saving everything that has to be
240 saved for a recursive call. On Unix, the stack can be large, and this works
243 It turns out that on some non-Unix-like systems there are problems with
244 programs that use a lot of stack. (This despite the fact that every last chip
245 has oodles of memory these days, and techniques for extending the stack have
246 been known for decades.) So....
248 There is a fudge, triggered by defining NO_RECURSE, which avoids recursive
249 calls by keeping local variables that need to be preserved in blocks of memory
250 obtained from malloc() instead instead of on the stack. Macros are used to
251 achieve this so that the actual code doesn't look very different to what it
254 The original heap-recursive code used longjmp(). However, it seems that this
255 can be very slow on some operating systems. Following a suggestion from Stan
256 Switzer, the use of longjmp() has been abolished, at the cost of having to
257 provide a unique number for each call to RMATCH. There is no way of generating
258 a sequence of numbers at compile time in C. I have given them names, to make
259 them stand out more clearly.
261 Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
262 FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
263 tests. Furthermore, not using longjmp() means that local dynamic variables
264 don't have indeterminate values; this has meant that the frame size can be
265 reduced because the result can be "passed back" by straight setting of the
266 variable instead of being passed in the frame.
267 ****************************************************************************
268 ***************************************************************************/
270 /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
271 below must be updated in sync. */
273 enum { RM1
=1, RM2
, RM3
, RM4
, RM5
, RM6
, RM7
, RM8
, RM9
, RM10
,
274 RM11
, RM12
, RM13
, RM14
, RM15
, RM16
, RM17
, RM18
, RM19
, RM20
,
275 RM21
, RM22
, RM23
, RM24
, RM25
, RM26
, RM27
, RM28
, RM29
, RM30
,
276 RM31
, RM32
, RM33
, RM34
, RM35
, RM36
, RM37
, RM38
, RM39
, RM40
,
277 RM41
, RM42
, RM43
, RM44
, RM45
, RM46
, RM47
, RM48
, RM49
, RM50
,
278 RM51
, RM52
, RM53
, RM54
, RM55
, RM56
, RM57
, RM58
, RM59
, RM60
,
279 RM61
, RM62
, RM63
, RM64
, RM65
, RM66
};
281 /* These versions of the macros use the stack, as normal. There are debugging
282 versions and production versions. Note that the "rw" argument of RMATCH isn't
283 actually used in this definition. */
288 #define RMATCH(ra,rb,rc,rd,re,rw) \
290 printf("match() called in line %d\n", __LINE__); \
291 rrc = match(ra,rb,mstart,rc,rd,re,rdepth+1); \
292 printf("to line %d\n", __LINE__); \
294 #define RRETURN(ra) \
296 printf("match() returned %d from line %d ", ra, __LINE__); \
300 #define RMATCH(ra,rb,rc,rd,re,rw) \
301 rrc = match(ra,rb,mstart,rc,rd,re,rdepth+1)
302 #define RRETURN(ra) return ra
308 /* These versions of the macros manage a private stack on the heap. Note that
309 the "rd" argument of RMATCH isn't actually used in this definition. It's the md
310 argument of match(), which never changes. */
312 #define RMATCH(ra,rb,rc,rd,re,rw)\
314 heapframe *newframe = frame->Xnextframe;\
315 if (newframe == NULL)\
317 newframe = (heapframe *)(PUBL(stack_malloc))(sizeof(heapframe));\
318 if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
319 newframe->Xnextframe = NULL;\
320 frame->Xnextframe = newframe;\
323 newframe->Xeptr = ra;\
324 newframe->Xecode = rb;\
325 newframe->Xmstart = mstart;\
326 newframe->Xoffset_top = rc;\
327 newframe->Xeptrb = re;\
328 newframe->Xrdepth = frame->Xrdepth + 1;\
329 newframe->Xprevframe = frame;\
331 DPRINTF(("restarting from line %d\n", __LINE__));\
334 DPRINTF(("jumped back to line %d\n", __LINE__));\
339 heapframe *oldframe = frame;\
340 frame = oldframe->Xprevframe;\
350 /* Structure for remembering the local variables in a private frame */
352 typedef struct heapframe
{
353 struct heapframe
*Xprevframe
;
354 struct heapframe
*Xnextframe
;
356 /* Function arguments that may change */
359 const pcre_uchar
*Xecode
;
363 unsigned int Xrdepth
;
365 /* Function local variables */
367 PCRE_PUCHAR Xcallpat
;
369 PCRE_PUCHAR Xcharptr
;
375 PCRE_PUCHAR Xsaved_eptr
;
377 recursion_info Xnew_recursive
;
386 int Xprop_fail_result
;
388 pcre_uchar Xocchars
[6];
401 int Xsave_capture_last
;
402 int Xsave_offset1
, Xsave_offset2
, Xsave_offset3
;
403 int Xstacksave
[REC_STACK_SAVE_MAX
];
407 /* Where to jump back to */
416 /***************************************************************************
417 ***************************************************************************/
421 /*************************************************
422 * Match from current position *
423 *************************************************/
425 /* This function is called recursively in many circumstances. Whenever it
426 returns a negative (error) response, the outer incarnation must also return the
429 /* These macros pack up tests that are used for partial matching, and which
430 appear several times in the code. We set the "hit end" flag if the pointer is
431 at the end of the subject and also past the start of the subject (i.e.
432 something has been matched). For hard partial matching, we then return
433 immediately. The second one is used when we already know we are past the end of
436 #define CHECK_PARTIAL()\
437 if (md->partial != 0 && eptr >= md->end_subject && \
438 eptr > md->start_used_ptr) \
441 if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); \
444 #define SCHECK_PARTIAL()\
445 if (md->partial != 0 && eptr > md->start_used_ptr) \
448 if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); \
452 /* Performance note: It might be tempting to extract commonly used fields from
453 the md structure (e.g. utf, end_subject) into individual variables to improve
454 performance. Tests using gcc on a SPARC disproved this; in the first case, it
455 made performance worse.
458 eptr pointer to current character in subject
459 ecode pointer to current position in compiled code
460 mstart pointer to the current match start position (can be modified
462 offset_top current top pointer
463 md pointer to "static" info for the match
464 eptrb pointer to chain of blocks containing eptr at start of
465 brackets - for testing for empty matches
466 rdepth the recursion depth
468 Returns: MATCH_MATCH if matched ) these values are >= 0
469 MATCH_NOMATCH if failed to match )
470 a negative MATCH_xxx value for PRUNE, SKIP, etc
471 a negative PCRE_ERROR_xxx value if aborted by an error condition
472 (e.g. stopped by repeated call or recursion limit)
476 match(PCRE_PUCHAR eptr
, const pcre_uchar
*ecode
,
477 PCRE_PUCHAR mstart
, int offset_top
, match_data
*md
, eptrblock
*eptrb
,
480 /* These variables do not need to be preserved over recursion in this function,
481 so they can be ordinary variables in all cases. Mark some of them with
482 "register" because they are used a lot in loops. */
484 int rrc
; /* Returns from recursive calls */
485 int i
; /* Used for loops not involving calls to RMATCH() */
486 unsigned int c
; /* Character values not kept over RMATCH() calls */
487 BOOL utf
; /* Local copy of UTF flag for speed */
489 BOOL minimize
, possessive
; /* Quantifier options */
493 /* When recursion is not being used, all "local" variables that have to be
494 preserved over calls to RMATCH() are part of a "frame". We set up the top-level
495 frame on the stack here; subsequent instantiations are obtained from the heap
496 whenever RMATCH() does a "recursion". See the macro definitions above. Putting
497 the top-level on the stack rather than malloc-ing them all gives a performance
498 boost in many cases where there is not much "recursion". */
501 heapframe
*frame
= (heapframe
*)md
->match_frames_base
;
503 /* Copy in the original argument variables */
506 frame
->Xecode
= ecode
;
507 frame
->Xmstart
= mstart
;
508 frame
->Xoffset_top
= offset_top
;
509 frame
->Xeptrb
= eptrb
;
510 frame
->Xrdepth
= rdepth
;
512 /* This is where control jumps back to to effect "recursion" */
516 /* Macros make the argument variables come from the current frame */
518 #define eptr frame->Xeptr
519 #define ecode frame->Xecode
520 #define mstart frame->Xmstart
521 #define offset_top frame->Xoffset_top
522 #define eptrb frame->Xeptrb
523 #define rdepth frame->Xrdepth
525 /* Ditto for the local variables */
528 #define charptr frame->Xcharptr
530 #define callpat frame->Xcallpat
531 #define codelink frame->Xcodelink
532 #define data frame->Xdata
533 #define next frame->Xnext
534 #define pp frame->Xpp
535 #define prev frame->Xprev
536 #define saved_eptr frame->Xsaved_eptr
538 #define new_recursive frame->Xnew_recursive
540 #define cur_is_word frame->Xcur_is_word
541 #define condition frame->Xcondition
542 #define prev_is_word frame->Xprev_is_word
545 #define prop_type frame->Xprop_type
546 #define prop_value frame->Xprop_value
547 #define prop_fail_result frame->Xprop_fail_result
548 #define oclength frame->Xoclength
549 #define occhars frame->Xocchars
552 #define ctype frame->Xctype
553 #define fc frame->Xfc
554 #define fi frame->Xfi
555 #define length frame->Xlength
556 #define max frame->Xmax
557 #define min frame->Xmin
558 #define number frame->Xnumber
559 #define offset frame->Xoffset
560 #define op frame->Xop
561 #define save_capture_last frame->Xsave_capture_last
562 #define save_offset1 frame->Xsave_offset1
563 #define save_offset2 frame->Xsave_offset2
564 #define save_offset3 frame->Xsave_offset3
565 #define stacksave frame->Xstacksave
567 #define newptrb frame->Xnewptrb
569 /* When recursion is being used, local variables are allocated on the stack and
570 get preserved during recursion in the normal way. In this environment, fi and
571 i, and fc and c, can be the same variables. */
573 #else /* NO_RECURSE not defined */
577 /* Many of the following variables are used only in small blocks of the code.
578 My normal style of coding would have declared them within each of those blocks.
579 However, in order to accommodate the version of this code that uses an external
580 "stack" implemented on the heap, it is easier to declare them all here, so the
581 declarations can be cut out in a block. The only declarations within blocks
582 below are for variables that do not have to be preserved over a recursive call
586 const pcre_uchar
*charptr
;
588 const pcre_uchar
*callpat
;
589 const pcre_uchar
*data
;
590 const pcre_uchar
*next
;
592 const pcre_uchar
*prev
;
593 PCRE_PUCHAR saved_eptr
;
595 recursion_info new_recursive
;
604 int prop_fail_result
;
606 pcre_uchar occhars
[6];
617 int save_capture_last
;
618 int save_offset1
, save_offset2
, save_offset3
;
619 int stacksave
[REC_STACK_SAVE_MAX
];
623 /* There is a special fudge for calling match() in a way that causes it to
624 measure the size of its basic stack frame when the stack is being used for
625 recursion. The second argument (ecode) being NULL triggers this behaviour. It
626 cannot normally ever be NULL. The return is the negated value of the frame
632 return match((PCRE_PUCHAR
)&rdepth
, NULL
, NULL
, 0, NULL
, NULL
, 1);
635 int len
= (char *)&rdepth
- (char *)eptr
;
636 return (len
> 0)? -len
: len
;
639 #endif /* NO_RECURSE */
641 /* To save space on the stack and in the heap frame, I have doubled up on some
642 of the local variables that are used only in localised parts of the code, but
643 still need to be preserved over recursive calls of match(). These macros define
644 the alternative names that are used. */
646 #define allow_zero cur_is_word
647 #define cbegroup condition
648 #define code_offset codelink
649 #define condassert condition
650 #define matched_once prev_is_word
652 #define save_mark data
654 /* These statements are here to stop the compiler complaining about unitialized
659 prop_fail_result
= 0;
663 /* This label is used for tail recursion, which is used in a few cases even
664 when NO_RECURSE is not defined, in order to reduce the amount of stack that is
665 used. Thanks to Ian Taylor for noticing this possibility and sending the
670 /* OK, now we can get on with the real code of the function. Recursive calls
671 are specified by the macro RMATCH and RRETURN is used to return. When
672 NO_RECURSE is *not* defined, these just turn into a recursive call to match()
673 and a "return", respectively (possibly with some debugging if PCRE_DEBUG is
674 defined). However, RMATCH isn't like a function call because it's quite a
675 complicated macro. It has to be used in one particular way. This shouldn't,
676 however, impact performance when true recursion is being used. */
679 utf
= md
->utf
; /* Local copy of the flag */
684 /* First check that we haven't called match() too many times, or that we
685 haven't exceeded the recursive call limit. */
687 if (md
->match_call_count
++ >= md
->match_limit
) RRETURN(PCRE_ERROR_MATCHLIMIT
);
688 if (rdepth
>= md
->match_limit_recursion
) RRETURN(PCRE_ERROR_RECURSIONLIMIT
);
690 /* At the start of a group with an unlimited repeat that may match an empty
691 string, the variable md->match_function_type is set to MATCH_CBEGROUP. It is
692 done this way to save having to use another function argument, which would take
693 up space on the stack. See also MATCH_CONDASSERT below.
695 When MATCH_CBEGROUP is set, add the current subject pointer to the chain of
696 such remembered pointers, to be checked when we hit the closing ket, in order
697 to break infinite loops that match no characters. When match() is called in
698 other circumstances, don't add to the chain. The MATCH_CBEGROUP feature must
699 NOT be used with tail recursion, because the memory block that is used is on
700 the stack, so a new one may be required for each match(). */
702 if (md
->match_function_type
== MATCH_CBEGROUP
)
704 newptrb
.epb_saved_eptr
= eptr
;
705 newptrb
.epb_prev
= eptrb
;
707 md
->match_function_type
= 0;
710 /* Now start processing the opcodes. */
714 minimize
= possessive
= FALSE
;
720 md
->nomatch_mark
= ecode
+ 2;
721 md
->mark
= NULL
; /* In case previously set by assertion */
722 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
] + ecode
[1], offset_top
, md
,
724 if ((rrc
== MATCH_MATCH
|| rrc
== MATCH_ACCEPT
) &&
725 md
->mark
== NULL
) md
->mark
= ecode
+ 2;
727 /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an
728 argument, and we must check whether that argument matches this MARK's
729 argument. It is passed back in md->start_match_ptr (an overloading of that
730 variable). If it does match, we reset that variable to the current subject
731 position and return MATCH_SKIP. Otherwise, pass back the return code
734 else if (rrc
== MATCH_SKIP_ARG
&&
735 STRCMP_UC_UC(ecode
+ 2, md
->start_match_ptr
) == 0)
737 md
->start_match_ptr
= eptr
;
743 RRETURN(MATCH_NOMATCH
);
745 /* COMMIT overrides PRUNE, SKIP, and THEN */
748 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
], offset_top
, md
,
750 if (rrc
!= MATCH_NOMATCH
&& rrc
!= MATCH_PRUNE
&&
751 rrc
!= MATCH_SKIP
&& rrc
!= MATCH_SKIP_ARG
&&
754 RRETURN(MATCH_COMMIT
);
756 /* PRUNE overrides THEN */
759 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
], offset_top
, md
,
761 if (rrc
!= MATCH_NOMATCH
&& rrc
!= MATCH_THEN
) RRETURN(rrc
);
762 RRETURN(MATCH_PRUNE
);
765 md
->nomatch_mark
= ecode
+ 2;
766 md
->mark
= NULL
; /* In case previously set by assertion */
767 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
] + ecode
[1], offset_top
, md
,
769 if ((rrc
== MATCH_MATCH
|| rrc
== MATCH_ACCEPT
) &&
770 md
->mark
== NULL
) md
->mark
= ecode
+ 2;
771 if (rrc
!= MATCH_NOMATCH
&& rrc
!= MATCH_THEN
) RRETURN(rrc
);
772 RRETURN(MATCH_PRUNE
);
774 /* SKIP overrides PRUNE and THEN */
777 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
], offset_top
, md
,
779 if (rrc
!= MATCH_NOMATCH
&& rrc
!= MATCH_PRUNE
&& rrc
!= MATCH_THEN
)
781 md
->start_match_ptr
= eptr
; /* Pass back current position */
784 /* Note that, for Perl compatibility, SKIP with an argument does NOT set
785 nomatch_mark. There is a flag that disables this opcode when re-matching a
786 pattern that ended with a SKIP for which there was not a matching MARK. */
789 if (md
->ignore_skip_arg
)
791 ecode
+= PRIV(OP_lengths
)[*ecode
] + ecode
[1];
794 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
] + ecode
[1], offset_top
, md
,
796 if (rrc
!= MATCH_NOMATCH
&& rrc
!= MATCH_PRUNE
&& rrc
!= MATCH_THEN
)
799 /* Pass back the current skip name by overloading md->start_match_ptr and
800 returning the special MATCH_SKIP_ARG return code. This will either be
801 caught by a matching MARK, or get to the top, where it causes a rematch
802 with the md->ignore_skip_arg flag set. */
804 md
->start_match_ptr
= ecode
+ 2;
805 RRETURN(MATCH_SKIP_ARG
);
807 /* For THEN (and THEN_ARG) we pass back the address of the opcode, so that
808 the branch in which it occurs can be determined. Overload the start of
809 match pointer to do this. */
812 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
], offset_top
, md
,
814 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
815 md
->start_match_ptr
= ecode
;
819 md
->nomatch_mark
= ecode
+ 2;
820 md
->mark
= NULL
; /* In case previously set by assertion */
821 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
] + ecode
[1], offset_top
,
823 if ((rrc
== MATCH_MATCH
|| rrc
== MATCH_ACCEPT
) &&
824 md
->mark
== NULL
) md
->mark
= ecode
+ 2;
825 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
826 md
->start_match_ptr
= ecode
;
829 /* Handle an atomic group that does not contain any capturing parentheses.
830 This can be handled like an assertion. Prior to 8.13, all atomic groups
831 were handled this way. In 8.13, the code was changed as below for ONCE, so
832 that backups pass through the group and thereby reset captured values.
833 However, this uses a lot more stack, so in 8.20, atomic groups that do not
834 contain any captures generate OP_ONCE_NC, which can be handled in the old,
835 less stack intensive way.
837 Check the alternative branches in turn - the matching won't pass the KET
838 for this kind of subpattern. If any one branch matches, we carry on as at
839 the end of a normal bracket, leaving the subject pointer, but resetting
840 the start-of-match value in case it was changed by \K. */
845 save_mark
= md
->mark
;
848 RMATCH(eptr
, ecode
+ 1 + LINK_SIZE
, offset_top
, md
, eptrb
, RM64
);
849 if (rrc
== MATCH_MATCH
) /* Note: _not_ MATCH_ACCEPT */
851 mstart
= md
->start_match_ptr
;
854 if (rrc
== MATCH_THEN
)
856 next
= ecode
+ GET(ecode
,1);
857 if (md
->start_match_ptr
< next
&&
858 (*ecode
== OP_ALT
|| *next
== OP_ALT
))
862 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
863 ecode
+= GET(ecode
,1);
864 md
->mark
= save_mark
;
866 while (*ecode
== OP_ALT
);
868 /* If hit the end of the group (which could be repeated), fail */
870 if (*ecode
!= OP_ONCE_NC
&& *ecode
!= OP_ALT
) RRETURN(MATCH_NOMATCH
);
872 /* Continue as from after the group, updating the offsets high water
873 mark, since extracts may have been taken. */
875 do ecode
+= GET(ecode
, 1); while (*ecode
== OP_ALT
);
877 offset_top
= md
->end_offset_top
;
878 eptr
= md
->end_match_ptr
;
880 /* For a non-repeating ket, just continue at this level. This also
881 happens for a repeating ket if no characters were matched in the group.
882 This is the forcible breaking of infinite loops as implemented in Perl
885 if (*ecode
== OP_KET
|| eptr
== saved_eptr
)
887 ecode
+= 1+LINK_SIZE
;
891 /* The repeating kets try the rest of the pattern or restart from the
892 preceding bracket, in the appropriate order. The second "call" of match()
893 uses tail recursion, to avoid using another stack frame. */
895 if (*ecode
== OP_KETRMIN
)
897 RMATCH(eptr
, ecode
+ 1 + LINK_SIZE
, offset_top
, md
, eptrb
, RM65
);
898 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
902 else /* OP_KETRMAX */
904 RMATCH(eptr
, prev
, offset_top
, md
, eptrb
, RM66
);
905 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
906 ecode
+= 1 + LINK_SIZE
;
909 /* Control never gets here */
911 /* Handle a capturing bracket, other than those that are possessive with an
912 unlimited repeat. If there is space in the offset vector, save the current
913 subject position in the working slot at the top of the vector. We mustn't
914 change the current values of the data slot, because they may be set from a
915 previous iteration of this group, and be referred to by a reference inside
916 the group. A failure to match might occur after the group has succeeded,
917 if something later on doesn't match. For this reason, we need to restore
918 the working value and also the values of the final offsets, in case they
919 were set by a previous iteration of the same bracket.
921 If there isn't enough space in the offset vector, treat this as if it were
922 a non-capturing bracket. Don't worry about setting the flag for the error
923 case here; that is handled in the code for KET. */
927 number
= GET2(ecode
, 1+LINK_SIZE
);
928 offset
= number
<< 1;
931 printf("start bracket %d\n", number
);
933 pchars(eptr
, 16, TRUE
, md
);
937 if (offset
< md
->offset_max
)
939 save_offset1
= md
->offset_vector
[offset
];
940 save_offset2
= md
->offset_vector
[offset
+1];
941 save_offset3
= md
->offset_vector
[md
->offset_end
- number
];
942 save_capture_last
= md
->capture_last
;
943 save_mark
= md
->mark
;
945 DPRINTF(("saving %d %d %d\n", save_offset1
, save_offset2
, save_offset3
));
946 md
->offset_vector
[md
->offset_end
- number
] =
947 (int)(eptr
- md
->start_subject
);
951 if (op
>= OP_SBRA
) md
->match_function_type
= MATCH_CBEGROUP
;
952 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
], offset_top
, md
,
954 if (rrc
== MATCH_ONCE
) break; /* Backing up through an atomic group */
956 /* If we backed up to a THEN, check whether it is within the current
957 branch by comparing the address of the THEN that is passed back with
958 the end of the branch. If it is within the current branch, and the
959 branch is one of two or more alternatives (it either starts or ends
960 with OP_ALT), we have reached the limit of THEN's action, so convert
961 the return code to NOMATCH, which will cause normal backtracking to
962 happen from now on. Otherwise, THEN is passed back to an outer
963 alternative. This implements Perl's treatment of parenthesized groups,
964 where a group not containing | does not affect the current alternative,
965 that is, (X) is NOT the same as (X|(*F)). */
967 if (rrc
== MATCH_THEN
)
969 next
= ecode
+ GET(ecode
,1);
970 if (md
->start_match_ptr
< next
&&
971 (*ecode
== OP_ALT
|| *next
== OP_ALT
))
975 /* Anything other than NOMATCH is passed back. */
977 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
978 md
->capture_last
= save_capture_last
;
979 ecode
+= GET(ecode
, 1);
980 md
->mark
= save_mark
;
981 if (*ecode
!= OP_ALT
) break;
984 DPRINTF(("bracket %d failed\n", number
));
985 md
->offset_vector
[offset
] = save_offset1
;
986 md
->offset_vector
[offset
+1] = save_offset2
;
987 md
->offset_vector
[md
->offset_end
- number
] = save_offset3
;
989 /* At this point, rrc will be one of MATCH_ONCE or MATCH_NOMATCH. */
994 /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
995 as a non-capturing bracket. */
997 /* VVVVVVVVVVVVVVVVVVVVVVVVV */
998 /* VVVVVVVVVVVVVVVVVVVVVVVVV */
1000 DPRINTF(("insufficient capture room: treat as non-capturing\n"));
1002 /* VVVVVVVVVVVVVVVVVVVVVVVVV */
1003 /* VVVVVVVVVVVVVVVVVVVVVVVVV */
1005 /* Non-capturing or atomic group, except for possessive with unlimited
1006 repeat and ONCE group with no captures. Loop for all the alternatives.
1008 When we get to the final alternative within the brackets, we used to return
1009 the result of a recursive call to match() whatever happened so it was
1010 possible to reduce stack usage by turning this into a tail recursion,
1011 except in the case of a possibly empty group. However, now that there is
1012 the possiblity of (*THEN) occurring in the final alternative, this
1013 optimization is no longer always possible.
1015 We can optimize if we know there are no (*THEN)s in the pattern; at present
1016 this is the best that can be done.
1018 MATCH_ONCE is returned when the end of an atomic group is successfully
1019 reached, but subsequent matching fails. It passes back up the tree (causing
1020 captured values to be reset) until the original atomic group level is
1021 reached. This is tested by comparing md->once_target with the start of the
1022 group. At this point, the return is converted into MATCH_NOMATCH so that
1023 previous backup points can be taken. */
1028 DPRINTF(("start non-capturing bracket\n"));
1032 if (op
>= OP_SBRA
|| op
== OP_ONCE
)
1033 md
->match_function_type
= MATCH_CBEGROUP
;
1035 /* If this is not a possibly empty group, and there are no (*THEN)s in
1036 the pattern, and this is the final alternative, optimize as described
1039 else if (!md
->hasthen
&& ecode
[GET(ecode
, 1)] != OP_ALT
)
1041 ecode
+= PRIV(OP_lengths
)[*ecode
];
1045 /* In all other cases, we have to make another call to match(). */
1047 save_mark
= md
->mark
;
1048 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
], offset_top
, md
, eptrb
,
1051 /* See comment in the code for capturing groups above about handling
1054 if (rrc
== MATCH_THEN
)
1056 next
= ecode
+ GET(ecode
,1);
1057 if (md
->start_match_ptr
< next
&&
1058 (*ecode
== OP_ALT
|| *next
== OP_ALT
))
1059 rrc
= MATCH_NOMATCH
;
1062 if (rrc
!= MATCH_NOMATCH
)
1064 if (rrc
== MATCH_ONCE
)
1066 const pcre_uchar
*scode
= ecode
;
1067 if (*scode
!= OP_ONCE
) /* If not at start, find it */
1069 while (*scode
== OP_ALT
) scode
+= GET(scode
, 1);
1070 scode
-= GET(scode
, 1);
1072 if (md
->once_target
== scode
) rrc
= MATCH_NOMATCH
;
1076 ecode
+= GET(ecode
, 1);
1077 md
->mark
= save_mark
;
1078 if (*ecode
!= OP_ALT
) break;
1081 RRETURN(MATCH_NOMATCH
);
1083 /* Handle possessive capturing brackets with an unlimited repeat. We come
1084 here from BRAZERO with allow_zero set TRUE. The offset_vector values are
1085 handled similarly to the normal case above. However, the matching is
1086 different. The end of these brackets will always be OP_KETRPOS, which
1087 returns MATCH_KETRPOS without going further in the pattern. By this means
1088 we can handle the group by iteration rather than recursion, thereby
1089 reducing the amount of stack needed. */
1096 number
= GET2(ecode
, 1+LINK_SIZE
);
1097 offset
= number
<< 1;
1100 printf("start possessive bracket %d\n", number
);
1102 pchars(eptr
, 16, TRUE
, md
);
1106 if (offset
< md
->offset_max
)
1108 matched_once
= FALSE
;
1109 code_offset
= (int)(ecode
- md
->start_code
);
1111 save_offset1
= md
->offset_vector
[offset
];
1112 save_offset2
= md
->offset_vector
[offset
+1];
1113 save_offset3
= md
->offset_vector
[md
->offset_end
- number
];
1114 save_capture_last
= md
->capture_last
;
1116 DPRINTF(("saving %d %d %d\n", save_offset1
, save_offset2
, save_offset3
));
1118 /* Each time round the loop, save the current subject position for use
1119 when the group matches. For MATCH_MATCH, the group has matched, so we
1120 restart it with a new subject starting position, remembering that we had
1121 at least one match. For MATCH_NOMATCH, carry on with the alternatives, as
1122 usual. If we haven't matched any alternatives in any iteration, check to
1123 see if a previous iteration matched. If so, the group has matched;
1124 continue from afterwards. Otherwise it has failed; restore the previous
1125 capture values before returning NOMATCH. */
1129 md
->offset_vector
[md
->offset_end
- number
] =
1130 (int)(eptr
- md
->start_subject
);
1131 if (op
>= OP_SBRA
) md
->match_function_type
= MATCH_CBEGROUP
;
1132 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
], offset_top
, md
,
1134 if (rrc
== MATCH_KETRPOS
)
1136 offset_top
= md
->end_offset_top
;
1137 eptr
= md
->end_match_ptr
;
1138 ecode
= md
->start_code
+ code_offset
;
1139 save_capture_last
= md
->capture_last
;
1140 matched_once
= TRUE
;
1144 /* See comment in the code for capturing groups above about handling
1147 if (rrc
== MATCH_THEN
)
1149 next
= ecode
+ GET(ecode
,1);
1150 if (md
->start_match_ptr
< next
&&
1151 (*ecode
== OP_ALT
|| *next
== OP_ALT
))
1152 rrc
= MATCH_NOMATCH
;
1155 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
1156 md
->capture_last
= save_capture_last
;
1157 ecode
+= GET(ecode
, 1);
1158 if (*ecode
!= OP_ALT
) break;
1163 md
->offset_vector
[offset
] = save_offset1
;
1164 md
->offset_vector
[offset
+1] = save_offset2
;
1165 md
->offset_vector
[md
->offset_end
- number
] = save_offset3
;
1168 if (allow_zero
|| matched_once
)
1170 ecode
+= 1 + LINK_SIZE
;
1174 RRETURN(MATCH_NOMATCH
);
1177 /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
1178 as a non-capturing bracket. */
1180 /* VVVVVVVVVVVVVVVVVVVVVVVVV */
1181 /* VVVVVVVVVVVVVVVVVVVVVVVVV */
1183 DPRINTF(("insufficient capture room: treat as non-capturing\n"));
1185 /* VVVVVVVVVVVVVVVVVVVVVVVVV */
1186 /* VVVVVVVVVVVVVVVVVVVVVVVVV */
1188 /* Non-capturing possessive bracket with unlimited repeat. We come here
1189 from BRAZERO with allow_zero = TRUE. The code is similar to the above,
1190 without the capturing complication. It is written out separately for speed
1197 POSSESSIVE_NON_CAPTURE
:
1198 matched_once
= FALSE
;
1199 code_offset
= (int)(ecode
- md
->start_code
);
1203 if (op
>= OP_SBRA
) md
->match_function_type
= MATCH_CBEGROUP
;
1204 RMATCH(eptr
, ecode
+ PRIV(OP_lengths
)[*ecode
], offset_top
, md
,
1206 if (rrc
== MATCH_KETRPOS
)
1208 offset_top
= md
->end_offset_top
;
1209 eptr
= md
->end_match_ptr
;
1210 ecode
= md
->start_code
+ code_offset
;
1211 matched_once
= TRUE
;
1215 /* See comment in the code for capturing groups above about handling
1218 if (rrc
== MATCH_THEN
)
1220 next
= ecode
+ GET(ecode
,1);
1221 if (md
->start_match_ptr
< next
&&
1222 (*ecode
== OP_ALT
|| *next
== OP_ALT
))
1223 rrc
= MATCH_NOMATCH
;
1226 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
1227 ecode
+= GET(ecode
, 1);
1228 if (*ecode
!= OP_ALT
) break;
1231 if (matched_once
|| allow_zero
)
1233 ecode
+= 1 + LINK_SIZE
;
1236 RRETURN(MATCH_NOMATCH
);
1238 /* Control never reaches here. */
1240 /* Conditional group: compilation checked that there are no more than
1241 two branches. If the condition is false, skipping the first branch takes us
1242 past the end if there is only one branch, but that's OK because that is
1243 exactly what going to the ket would do. */
1247 codelink
= GET(ecode
, 1);
1249 /* Because of the way auto-callout works during compile, a callout item is
1250 inserted between OP_COND and an assertion condition. */
1252 if (ecode
[LINK_SIZE
+1] == OP_CALLOUT
)
1254 if (PUBL(callout
) != NULL
)
1256 PUBL(callout_block
) cb
;
1257 cb
.version
= 2; /* Version 1 of the callout block */
1258 cb
.callout_number
= ecode
[LINK_SIZE
+2];
1259 cb
.offset_vector
= md
->offset_vector
;
1260 #ifdef COMPILE_PCRE8
1261 cb
.subject
= (PCRE_SPTR
)md
->start_subject
;
1263 cb
.subject
= (PCRE_SPTR16
)md
->start_subject
;
1265 cb
.subject_length
= (int)(md
->end_subject
- md
->start_subject
);
1266 cb
.start_match
= (int)(mstart
- md
->start_subject
);
1267 cb
.current_position
= (int)(eptr
- md
->start_subject
);
1268 cb
.pattern_position
= GET(ecode
, LINK_SIZE
+ 3);
1269 cb
.next_item_length
= GET(ecode
, 3 + 2*LINK_SIZE
);
1270 cb
.capture_top
= offset_top
/2;
1271 cb
.capture_last
= md
->capture_last
;
1272 cb
.callout_data
= md
->callout_data
;
1273 cb
.mark
= md
->nomatch_mark
;
1274 if ((rrc
= (*PUBL(callout
))(&cb
)) > 0) RRETURN(MATCH_NOMATCH
);
1275 if (rrc
< 0) RRETURN(rrc
);
1277 ecode
+= PRIV(OP_lengths
)[OP_CALLOUT
];
1280 condcode
= ecode
[LINK_SIZE
+1];
1282 /* Now see what the actual condition is */
1284 if (condcode
== OP_RREF
|| condcode
== OP_NRREF
) /* Recursion test */
1286 if (md
->recursive
== NULL
) /* Not recursing => FALSE */
1289 ecode
+= GET(ecode
, 1);
1293 int recno
= GET2(ecode
, LINK_SIZE
+ 2); /* Recursion group number*/
1294 condition
= (recno
== RREF_ANY
|| recno
== md
->recursive
->group_num
);
1296 /* If the test is for recursion into a specific subpattern, and it is
1297 false, but the test was set up by name, scan the table to see if the
1298 name refers to any other numbers, and test them. The condition is true
1299 if any one is set. */
1301 if (!condition
&& condcode
== OP_NRREF
)
1303 pcre_uchar
*slotA
= md
->name_table
;
1304 for (i
= 0; i
< md
->name_count
; i
++)
1306 if (GET2(slotA
, 0) == recno
) break;
1307 slotA
+= md
->name_entry_size
;
1310 /* Found a name for the number - there can be only one; duplicate
1311 names for different numbers are allowed, but not vice versa. First
1312 scan down for duplicates. */
1314 if (i
< md
->name_count
)
1316 pcre_uchar
*slotB
= slotA
;
1317 while (slotB
> md
->name_table
)
1319 slotB
-= md
->name_entry_size
;
1320 if (STRCMP_UC_UC(slotA
+ IMM2_SIZE
, slotB
+ IMM2_SIZE
) == 0)
1322 condition
= GET2(slotB
, 0) == md
->recursive
->group_num
;
1323 if (condition
) break;
1328 /* Scan up for duplicates */
1333 for (i
++; i
< md
->name_count
; i
++)
1335 slotB
+= md
->name_entry_size
;
1336 if (STRCMP_UC_UC(slotA
+ IMM2_SIZE
, slotB
+ IMM2_SIZE
) == 0)
1338 condition
= GET2(slotB
, 0) == md
->recursive
->group_num
;
1339 if (condition
) break;
1347 /* Chose branch according to the condition */
1349 ecode
+= condition
? 1 + IMM2_SIZE
: GET(ecode
, 1);
1353 else if (condcode
== OP_CREF
|| condcode
== OP_NCREF
) /* Group used test */
1355 offset
= GET2(ecode
, LINK_SIZE
+2) << 1; /* Doubled ref number */
1356 condition
= offset
< offset_top
&& md
->offset_vector
[offset
] >= 0;
1358 /* If the numbered capture is unset, but the reference was by name,
1359 scan the table to see if the name refers to any other numbers, and test
1360 them. The condition is true if any one is set. This is tediously similar
1361 to the code above, but not close enough to try to amalgamate. */
1363 if (!condition
&& condcode
== OP_NCREF
)
1365 int refno
= offset
>> 1;
1366 pcre_uchar
*slotA
= md
->name_table
;
1368 for (i
= 0; i
< md
->name_count
; i
++)
1370 if (GET2(slotA
, 0) == refno
) break;
1371 slotA
+= md
->name_entry_size
;
1374 /* Found a name for the number - there can be only one; duplicate names
1375 for different numbers are allowed, but not vice versa. First scan down
1378 if (i
< md
->name_count
)
1380 pcre_uchar
*slotB
= slotA
;
1381 while (slotB
> md
->name_table
)
1383 slotB
-= md
->name_entry_size
;
1384 if (STRCMP_UC_UC(slotA
+ IMM2_SIZE
, slotB
+ IMM2_SIZE
) == 0)
1386 offset
= GET2(slotB
, 0) << 1;
1387 condition
= offset
< offset_top
&&
1388 md
->offset_vector
[offset
] >= 0;
1389 if (condition
) break;
1394 /* Scan up for duplicates */
1399 for (i
++; i
< md
->name_count
; i
++)
1401 slotB
+= md
->name_entry_size
;
1402 if (STRCMP_UC_UC(slotA
+ IMM2_SIZE
, slotB
+ IMM2_SIZE
) == 0)
1404 offset
= GET2(slotB
, 0) << 1;
1405 condition
= offset
< offset_top
&&
1406 md
->offset_vector
[offset
] >= 0;
1407 if (condition
) break;
1415 /* Chose branch according to the condition */
1417 ecode
+= condition
? 1 + IMM2_SIZE
: GET(ecode
, 1);
1420 else if (condcode
== OP_DEF
) /* DEFINE - always false */
1423 ecode
+= GET(ecode
, 1);
1426 /* The condition is an assertion. Call match() to evaluate it - setting
1427 md->match_function_type to MATCH_CONDASSERT causes it to stop at the end of
1432 md
->match_function_type
= MATCH_CONDASSERT
;
1433 RMATCH(eptr
, ecode
+ 1 + LINK_SIZE
, offset_top
, md
, NULL
, RM3
);
1434 if (rrc
== MATCH_MATCH
)
1436 if (md
->end_offset_top
> offset_top
)
1437 offset_top
= md
->end_offset_top
; /* Captures may have happened */
1439 ecode
+= 1 + LINK_SIZE
+ GET(ecode
, LINK_SIZE
+ 2);
1440 while (*ecode
== OP_ALT
) ecode
+= GET(ecode
, 1);
1443 /* PCRE doesn't allow the effect of (*THEN) to escape beyond an
1444 assertion; it is therefore treated as NOMATCH. */
1446 else if (rrc
!= MATCH_NOMATCH
&& rrc
!= MATCH_THEN
)
1448 RRETURN(rrc
); /* Need braces because of following else */
1457 /* We are now at the branch that is to be obeyed. As there is only one, can
1458 use tail recursion to avoid using another stack frame, except when there is
1459 unlimited repeat of a possibly empty group. In the latter case, a recursive
1460 call to match() is always required, unless the second alternative doesn't
1461 exist, in which case we can just plough on. Note that, for compatibility
1462 with Perl, the | in a conditional group is NOT treated as creating two
1463 alternatives. If a THEN is encountered in the branch, it propagates out to
1464 the enclosing alternative (unless nested in a deeper set of alternatives,
1467 if (condition
|| *ecode
== OP_ALT
)
1471 ecode
+= 1 + LINK_SIZE
;
1475 md
->match_function_type
= MATCH_CBEGROUP
;
1476 RMATCH(eptr
, ecode
+ 1 + LINK_SIZE
, offset_top
, md
, eptrb
, RM49
);
1480 /* Condition false & no alternative; continue after the group. */
1484 ecode
+= 1 + LINK_SIZE
;
1489 /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes,
1490 to close any currently open capturing brackets. */
1493 number
= GET2(ecode
, 1);
1494 offset
= number
<< 1;
1497 printf("end bracket %d at *ACCEPT", number
);
1501 md
->capture_last
= number
;
1502 if (offset
>= md
->offset_max
) md
->offset_overflow
= TRUE
; else
1504 md
->offset_vector
[offset
] =
1505 md
->offset_vector
[md
->offset_end
- number
];
1506 md
->offset_vector
[offset
+1] = (int)(eptr
- md
->start_subject
);
1507 if (offset_top
<= offset
) offset_top
= offset
+ 2;
1509 ecode
+= 1 + IMM2_SIZE
;
1513 /* End of the pattern, either real or forced. */
1517 case OP_ASSERT_ACCEPT
:
1519 /* If we have matched an empty string, fail if not in an assertion and not
1520 in a recursion if either PCRE_NOTEMPTY is set, or if PCRE_NOTEMPTY_ATSTART
1521 is set and we have matched at the start of the subject. In both cases,
1522 backtracking will then try other alternatives, if any. */
1524 if (eptr
== mstart
&& op
!= OP_ASSERT_ACCEPT
&&
1525 md
->recursive
== NULL
&&
1527 (md
->notempty_atstart
&&
1528 mstart
== md
->start_subject
+ md
->start_offset
)))
1529 RRETURN(MATCH_NOMATCH
);
1531 /* Otherwise, we have a match. */
1533 md
->end_match_ptr
= eptr
; /* Record where we ended */
1534 md
->end_offset_top
= offset_top
; /* and how many extracts were taken */
1535 md
->start_match_ptr
= mstart
; /* and the start (\K can modify) */
1537 /* For some reason, the macros don't work properly if an expression is
1538 given as the argument to RRETURN when the heap is in use. */
1540 rrc
= (op
== OP_END
)? MATCH_MATCH
: MATCH_ACCEPT
;
1543 /* Assertion brackets. Check the alternative branches in turn - the
1544 matching won't pass the KET for an assertion. If any one branch matches,
1545 the assertion is true. Lookbehind assertions have an OP_REVERSE item at the
1546 start of each branch to move the current point backwards, so the code at
1547 this level is identical to the lookahead case. When the assertion is part
1548 of a condition, we want to return immediately afterwards. The caller of
1549 this incarnation of the match() function will have set MATCH_CONDASSERT in
1550 md->match_function type, and one of these opcodes will be the first opcode
1551 that is processed. We use a local variable that is preserved over calls to
1552 match() to remember this case. */
1556 save_mark
= md
->mark
;
1557 if (md
->match_function_type
== MATCH_CONDASSERT
)
1560 md
->match_function_type
= 0;
1562 else condassert
= FALSE
;
1566 RMATCH(eptr
, ecode
+ 1 + LINK_SIZE
, offset_top
, md
, NULL
, RM4
);
1567 if (rrc
== MATCH_MATCH
|| rrc
== MATCH_ACCEPT
)
1569 mstart
= md
->start_match_ptr
; /* In case \K reset it */
1572 md
->mark
= save_mark
;
1574 /* A COMMIT failure must fail the entire assertion, without trying any
1575 subsequent branches. */
1577 if (rrc
== MATCH_COMMIT
) RRETURN(MATCH_NOMATCH
);
1579 /* PCRE does not allow THEN to escape beyond an assertion; it
1580 is treated as NOMATCH. */
1582 if (rrc
!= MATCH_NOMATCH
&& rrc
!= MATCH_THEN
) RRETURN(rrc
);
1583 ecode
+= GET(ecode
, 1);
1585 while (*ecode
== OP_ALT
);
1587 if (*ecode
== OP_KET
) RRETURN(MATCH_NOMATCH
);
1589 /* If checking an assertion for a condition, return MATCH_MATCH. */
1591 if (condassert
) RRETURN(MATCH_MATCH
);
1593 /* Continue from after the assertion, updating the offsets high water
1594 mark, since extracts may have been taken during the assertion. */
1596 do ecode
+= GET(ecode
,1); while (*ecode
== OP_ALT
);
1597 ecode
+= 1 + LINK_SIZE
;
1598 offset_top
= md
->end_offset_top
;
1601 /* Negative assertion: all branches must fail to match. Encountering SKIP,
1602 PRUNE, or COMMIT means we must assume failure without checking subsequent
1606 case OP_ASSERTBACK_NOT
:
1607 save_mark
= md
->mark
;
1608 if (md
->match_function_type
== MATCH_CONDASSERT
)
1611 md
->match_function_type
= 0;
1613 else condassert
= FALSE
;
1617 RMATCH(eptr
, ecode
+ 1 + LINK_SIZE
, offset_top
, md
, NULL
, RM5
);
1618 md
->mark
= save_mark
;
1619 if (rrc
== MATCH_MATCH
|| rrc
== MATCH_ACCEPT
) RRETURN(MATCH_NOMATCH
);
1620 if (rrc
== MATCH_SKIP
|| rrc
== MATCH_PRUNE
|| rrc
== MATCH_COMMIT
)
1622 do ecode
+= GET(ecode
,1); while (*ecode
== OP_ALT
);
1626 /* PCRE does not allow THEN to escape beyond an assertion; it is treated
1629 if (rrc
!= MATCH_NOMATCH
&& rrc
!= MATCH_THEN
) RRETURN(rrc
);
1630 ecode
+= GET(ecode
,1);
1632 while (*ecode
== OP_ALT
);
1634 if (condassert
) RRETURN(MATCH_MATCH
); /* Condition assertion */
1636 ecode
+= 1 + LINK_SIZE
;
1639 /* Move the subject pointer back. This occurs only at the start of
1640 each branch of a lookbehind assertion. If we are too close to the start to
1641 move back, this match function fails. When working with UTF-8 we move
1642 back a number of characters, not bytes. */
1652 if (eptr
< md
->start_subject
) RRETURN(MATCH_NOMATCH
);
1659 /* No UTF-8 support, or not in UTF-8 mode: count is byte count */
1662 eptr
-= GET(ecode
, 1);
1663 if (eptr
< md
->start_subject
) RRETURN(MATCH_NOMATCH
);
1666 /* Save the earliest consulted character, then skip to next op code */
1668 if (eptr
< md
->start_used_ptr
) md
->start_used_ptr
= eptr
;
1669 ecode
+= 1 + LINK_SIZE
;
1672 /* The callout item calls an external function, if one is provided, passing
1673 details of the match so far. This is mainly for debugging, though the
1674 function is able to force a failure. */
1677 if (PUBL(callout
) != NULL
)
1679 PUBL(callout_block
) cb
;
1680 cb
.version
= 2; /* Version 1 of the callout block */
1681 cb
.callout_number
= ecode
[1];
1682 cb
.offset_vector
= md
->offset_vector
;
1683 #ifdef COMPILE_PCRE8
1684 cb
.subject
= (PCRE_SPTR
)md
->start_subject
;
1686 cb
.subject
= (PCRE_SPTR16
)md
->start_subject
;
1688 cb
.subject_length
= (int)(md
->end_subject
- md
->start_subject
);
1689 cb
.start_match
= (int)(mstart
- md
->start_subject
);
1690 cb
.current_position
= (int)(eptr
- md
->start_subject
);
1691 cb
.pattern_position
= GET(ecode
, 2);
1692 cb
.next_item_length
= GET(ecode
, 2 + LINK_SIZE
);
1693 cb
.capture_top
= offset_top
/2;
1694 cb
.capture_last
= md
->capture_last
;
1695 cb
.callout_data
= md
->callout_data
;
1696 cb
.mark
= md
->nomatch_mark
;
1697 if ((rrc
= (*PUBL(callout
))(&cb
)) > 0) RRETURN(MATCH_NOMATCH
);
1698 if (rrc
< 0) RRETURN(rrc
);
1700 ecode
+= 2 + 2*LINK_SIZE
;
1703 /* Recursion either matches the current regex, or some subexpression. The
1704 offset data is the offset to the starting bracket from the start of the
1705 whole pattern. (This is so that it works from duplicated subpatterns.)
1707 The state of the capturing groups is preserved over recursion, and
1708 re-instated afterwards. We don't know how many are started and not yet
1709 finished (offset_top records the completed total) so we just have to save
1710 all the potential data. There may be up to 65535 such values, which is too
1711 large to put on the stack, but using malloc for small numbers seems
1712 expensive. As a compromise, the stack is used when there are no more than
1713 REC_STACK_SAVE_MAX values to store; otherwise malloc is used.
1715 There are also other values that have to be saved. We use a chained
1716 sequence of blocks that actually live on the stack. Thanks to Robin Houston
1717 for the original version of this logic. It has, however, been hacked around
1718 a lot, so he is not to blame for the current way it works. */
1725 callpat
= md
->start_code
+ GET(ecode
, 1);
1726 recno
= (callpat
== md
->start_code
)? 0 :
1727 GET2(callpat
, 1 + LINK_SIZE
);
1729 /* Check for repeating a recursion without advancing the subject pointer.
1730 This should catch convoluted mutual recursions. (Some simple cases are
1731 caught at compile time.) */
1733 for (ri
= md
->recursive
; ri
!= NULL
; ri
= ri
->prevrec
)
1734 if (recno
== ri
->group_num
&& eptr
== ri
->subject_position
)
1735 RRETURN(PCRE_ERROR_RECURSELOOP
);
1737 /* Add to "recursing stack" */
1739 new_recursive
.group_num
= recno
;
1740 new_recursive
.subject_position
= eptr
;
1741 new_recursive
.prevrec
= md
->recursive
;
1742 md
->recursive
= &new_recursive
;
1744 /* Where to continue from afterwards */
1746 ecode
+= 1 + LINK_SIZE
;
1748 /* Now save the offset data */
1750 new_recursive
.saved_max
= md
->offset_end
;
1751 if (new_recursive
.saved_max
<= REC_STACK_SAVE_MAX
)
1752 new_recursive
.offset_save
= stacksave
;
1755 new_recursive
.offset_save
=
1756 (int *)(PUBL(malloc
))(new_recursive
.saved_max
* sizeof(int));
1757 if (new_recursive
.offset_save
== NULL
) RRETURN(PCRE_ERROR_NOMEMORY
);
1759 memcpy(new_recursive
.offset_save
, md
->offset_vector
,
1760 new_recursive
.saved_max
* sizeof(int));
1762 /* OK, now we can do the recursion. After processing each alternative,
1763 restore the offset data. If there were nested recursions, md->recursive
1764 might be changed, so reset it before looping. */
1766 DPRINTF(("Recursing into group %d\n", new_recursive
.group_num
));
1767 cbegroup
= (*callpat
>= OP_SBRA
);
1770 if (cbegroup
) md
->match_function_type
= MATCH_CBEGROUP
;
1771 RMATCH(eptr
, callpat
+ PRIV(OP_lengths
)[*callpat
], offset_top
,
1773 memcpy(md
->offset_vector
, new_recursive
.offset_save
,
1774 new_recursive
.saved_max
* sizeof(int));
1775 md
->recursive
= new_recursive
.prevrec
;
1776 if (rrc
== MATCH_MATCH
|| rrc
== MATCH_ACCEPT
)
1778 DPRINTF(("Recursion matched\n"));
1779 if (new_recursive
.offset_save
!= stacksave
)
1780 (PUBL(free
))(new_recursive
.offset_save
);
1782 /* Set where we got to in the subject, and reset the start in case
1783 it was changed by \K. This *is* propagated back out of a recursion,
1784 for Perl compatibility. */
1786 eptr
= md
->end_match_ptr
;
1787 mstart
= md
->start_match_ptr
;
1788 goto RECURSION_MATCHED
; /* Exit loop; end processing */
1791 /* PCRE does not allow THEN or COMMIT to escape beyond a recursion; it
1792 is treated as NOMATCH. */
1794 else if (rrc
!= MATCH_NOMATCH
&& rrc
!= MATCH_THEN
&&
1795 rrc
!= MATCH_COMMIT
)
1797 DPRINTF(("Recursion gave error %d\n", rrc
));
1798 if (new_recursive
.offset_save
!= stacksave
)
1799 (PUBL(free
))(new_recursive
.offset_save
);
1803 md
->recursive
= &new_recursive
;
1804 callpat
+= GET(callpat
, 1);
1806 while (*callpat
== OP_ALT
);
1808 DPRINTF(("Recursion didn't match\n"));
1809 md
->recursive
= new_recursive
.prevrec
;
1810 if (new_recursive
.offset_save
!= stacksave
)
1811 (PUBL(free
))(new_recursive
.offset_save
);
1812 RRETURN(MATCH_NOMATCH
);
1818 /* An alternation is the end of a branch; scan along to find the end of the
1819 bracketed group and go to there. */
1822 do ecode
+= GET(ecode
,1); while (*ecode
== OP_ALT
);
1825 /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1826 indicating that it may occur zero times. It may repeat infinitely, or not
1827 at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1828 with fixed upper repeat limits are compiled as a number of copies, with the
1829 optional ones preceded by BRAZERO or BRAMINZERO. */
1833 RMATCH(eptr
, next
, offset_top
, md
, eptrb
, RM10
);
1834 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
1835 do next
+= GET(next
, 1); while (*next
== OP_ALT
);
1836 ecode
= next
+ 1 + LINK_SIZE
;
1841 do next
+= GET(next
, 1); while (*next
== OP_ALT
);
1842 RMATCH(eptr
, next
+ 1+LINK_SIZE
, offset_top
, md
, eptrb
, RM11
);
1843 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
1849 do next
+= GET(next
,1); while (*next
== OP_ALT
);
1850 ecode
= next
+ 1 + LINK_SIZE
;
1853 /* BRAPOSZERO occurs before a possessive bracket group. Don't do anything
1854 here; just jump to the group, with allow_zero set TRUE. */
1859 if (op
== OP_CBRAPOS
|| op
== OP_SCBRAPOS
) goto POSSESSIVE_CAPTURE
;
1860 goto POSSESSIVE_NON_CAPTURE
;
1862 /* End of a group, repeated or non-repeating. */
1868 prev
= ecode
- GET(ecode
, 1);
1870 /* If this was a group that remembered the subject start, in order to break
1871 infinite repeats of empty string matches, retrieve the subject start from
1872 the chain. Otherwise, set it NULL. */
1874 if (*prev
>= OP_SBRA
|| *prev
== OP_ONCE
)
1876 saved_eptr
= eptrb
->epb_saved_eptr
; /* Value at start of group */
1877 eptrb
= eptrb
->epb_prev
; /* Backup to previous group */
1879 else saved_eptr
= NULL
;
1881 /* If we are at the end of an assertion group or a non-capturing atomic
1882 group, stop matching and return MATCH_MATCH, but record the current high
1883 water mark for use by positive assertions. We also need to record the match
1884 start in case it was changed by \K. */
1886 if ((*prev
>= OP_ASSERT
&& *prev
<= OP_ASSERTBACK_NOT
) ||
1887 *prev
== OP_ONCE_NC
)
1889 md
->end_match_ptr
= eptr
; /* For ONCE_NC */
1890 md
->end_offset_top
= offset_top
;
1891 md
->start_match_ptr
= mstart
;
1892 RRETURN(MATCH_MATCH
); /* Sets md->mark */
1895 /* For capturing groups we have to check the group number back at the start
1896 and if necessary complete handling an extraction by setting the offsets and
1897 bumping the high water mark. Whole-pattern recursion is coded as a recurse
1898 into group 0, so it won't be picked up here. Instead, we catch it when the
1899 OP_END is reached. Other recursion is handled here. We just have to record
1900 the current subject position and start match pointer and give a MATCH
1903 if (*prev
== OP_CBRA
|| *prev
== OP_SCBRA
||
1904 *prev
== OP_CBRAPOS
|| *prev
== OP_SCBRAPOS
)
1906 number
= GET2(prev
, 1+LINK_SIZE
);
1907 offset
= number
<< 1;
1910 printf("end bracket %d", number
);
1914 /* Handle a recursively called group. */
1916 if (md
->recursive
!= NULL
&& md
->recursive
->group_num
== number
)
1918 md
->end_match_ptr
= eptr
;
1919 md
->start_match_ptr
= mstart
;
1920 RRETURN(MATCH_MATCH
);
1923 /* Deal with capturing */
1925 md
->capture_last
= number
;
1926 if (offset
>= md
->offset_max
) md
->offset_overflow
= TRUE
; else
1928 /* If offset is greater than offset_top, it means that we are
1929 "skipping" a capturing group, and that group's offsets must be marked
1930 unset. In earlier versions of PCRE, all the offsets were unset at the
1931 start of matching, but this doesn't work because atomic groups and
1932 assertions can cause a value to be set that should later be unset.
1933 Example: matching /(?>(a))b|(a)c/ against "ac". This sets group 1 as
1934 part of the atomic group, but this is not on the final matching path,
1935 so must be unset when 2 is set. (If there is no group 2, there is no
1936 problem, because offset_top will then be 2, indicating no capture.) */
1938 if (offset
> offset_top
)
1940 int *iptr
= md
->offset_vector
+ offset_top
;
1941 int *iend
= md
->offset_vector
+ offset
;
1942 while (iptr
< iend
) *iptr
++ = -1;
1945 /* Now make the extraction */
1947 md
->offset_vector
[offset
] =
1948 md
->offset_vector
[md
->offset_end
- number
];
1949 md
->offset_vector
[offset
+1] = (int)(eptr
- md
->start_subject
);
1950 if (offset_top
<= offset
) offset_top
= offset
+ 2;
1954 /* For an ordinary non-repeating ket, just continue at this level. This
1955 also happens for a repeating ket if no characters were matched in the
1956 group. This is the forcible breaking of infinite loops as implemented in
1957 Perl 5.005. For a non-repeating atomic group that includes captures,
1958 establish a backup point by processing the rest of the pattern at a lower
1959 level. If this results in a NOMATCH return, pass MATCH_ONCE back to the
1960 original OP_ONCE level, thereby bypassing intermediate backup points, but
1961 resetting any captures that happened along the way. */
1963 if (*ecode
== OP_KET
|| eptr
== saved_eptr
)
1965 if (*prev
== OP_ONCE
)
1967 RMATCH(eptr
, ecode
+ 1 + LINK_SIZE
, offset_top
, md
, eptrb
, RM12
);
1968 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
1969 md
->once_target
= prev
; /* Level at which to change to MATCH_NOMATCH */
1970 RRETURN(MATCH_ONCE
);
1972 ecode
+= 1 + LINK_SIZE
; /* Carry on at this level */
1976 /* OP_KETRPOS is a possessive repeating ket. Remember the current position,
1977 and return the MATCH_KETRPOS. This makes it possible to do the repeats one
1978 at a time from the outer level, thus saving stack. */
1980 if (*ecode
== OP_KETRPOS
)
1982 md
->end_match_ptr
= eptr
;
1983 md
->end_offset_top
= offset_top
;
1984 RRETURN(MATCH_KETRPOS
);
1987 /* The normal repeating kets try the rest of the pattern or restart from
1988 the preceding bracket, in the appropriate order. In the second case, we can
1989 use tail recursion to avoid using another stack frame, unless we have an
1990 an atomic group or an unlimited repeat of a group that can match an empty
1993 if (*ecode
== OP_KETRMIN
)
1995 RMATCH(eptr
, ecode
+ 1 + LINK_SIZE
, offset_top
, md
, eptrb
, RM7
);
1996 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
1997 if (*prev
== OP_ONCE
)
1999 RMATCH(eptr
, prev
, offset_top
, md
, eptrb
, RM8
);
2000 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
2001 md
->once_target
= prev
; /* Level at which to change to MATCH_NOMATCH */
2002 RRETURN(MATCH_ONCE
);
2004 if (*prev
>= OP_SBRA
) /* Could match an empty string */
2006 RMATCH(eptr
, prev
, offset_top
, md
, eptrb
, RM50
);
2012 else /* OP_KETRMAX */
2014 RMATCH(eptr
, prev
, offset_top
, md
, eptrb
, RM13
);
2015 if (rrc
== MATCH_ONCE
&& md
->once_target
== prev
) rrc
= MATCH_NOMATCH
;
2016 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
2017 if (*prev
== OP_ONCE
)
2019 RMATCH(eptr
, ecode
+ 1 + LINK_SIZE
, offset_top
, md
, eptrb
, RM9
);
2020 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
2021 md
->once_target
= prev
;
2022 RRETURN(MATCH_ONCE
);
2024 ecode
+= 1 + LINK_SIZE
;
2027 /* Control never gets here */
2029 /* Not multiline mode: start of subject assertion, unless notbol. */
2032 if (md
->notbol
&& eptr
== md
->start_subject
) RRETURN(MATCH_NOMATCH
);
2034 /* Start of subject assertion */
2037 if (eptr
!= md
->start_subject
) RRETURN(MATCH_NOMATCH
);
2041 /* Multiline mode: start of subject unless notbol, or after any newline. */
2044 if (md
->notbol
&& eptr
== md
->start_subject
) RRETURN(MATCH_NOMATCH
);
2045 if (eptr
!= md
->start_subject
&&
2046 (eptr
== md
->end_subject
|| !WAS_NEWLINE(eptr
)))
2047 RRETURN(MATCH_NOMATCH
);
2051 /* Start of match assertion */
2054 if (eptr
!= md
->start_subject
+ md
->start_offset
) RRETURN(MATCH_NOMATCH
);
2058 /* Reset the start of match point */
2065 /* Multiline mode: assert before any newline, or before end of subject
2066 unless noteol is set. */
2069 if (eptr
< md
->end_subject
)
2071 if (!IS_NEWLINE(eptr
))
2073 if (md
->partial
!= 0 &&
2074 eptr
+ 1 >= md
->end_subject
&&
2075 NLBLOCK
->nltype
== NLTYPE_FIXED
&&
2076 NLBLOCK
->nllen
== 2 &&
2077 *eptr
== NLBLOCK
->nl
[0])
2080 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
2082 RRETURN(MATCH_NOMATCH
);
2087 if (md
->noteol
) RRETURN(MATCH_NOMATCH
);
2093 /* Not multiline mode: assert before a terminating newline or before end of
2094 subject unless noteol is set. */
2097 if (md
->noteol
) RRETURN(MATCH_NOMATCH
);
2098 if (!md
->endonly
) goto ASSERT_NL_OR_EOS
;
2100 /* ... else fall through for endonly */
2102 /* End of subject assertion (\z) */
2105 if (eptr
< md
->end_subject
) RRETURN(MATCH_NOMATCH
);
2110 /* End of subject or ending \n assertion (\Z) */
2114 if (eptr
< md
->end_subject
&&
2115 (!IS_NEWLINE(eptr
) || eptr
!= md
->end_subject
- md
->nllen
))
2117 if (md
->partial
!= 0 &&
2118 eptr
+ 1 >= md
->end_subject
&&
2119 NLBLOCK
->nltype
== NLTYPE_FIXED
&&
2120 NLBLOCK
->nllen
== 2 &&
2121 *eptr
== NLBLOCK
->nl
[0])
2124 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
2126 RRETURN(MATCH_NOMATCH
);
2129 /* Either at end of string or \n before end. */
2135 /* Word boundary assertions */
2137 case OP_NOT_WORD_BOUNDARY
:
2138 case OP_WORD_BOUNDARY
:
2141 /* Find out if the previous and current characters are "word" characters.
2142 It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
2143 be "non-word" characters. Remember the earliest consulted character for
2144 partial matching. */
2149 /* Get status of previous character */
2151 if (eptr
== md
->start_subject
) prev_is_word
= FALSE
; else
2153 PCRE_PUCHAR lastptr
= eptr
- 1;
2155 if (lastptr
< md
->start_used_ptr
) md
->start_used_ptr
= lastptr
;
2156 GETCHAR(c
, lastptr
);
2160 if (c
== '_') prev_is_word
= TRUE
; else
2162 int cat
= UCD_CATEGORY(c
);
2163 prev_is_word
= (cat
== ucp_L
|| cat
== ucp_N
);
2168 prev_is_word
= c
< 256 && (md
->ctypes
[c
] & ctype_word
) != 0;
2171 /* Get status of next character */
2173 if (eptr
>= md
->end_subject
)
2176 cur_is_word
= FALSE
;
2184 if (c
== '_') cur_is_word
= TRUE
; else
2186 int cat
= UCD_CATEGORY(c
);
2187 cur_is_word
= (cat
== ucp_L
|| cat
== ucp_N
);
2192 cur_is_word
= c
< 256 && (md
->ctypes
[c
] & ctype_word
) != 0;
2198 /* Not in UTF-8 mode, but we may still have PCRE_UCP set, and for
2199 consistency with the behaviour of \w we do use it in this case. */
2202 /* Get status of previous character */
2204 if (eptr
== md
->start_subject
) prev_is_word
= FALSE
; else
2206 if (eptr
<= md
->start_used_ptr
) md
->start_used_ptr
= eptr
- 1;
2211 if (c
== '_') prev_is_word
= TRUE
; else
2213 int cat
= UCD_CATEGORY(c
);
2214 prev_is_word
= (cat
== ucp_L
|| cat
== ucp_N
);
2219 prev_is_word
= MAX_255(eptr
[-1])
2220 && ((md
->ctypes
[eptr
[-1]] & ctype_word
) != 0);
2223 /* Get status of next character */
2225 if (eptr
>= md
->end_subject
)
2228 cur_is_word
= FALSE
;
2235 if (c
== '_') cur_is_word
= TRUE
; else
2237 int cat
= UCD_CATEGORY(c
);
2238 cur_is_word
= (cat
== ucp_L
|| cat
== ucp_N
);
2243 cur_is_word
= MAX_255(*eptr
)
2244 && ((md
->ctypes
[*eptr
] & ctype_word
) != 0);
2247 /* Now see if the situation is what we want */
2249 if ((*ecode
++ == OP_WORD_BOUNDARY
)?
2250 cur_is_word
== prev_is_word
: cur_is_word
!= prev_is_word
)
2251 RRETURN(MATCH_NOMATCH
);
2255 /* Match any single character type except newline; have to take care with
2256 CRLF newlines and partial matching. */
2259 if (IS_NEWLINE(eptr
)) RRETURN(MATCH_NOMATCH
);
2260 if (md
->partial
!= 0 &&
2261 eptr
+ 1 >= md
->end_subject
&&
2262 NLBLOCK
->nltype
== NLTYPE_FIXED
&&
2263 NLBLOCK
->nllen
== 2 &&
2264 *eptr
== NLBLOCK
->nl
[0])
2267 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
2272 /* Match any single character whatsoever. */
2275 if (eptr
>= md
->end_subject
) /* DO NOT merge the eptr++ here; it must */
2276 { /* not be updated before SCHECK_PARTIAL. */
2278 RRETURN(MATCH_NOMATCH
);
2282 if (utf
) ACROSSCHAR(eptr
< md
->end_subject
, *eptr
, eptr
++);
2287 /* Match a single byte, even in UTF-8 mode. This opcode really does match
2288 any byte, even newline, independent of the setting of PCRE_DOTALL. */
2291 if (eptr
>= md
->end_subject
) /* DO NOT merge the eptr++ here; it must */
2292 { /* not be updated before SCHECK_PARTIAL. */
2294 RRETURN(MATCH_NOMATCH
);
2301 if (eptr
>= md
->end_subject
)
2304 RRETURN(MATCH_NOMATCH
);
2306 GETCHARINCTEST(c
, eptr
);
2308 #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2311 (md
->ctypes
[c
] & ctype_digit
) != 0
2313 RRETURN(MATCH_NOMATCH
);
2318 if (eptr
>= md
->end_subject
)
2321 RRETURN(MATCH_NOMATCH
);
2323 GETCHARINCTEST(c
, eptr
);
2325 #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2328 (md
->ctypes
[c
] & ctype_digit
) == 0
2330 RRETURN(MATCH_NOMATCH
);
2334 case OP_NOT_WHITESPACE
:
2335 if (eptr
>= md
->end_subject
)
2338 RRETURN(MATCH_NOMATCH
);
2340 GETCHARINCTEST(c
, eptr
);
2342 #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2345 (md
->ctypes
[c
] & ctype_space
) != 0
2347 RRETURN(MATCH_NOMATCH
);
2352 if (eptr
>= md
->end_subject
)
2355 RRETURN(MATCH_NOMATCH
);
2357 GETCHARINCTEST(c
, eptr
);
2359 #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2362 (md
->ctypes
[c
] & ctype_space
) == 0
2364 RRETURN(MATCH_NOMATCH
);
2368 case OP_NOT_WORDCHAR
:
2369 if (eptr
>= md
->end_subject
)
2372 RRETURN(MATCH_NOMATCH
);
2374 GETCHARINCTEST(c
, eptr
);
2376 #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2379 (md
->ctypes
[c
] & ctype_word
) != 0
2381 RRETURN(MATCH_NOMATCH
);
2386 if (eptr
>= md
->end_subject
)
2389 RRETURN(MATCH_NOMATCH
);
2391 GETCHARINCTEST(c
, eptr
);
2393 #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2396 (md
->ctypes
[c
] & ctype_word
) == 0
2398 RRETURN(MATCH_NOMATCH
);
2403 if (eptr
>= md
->end_subject
)
2406 RRETURN(MATCH_NOMATCH
);
2408 GETCHARINCTEST(c
, eptr
);
2411 default: RRETURN(MATCH_NOMATCH
);
2414 if (eptr
>= md
->end_subject
)
2418 else if (*eptr
== 0x0a) eptr
++;
2429 if (md
->bsr_anycrlf
) RRETURN(MATCH_NOMATCH
);
2436 if (eptr
>= md
->end_subject
)
2439 RRETURN(MATCH_NOMATCH
);
2441 GETCHARINCTEST(c
, eptr
);
2446 case 0x20: /* SPACE */
2447 case 0xa0: /* NBSP */
2448 case 0x1680: /* OGHAM SPACE MARK */
2449 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
2450 case 0x2000: /* EN QUAD */
2451 case 0x2001: /* EM QUAD */
2452 case 0x2002: /* EN SPACE */
2453 case 0x2003: /* EM SPACE */
2454 case 0x2004: /* THREE-PER-EM SPACE */
2455 case 0x2005: /* FOUR-PER-EM SPACE */
2456 case 0x2006: /* SIX-PER-EM SPACE */
2457 case 0x2007: /* FIGURE SPACE */
2458 case 0x2008: /* PUNCTUATION SPACE */
2459 case 0x2009: /* THIN SPACE */
2460 case 0x200A: /* HAIR SPACE */
2461 case 0x202f: /* NARROW NO-BREAK SPACE */
2462 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
2463 case 0x3000: /* IDEOGRAPHIC SPACE */
2464 RRETURN(MATCH_NOMATCH
);
2470 if (eptr
>= md
->end_subject
)
2473 RRETURN(MATCH_NOMATCH
);
2475 GETCHARINCTEST(c
, eptr
);
2478 default: RRETURN(MATCH_NOMATCH
);
2480 case 0x20: /* SPACE */
2481 case 0xa0: /* NBSP */
2482 case 0x1680: /* OGHAM SPACE MARK */
2483 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
2484 case 0x2000: /* EN QUAD */
2485 case 0x2001: /* EM QUAD */
2486 case 0x2002: /* EN SPACE */
2487 case 0x2003: /* EM SPACE */
2488 case 0x2004: /* THREE-PER-EM SPACE */
2489 case 0x2005: /* FOUR-PER-EM SPACE */
2490 case 0x2006: /* SIX-PER-EM SPACE */
2491 case 0x2007: /* FIGURE SPACE */
2492 case 0x2008: /* PUNCTUATION SPACE */
2493 case 0x2009: /* THIN SPACE */
2494 case 0x200A: /* HAIR SPACE */
2495 case 0x202f: /* NARROW NO-BREAK SPACE */
2496 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
2497 case 0x3000: /* IDEOGRAPHIC SPACE */
2504 if (eptr
>= md
->end_subject
)
2507 RRETURN(MATCH_NOMATCH
);
2509 GETCHARINCTEST(c
, eptr
);
2517 case 0x85: /* NEL */
2518 case 0x2028: /* LINE SEPARATOR */
2519 case 0x2029: /* PARAGRAPH SEPARATOR */
2520 RRETURN(MATCH_NOMATCH
);
2526 if (eptr
>= md
->end_subject
)
2529 RRETURN(MATCH_NOMATCH
);
2531 GETCHARINCTEST(c
, eptr
);
2534 default: RRETURN(MATCH_NOMATCH
);
2539 case 0x85: /* NEL */
2540 case 0x2028: /* LINE SEPARATOR */
2541 case 0x2029: /* PARAGRAPH SEPARATOR */
2548 /* Check the next character by Unicode property. We will get here only
2549 if the support is in the binary; otherwise a compile-time error occurs. */
2553 if (eptr
>= md
->end_subject
)
2556 RRETURN(MATCH_NOMATCH
);
2558 GETCHARINCTEST(c
, eptr
);
2560 const pcre_uint8 chartype
= UCD_CHARTYPE(c
);
2565 if (op
== OP_NOTPROP
) RRETURN(MATCH_NOMATCH
);
2569 if ((chartype
== ucp_Lu
||
2570 chartype
== ucp_Ll
||
2571 chartype
== ucp_Lt
) == (op
== OP_NOTPROP
))
2572 RRETURN(MATCH_NOMATCH
);
2576 if ((ecode
[2] != PRIV(ucp_gentype
)[chartype
]) == (op
== OP_PROP
))
2577 RRETURN(MATCH_NOMATCH
);
2581 if ((ecode
[2] != chartype
) == (op
== OP_PROP
))
2582 RRETURN(MATCH_NOMATCH
);
2586 if ((ecode
[2] != UCD_SCRIPT(c
)) == (op
== OP_PROP
))
2587 RRETURN(MATCH_NOMATCH
);
2590 /* These are specials */
2593 if ((PRIV(ucp_gentype
)[chartype
] == ucp_L
||
2594 PRIV(ucp_gentype
)[chartype
] == ucp_N
) == (op
== OP_NOTPROP
))
2595 RRETURN(MATCH_NOMATCH
);
2598 case PT_SPACE
: /* Perl space */
2599 if ((PRIV(ucp_gentype
)[chartype
] == ucp_Z
||
2600 c
== CHAR_HT
|| c
== CHAR_NL
|| c
== CHAR_FF
|| c
== CHAR_CR
)
2601 == (op
== OP_NOTPROP
))
2602 RRETURN(MATCH_NOMATCH
);
2605 case PT_PXSPACE
: /* POSIX space */
2606 if ((PRIV(ucp_gentype
)[chartype
] == ucp_Z
||
2607 c
== CHAR_HT
|| c
== CHAR_NL
|| c
== CHAR_VT
||
2608 c
== CHAR_FF
|| c
== CHAR_CR
)
2609 == (op
== OP_NOTPROP
))
2610 RRETURN(MATCH_NOMATCH
);
2614 if ((PRIV(ucp_gentype
)[chartype
] == ucp_L
||
2615 PRIV(ucp_gentype
)[chartype
] == ucp_N
||
2616 c
== CHAR_UNDERSCORE
) == (op
== OP_NOTPROP
))
2617 RRETURN(MATCH_NOMATCH
);
2620 /* This should never occur */
2623 RRETURN(PCRE_ERROR_INTERNAL
);
2630 /* Match an extended Unicode sequence. We will get here only if the support
2631 is in the binary; otherwise a compile-time error occurs. */
2634 if (eptr
>= md
->end_subject
)
2637 RRETURN(MATCH_NOMATCH
);
2639 GETCHARINCTEST(c
, eptr
);
2640 if (UCD_CATEGORY(c
) == ucp_M
) RRETURN(MATCH_NOMATCH
);
2641 while (eptr
< md
->end_subject
)
2644 if (!utf
) c
= *eptr
; else { GETCHARLEN(c
, eptr
, len
); }
2645 if (UCD_CATEGORY(c
) != ucp_M
) break;
2654 /* Match a back reference, possibly repeatedly. Look past the end of the
2655 item to see if there is repeat information following. The code is similar
2656 to that for character classes, but repeated for efficiency. Then obey
2657 similar code to character type repeats - written out again for speed.
2658 However, if the referenced string is the empty string, always treat
2659 it as matched, any number of times (otherwise there could be infinite
2664 caseless
= op
== OP_REFI
;
2665 offset
= GET2(ecode
, 1) << 1; /* Doubled ref number */
2666 ecode
+= 1 + IMM2_SIZE
;
2668 /* If the reference is unset, there are two possibilities:
2670 (a) In the default, Perl-compatible state, set the length negative;
2671 this ensures that every attempt at a match fails. We can't just fail
2672 here, because of the possibility of quantifiers with zero minima.
2674 (b) If the JavaScript compatibility flag is set, set the length to zero
2675 so that the back reference matches an empty string.
2677 Otherwise, set the length to the length of what was matched by the
2678 referenced subpattern. */
2680 if (offset
>= offset_top
|| md
->offset_vector
[offset
] < 0)
2681 length
= (md
->jscript_compat
)? 0 : -1;
2683 length
= md
->offset_vector
[offset
+1] - md
->offset_vector
[offset
];
2685 /* Set up for repetition, or handle the non-repeated case */
2695 c
= *ecode
++ - OP_CRSTAR
;
2696 minimize
= (c
& 1) != 0;
2697 min
= rep_min
[c
]; /* Pick up values from tables; */
2698 max
= rep_max
[c
]; /* zero for max => infinity */
2699 if (max
== 0) max
= INT_MAX
;
2704 minimize
= (*ecode
== OP_CRMINRANGE
);
2705 min
= GET2(ecode
, 1);
2706 max
= GET2(ecode
, 1 + IMM2_SIZE
);
2707 if (max
== 0) max
= INT_MAX
;
2708 ecode
+= 1 + 2 * IMM2_SIZE
;
2711 default: /* No repeat follows */
2712 if ((length
= match_ref(offset
, eptr
, length
, md
, caseless
)) < 0)
2714 if (length
== -2) eptr
= md
->end_subject
; /* Partial match */
2716 RRETURN(MATCH_NOMATCH
);
2719 continue; /* With the main loop */
2722 /* Handle repeated back references. If the length of the reference is
2723 zero, just continue with the main loop. If the length is negative, it
2724 means the reference is unset in non-Java-compatible mode. If the minimum is
2725 zero, we can continue at the same level without recursion. For any other
2726 minimum, carrying on will result in NOMATCH. */
2728 if (length
== 0) continue;
2729 if (length
< 0 && min
== 0) continue;
2731 /* First, ensure the minimum number of matches are present. We get back
2732 the length of the reference string explicitly rather than passing the
2733 address of eptr, so that eptr can be a register variable. */
2735 for (i
= 1; i
<= min
; i
++)
2738 if ((slength
= match_ref(offset
, eptr
, length
, md
, caseless
)) < 0)
2740 if (slength
== -2) eptr
= md
->end_subject
; /* Partial match */
2742 RRETURN(MATCH_NOMATCH
);
2747 /* If min = max, continue at the same level without recursion.
2748 They are not both allowed to be zero. */
2750 if (min
== max
) continue;
2752 /* If minimizing, keep trying and advancing the pointer */
2756 for (fi
= min
;; fi
++)
2759 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM14
);
2760 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
2761 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
2762 if ((slength
= match_ref(offset
, eptr
, length
, md
, caseless
)) < 0)
2764 if (slength
== -2) eptr
= md
->end_subject
; /* Partial match */
2766 RRETURN(MATCH_NOMATCH
);
2770 /* Control never gets here */
2773 /* If maximizing, find the longest string and work backwards */
2778 for (i
= min
; i
< max
; i
++)
2781 if ((slength
= match_ref(offset
, eptr
, length
, md
, caseless
)) < 0)
2783 /* Can't use CHECK_PARTIAL because we don't want to update eptr in
2784 the soft partial matching case. */
2786 if (slength
== -2 && md
->partial
!= 0 &&
2787 md
->end_subject
> md
->start_used_ptr
)
2790 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
2799 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM15
);
2800 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
2803 RRETURN(MATCH_NOMATCH
);
2805 /* Control never gets here */
2807 /* Match a bit-mapped character class, possibly repeatedly. This op code is
2808 used when all the characters in the class have values in the range 0-255,
2809 and either the matching is caseful, or the characters are in the range
2810 0-127 when UTF-8 processing is enabled. The only difference between
2811 OP_CLASS and OP_NCLASS occurs when a data character outside the range is
2814 First, look past the end of the item to see if there is repeat information
2815 following. Then obey similar code to character type repeats - written out
2821 /* The data variable is saved across frames, so the byte map needs to
2823 #define BYTE_MAP ((pcre_uint8 *)data)
2824 data
= ecode
+ 1; /* Save for matching */
2825 ecode
+= 1 + (32 / sizeof(pcre_uchar
)); /* Advance past the item */
2835 c
= *ecode
++ - OP_CRSTAR
;
2836 minimize
= (c
& 1) != 0;
2837 min
= rep_min
[c
]; /* Pick up values from tables; */
2838 max
= rep_max
[c
]; /* zero for max => infinity */
2839 if (max
== 0) max
= INT_MAX
;
2844 minimize
= (*ecode
== OP_CRMINRANGE
);
2845 min
= GET2(ecode
, 1);
2846 max
= GET2(ecode
, 1 + IMM2_SIZE
);
2847 if (max
== 0) max
= INT_MAX
;
2848 ecode
+= 1 + 2 * IMM2_SIZE
;
2851 default: /* No repeat follows */
2856 /* First, ensure the minimum number of matches are present. */
2861 for (i
= 1; i
<= min
; i
++)
2863 if (eptr
>= md
->end_subject
)
2866 RRETURN(MATCH_NOMATCH
);
2868 GETCHARINC(c
, eptr
);
2871 if (op
== OP_CLASS
) RRETURN(MATCH_NOMATCH
);
2874 if ((BYTE_MAP
[c
/8] & (1 << (c
&7))) == 0) RRETURN(MATCH_NOMATCH
);
2881 for (i
= 1; i
<= min
; i
++)
2883 if (eptr
>= md
->end_subject
)
2886 RRETURN(MATCH_NOMATCH
);
2889 #ifndef COMPILE_PCRE8
2892 if (op
== OP_CLASS
) RRETURN(MATCH_NOMATCH
);
2896 if ((BYTE_MAP
[c
/8] & (1 << (c
&7))) == 0) RRETURN(MATCH_NOMATCH
);
2900 /* If max == min we can continue with the main loop without the
2903 if (min
== max
) continue;
2905 /* If minimizing, keep testing the rest of the expression and advancing
2906 the pointer while it matches the class. */
2913 for (fi
= min
;; fi
++)
2915 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM16
);
2916 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
2917 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
2918 if (eptr
>= md
->end_subject
)
2921 RRETURN(MATCH_NOMATCH
);
2923 GETCHARINC(c
, eptr
);
2926 if (op
== OP_CLASS
) RRETURN(MATCH_NOMATCH
);
2929 if ((BYTE_MAP
[c
/8] & (1 << (c
&7))) == 0) RRETURN(MATCH_NOMATCH
);
2936 for (fi
= min
;; fi
++)
2938 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM17
);
2939 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
2940 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
2941 if (eptr
>= md
->end_subject
)
2944 RRETURN(MATCH_NOMATCH
);
2947 #ifndef COMPILE_PCRE8
2950 if (op
== OP_CLASS
) RRETURN(MATCH_NOMATCH
);
2954 if ((BYTE_MAP
[c
/8] & (1 << (c
&7))) == 0) RRETURN(MATCH_NOMATCH
);
2957 /* Control never gets here */
2960 /* If maximizing, find the longest possible run, then work backwards. */
2969 for (i
= min
; i
< max
; i
++)
2972 if (eptr
>= md
->end_subject
)
2977 GETCHARLEN(c
, eptr
, len
);
2980 if (op
== OP_CLASS
) break;
2983 if ((BYTE_MAP
[c
/8] & (1 << (c
&7))) == 0) break;
2988 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM18
);
2989 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
2990 if (eptr
-- == pp
) break; /* Stop if tried at original pos */
2998 for (i
= min
; i
< max
; i
++)
3000 if (eptr
>= md
->end_subject
)
3006 #ifndef COMPILE_PCRE8
3009 if (op
== OP_CLASS
) break;
3013 if ((BYTE_MAP
[c
/8] & (1 << (c
&7))) == 0) break;
3018 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM19
);
3019 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3024 RRETURN(MATCH_NOMATCH
);
3028 /* Control never gets here */
3031 /* Match an extended character class. This opcode is encountered only
3032 when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
3033 mode, because Unicode properties are supported in non-UTF-8 mode. */
3035 #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3038 data
= ecode
+ 1 + LINK_SIZE
; /* Save for matching */
3039 ecode
+= GET(ecode
, 1); /* Advance past the item */
3049 c
= *ecode
++ - OP_CRSTAR
;
3050 minimize
= (c
& 1) != 0;
3051 min
= rep_min
[c
]; /* Pick up values from tables; */
3052 max
= rep_max
[c
]; /* zero for max => infinity */
3053 if (max
== 0) max
= INT_MAX
;
3058 minimize
= (*ecode
== OP_CRMINRANGE
);
3059 min
= GET2(ecode
, 1);
3060 max
= GET2(ecode
, 1 + IMM2_SIZE
);
3061 if (max
== 0) max
= INT_MAX
;
3062 ecode
+= 1 + 2 * IMM2_SIZE
;
3065 default: /* No repeat follows */
3070 /* First, ensure the minimum number of matches are present. */
3072 for (i
= 1; i
<= min
; i
++)
3074 if (eptr
>= md
->end_subject
)
3077 RRETURN(MATCH_NOMATCH
);
3079 GETCHARINCTEST(c
, eptr
);
3080 if (!PRIV(xclass
)(c
, data
, utf
)) RRETURN(MATCH_NOMATCH
);
3083 /* If max == min we can continue with the main loop without the
3086 if (min
== max
) continue;
3088 /* If minimizing, keep testing the rest of the expression and advancing
3089 the pointer while it matches the class. */
3093 for (fi
= min
;; fi
++)
3095 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM20
);
3096 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3097 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
3098 if (eptr
>= md
->end_subject
)
3101 RRETURN(MATCH_NOMATCH
);
3103 GETCHARINCTEST(c
, eptr
);
3104 if (!PRIV(xclass
)(c
, data
, utf
)) RRETURN(MATCH_NOMATCH
);
3106 /* Control never gets here */
3109 /* If maximizing, find the longest possible run, then work backwards. */
3114 for (i
= min
; i
< max
; i
++)
3117 if (eptr
>= md
->end_subject
)
3123 GETCHARLENTEST(c
, eptr
, len
);
3127 if (!PRIV(xclass
)(c
, data
, utf
)) break;
3132 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM21
);
3133 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3134 if (eptr
-- == pp
) break; /* Stop if tried at original pos */
3136 if (utf
) BACKCHAR(eptr
);
3139 RRETURN(MATCH_NOMATCH
);
3142 /* Control never gets here */
3144 #endif /* End of XCLASS */
3146 /* Match a single character, casefully */
3154 GETCHARLEN(fc
, ecode
, length
);
3155 if (length
> md
->end_subject
- eptr
)
3157 CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */
3158 RRETURN(MATCH_NOMATCH
);
3160 while (length
-- > 0) if (*ecode
++ != *eptr
++) RRETURN(MATCH_NOMATCH
);
3166 if (md
->end_subject
- eptr
< 1)
3168 SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */
3169 RRETURN(MATCH_NOMATCH
);
3171 if (ecode
[1] != *eptr
++) RRETURN(MATCH_NOMATCH
);
3176 /* Match a single character, caselessly. If we are at the end of the
3177 subject, give up immediately. */
3180 if (eptr
>= md
->end_subject
)
3183 RRETURN(MATCH_NOMATCH
);
3191 GETCHARLEN(fc
, ecode
, length
);
3193 /* If the pattern character's value is < 128, we have only one byte, and
3194 we know that its other case must also be one byte long, so we can use the
3195 fast lookup table. We know that there is at least one byte left in the
3201 != TABLE_GET(*eptr
, md
->lcc
, *eptr
)) RRETURN(MATCH_NOMATCH
);
3206 /* Otherwise we must pick up the subject character. Note that we cannot
3207 use the value of "length" to check for sufficient bytes left, because the
3208 other case of the character may have more or fewer bytes. */
3213 GETCHARINC(dc
, eptr
);
3216 /* If we have Unicode property support, we can use it to test the other
3217 case of the character, if there is one. */
3222 if (dc
!= UCD_OTHERCASE(fc
))
3224 RRETURN(MATCH_NOMATCH
);
3229 #endif /* SUPPORT_UTF */
3233 if (TABLE_GET(ecode
[1], md
->lcc
, ecode
[1])
3234 != TABLE_GET(*eptr
, md
->lcc
, *eptr
)) RRETURN(MATCH_NOMATCH
);
3240 /* Match a single character repeatedly. */
3244 min
= max
= GET2(ecode
, 1);
3245 ecode
+= 1 + IMM2_SIZE
;
3258 max
= GET2(ecode
, 1);
3259 minimize
= *ecode
== OP_MINUPTO
|| *ecode
== OP_MINUPTOI
;
3260 ecode
+= 1 + IMM2_SIZE
;
3299 c
= *ecode
++ - ((op
< OP_STARI
)? OP_STAR
: OP_STARI
);
3300 minimize
= (c
& 1) != 0;
3301 min
= rep_min
[c
]; /* Pick up values from tables; */
3302 max
= rep_max
[c
]; /* zero for max => infinity */
3303 if (max
== 0) max
= INT_MAX
;
3305 /* Common code for all repeated single-character matches. */
3313 GETCHARLEN(fc
, ecode
, length
);
3316 /* Handle multibyte character matching specially here. There is
3317 support for caseless matching if UCP support is present. */
3322 unsigned int othercase
;
3323 if (op
>= OP_STARI
&& /* Caseless */
3324 (othercase
= UCD_OTHERCASE(fc
)) != fc
)
3325 oclength
= PRIV(ord2utf
)(othercase
, occhars
);
3327 #endif /* SUPPORT_UCP */
3329 for (i
= 1; i
<= min
; i
++)
3331 if (eptr
<= md
->end_subject
- length
&&
3332 memcmp(eptr
, charptr
, IN_UCHARS(length
)) == 0) eptr
+= length
;
3334 else if (oclength
> 0 &&
3335 eptr
<= md
->end_subject
- oclength
&&
3336 memcmp(eptr
, occhars
, IN_UCHARS(oclength
)) == 0) eptr
+= oclength
;
3337 #endif /* SUPPORT_UCP */
3341 RRETURN(MATCH_NOMATCH
);
3345 if (min
== max
) continue;
3349 for (fi
= min
;; fi
++)
3351 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM22
);
3352 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3353 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
3354 if (eptr
<= md
->end_subject
- length
&&
3355 memcmp(eptr
, charptr
, IN_UCHARS(length
)) == 0) eptr
+= length
;
3357 else if (oclength
> 0 &&
3358 eptr
<= md
->end_subject
- oclength
&&
3359 memcmp(eptr
, occhars
, IN_UCHARS(oclength
)) == 0) eptr
+= oclength
;
3360 #endif /* SUPPORT_UCP */
3364 RRETURN(MATCH_NOMATCH
);
3367 /* Control never gets here */
3373 for (i
= min
; i
< max
; i
++)
3375 if (eptr
<= md
->end_subject
- length
&&
3376 memcmp(eptr
, charptr
, IN_UCHARS(length
)) == 0) eptr
+= length
;
3378 else if (oclength
> 0 &&
3379 eptr
<= md
->end_subject
- oclength
&&
3380 memcmp(eptr
, occhars
, IN_UCHARS(oclength
)) == 0) eptr
+= oclength
;
3381 #endif /* SUPPORT_UCP */
3389 if (possessive
) continue;
3393 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM23
);
3394 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3395 if (eptr
== pp
) { RRETURN(MATCH_NOMATCH
); }
3399 #else /* without SUPPORT_UCP */
3401 #endif /* SUPPORT_UCP */
3404 /* Control never gets here */
3407 /* If the length of a UTF-8 character is 1, we fall through here, and
3408 obey the code as for non-UTF-8 characters below, though in this case the
3409 value of fc will always be < 128. */
3412 #endif /* SUPPORT_UTF */
3413 /* When not in UTF-8 mode, load a single-byte character. */
3416 /* The value of fc at this point is always one character, though we may
3417 or may not be in UTF mode. The code is duplicated for the caseless and
3418 caseful cases, for speed, since matching characters is likely to be quite
3419 common. First, ensure the minimum number of matches are present. If min =
3420 max, continue at the same level without recursing. Otherwise, if
3421 minimizing, keep trying the rest of the expression and advancing one
3422 matching character if failing, up to the maximum. Alternatively, if
3423 maximizing, find the maximum number of characters and work backwards. */
3425 DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc
, min
, max
,
3426 max
, (char *)eptr
));
3428 if (op
>= OP_STARI
) /* Caseless */
3430 #ifdef COMPILE_PCRE8
3431 /* fc must be < 128 if UTF is enabled. */
3436 if (utf
&& fc
> 127)
3437 foc
= UCD_OTHERCASE(fc
);
3439 if (utf
&& fc
> 127)
3441 #endif /* SUPPORT_UCP */
3443 #endif /* SUPPORT_UTF */
3444 foc
= TABLE_GET(fc
, md
->fcc
, fc
);
3445 #endif /* COMPILE_PCRE8 */
3447 for (i
= 1; i
<= min
; i
++)
3449 if (eptr
>= md
->end_subject
)
3452 RRETURN(MATCH_NOMATCH
);
3454 if (fc
!= *eptr
&& foc
!= *eptr
) RRETURN(MATCH_NOMATCH
);
3457 if (min
== max
) continue;
3460 for (fi
= min
;; fi
++)
3462 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM24
);
3463 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3464 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
3465 if (eptr
>= md
->end_subject
)
3468 RRETURN(MATCH_NOMATCH
);
3470 if (fc
!= *eptr
&& foc
!= *eptr
) RRETURN(MATCH_NOMATCH
);
3473 /* Control never gets here */
3478 for (i
= min
; i
< max
; i
++)
3480 if (eptr
>= md
->end_subject
)
3485 if (fc
!= *eptr
&& foc
!= *eptr
) break;
3489 if (possessive
) continue;
3493 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM25
);
3495 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3497 RRETURN(MATCH_NOMATCH
);
3499 /* Control never gets here */
3502 /* Caseful comparisons (includes all multi-byte characters) */
3506 for (i
= 1; i
<= min
; i
++)
3508 if (eptr
>= md
->end_subject
)
3511 RRETURN(MATCH_NOMATCH
);
3513 if (fc
!= *eptr
++) RRETURN(MATCH_NOMATCH
);
3516 if (min
== max
) continue;
3520 for (fi
= min
;; fi
++)
3522 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM26
);
3523 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3524 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
3525 if (eptr
>= md
->end_subject
)
3528 RRETURN(MATCH_NOMATCH
);
3530 if (fc
!= *eptr
++) RRETURN(MATCH_NOMATCH
);
3532 /* Control never gets here */
3537 for (i
= min
; i
< max
; i
++)
3539 if (eptr
>= md
->end_subject
)
3544 if (fc
!= *eptr
) break;
3547 if (possessive
) continue;
3551 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM27
);
3553 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3555 RRETURN(MATCH_NOMATCH
);
3558 /* Control never gets here */
3560 /* Match a negated single one-byte character. The character we are
3561 checking can be multibyte. */
3565 if (eptr
>= md
->end_subject
)
3568 RRETURN(MATCH_NOMATCH
);
3573 unsigned int ch
, och
;
3576 GETCHARINC(ch
, ecode
);
3577 GETCHARINC(c
, eptr
);
3581 if (ch
== c
) RRETURN(MATCH_NOMATCH
);
3587 och
= UCD_OTHERCASE(ch
);
3591 #endif /* SUPPORT_UCP */
3593 och
= TABLE_GET(ch
, md
->fcc
, ch
);
3594 if (ch
== c
|| och
== c
) RRETURN(MATCH_NOMATCH
);
3600 unsigned int ch
= ecode
[1];
3602 if (ch
== c
|| (op
== OP_NOTI
&& TABLE_GET(ch
, md
->fcc
, ch
) == c
))
3603 RRETURN(MATCH_NOMATCH
);
3608 /* Match a negated single one-byte character repeatedly. This is almost a
3609 repeat of the code for a repeated single character, but I haven't found a
3610 nice way of commoning these up that doesn't require a test of the
3611 positive/negative option for each character match. Maybe that wouldn't add
3612 very much to the time taken, but character matching *is* what this is all
3617 min
= max
= GET2(ecode
, 1);
3618 ecode
+= 1 + IMM2_SIZE
;
3624 case OP_NOTMINUPTOI
:
3626 max
= GET2(ecode
, 1);
3627 minimize
= *ecode
== OP_NOTMINUPTO
|| *ecode
== OP_NOTMINUPTOI
;
3628 ecode
+= 1 + IMM2_SIZE
;
3632 case OP_NOTPOSSTARI
:
3640 case OP_NOTPOSPLUSI
:
3647 case OP_NOTPOSQUERY
:
3648 case OP_NOTPOSQUERYI
:
3656 case OP_NOTPOSUPTOI
:
3659 max
= GET2(ecode
, 1);
3660 ecode
+= 1 + IMM2_SIZE
;
3666 case OP_NOTMINSTARI
:
3670 case OP_NOTMINPLUSI
:
3673 case OP_NOTMINQUERY
:
3674 case OP_NOTMINQUERYI
:
3675 c
= *ecode
++ - ((op
>= OP_NOTSTARI
)? OP_NOTSTARI
: OP_NOTSTAR
);
3676 minimize
= (c
& 1) != 0;
3677 min
= rep_min
[c
]; /* Pick up values from tables; */
3678 max
= rep_max
[c
]; /* zero for max => infinity */
3679 if (max
== 0) max
= INT_MAX
;
3681 /* Common code for all repeated single-byte matches. */
3684 GETCHARINCTEST(fc
, ecode
);
3686 /* The code is duplicated for the caseless and caseful cases, for speed,
3687 since matching characters is likely to be quite common. First, ensure the
3688 minimum number of matches are present. If min = max, continue at the same
3689 level without recursing. Otherwise, if minimizing, keep trying the rest of
3690 the expression and advancing one matching character if failing, up to the
3691 maximum. Alternatively, if maximizing, find the maximum number of
3692 characters and work backwards. */
3694 DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc
, min
, max
,
3695 max
, (char *)eptr
));
3697 if (op
>= OP_NOTSTARI
) /* Caseless */
3701 if (utf
&& fc
> 127)
3702 foc
= UCD_OTHERCASE(fc
);
3704 if (utf
&& fc
> 127)
3706 #endif /* SUPPORT_UCP */
3708 #endif /* SUPPORT_UTF */
3709 foc
= TABLE_GET(fc
, md
->fcc
, fc
);
3715 for (i
= 1; i
<= min
; i
++)
3717 if (eptr
>= md
->end_subject
)
3720 RRETURN(MATCH_NOMATCH
);
3722 GETCHARINC(d
, eptr
);
3723 if (fc
== d
|| (unsigned int)foc
== d
) RRETURN(MATCH_NOMATCH
);
3730 for (i
= 1; i
<= min
; i
++)
3732 if (eptr
>= md
->end_subject
)
3735 RRETURN(MATCH_NOMATCH
);
3737 if (fc
== *eptr
|| foc
== *eptr
) RRETURN(MATCH_NOMATCH
);
3742 if (min
== max
) continue;
3750 for (fi
= min
;; fi
++)
3752 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM28
);
3753 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3754 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
3755 if (eptr
>= md
->end_subject
)
3758 RRETURN(MATCH_NOMATCH
);
3760 GETCHARINC(d
, eptr
);
3761 if (fc
== d
|| (unsigned int)foc
== d
) RRETURN(MATCH_NOMATCH
);
3768 for (fi
= min
;; fi
++)
3770 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM29
);
3771 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3772 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
3773 if (eptr
>= md
->end_subject
)
3776 RRETURN(MATCH_NOMATCH
);
3778 if (fc
== *eptr
|| foc
== *eptr
) RRETURN(MATCH_NOMATCH
);
3782 /* Control never gets here */
3795 for (i
= min
; i
< max
; i
++)
3798 if (eptr
>= md
->end_subject
)
3803 GETCHARLEN(d
, eptr
, len
);
3804 if (fc
== d
|| (unsigned int)foc
== d
) break;
3807 if (possessive
) continue;
3810 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM30
);
3811 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3812 if (eptr
-- == pp
) break; /* Stop if tried at original pos */
3820 for (i
= min
; i
< max
; i
++)
3822 if (eptr
>= md
->end_subject
)
3827 if (fc
== *eptr
|| foc
== *eptr
) break;
3830 if (possessive
) continue;
3833 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM31
);
3834 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3839 RRETURN(MATCH_NOMATCH
);
3841 /* Control never gets here */
3844 /* Caseful comparisons */
3852 for (i
= 1; i
<= min
; i
++)
3854 if (eptr
>= md
->end_subject
)
3857 RRETURN(MATCH_NOMATCH
);
3859 GETCHARINC(d
, eptr
);
3860 if (fc
== d
) RRETURN(MATCH_NOMATCH
);
3867 for (i
= 1; i
<= min
; i
++)
3869 if (eptr
>= md
->end_subject
)
3872 RRETURN(MATCH_NOMATCH
);
3874 if (fc
== *eptr
++) RRETURN(MATCH_NOMATCH
);
3878 if (min
== max
) continue;
3886 for (fi
= min
;; fi
++)
3888 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM32
);
3889 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3890 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
3891 if (eptr
>= md
->end_subject
)
3894 RRETURN(MATCH_NOMATCH
);
3896 GETCHARINC(d
, eptr
);
3897 if (fc
== d
) RRETURN(MATCH_NOMATCH
);
3904 for (fi
= min
;; fi
++)
3906 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM33
);
3907 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3908 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
3909 if (eptr
>= md
->end_subject
)
3912 RRETURN(MATCH_NOMATCH
);
3914 if (fc
== *eptr
++) RRETURN(MATCH_NOMATCH
);
3917 /* Control never gets here */
3930 for (i
= min
; i
< max
; i
++)
3933 if (eptr
>= md
->end_subject
)
3938 GETCHARLEN(d
, eptr
, len
);
3942 if (possessive
) continue;
3945 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM34
);
3946 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3947 if (eptr
-- == pp
) break; /* Stop if tried at original pos */
3955 for (i
= min
; i
< max
; i
++)
3957 if (eptr
>= md
->end_subject
)
3962 if (fc
== *eptr
) break;
3965 if (possessive
) continue;
3968 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM35
);
3969 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
3974 RRETURN(MATCH_NOMATCH
);
3977 /* Control never gets here */
3979 /* Match a single character type repeatedly; several different opcodes
3980 share code. This is very similar to the code for single characters, but we
3981 repeat it in the interests of efficiency. */
3984 min
= max
= GET2(ecode
, 1);
3986 ecode
+= 1 + IMM2_SIZE
;
3990 case OP_TYPEMINUPTO
:
3992 max
= GET2(ecode
, 1);
3993 minimize
= *ecode
== OP_TYPEMINUPTO
;
3994 ecode
+= 1 + IMM2_SIZE
;
3997 case OP_TYPEPOSSTAR
:
4004 case OP_TYPEPOSPLUS
:
4011 case OP_TYPEPOSQUERY
:
4018 case OP_TYPEPOSUPTO
:
4021 max
= GET2(ecode
, 1);
4022 ecode
+= 1 + IMM2_SIZE
;
4026 case OP_TYPEMINSTAR
:
4028 case OP_TYPEMINPLUS
:
4030 case OP_TYPEMINQUERY
:
4031 c
= *ecode
++ - OP_TYPESTAR
;
4032 minimize
= (c
& 1) != 0;
4033 min
= rep_min
[c
]; /* Pick up values from tables; */
4034 max
= rep_max
[c
]; /* zero for max => infinity */
4035 if (max
== 0) max
= INT_MAX
;
4037 /* Common code for all repeated single character type matches. Note that
4038 in UTF-8 mode, '.' matches a character of any length, but for the other
4039 character types, the valid characters are all one-byte long. */
4042 ctype
= *ecode
++; /* Code for the character type */
4045 if (ctype
== OP_PROP
|| ctype
== OP_NOTPROP
)
4047 prop_fail_result
= ctype
== OP_NOTPROP
;
4048 prop_type
= *ecode
++;
4049 prop_value
= *ecode
++;
4051 else prop_type
= -1;
4054 /* First, ensure the minimum number of matches are present. Use inline
4055 code for maximizing the speed, and do the type test once at the start
4056 (i.e. keep it out of the loop). Separate the UTF-8 code completely as that
4057 is tidier. Also separate the UCP code, which can be the same for both UTF-8
4058 and single-bytes. */
4068 if (prop_fail_result
) RRETURN(MATCH_NOMATCH
);
4069 for (i
= 1; i
<= min
; i
++)
4071 if (eptr
>= md
->end_subject
)
4074 RRETURN(MATCH_NOMATCH
);
4076 GETCHARINCTEST(c
, eptr
);
4081 for (i
= 1; i
<= min
; i
++)
4084 if (eptr
>= md
->end_subject
)
4087 RRETURN(MATCH_NOMATCH
);
4089 GETCHARINCTEST(c
, eptr
);
4090 chartype
= UCD_CHARTYPE(c
);
4091 if ((chartype
== ucp_Lu
||
4092 chartype
== ucp_Ll
||
4093 chartype
== ucp_Lt
) == prop_fail_result
)
4094 RRETURN(MATCH_NOMATCH
);
4099 for (i
= 1; i
<= min
; i
++)
4101 if (eptr
>= md
->end_subject
)
4104 RRETURN(MATCH_NOMATCH
);
4106 GETCHARINCTEST(c
, eptr
);
4107 if ((UCD_CATEGORY(c
) == prop_value
) == prop_fail_result
)
4108 RRETURN(MATCH_NOMATCH
);
4113 for (i
= 1; i
<= min
; i
++)
4115 if (eptr
>= md
->end_subject
)
4118 RRETURN(MATCH_NOMATCH
);
4120 GETCHARINCTEST(c
, eptr
);
4121 if ((UCD_CHARTYPE(c
) == prop_value
) == prop_fail_result
)
4122 RRETURN(MATCH_NOMATCH
);
4127 for (i
= 1; i
<= min
; i
++)
4129 if (eptr
>= md
->end_subject
)
4132 RRETURN(MATCH_NOMATCH
);
4134 GETCHARINCTEST(c
, eptr
);
4135 if ((UCD_SCRIPT(c
) == prop_value
) == prop_fail_result
)
4136 RRETURN(MATCH_NOMATCH
);
4141 for (i
= 1; i
<= min
; i
++)
4144 if (eptr
>= md
->end_subject
)
4147 RRETURN(MATCH_NOMATCH
);
4149 GETCHARINCTEST(c
, eptr
);
4150 category
= UCD_CATEGORY(c
);
4151 if ((category
== ucp_L
|| category
== ucp_N
) == prop_fail_result
)
4152 RRETURN(MATCH_NOMATCH
);
4156 case PT_SPACE
: /* Perl space */
4157 for (i
= 1; i
<= min
; i
++)
4159 if (eptr
>= md
->end_subject
)
4162 RRETURN(MATCH_NOMATCH
);
4164 GETCHARINCTEST(c
, eptr
);
4165 if ((UCD_CATEGORY(c
) == ucp_Z
|| c
== CHAR_HT
|| c
== CHAR_NL
||
4166 c
== CHAR_FF
|| c
== CHAR_CR
)
4167 == prop_fail_result
)
4168 RRETURN(MATCH_NOMATCH
);
4172 case PT_PXSPACE
: /* POSIX space */
4173 for (i
= 1; i
<= min
; i
++)
4175 if (eptr
>= md
->end_subject
)
4178 RRETURN(MATCH_NOMATCH
);
4180 GETCHARINCTEST(c
, eptr
);
4181 if ((UCD_CATEGORY(c
) == ucp_Z
|| c
== CHAR_HT
|| c
== CHAR_NL
||
4182 c
== CHAR_VT
|| c
== CHAR_FF
|| c
== CHAR_CR
)
4183 == prop_fail_result
)
4184 RRETURN(MATCH_NOMATCH
);
4189 for (i
= 1; i
<= min
; i
++)
4192 if (eptr
>= md
->end_subject
)
4195 RRETURN(MATCH_NOMATCH
);
4197 GETCHARINCTEST(c
, eptr
);
4198 category
= UCD_CATEGORY(c
);
4199 if ((category
== ucp_L
|| category
== ucp_N
|| c
== CHAR_UNDERSCORE
)
4200 == prop_fail_result
)
4201 RRETURN(MATCH_NOMATCH
);
4205 /* This should not occur */
4208 RRETURN(PCRE_ERROR_INTERNAL
);
4212 /* Match extended Unicode sequences. We will get here only if the
4213 support is in the binary; otherwise a compile-time error occurs. */
4215 else if (ctype
== OP_EXTUNI
)
4217 for (i
= 1; i
<= min
; i
++)
4219 if (eptr
>= md
->end_subject
)
4222 RRETURN(MATCH_NOMATCH
);
4224 GETCHARINCTEST(c
, eptr
);
4225 if (UCD_CATEGORY(c
) == ucp_M
) RRETURN(MATCH_NOMATCH
);
4226 while (eptr
< md
->end_subject
)
4229 if (!utf
) c
= *eptr
; else { GETCHARLEN(c
, eptr
, len
); }
4230 if (UCD_CATEGORY(c
) != ucp_M
) break;
4238 #endif /* SUPPORT_UCP */
4240 /* Handle all other cases when the coding is UTF-8 */
4243 if (utf
) switch(ctype
)
4246 for (i
= 1; i
<= min
; i
++)
4248 if (eptr
>= md
->end_subject
)
4251 RRETURN(MATCH_NOMATCH
);
4253 if (IS_NEWLINE(eptr
)) RRETURN(MATCH_NOMATCH
);
4254 if (md
->partial
!= 0 &&
4255 eptr
+ 1 >= md
->end_subject
&&
4256 NLBLOCK
->nltype
== NLTYPE_FIXED
&&
4257 NLBLOCK
->nllen
== 2 &&
4258 *eptr
== NLBLOCK
->nl
[0])
4261 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
4264 ACROSSCHAR(eptr
< md
->end_subject
, *eptr
, eptr
++);
4269 for (i
= 1; i
<= min
; i
++)
4271 if (eptr
>= md
->end_subject
)
4274 RRETURN(MATCH_NOMATCH
);
4277 ACROSSCHAR(eptr
< md
->end_subject
, *eptr
, eptr
++);
4282 if (eptr
> md
->end_subject
- min
) RRETURN(MATCH_NOMATCH
);
4287 for (i
= 1; i
<= min
; i
++)
4289 if (eptr
>= md
->end_subject
)
4292 RRETURN(MATCH_NOMATCH
);
4294 GETCHARINC(c
, eptr
);
4297 default: RRETURN(MATCH_NOMATCH
);
4300 if (eptr
< md
->end_subject
&& *eptr
== 0x0a) eptr
++;
4311 if (md
->bsr_anycrlf
) RRETURN(MATCH_NOMATCH
);
4318 for (i
= 1; i
<= min
; i
++)
4320 if (eptr
>= md
->end_subject
)
4323 RRETURN(MATCH_NOMATCH
);
4325 GETCHARINC(c
, eptr
);
4330 case 0x20: /* SPACE */
4331 case 0xa0: /* NBSP */
4332 case 0x1680: /* OGHAM SPACE MARK */
4333 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
4334 case 0x2000: /* EN QUAD */
4335 case 0x2001: /* EM QUAD */
4336 case 0x2002: /* EN SPACE */
4337 case 0x2003: /* EM SPACE */
4338 case 0x2004: /* THREE-PER-EM SPACE */
4339 case 0x2005: /* FOUR-PER-EM SPACE */
4340 case 0x2006: /* SIX-PER-EM SPACE */
4341 case 0x2007: /* FIGURE SPACE */
4342 case 0x2008: /* PUNCTUATION SPACE */
4343 case 0x2009: /* THIN SPACE */
4344 case 0x200A: /* HAIR SPACE */
4345 case 0x202f: /* NARROW NO-BREAK SPACE */
4346 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
4347 case 0x3000: /* IDEOGRAPHIC SPACE */
4348 RRETURN(MATCH_NOMATCH
);
4354 for (i
= 1; i
<= min
; i
++)
4356 if (eptr
>= md
->end_subject
)
4359 RRETURN(MATCH_NOMATCH
);
4361 GETCHARINC(c
, eptr
);
4364 default: RRETURN(MATCH_NOMATCH
);
4366 case 0x20: /* SPACE */
4367 case 0xa0: /* NBSP */
4368 case 0x1680: /* OGHAM SPACE MARK */
4369 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
4370 case 0x2000: /* EN QUAD */
4371 case 0x2001: /* EM QUAD */
4372 case 0x2002: /* EN SPACE */
4373 case 0x2003: /* EM SPACE */
4374 case 0x2004: /* THREE-PER-EM SPACE */
4375 case 0x2005: /* FOUR-PER-EM SPACE */
4376 case 0x2006: /* SIX-PER-EM SPACE */
4377 case 0x2007: /* FIGURE SPACE */
4378 case 0x2008: /* PUNCTUATION SPACE */
4379 case 0x2009: /* THIN SPACE */
4380 case 0x200A: /* HAIR SPACE */
4381 case 0x202f: /* NARROW NO-BREAK SPACE */
4382 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
4383 case 0x3000: /* IDEOGRAPHIC SPACE */
4390 for (i
= 1; i
<= min
; i
++)
4392 if (eptr
>= md
->end_subject
)
4395 RRETURN(MATCH_NOMATCH
);
4397 GETCHARINC(c
, eptr
);
4405 case 0x85: /* NEL */
4406 case 0x2028: /* LINE SEPARATOR */
4407 case 0x2029: /* PARAGRAPH SEPARATOR */
4408 RRETURN(MATCH_NOMATCH
);
4414 for (i
= 1; i
<= min
; i
++)
4416 if (eptr
>= md
->end_subject
)
4419 RRETURN(MATCH_NOMATCH
);
4421 GETCHARINC(c
, eptr
);
4424 default: RRETURN(MATCH_NOMATCH
);
4429 case 0x85: /* NEL */
4430 case 0x2028: /* LINE SEPARATOR */
4431 case 0x2029: /* PARAGRAPH SEPARATOR */
4438 for (i
= 1; i
<= min
; i
++)
4440 if (eptr
>= md
->end_subject
)
4443 RRETURN(MATCH_NOMATCH
);
4445 GETCHARINC(c
, eptr
);
4446 if (c
< 128 && (md
->ctypes
[c
] & ctype_digit
) != 0)
4447 RRETURN(MATCH_NOMATCH
);
4452 for (i
= 1; i
<= min
; i
++)
4454 if (eptr
>= md
->end_subject
)
4457 RRETURN(MATCH_NOMATCH
);
4459 if (*eptr
>= 128 || (md
->ctypes
[*eptr
] & ctype_digit
) == 0)
4460 RRETURN(MATCH_NOMATCH
);
4462 /* No need to skip more bytes - we know it's a 1-byte character */
4466 case OP_NOT_WHITESPACE
:
4467 for (i
= 1; i
<= min
; i
++)
4469 if (eptr
>= md
->end_subject
)
4472 RRETURN(MATCH_NOMATCH
);
4474 if (*eptr
< 128 && (md
->ctypes
[*eptr
] & ctype_space
) != 0)
4475 RRETURN(MATCH_NOMATCH
);
4477 ACROSSCHAR(eptr
< md
->end_subject
, *eptr
, eptr
++);
4482 for (i
= 1; i
<= min
; i
++)
4484 if (eptr
>= md
->end_subject
)
4487 RRETURN(MATCH_NOMATCH
);
4489 if (*eptr
>= 128 || (md
->ctypes
[*eptr
] & ctype_space
) == 0)
4490 RRETURN(MATCH_NOMATCH
);
4492 /* No need to skip more bytes - we know it's a 1-byte character */
4496 case OP_NOT_WORDCHAR
:
4497 for (i
= 1; i
<= min
; i
++)
4499 if (eptr
>= md
->end_subject
)
4502 RRETURN(MATCH_NOMATCH
);
4504 if (*eptr
< 128 && (md
->ctypes
[*eptr
] & ctype_word
) != 0)
4505 RRETURN(MATCH_NOMATCH
);
4507 ACROSSCHAR(eptr
< md
->end_subject
, *eptr
, eptr
++);
4512 for (i
= 1; i
<= min
; i
++)
4514 if (eptr
>= md
->end_subject
)
4517 RRETURN(MATCH_NOMATCH
);
4519 if (*eptr
>= 128 || (md
->ctypes
[*eptr
] & ctype_word
) == 0)
4520 RRETURN(MATCH_NOMATCH
);
4522 /* No need to skip more bytes - we know it's a 1-byte character */
4527 RRETURN(PCRE_ERROR_INTERNAL
);
4528 } /* End switch(ctype) */
4531 #endif /* SUPPORT_UTF */
4533 /* Code for the non-UTF-8 case for minimum matching of operators other
4534 than OP_PROP and OP_NOTPROP. */
4539 for (i
= 1; i
<= min
; i
++)
4541 if (eptr
>= md
->end_subject
)
4544 RRETURN(MATCH_NOMATCH
);
4546 if (IS_NEWLINE(eptr
)) RRETURN(MATCH_NOMATCH
);
4547 if (md
->partial
!= 0 &&
4548 eptr
+ 1 >= md
->end_subject
&&
4549 NLBLOCK
->nltype
== NLTYPE_FIXED
&&
4550 NLBLOCK
->nllen
== 2 &&
4551 *eptr
== NLBLOCK
->nl
[0])
4554 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
4561 if (eptr
> md
->end_subject
- min
)
4564 RRETURN(MATCH_NOMATCH
);
4570 if (eptr
> md
->end_subject
- min
)
4573 RRETURN(MATCH_NOMATCH
);
4579 for (i
= 1; i
<= min
; i
++)
4581 if (eptr
>= md
->end_subject
)
4584 RRETURN(MATCH_NOMATCH
);
4588 default: RRETURN(MATCH_NOMATCH
);
4591 if (eptr
< md
->end_subject
&& *eptr
== 0x0a) eptr
++;
4600 #ifdef COMPILE_PCRE16
4604 if (md
->bsr_anycrlf
) RRETURN(MATCH_NOMATCH
);
4611 for (i
= 1; i
<= min
; i
++)
4613 if (eptr
>= md
->end_subject
)
4616 RRETURN(MATCH_NOMATCH
);
4622 case 0x20: /* SPACE */
4623 case 0xa0: /* NBSP */
4624 #ifdef COMPILE_PCRE16
4625 case 0x1680: /* OGHAM SPACE MARK */
4626 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
4627 case 0x2000: /* EN QUAD */
4628 case 0x2001: /* EM QUAD */
4629 case 0x2002: /* EN SPACE */
4630 case 0x2003: /* EM SPACE */
4631 case 0x2004: /* THREE-PER-EM SPACE */
4632 case 0x2005: /* FOUR-PER-EM SPACE */
4633 case 0x2006: /* SIX-PER-EM SPACE */
4634 case 0x2007: /* FIGURE SPACE */
4635 case 0x2008: /* PUNCTUATION SPACE */
4636 case 0x2009: /* THIN SPACE */
4637 case 0x200A: /* HAIR SPACE */
4638 case 0x202f: /* NARROW NO-BREAK SPACE */
4639 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
4640 case 0x3000: /* IDEOGRAPHIC SPACE */
4642 RRETURN(MATCH_NOMATCH
);
4648 for (i
= 1; i
<= min
; i
++)
4650 if (eptr
>= md
->end_subject
)
4653 RRETURN(MATCH_NOMATCH
);
4657 default: RRETURN(MATCH_NOMATCH
);
4659 case 0x20: /* SPACE */
4660 case 0xa0: /* NBSP */
4661 #ifdef COMPILE_PCRE16
4662 case 0x1680: /* OGHAM SPACE MARK */
4663 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
4664 case 0x2000: /* EN QUAD */
4665 case 0x2001: /* EM QUAD */
4666 case 0x2002: /* EN SPACE */
4667 case 0x2003: /* EM SPACE */
4668 case 0x2004: /* THREE-PER-EM SPACE */
4669 case 0x2005: /* FOUR-PER-EM SPACE */
4670 case 0x2006: /* SIX-PER-EM SPACE */
4671 case 0x2007: /* FIGURE SPACE */
4672 case 0x2008: /* PUNCTUATION SPACE */
4673 case 0x2009: /* THIN SPACE */
4674 case 0x200A: /* HAIR SPACE */
4675 case 0x202f: /* NARROW NO-BREAK SPACE */
4676 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
4677 case 0x3000: /* IDEOGRAPHIC SPACE */
4685 for (i
= 1; i
<= min
; i
++)
4687 if (eptr
>= md
->end_subject
)
4690 RRETURN(MATCH_NOMATCH
);
4699 case 0x85: /* NEL */
4700 #ifdef COMPILE_PCRE16
4701 case 0x2028: /* LINE SEPARATOR */
4702 case 0x2029: /* PARAGRAPH SEPARATOR */
4704 RRETURN(MATCH_NOMATCH
);
4710 for (i
= 1; i
<= min
; i
++)
4712 if (eptr
>= md
->end_subject
)
4715 RRETURN(MATCH_NOMATCH
);
4719 default: RRETURN(MATCH_NOMATCH
);
4724 case 0x85: /* NEL */
4725 #ifdef COMPILE_PCRE16
4726 case 0x2028: /* LINE SEPARATOR */
4727 case 0x2029: /* PARAGRAPH SEPARATOR */
4735 for (i
= 1; i
<= min
; i
++)
4737 if (eptr
>= md
->end_subject
)
4740 RRETURN(MATCH_NOMATCH
);
4742 if (MAX_255(*eptr
) && (md
->ctypes
[*eptr
] & ctype_digit
) != 0)
4743 RRETURN(MATCH_NOMATCH
);
4749 for (i
= 1; i
<= min
; i
++)
4751 if (eptr
>= md
->end_subject
)
4754 RRETURN(MATCH_NOMATCH
);
4756 if (!MAX_255(*eptr
) || (md
->ctypes
[*eptr
] & ctype_digit
) == 0)
4757 RRETURN(MATCH_NOMATCH
);
4762 case OP_NOT_WHITESPACE
:
4763 for (i
= 1; i
<= min
; i
++)
4765 if (eptr
>= md
->end_subject
)
4768 RRETURN(MATCH_NOMATCH
);
4770 if (MAX_255(*eptr
) && (md
->ctypes
[*eptr
] & ctype_space
) != 0)
4771 RRETURN(MATCH_NOMATCH
);
4777 for (i
= 1; i
<= min
; i
++)
4779 if (eptr
>= md
->end_subject
)
4782 RRETURN(MATCH_NOMATCH
);
4784 if (!MAX_255(*eptr
) || (md
->ctypes
[*eptr
] & ctype_space
) == 0)
4785 RRETURN(MATCH_NOMATCH
);
4790 case OP_NOT_WORDCHAR
:
4791 for (i
= 1; i
<= min
; i
++)
4793 if (eptr
>= md
->end_subject
)
4796 RRETURN(MATCH_NOMATCH
);
4798 if (MAX_255(*eptr
) && (md
->ctypes
[*eptr
] & ctype_word
) != 0)
4799 RRETURN(MATCH_NOMATCH
);
4805 for (i
= 1; i
<= min
; i
++)
4807 if (eptr
>= md
->end_subject
)
4810 RRETURN(MATCH_NOMATCH
);
4812 if (!MAX_255(*eptr
) || (md
->ctypes
[*eptr
] & ctype_word
) == 0)
4813 RRETURN(MATCH_NOMATCH
);
4819 RRETURN(PCRE_ERROR_INTERNAL
);
4823 /* If min = max, continue at the same level without recursing */
4825 if (min
== max
) continue;
4827 /* If minimizing, we have to test the rest of the pattern before each
4828 subsequent match. Again, separate the UTF-8 case for speed, and also
4829 separate the UCP cases. */
4839 for (fi
= min
;; fi
++)
4841 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM36
);
4842 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
4843 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
4844 if (eptr
>= md
->end_subject
)
4847 RRETURN(MATCH_NOMATCH
);
4849 GETCHARINCTEST(c
, eptr
);
4850 if (prop_fail_result
) RRETURN(MATCH_NOMATCH
);
4852 /* Control never gets here */
4855 for (fi
= min
;; fi
++)
4858 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM37
);
4859 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
4860 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
4861 if (eptr
>= md
->end_subject
)
4864 RRETURN(MATCH_NOMATCH
);
4866 GETCHARINCTEST(c
, eptr
);
4867 chartype
= UCD_CHARTYPE(c
);
4868 if ((chartype
== ucp_Lu
||
4869 chartype
== ucp_Ll
||
4870 chartype
== ucp_Lt
) == prop_fail_result
)
4871 RRETURN(MATCH_NOMATCH
);
4873 /* Control never gets here */
4876 for (fi
= min
;; fi
++)
4878 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM38
);
4879 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
4880 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
4881 if (eptr
>= md
->end_subject
)
4884 RRETURN(MATCH_NOMATCH
);
4886 GETCHARINCTEST(c
, eptr
);
4887 if ((UCD_CATEGORY(c
) == prop_value
) == prop_fail_result
)
4888 RRETURN(MATCH_NOMATCH
);
4890 /* Control never gets here */
4893 for (fi
= min
;; fi
++)
4895 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM39
);
4896 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
4897 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
4898 if (eptr
>= md
->end_subject
)
4901 RRETURN(MATCH_NOMATCH
);
4903 GETCHARINCTEST(c
, eptr
);
4904 if ((UCD_CHARTYPE(c
) == prop_value
) == prop_fail_result
)
4905 RRETURN(MATCH_NOMATCH
);
4907 /* Control never gets here */
4910 for (fi
= min
;; fi
++)
4912 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM40
);
4913 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
4914 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
4915 if (eptr
>= md
->end_subject
)
4918 RRETURN(MATCH_NOMATCH
);
4920 GETCHARINCTEST(c
, eptr
);
4921 if ((UCD_SCRIPT(c
) == prop_value
) == prop_fail_result
)
4922 RRETURN(MATCH_NOMATCH
);
4924 /* Control never gets here */
4927 for (fi
= min
;; fi
++)
4930 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM59
);
4931 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
4932 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
4933 if (eptr
>= md
->end_subject
)
4936 RRETURN(MATCH_NOMATCH
);
4938 GETCHARINCTEST(c
, eptr
);
4939 category
= UCD_CATEGORY(c
);
4940 if ((category
== ucp_L
|| category
== ucp_N
) == prop_fail_result
)
4941 RRETURN(MATCH_NOMATCH
);
4943 /* Control never gets here */
4945 case PT_SPACE
: /* Perl space */
4946 for (fi
= min
;; fi
++)
4948 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM60
);
4949 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
4950 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
4951 if (eptr
>= md
->end_subject
)
4954 RRETURN(MATCH_NOMATCH
);
4956 GETCHARINCTEST(c
, eptr
);
4957 if ((UCD_CATEGORY(c
) == ucp_Z
|| c
== CHAR_HT
|| c
== CHAR_NL
||
4958 c
== CHAR_FF
|| c
== CHAR_CR
)
4959 == prop_fail_result
)
4960 RRETURN(MATCH_NOMATCH
);
4962 /* Control never gets here */
4964 case PT_PXSPACE
: /* POSIX space */
4965 for (fi
= min
;; fi
++)
4967 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM61
);
4968 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
4969 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
4970 if (eptr
>= md
->end_subject
)
4973 RRETURN(MATCH_NOMATCH
);
4975 GETCHARINCTEST(c
, eptr
);
4976 if ((UCD_CATEGORY(c
) == ucp_Z
|| c
== CHAR_HT
|| c
== CHAR_NL
||
4977 c
== CHAR_VT
|| c
== CHAR_FF
|| c
== CHAR_CR
)
4978 == prop_fail_result
)
4979 RRETURN(MATCH_NOMATCH
);
4981 /* Control never gets here */
4984 for (fi
= min
;; fi
++)
4987 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM62
);
4988 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
4989 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
4990 if (eptr
>= md
->end_subject
)
4993 RRETURN(MATCH_NOMATCH
);
4995 GETCHARINCTEST(c
, eptr
);
4996 category
= UCD_CATEGORY(c
);
4997 if ((category
== ucp_L
||
4998 category
== ucp_N
||
4999 c
== CHAR_UNDERSCORE
)
5000 == prop_fail_result
)
5001 RRETURN(MATCH_NOMATCH
);
5003 /* Control never gets here */
5005 /* This should never occur */
5008 RRETURN(PCRE_ERROR_INTERNAL
);
5012 /* Match extended Unicode sequences. We will get here only if the
5013 support is in the binary; otherwise a compile-time error occurs. */
5015 else if (ctype
== OP_EXTUNI
)
5017 for (fi
= min
;; fi
++)
5019 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM41
);
5020 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
5021 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
5022 if (eptr
>= md
->end_subject
)
5025 RRETURN(MATCH_NOMATCH
);
5027 GETCHARINCTEST(c
, eptr
);
5028 if (UCD_CATEGORY(c
) == ucp_M
) RRETURN(MATCH_NOMATCH
);
5029 while (eptr
< md
->end_subject
)
5032 if (!utf
) c
= *eptr
; else { GETCHARLEN(c
, eptr
, len
); }
5033 if (UCD_CATEGORY(c
) != ucp_M
) break;
5040 #endif /* SUPPORT_UCP */
5045 for (fi
= min
;; fi
++)
5047 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM42
);
5048 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
5049 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
5050 if (eptr
>= md
->end_subject
)
5053 RRETURN(MATCH_NOMATCH
);
5055 if (ctype
== OP_ANY
&& IS_NEWLINE(eptr
))
5056 RRETURN(MATCH_NOMATCH
);
5057 GETCHARINC(c
, eptr
);
5060 case OP_ANY
: /* This is the non-NL case */
5061 if (md
->partial
!= 0 && /* Take care with CRLF partial */
5062 eptr
>= md
->end_subject
&&
5063 NLBLOCK
->nltype
== NLTYPE_FIXED
&&
5064 NLBLOCK
->nllen
== 2 &&
5065 c
== NLBLOCK
->nl
[0])
5068 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
5079 default: RRETURN(MATCH_NOMATCH
);
5081 if (eptr
< md
->end_subject
&& *eptr
== 0x0a) eptr
++;
5091 if (md
->bsr_anycrlf
) RRETURN(MATCH_NOMATCH
);
5101 case 0x20: /* SPACE */
5102 case 0xa0: /* NBSP */
5103 case 0x1680: /* OGHAM SPACE MARK */
5104 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
5105 case 0x2000: /* EN QUAD */
5106 case 0x2001: /* EM QUAD */
5107 case 0x2002: /* EN SPACE */
5108 case 0x2003: /* EM SPACE */
5109 case 0x2004: /* THREE-PER-EM SPACE */
5110 case 0x2005: /* FOUR-PER-EM SPACE */
5111 case 0x2006: /* SIX-PER-EM SPACE */
5112 case 0x2007: /* FIGURE SPACE */
5113 case 0x2008: /* PUNCTUATION SPACE */
5114 case 0x2009: /* THIN SPACE */
5115 case 0x200A: /* HAIR SPACE */
5116 case 0x202f: /* NARROW NO-BREAK SPACE */
5117 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
5118 case 0x3000: /* IDEOGRAPHIC SPACE */
5119 RRETURN(MATCH_NOMATCH
);
5126 default: RRETURN(MATCH_NOMATCH
);
5128 case 0x20: /* SPACE */
5129 case 0xa0: /* NBSP */
5130 case 0x1680: /* OGHAM SPACE MARK */
5131 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
5132 case 0x2000: /* EN QUAD */
5133 case 0x2001: /* EM QUAD */
5134 case 0x2002: /* EN SPACE */
5135 case 0x2003: /* EM SPACE */
5136 case 0x2004: /* THREE-PER-EM SPACE */
5137 case 0x2005: /* FOUR-PER-EM SPACE */
5138 case 0x2006: /* SIX-PER-EM SPACE */
5139 case 0x2007: /* FIGURE SPACE */
5140 case 0x2008: /* PUNCTUATION SPACE */
5141 case 0x2009: /* THIN SPACE */
5142 case 0x200A: /* HAIR SPACE */
5143 case 0x202f: /* NARROW NO-BREAK SPACE */
5144 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
5145 case 0x3000: /* IDEOGRAPHIC SPACE */
5158 case 0x85: /* NEL */
5159 case 0x2028: /* LINE SEPARATOR */
5160 case 0x2029: /* PARAGRAPH SEPARATOR */
5161 RRETURN(MATCH_NOMATCH
);
5168 default: RRETURN(MATCH_NOMATCH
);
5173 case 0x85: /* NEL */
5174 case 0x2028: /* LINE SEPARATOR */
5175 case 0x2029: /* PARAGRAPH SEPARATOR */
5181 if (c
< 256 && (md
->ctypes
[c
] & ctype_digit
) != 0)
5182 RRETURN(MATCH_NOMATCH
);
5186 if (c
>= 256 || (md
->ctypes
[c
] & ctype_digit
) == 0)
5187 RRETURN(MATCH_NOMATCH
);
5190 case OP_NOT_WHITESPACE
:
5191 if (c
< 256 && (md
->ctypes
[c
] & ctype_space
) != 0)
5192 RRETURN(MATCH_NOMATCH
);
5196 if (c
>= 256 || (md
->ctypes
[c
] & ctype_space
) == 0)
5197 RRETURN(MATCH_NOMATCH
);
5200 case OP_NOT_WORDCHAR
:
5201 if (c
< 256 && (md
->ctypes
[c
] & ctype_word
) != 0)
5202 RRETURN(MATCH_NOMATCH
);
5206 if (c
>= 256 || (md
->ctypes
[c
] & ctype_word
) == 0)
5207 RRETURN(MATCH_NOMATCH
);
5211 RRETURN(PCRE_ERROR_INTERNAL
);
5219 for (fi
= min
;; fi
++)
5221 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM43
);
5222 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
5223 if (fi
>= max
) RRETURN(MATCH_NOMATCH
);
5224 if (eptr
>= md
->end_subject
)
5227 RRETURN(MATCH_NOMATCH
);
5229 if (ctype
== OP_ANY
&& IS_NEWLINE(eptr
))
5230 RRETURN(MATCH_NOMATCH
);
5234 case OP_ANY
: /* This is the non-NL case */
5235 if (md
->partial
!= 0 && /* Take care with CRLF partial */
5236 eptr
>= md
->end_subject
&&
5237 NLBLOCK
->nltype
== NLTYPE_FIXED
&&
5238 NLBLOCK
->nllen
== 2 &&
5239 c
== NLBLOCK
->nl
[0])
5242 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
5253 default: RRETURN(MATCH_NOMATCH
);
5255 if (eptr
< md
->end_subject
&& *eptr
== 0x0a) eptr
++;
5264 #ifdef COMPILE_PCRE16
5268 if (md
->bsr_anycrlf
) RRETURN(MATCH_NOMATCH
);
5278 case 0x20: /* SPACE */
5279 case 0xa0: /* NBSP */
5280 #ifdef COMPILE_PCRE16
5281 case 0x1680: /* OGHAM SPACE MARK */
5282 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
5283 case 0x2000: /* EN QUAD */
5284 case 0x2001: /* EM QUAD */
5285 case 0x2002: /* EN SPACE */
5286 case 0x2003: /* EM SPACE */
5287 case 0x2004: /* THREE-PER-EM SPACE */
5288 case 0x2005: /* FOUR-PER-EM SPACE */
5289 case 0x2006: /* SIX-PER-EM SPACE */
5290 case 0x2007: /* FIGURE SPACE */
5291 case 0x2008: /* PUNCTUATION SPACE */
5292 case 0x2009: /* THIN SPACE */
5293 case 0x200A: /* HAIR SPACE */
5294 case 0x202f: /* NARROW NO-BREAK SPACE */
5295 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
5296 case 0x3000: /* IDEOGRAPHIC SPACE */
5298 RRETURN(MATCH_NOMATCH
);
5305 default: RRETURN(MATCH_NOMATCH
);
5307 case 0x20: /* SPACE */
5308 case 0xa0: /* NBSP */
5309 #ifdef COMPILE_PCRE16
5310 case 0x1680: /* OGHAM SPACE MARK */
5311 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
5312 case 0x2000: /* EN QUAD */
5313 case 0x2001: /* EM QUAD */
5314 case 0x2002: /* EN SPACE */
5315 case 0x2003: /* EM SPACE */
5316 case 0x2004: /* THREE-PER-EM SPACE */
5317 case 0x2005: /* FOUR-PER-EM SPACE */
5318 case 0x2006: /* SIX-PER-EM SPACE */
5319 case 0x2007: /* FIGURE SPACE */
5320 case 0x2008: /* PUNCTUATION SPACE */
5321 case 0x2009: /* THIN SPACE */
5322 case 0x200A: /* HAIR SPACE */
5323 case 0x202f: /* NARROW NO-BREAK SPACE */
5324 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
5325 case 0x3000: /* IDEOGRAPHIC SPACE */
5339 case 0x85: /* NEL */
5340 #ifdef COMPILE_PCRE16
5341 case 0x2028: /* LINE SEPARATOR */
5342 case 0x2029: /* PARAGRAPH SEPARATOR */
5344 RRETURN(MATCH_NOMATCH
);
5351 default: RRETURN(MATCH_NOMATCH
);
5356 case 0x85: /* NEL */
5357 #ifdef COMPILE_PCRE16
5358 case 0x2028: /* LINE SEPARATOR */
5359 case 0x2029: /* PARAGRAPH SEPARATOR */
5366 if (MAX_255(c
) && (md
->ctypes
[c
] & ctype_digit
) != 0) RRETURN(MATCH_NOMATCH
);
5370 if (!MAX_255(c
) || (md
->ctypes
[c
] & ctype_digit
) == 0) RRETURN(MATCH_NOMATCH
);
5373 case OP_NOT_WHITESPACE
:
5374 if (MAX_255(c
) && (md
->ctypes
[c
] & ctype_space
) != 0) RRETURN(MATCH_NOMATCH
);
5378 if (!MAX_255(c
) || (md
->ctypes
[c
] & ctype_space
) == 0) RRETURN(MATCH_NOMATCH
);
5381 case OP_NOT_WORDCHAR
:
5382 if (MAX_255(c
) && (md
->ctypes
[c
] & ctype_word
) != 0) RRETURN(MATCH_NOMATCH
);
5386 if (!MAX_255(c
) || (md
->ctypes
[c
] & ctype_word
) == 0) RRETURN(MATCH_NOMATCH
);
5390 RRETURN(PCRE_ERROR_INTERNAL
);
5394 /* Control never gets here */
5397 /* If maximizing, it is worth using inline code for speed, doing the type
5398 test once at the start (i.e. keep it out of the loop). Again, keep the
5399 UTF-8 and UCP stuff separate. */
5403 pp
= eptr
; /* Remember where we started */
5411 for (i
= min
; i
< max
; i
++)
5414 if (eptr
>= md
->end_subject
)
5419 GETCHARLENTEST(c
, eptr
, len
);
5420 if (prop_fail_result
) break;
5426 for (i
= min
; i
< max
; i
++)
5430 if (eptr
>= md
->end_subject
)
5435 GETCHARLENTEST(c
, eptr
, len
);
5436 chartype
= UCD_CHARTYPE(c
);
5437 if ((chartype
== ucp_Lu
||
5438 chartype
== ucp_Ll
||
5439 chartype
== ucp_Lt
) == prop_fail_result
)
5446 for (i
= min
; i
< max
; i
++)
5449 if (eptr
>= md
->end_subject
)
5454 GETCHARLENTEST(c
, eptr
, len
);
5455 if ((UCD_CATEGORY(c
) == prop_value
) == prop_fail_result
) break;
5461 for (i
= min
; i
< max
; i
++)
5464 if (eptr
>= md
->end_subject
)
5469 GETCHARLENTEST(c
, eptr
, len
);
5470 if ((UCD_CHARTYPE(c
) == prop_value
) == prop_fail_result
) break;
5476 for (i
= min
; i
< max
; i
++)
5479 if (eptr
>= md
->end_subject
)
5484 GETCHARLENTEST(c
, eptr
, len
);
5485 if ((UCD_SCRIPT(c
) == prop_value
) == prop_fail_result
) break;
5491 for (i
= min
; i
< max
; i
++)
5495 if (eptr
>= md
->end_subject
)
5500 GETCHARLENTEST(c
, eptr
, len
);
5501 category
= UCD_CATEGORY(c
);
5502 if ((category
== ucp_L
|| category
== ucp_N
) == prop_fail_result
)
5508 case PT_SPACE
: /* Perl space */
5509 for (i
= min
; i
< max
; i
++)
5512 if (eptr
>= md
->end_subject
)
5517 GETCHARLENTEST(c
, eptr
, len
);
5518 if ((UCD_CATEGORY(c
) == ucp_Z
|| c
== CHAR_HT
|| c
== CHAR_NL
||
5519 c
== CHAR_FF
|| c
== CHAR_CR
)
5520 == prop_fail_result
)
5526 case PT_PXSPACE
: /* POSIX space */
5527 for (i
= min
; i
< max
; i
++)
5530 if (eptr
>= md
->end_subject
)
5535 GETCHARLENTEST(c
, eptr
, len
);
5536 if ((UCD_CATEGORY(c
) == ucp_Z
|| c
== CHAR_HT
|| c
== CHAR_NL
||
5537 c
== CHAR_VT
|| c
== CHAR_FF
|| c
== CHAR_CR
)
5538 == prop_fail_result
)
5545 for (i
= min
; i
< max
; i
++)
5549 if (eptr
>= md
->end_subject
)
5554 GETCHARLENTEST(c
, eptr
, len
);
5555 category
= UCD_CATEGORY(c
);
5556 if ((category
== ucp_L
|| category
== ucp_N
||
5557 c
== CHAR_UNDERSCORE
) == prop_fail_result
)
5564 RRETURN(PCRE_ERROR_INTERNAL
);
5567 /* eptr is now past the end of the maximum run */
5569 if (possessive
) continue;
5572 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM44
);
5573 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
5574 if (eptr
-- == pp
) break; /* Stop if tried at original pos */
5575 if (utf
) BACKCHAR(eptr
);
5579 /* Match extended Unicode sequences. We will get here only if the
5580 support is in the binary; otherwise a compile-time error occurs. */
5582 else if (ctype
== OP_EXTUNI
)
5584 for (i
= min
; i
< max
; i
++)
5587 if (eptr
>= md
->end_subject
)
5592 if (!utf
) c
= *eptr
; else { GETCHARLEN(c
, eptr
, len
); }
5593 if (UCD_CATEGORY(c
) == ucp_M
) break;
5595 while (eptr
< md
->end_subject
)
5598 if (!utf
) c
= *eptr
; else { GETCHARLEN(c
, eptr
, len
); }
5599 if (UCD_CATEGORY(c
) != ucp_M
) break;
5605 /* eptr is now past the end of the maximum run */
5607 if (possessive
) continue;
5611 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM45
);
5612 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
5613 if (eptr
-- == pp
) break; /* Stop if tried at original pos */
5614 for (;;) /* Move back over one extended */
5616 if (!utf
) c
= *eptr
; else
5621 if (UCD_CATEGORY(c
) != ucp_M
) break;
5628 #endif /* SUPPORT_UCP */
5638 for (i
= min
; i
< max
; i
++)
5640 if (eptr
>= md
->end_subject
)
5645 if (IS_NEWLINE(eptr
)) break;
5646 if (md
->partial
!= 0 && /* Take care with CRLF partial */
5647 eptr
+ 1 >= md
->end_subject
&&
5648 NLBLOCK
->nltype
== NLTYPE_FIXED
&&
5649 NLBLOCK
->nllen
== 2 &&
5650 *eptr
== NLBLOCK
->nl
[0])
5653 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
5656 ACROSSCHAR(eptr
< md
->end_subject
, *eptr
, eptr
++);
5660 /* Handle unlimited UTF-8 repeat */
5664 for (i
= min
; i
< max
; i
++)
5666 if (eptr
>= md
->end_subject
)
5671 if (IS_NEWLINE(eptr
)) break;
5672 if (md
->partial
!= 0 && /* Take care with CRLF partial */
5673 eptr
+ 1 >= md
->end_subject
&&
5674 NLBLOCK
->nltype
== NLTYPE_FIXED
&&
5675 NLBLOCK
->nllen
== 2 &&
5676 *eptr
== NLBLOCK
->nl
[0])
5679 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
5682 ACROSSCHAR(eptr
< md
->end_subject
, *eptr
, eptr
++);
5690 for (i
= min
; i
< max
; i
++)
5692 if (eptr
>= md
->end_subject
)
5698 ACROSSCHAR(eptr
< md
->end_subject
, *eptr
, eptr
++);
5703 eptr
= md
->end_subject
; /* Unlimited UTF-8 repeat */
5708 /* The byte case is the same as non-UTF8 */
5712 if (c
> (unsigned int)(md
->end_subject
- eptr
))
5714 eptr
= md
->end_subject
;
5721 for (i
= min
; i
< max
; i
++)
5724 if (eptr
>= md
->end_subject
)
5729 GETCHARLEN(c
, eptr
, len
);
5732 if (++eptr
>= md
->end_subject
) break;
5733 if (*eptr
== 0x000a) eptr
++;
5739 (c
!= 0x000b && c
!= 0x000c &&
5740 c
!= 0x0085 && c
!= 0x2028 && c
!= 0x2029)))
5749 for (i
= min
; i
< max
; i
++)
5753 if (eptr
>= md
->end_subject
)
5758 GETCHARLEN(c
, eptr
, len
);
5761 default: gotspace
= FALSE
; break;
5763 case 0x20: /* SPACE */
5764 case 0xa0: /* NBSP */
5765 case 0x1680: /* OGHAM SPACE MARK */
5766 case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
5767 case 0x2000: /* EN QUAD */
5768 case 0x2001: /* EM QUAD */
5769 case 0x2002: /* EN SPACE */
5770 case 0x2003: /* EM SPACE */
5771 case 0x2004: /* THREE-PER-EM SPACE */
5772 case 0x2005: /* FOUR-PER-EM SPACE */
5773 case 0x2006: /* SIX-PER-EM SPACE */
5774 case 0x2007: /* FIGURE SPACE */
5775 case 0x2008: /* PUNCTUATION SPACE */
5776 case 0x2009: /* THIN SPACE */
5777 case 0x200A: /* HAIR SPACE */
5778 case 0x202f: /* NARROW NO-BREAK SPACE */
5779 case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
5780 case 0x3000: /* IDEOGRAPHIC SPACE */
5784 if (gotspace
== (ctype
== OP_NOT_HSPACE
)) break;
5791 for (i
= min
; i
< max
; i
++)
5795 if (eptr
>= md
->end_subject
)
5800 GETCHARLEN(c
, eptr
, len
);
5803 default: gotspace
= FALSE
; break;
5808 case 0x85: /* NEL */
5809 case 0x2028: /* LINE SEPARATOR */
5810 case 0x2029: /* PARAGRAPH SEPARATOR */
5814 if (gotspace
== (ctype
== OP_NOT_VSPACE
)) break;
5820 for (i
= min
; i
< max
; i
++)
5823 if (eptr
>= md
->end_subject
)
5828 GETCHARLEN(c
, eptr
, len
);
5829 if (c
< 256 && (md
->ctypes
[c
] & ctype_digit
) != 0) break;
5835 for (i
= min
; i
< max
; i
++)
5838 if (eptr
>= md
->end_subject
)
5843 GETCHARLEN(c
, eptr
, len
);
5844 if (c
>= 256 ||(md
->ctypes
[c
] & ctype_digit
) == 0) break;
5849 case OP_NOT_WHITESPACE
:
5850 for (i
= min
; i
< max
; i
++)
5853 if (eptr
>= md
->end_subject
)
5858 GETCHARLEN(c
, eptr
, len
);
5859 if (c
< 256 && (md
->ctypes
[c
] & ctype_space
) != 0) break;
5865 for (i
= min
; i
< max
; i
++)
5868 if (eptr
>= md
->end_subject
)
5873 GETCHARLEN(c
, eptr
, len
);
5874 if (c
>= 256 ||(md
->ctypes
[c
] & ctype_space
) == 0) break;
5879 case OP_NOT_WORDCHAR
:
5880 for (i
= min
; i
< max
; i
++)
5883 if (eptr
>= md
->end_subject
)
5888 GETCHARLEN(c
, eptr
, len
);
5889 if (c
< 256 && (md
->ctypes
[c
] & ctype_word
) != 0) break;
5895 for (i
= min
; i
< max
; i
++)
5898 if (eptr
>= md
->end_subject
)
5903 GETCHARLEN(c
, eptr
, len
);
5904 if (c
>= 256 || (md
->ctypes
[c
] & ctype_word
) == 0) break;
5910 RRETURN(PCRE_ERROR_INTERNAL
);
5913 /* eptr is now past the end of the maximum run. If possessive, we are
5914 done (no backing up). Otherwise, match at this position; anything other
5915 than no match is immediately returned. For nomatch, back up one
5916 character, unless we are matching \R and the last thing matched was
5917 \r\n, in which case, back up two bytes. */
5919 if (possessive
) continue;
5922 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM46
);
5923 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
5924 if (eptr
-- == pp
) break; /* Stop if tried at original pos */
5926 if (ctype
== OP_ANYNL
&& eptr
> pp
&& *eptr
== '\n' &&
5927 eptr
[-1] == '\r') eptr
--;
5931 #endif /* SUPPORT_UTF */
5937 for (i
= min
; i
< max
; i
++)
5939 if (eptr
>= md
->end_subject
)
5944 if (IS_NEWLINE(eptr
)) break;
5945 if (md
->partial
!= 0 && /* Take care with CRLF partial */
5946 eptr
+ 1 >= md
->end_subject
&&
5947 NLBLOCK
->nltype
== NLTYPE_FIXED
&&
5948 NLBLOCK
->nllen
== 2 &&
5949 *eptr
== NLBLOCK
->nl
[0])
5952 if (md
->partial
> 1) RRETURN(PCRE_ERROR_PARTIAL
);
5961 if (c
> (unsigned int)(md
->end_subject
- eptr
))
5963 eptr
= md
->end_subject
;
5970 for (i
= min
; i
< max
; i
++)
5972 if (eptr
>= md
->end_subject
)
5980 if (++eptr
>= md
->end_subject
) break;
5981 if (*eptr
== 0x000a) eptr
++;
5985 if (c
!= 0x000a && (md
->bsr_anycrlf
||
5986 (c
!= 0x000b && c
!= 0x000c && c
!= 0x0085
5987 #ifdef COMPILE_PCRE16
5988 && c
!= 0x2028 && c
!= 0x2029
5997 for (i
= min
; i
< max
; i
++)
5999 if (eptr
>= md
->end_subject
)
6005 if (c
== 0x09 || c
== 0x20 || c
== 0xa0
6006 #ifdef COMPILE_PCRE16
6007 || c
== 0x1680 || c
== 0x180e || (c
>= 0x2000 && c
<= 0x200A)
6008 || c
== 0x202f || c
== 0x205f || c
== 0x3000
6016 for (i
= min
; i
< max
; i
++)
6018 if (eptr
>= md
->end_subject
)
6024 if (c
!= 0x09 && c
!= 0x20 && c
!= 0xa0
6025 #ifdef COMPILE_PCRE16
6026 && c
!= 0x1680 && c
!= 0x180e && (c
< 0x2000 || c
> 0x200A)
6027 && c
!= 0x202f && c
!= 0x205f && c
!= 0x3000
6035 for (i
= min
; i
< max
; i
++)
6037 if (eptr
>= md
->end_subject
)
6043 if (c
== 0x0a || c
== 0x0b || c
== 0x0c || c
== 0x0d || c
== 0x85
6044 #ifdef COMPILE_PCRE16
6045 || c
== 0x2028 || c
== 0x2029
6053 for (i
= min
; i
< max
; i
++)
6055 if (eptr
>= md
->end_subject
)
6061 if (c
!= 0x0a && c
!= 0x0b && c
!= 0x0c && c
!= 0x0d && c
!= 0x85
6062 #ifdef COMPILE_PCRE16
6063 && c
!= 0x2028 && c
!= 0x2029
6071 for (i
= min
; i
< max
; i
++)
6073 if (eptr
>= md
->end_subject
)
6078 if (MAX_255(*eptr
) && (md
->ctypes
[*eptr
] & ctype_digit
) != 0) break;
6084 for (i
= min
; i
< max
; i
++)
6086 if (eptr
>= md
->end_subject
)
6091 if (!MAX_255(*eptr
) || (md
->ctypes
[*eptr
] & ctype_digit
) == 0) break;
6096 case OP_NOT_WHITESPACE
:
6097 for (i
= min
; i
< max
; i
++)
6099 if (eptr
>= md
->end_subject
)
6104 if (MAX_255(*eptr
) && (md
->ctypes
[*eptr
] & ctype_space
) != 0) break;
6110 for (i
= min
; i
< max
; i
++)
6112 if (eptr
>= md
->end_subject
)
6117 if (!MAX_255(*eptr
) || (md
->ctypes
[*eptr
] & ctype_space
) == 0) break;
6122 case OP_NOT_WORDCHAR
:
6123 for (i
= min
; i
< max
; i
++)
6125 if (eptr
>= md
->end_subject
)
6130 if (MAX_255(*eptr
) && (md
->ctypes
[*eptr
] & ctype_word
) != 0) break;
6136 for (i
= min
; i
< max
; i
++)
6138 if (eptr
>= md
->end_subject
)
6143 if (!MAX_255(*eptr
) || (md
->ctypes
[*eptr
] & ctype_word
) == 0) break;
6149 RRETURN(PCRE_ERROR_INTERNAL
);
6152 /* eptr is now past the end of the maximum run. If possessive, we are
6153 done (no backing up). Otherwise, match at this position; anything other
6154 than no match is immediately returned. For nomatch, back up one
6155 character (byte), unless we are matching \R and the last thing matched
6156 was \r\n, in which case, back up two bytes. */
6158 if (possessive
) continue;
6161 RMATCH(eptr
, ecode
, offset_top
, md
, eptrb
, RM47
);
6162 if (rrc
!= MATCH_NOMATCH
) RRETURN(rrc
);
6164 if (ctype
== OP_ANYNL
&& eptr
> pp
&& *eptr
== '\n' &&
6165 eptr
[-1] == '\r') eptr
--;
6169 /* Get here if we can't make it match with any permitted repetitions */
6171 RRETURN(MATCH_NOMATCH
);
6173 /* Control never gets here */
6175 /* There's been some horrible disaster. Arrival here can only mean there is
6176 something seriously wrong in the code above or the OP_xxx definitions. */
6179 DPRINTF(("Unknown opcode %d\n", *ecode
));
6180 RRETURN(PCRE_ERROR_UNKNOWN_OPCODE
);
6183 /* Do not stick any code in here without much thought; it is assumed
6184 that "continue" in the code above comes out to here to repeat the main
6187 } /* End of main loop */
6188 /* Control never reaches here */
6191 /* When compiling to use the heap rather than the stack for recursive calls to
6192 match(), the RRETURN() macro jumps here. The number that is saved in
6193 frame->Xwhere indicates which label we actually want to return to. */
6196 #define LBL(val) case val: goto L_RM##val;
6198 switch (frame
->Xwhere
)
6200 LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
6201 LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
6202 LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
6203 LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
6204 LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58) LBL(63) LBL(64)
6206 #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
6210 LBL(16) LBL(18) LBL(20)
6211 LBL(22) LBL(23) LBL(28) LBL(30)
6212 LBL(32) LBL(34) LBL(42) LBL(46)
6214 LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
6215 LBL(59) LBL(60) LBL(61) LBL(62)
6216 #endif /* SUPPORT_UCP */
6217 #endif /* SUPPORT_UTF */
6219 DPRINTF(("jump error in pcre match: label %d non-existent\n", frame
->Xwhere
));
6221 printf("+++jump error in pcre match: label %d non-existent\n", frame
->Xwhere
);
6223 return PCRE_ERROR_INTERNAL
;
6226 #endif /* NO_RECURSE */
6230 /***************************************************************************
6231 ****************************************************************************
6232 RECURSION IN THE match() FUNCTION
6234 Undefine all the macros that were defined above to handle this. */
6252 #undef new_recursive
6265 #undef save_capture_last
6275 /* These two are defined as macros in both cases */
6280 /***************************************************************************
6281 ***************************************************************************/
6285 /*************************************************
6286 * Release allocated heap frames *
6287 *************************************************/
6289 /* This function releases all the allocated frames. The base frame is on the
6290 machine stack, and so must not be freed.
6292 Argument: the address of the base frame
6297 release_match_heapframes (heapframe
*frame_base
)
6299 heapframe
*nextframe
= frame_base
->Xnextframe
;
6300 while (nextframe
!= NULL
)
6302 heapframe
*oldframe
= nextframe
;
6303 nextframe
= nextframe
->Xnextframe
;
6304 (PUBL(stack_free
))(oldframe
);
6310 /*************************************************
6311 * Execute a Regular Expression *
6312 *************************************************/
6314 /* This function applies a compiled re to a subject string and picks out
6315 portions of the string if it matches. Two elements in the vector are set for
6316 each substring: the offsets to the start and end of the substring.
6319 argument_re points to the compiled expression
6320 extra_data points to extra data or is NULL
6321 subject points to the subject string
6322 length length of subject string (may contain binary zeros)
6323 start_offset where to start in the subject string
6325 offsets points to a vector of ints to be filled in with offsets
6326 offsetcount the number of elements in the vector
6328 Returns: > 0 => success; value is the number of elements filled in
6329 = 0 => success, but offsets is not big enough
6330 -1 => failed to match
6331 < -1 => some kind of unexpected problem
6334 #ifdef COMPILE_PCRE8
6335 PCRE_EXP_DEFN
int PCRE_CALL_CONVENTION
6336 pcre_exec(const pcre
*argument_re
, const pcre_extra
*extra_data
,
6337 PCRE_SPTR subject
, int length
, int start_offset
, int options
, int *offsets
,
6340 PCRE_EXP_DEFN
int PCRE_CALL_CONVENTION
6341 pcre16_exec(const pcre16
*argument_re
, const pcre16_extra
*extra_data
,
6342 PCRE_SPTR16 subject
, int length
, int start_offset
, int options
, int *offsets
,
6346 int rc
, ocount
, arg_offset_max
;
6348 BOOL using_temporary_offsets
= FALSE
;
6353 BOOL has_first_char
= FALSE
;
6354 BOOL has_req_char
= FALSE
;
6355 pcre_uchar first_char
= 0;
6356 pcre_uchar first_char2
= 0;
6357 pcre_uchar req_char
= 0;
6358 pcre_uchar req_char2
= 0;
6359 match_data match_block
;
6360 match_data
*md
= &match_block
;
6361 const pcre_uint8
*tables
;
6362 const pcre_uint8
*start_bits
= NULL
;
6363 PCRE_PUCHAR start_match
= (PCRE_PUCHAR
)subject
+ start_offset
;
6364 PCRE_PUCHAR end_subject
;
6365 PCRE_PUCHAR start_partial
= NULL
;
6366 PCRE_PUCHAR req_char_ptr
= start_match
- 1;
6368 const pcre_study_data
*study
;
6369 const REAL_PCRE
*re
= (const REAL_PCRE
*)argument_re
;
6372 heapframe frame_zero
;
6373 frame_zero
.Xprevframe
= NULL
; /* Marks the top level */
6374 frame_zero
.Xnextframe
= NULL
; /* None are allocated yet */
6375 md
->match_frames_base
= &frame_zero
;
6378 /* Check for the special magic call that measures the size of the stack used
6379 per recursive call of match(). Without the funny casting for sizeof, a Windows
6380 compiler gave this error: "unary minus operator applied to unsigned type,
6381 result still unsigned". Hopefully the cast fixes that. */
6383 if (re
== NULL
&& extra_data
== NULL
&& subject
== NULL
&& length
== -999 &&
6384 start_offset
== -999)
6386 return -((int)sizeof(heapframe
));
6388 return match(NULL
, NULL
, NULL
, 0, NULL
, NULL
, 0);
6391 /* Plausibility checks */
6393 if ((options
& ~PUBLIC_EXEC_OPTIONS
) != 0) return PCRE_ERROR_BADOPTION
;
6394 if (re
== NULL
|| subject
== NULL
|| (offsets
== NULL
&& offsetcount
> 0))
6395 return PCRE_ERROR_NULL
;
6396 if (offsetcount
< 0) return PCRE_ERROR_BADCOUNT
;
6397 if (start_offset
< 0 || start_offset
> length
) return PCRE_ERROR_BADOFFSET
;
6399 /* Check that the first field in the block is the magic number. If it is not,
6400 return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to
6401 REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which
6402 means that the pattern is likely compiled with different endianness. */
6404 if (re
->magic_number
!= MAGIC_NUMBER
)
6405 return re
->magic_number
== REVERSED_MAGIC_NUMBER
?
6406 PCRE_ERROR_BADENDIANNESS
:PCRE_ERROR_BADMAGIC
;
6407 if ((re
->flags
& PCRE_MODE
) == 0) return PCRE_ERROR_BADMODE
;
6409 /* These two settings are used in the code for checking a UTF-8 string that
6410 follows immediately afterwards. Other values in the md block are used only
6411 during "normal" pcre_exec() processing, not when the JIT support is in use,
6412 so they are set up later. */
6414 /* PCRE_UTF16 has the same value as PCRE_UTF8. */
6415 utf
= md
->utf
= (re
->options
& PCRE_UTF8
) != 0;
6416 md
->partial
= ((options
& PCRE_PARTIAL_HARD
) != 0)? 2 :
6417 ((options
& PCRE_PARTIAL_SOFT
) != 0)? 1 : 0;
6419 /* Check a UTF-8 string if required. Pass back the character offset and error
6420 code for an invalid string if a results vector is available. */
6423 if (utf
&& (options
& PCRE_NO_UTF8_CHECK
) == 0)
6426 int errorcode
= PRIV(valid_utf
)((PCRE_PUCHAR
)subject
, length
, &erroroffset
);
6429 if (offsetcount
>= 2)
6431 offsets
[0] = erroroffset
;
6432 offsets
[1] = errorcode
;
6434 #ifdef COMPILE_PCRE16
6435 return (errorcode
<= PCRE_UTF16_ERR1
&& md
->partial
> 1)?
6436 PCRE_ERROR_SHORTUTF16
: PCRE_ERROR_BADUTF16
;
6438 return (errorcode
<= PCRE_UTF8_ERR5
&& md
->partial
> 1)?
6439 PCRE_ERROR_SHORTUTF8
: PCRE_ERROR_BADUTF8
;
6443 /* Check that a start_offset points to the start of a UTF character. */
6444 if (start_offset
> 0 && start_offset
< length
&&
6445 NOT_FIRSTCHAR(((PCRE_PUCHAR
)subject
)[start_offset
]))
6446 return PCRE_ERROR_BADUTF8_OFFSET
;
6450 /* If the pattern was successfully studied with JIT support, run the JIT
6451 executable instead of the rest of this function. Most options must be set at
6452 compile time for the JIT code to be usable. Fallback to the normal code path if
6453 an unsupported flag is set. */
6456 if (extra_data
!= NULL
6457 && (extra_data
->flags
& (PCRE_EXTRA_EXECUTABLE_JIT
|
6458 PCRE_EXTRA_TABLES
)) == PCRE_EXTRA_EXECUTABLE_JIT
6459 && extra_data
->executable_jit
!= NULL
6460 && (options
& ~(PCRE_NO_UTF8_CHECK
| PCRE_NOTBOL
| PCRE_NOTEOL
|
6461 PCRE_NOTEMPTY
| PCRE_NOTEMPTY_ATSTART
|
6462 PCRE_PARTIAL_SOFT
| PCRE_PARTIAL_HARD
)) == 0)
6464 rc
= PRIV(jit_exec
)(re
, extra_data
, (const pcre_uchar
*)subject
, length
,
6465 start_offset
, options
, offsets
, offsetcount
);
6467 /* PCRE_ERROR_NULL means that the selected normal or partial matching
6468 mode is not compiled. In this case we simply fallback to interpreter. */
6470 if (rc
!= PCRE_ERROR_NULL
) return rc
;
6474 /* Carry on with non-JIT matching. This information is for finding all the
6475 numbers associated with a given name, for condition testing. */
6477 md
->name_table
= (pcre_uchar
*)re
+ re
->name_table_offset
;
6478 md
->name_count
= re
->name_count
;
6479 md
->name_entry_size
= re
->name_entry_size
;
6481 /* Fish out the optional data from the extra_data structure, first setting
6482 the default values. */
6485 md
->match_limit
= MATCH_LIMIT
;
6486 md
->match_limit_recursion
= MATCH_LIMIT_RECURSION
;
6487 md
->callout_data
= NULL
;
6489 /* The table pointer is always in native byte order. */
6491 tables
= re
->tables
;
6493 if (extra_data
!= NULL
)
6495 unsigned int flags
= extra_data
->flags
;
6496 if ((flags
& PCRE_EXTRA_STUDY_DATA
) != 0)
6497 study
= (const pcre_study_data
*)extra_data
->study_data
;
6498 if ((flags
& PCRE_EXTRA_MATCH_LIMIT
) != 0)
6499 md
->match_limit
= extra_data
->match_limit
;
6500 if ((flags
& PCRE_EXTRA_MATCH_LIMIT_RECURSION
) != 0)
6501 md
->match_limit_recursion
= extra_data
->match_limit_recursion
;
6502 if ((flags
& PCRE_EXTRA_CALLOUT_DATA
) != 0)
6503 md
->callout_data
= extra_data
->callout_data
;
6504 if ((flags
& PCRE_EXTRA_TABLES
) != 0) tables
= extra_data
->tables
;
6507 /* If the exec call supplied NULL for tables, use the inbuilt ones. This
6508 is a feature that makes it possible to save compiled regex and re-use them
6509 in other programs later. */
6511 if (tables
== NULL
) tables
= PRIV(default_tables
);
6513 /* Set up other data */
6515 anchored
= ((re
->options
| options
) & PCRE_ANCHORED
) != 0;
6516 startline
= (re
->flags
& PCRE_STARTLINE
) != 0;
6517 firstline
= (re
->options
& PCRE_FIRSTLINE
) != 0;
6519 /* The code starts after the real_pcre block and the capture name table. */
6521 md
->start_code
= (const pcre_uchar
*)re
+ re
->name_table_offset
+
6522 re
->name_count
* re
->name_entry_size
;
6524 md
->start_subject
= (PCRE_PUCHAR
)subject
;
6525 md
->start_offset
= start_offset
;
6526 md
->end_subject
= md
->start_subject
+ length
;
6527 end_subject
= md
->end_subject
;
6529 md
->endonly
= (re
->options
& PCRE_DOLLAR_ENDONLY
) != 0;
6530 md
->use_ucp
= (re
->options
& PCRE_UCP
) != 0;
6531 md
->jscript_compat
= (re
->options
& PCRE_JAVASCRIPT_COMPAT
) != 0;
6532 md
->ignore_skip_arg
= FALSE
;
6534 /* Some options are unpacked into BOOL variables in the hope that testing
6535 them will be faster than individual option bits. */
6537 md
->notbol
= (options
& PCRE_NOTBOL
) != 0;
6538 md
->noteol
= (options
& PCRE_NOTEOL
) != 0;
6539 md
->notempty
= (options
& PCRE_NOTEMPTY
) != 0;
6540 md
->notempty_atstart
= (options
& PCRE_NOTEMPTY_ATSTART
) != 0;
6543 md
->mark
= md
->nomatch_mark
= NULL
; /* In case never set */
6545 md
->recursive
= NULL
; /* No recursion at top level */
6546 md
->hasthen
= (re
->flags
& PCRE_HASTHEN
) != 0;
6548 md
->lcc
= tables
+ lcc_offset
;
6549 md
->fcc
= tables
+ fcc_offset
;
6550 md
->ctypes
= tables
+ ctypes_offset
;
6552 /* Handle different \R options. */
6554 switch (options
& (PCRE_BSR_ANYCRLF
|PCRE_BSR_UNICODE
))
6557 if ((re
->options
& (PCRE_BSR_ANYCRLF
|PCRE_BSR_UNICODE
)) != 0)
6558 md
->bsr_anycrlf
= (re
->options
& PCRE_BSR_ANYCRLF
) != 0;
6561 md
->bsr_anycrlf
= TRUE
;
6563 md
->bsr_anycrlf
= FALSE
;
6567 case PCRE_BSR_ANYCRLF
:
6568 md
->bsr_anycrlf
= TRUE
;
6571 case PCRE_BSR_UNICODE
:
6572 md
->bsr_anycrlf
= FALSE
;
6575 default: return PCRE_ERROR_BADNEWLINE
;
6578 /* Handle different types of newline. The three bits give eight cases. If
6579 nothing is set at run time, whatever was used at compile time applies. */
6581 switch ((((options
& PCRE_NEWLINE_BITS
) == 0)? re
->options
:
6582 (pcre_uint32
)options
) & PCRE_NEWLINE_BITS
)
6584 case 0: newline
= NEWLINE
; break; /* Compile-time default */
6585 case PCRE_NEWLINE_CR
: newline
= CHAR_CR
; break;
6586 case PCRE_NEWLINE_LF
: newline
= CHAR_NL
; break;
6587 case PCRE_NEWLINE_CR
+
6588 PCRE_NEWLINE_LF
: newline
= (CHAR_CR
<< 8) | CHAR_NL
; break;
6589 case PCRE_NEWLINE_ANY
: newline
= -1; break;
6590 case PCRE_NEWLINE_ANYCRLF
: newline
= -2; break;
6591 default: return PCRE_ERROR_BADNEWLINE
;
6596 md
->nltype
= NLTYPE_ANYCRLF
;
6598 else if (newline
< 0)
6600 md
->nltype
= NLTYPE_ANY
;
6604 md
->nltype
= NLTYPE_FIXED
;
6608 md
->nl
[0] = (newline
>> 8) & 255;
6609 md
->nl
[1] = newline
& 255;
6614 md
->nl
[0] = newline
;
6618 /* Partial matching was originally supported only for a restricted set of
6619 regexes; from release 8.00 there are no restrictions, but the bits are still
6620 defined (though never set). So there's no harm in leaving this code. */
6622 if (md
->partial
&& (re
->flags
& PCRE_NOPARTIAL
) != 0)
6623 return PCRE_ERROR_BADPARTIAL
;
6625 /* If the expression has got more back references than the offsets supplied can
6626 hold, we get a temporary chunk of working store to use during the matching.
6627 Otherwise, we can use the vector supplied, rounding down its size to a multiple
6630 ocount
= offsetcount
- (offsetcount
% 3);
6631 arg_offset_max
= (2*ocount
)/3;
6633 if (re
->top_backref
> 0 && re
->top_backref
>= ocount
/3)
6635 ocount
= re
->top_backref
* 3 + 3;
6636 md
->offset_vector
= (int *)(PUBL(malloc
))(ocount
* sizeof(int));
6637 if (md
->offset_vector
== NULL
) return PCRE_ERROR_NOMEMORY
;
6638 using_temporary_offsets
= TRUE
;
6639 DPRINTF(("Got memory to hold back references\n"));
6641 else md
->offset_vector
= offsets
;
6643 md
->offset_end
= ocount
;
6644 md
->offset_max
= (2*ocount
)/3;
6645 md
->offset_overflow
= FALSE
;
6646 md
->capture_last
= -1;
6648 /* Reset the working variable associated with each extraction. These should
6649 never be used unless previously set, but they get saved and restored, and so we
6650 initialize them to avoid reading uninitialized locations. Also, unset the
6651 offsets for the matched string. This is really just for tidiness with callouts,
6652 in case they inspect these fields. */
6654 if (md
->offset_vector
!= NULL
)
6656 int *iptr
= md
->offset_vector
+ ocount
;
6657 int *iend
= iptr
- re
->top_bracket
;
6658 if (iend
< md
->offset_vector
+ 2) iend
= md
->offset_vector
+ 2;
6659 while (--iptr
>= iend
) *iptr
= -1;
6660 md
->offset_vector
[0] = md
->offset_vector
[1] = -1;
6663 /* Set up the first character to match, if available. The first_char value is
6664 never set for an anchored regular expression, but the anchoring may be forced
6665 at run time, so we have to test for anchoring. The first char may be unset for
6666 an unanchored pattern, of course. If there's no first char and the pattern was
6667 studied, there may be a bitmap of possible first characters. */
6671 if ((re
->flags
& PCRE_FIRSTSET
) != 0)
6673 has_first_char
= TRUE
;
6674 first_char
= first_char2
= (pcre_uchar
)(re
->first_char
);
6675 if ((re
->flags
& PCRE_FCH_CASELESS
) != 0)
6677 first_char2
= TABLE_GET(first_char
, md
->fcc
, first_char
);
6678 #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
6679 if (utf
&& first_char
> 127)
6680 first_char2
= UCD_OTHERCASE(first_char
);
6685 if (!startline
&& study
!= NULL
&&
6686 (study
->flags
& PCRE_STUDY_MAPPED
) != 0)
6687 start_bits
= study
->start_bits
;
6690 /* For anchored or unanchored matches, there may be a "last known required
6693 if ((re
->flags
& PCRE_REQCHSET
) != 0)
6695 has_req_char
= TRUE
;
6696 req_char
= req_char2
= (pcre_uchar
)(re
->req_char
);
6697 if ((re
->flags
& PCRE_RCH_CASELESS
) != 0)
6699 req_char2
= TABLE_GET(req_char
, md
->fcc
, req_char
);
6700 #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
6701 if (utf
&& req_char
> 127)
6702 req_char2
= UCD_OTHERCASE(req_char
);
6708 /* ==========================================================================*/
6710 /* Loop for handling unanchored repeated matching attempts; for anchored regexs
6711 the loop runs just once. */
6715 PCRE_PUCHAR save_end_subject
= end_subject
;
6716 PCRE_PUCHAR new_start_match
;
6718 /* If firstline is TRUE, the start of the match is constrained to the first
6719 line of a multiline string. That is, the match must be before or at the first
6720 newline. Implement this by temporarily adjusting end_subject so that we stop
6721 scanning at a newline. If the match fails at the newline, later code breaks
6726 PCRE_PUCHAR t
= start_match
;
6730 while (t
< md
->end_subject
&& !IS_NEWLINE(t
))
6733 ACROSSCHAR(t
< end_subject
, *t
, t
++);
6738 while (t
< md
->end_subject
&& !IS_NEWLINE(t
)) t
++;
6742 /* There are some optimizations that avoid running the match if a known
6743 starting point is not found, or if a known later character is not present.
6744 However, there is an option that disables these, for testing and for ensuring
6745 that all callouts do actually occur. The option can be set in the regex by
6746 (*NO_START_OPT) or passed in match-time options. */
6748 if (((options
| re
->options
) & PCRE_NO_START_OPTIMIZE
) == 0)
6750 /* Advance to a unique first char if there is one. */
6754 if (first_char
!= first_char2
)
6755 while (start_match
< end_subject
&&
6756 *start_match
!= first_char
&& *start_match
!= first_char2
)
6759 while (start_match
< end_subject
&& *start_match
!= first_char
)
6763 /* Or to just after a linebreak for a multiline match */
6767 if (start_match
> md
->start_subject
+ start_offset
)
6772 while (start_match
< end_subject
&& !WAS_NEWLINE(start_match
))
6775 ACROSSCHAR(start_match
< end_subject
, *start_match
,
6781 while (start_match
< end_subject
&& !WAS_NEWLINE(start_match
))
6784 /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
6785 and we are now at a LF, advance the match position by one more character.
6788 if (start_match
[-1] == CHAR_CR
&&
6789 (md
->nltype
== NLTYPE_ANY
|| md
->nltype
== NLTYPE_ANYCRLF
) &&
6790 start_match
< end_subject
&&
6791 *start_match
== CHAR_NL
)
6796 /* Or to a non-unique first byte after study */
6798 else if (start_bits
!= NULL
)
6800 while (start_match
< end_subject
)
6802 unsigned int c
= *start_match
;
6803 #ifndef COMPILE_PCRE8
6804 if (c
> 255) c
= 255;
6806 if ((start_bits
[c
/8] & (1 << (c
&7))) == 0)
6809 #if defined SUPPORT_UTF && defined COMPILE_PCRE8
6810 /* In non 8-bit mode, the iteration will stop for
6811 characters > 255 at the beginning or not stop at all. */
6813 ACROSSCHAR(start_match
< end_subject
, *start_match
,
6820 } /* Starting optimizations */
6822 /* Restore fudged end_subject */
6824 end_subject
= save_end_subject
;
6826 /* The following two optimizations are disabled for partial matching or if
6827 disabling is explicitly requested. */
6829 if (((options
| re
->options
) & PCRE_NO_START_OPTIMIZE
) == 0 && !md
->partial
)
6831 /* If the pattern was studied, a minimum subject length may be set. This is
6832 a lower bound; no actual string of that length may actually match the
6833 pattern. Although the value is, strictly, in characters, we treat it as
6834 bytes to avoid spending too much time in this optimization. */
6836 if (study
!= NULL
&& (study
->flags
& PCRE_STUDY_MINLEN
) != 0 &&
6837 (pcre_uint32
)(end_subject
- start_match
) < study
->minlength
)
6843 /* If req_char is set, we know that that character must appear in the
6844 subject for the match to succeed. If the first character is set, req_char
6845 must be later in the subject; otherwise the test starts at the match point.
6846 This optimization can save a huge amount of backtracking in patterns with
6847 nested unlimited repeats that aren't going to match. Writing separate code
6848 for cased/caseless versions makes it go faster, as does using an
6849 autoincrement and backing off on a match.
6851 HOWEVER: when the subject string is very, very long, searching to its end
6852 can take a long time, and give bad performance on quite ordinary patterns.
6853 This showed up when somebody was matching something like /^\d+C/ on a
6854 32-megabyte string... so we don't do this when the string is sufficiently
6857 if (has_req_char
&& end_subject
- start_match
< REQ_BYTE_MAX
)
6859 PCRE_PUCHAR p
= start_match
+ (has_first_char
? 1:0);
6861 /* We don't need to repeat the search if we haven't yet reached the
6862 place we found it at last time. */
6864 if (p
> req_char_ptr
)
6866 if (req_char
!= req_char2
)
6868 while (p
< end_subject
)
6871 if (pp
== req_char
|| pp
== req_char2
) { p
--; break; }
6876 while (p
< end_subject
)
6878 if (*p
++ == req_char
) { p
--; break; }
6882 /* If we can't find the required character, break the matching loop,
6883 forcing a match failure. */
6885 if (p
>= end_subject
)
6891 /* If we have found the required character, save the point where we
6892 found it, so that we don't search again next time round the loop if
6893 the start hasn't passed this character yet. */
6900 #ifdef PCRE_DEBUG /* Sigh. Some compilers never learn. */
6901 printf(">>>> Match against: ");
6902 pchars(start_match
, end_subject
- start_match
, TRUE
, md
);
6906 /* OK, we can now run the match. If "hitend" is set afterwards, remember the
6907 first starting point for which a partial match was found. */
6909 md
->start_match_ptr
= start_match
;
6910 md
->start_used_ptr
= start_match
;
6911 md
->match_call_count
= 0;
6912 md
->match_function_type
= 0;
6913 md
->end_offset_top
= 0;
6914 rc
= match(start_match
, md
->start_code
, start_match
, 2, md
, NULL
, 0);
6915 if (md
->hitend
&& start_partial
== NULL
) start_partial
= md
->start_used_ptr
;
6919 /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched
6920 the SKIP's arg was not found. In this circumstance, Perl ignores the SKIP
6921 entirely. The only way we can do that is to re-do the match at the same
6922 point, with a flag to force SKIP with an argument to be ignored. Just
6923 treating this case as NOMATCH does not work because it does not check other
6924 alternatives in patterns such as A(*SKIP:A)B|AC when the subject is AC. */
6926 case MATCH_SKIP_ARG
:
6927 new_start_match
= start_match
;
6928 md
->ignore_skip_arg
= TRUE
;
6931 /* SKIP passes back the next starting point explicitly, but if it is the
6932 same as the match we have just done, treat it as NOMATCH. */
6935 if (md
->start_match_ptr
!= start_match
)
6937 new_start_match
= md
->start_match_ptr
;
6942 /* NOMATCH and PRUNE advance by one character. THEN at this level acts
6943 exactly like PRUNE. Unset the ignore SKIP-with-argument flag. */
6948 md
->ignore_skip_arg
= FALSE
;
6949 new_start_match
= start_match
+ 1;
6952 ACROSSCHAR(new_start_match
< end_subject
, *new_start_match
,
6957 /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
6963 /* Any other return is either a match, or some kind of error. */
6969 /* Control reaches here for the various types of "no match at this point"
6970 result. Reset the code to MATCH_NOMATCH for subsequent checking. */
6974 /* If PCRE_FIRSTLINE is set, the match must happen before or at the first
6975 newline in the subject (though it may continue over the newline). Therefore,
6976 if we have just failed to match, starting at a newline, do not continue. */
6978 if (firstline
&& IS_NEWLINE(start_match
)) break;
6980 /* Advance to new matching position */
6982 start_match
= new_start_match
;
6984 /* Break the loop if the pattern is anchored or if we have passed the end of
6987 if (anchored
|| start_match
> end_subject
) break;
6989 /* If we have just passed a CR and we are now at a LF, and the pattern does
6990 not contain any explicit matches for \r or \n, and the newline option is CRLF
6991 or ANY or ANYCRLF, advance the match position by one more character. In
6992 normal matching start_match will aways be greater than the first position at
6993 this stage, but a failed *SKIP can cause a return at the same point, which is
6994 why the first test exists. */
6996 if (start_match
> (PCRE_PUCHAR
)subject
+ start_offset
&&
6997 start_match
[-1] == CHAR_CR
&&
6998 start_match
< end_subject
&&
6999 *start_match
== CHAR_NL
&&
7000 (re
->flags
& PCRE_HASCRORLF
) == 0 &&
7001 (md
->nltype
== NLTYPE_ANY
||
7002 md
->nltype
== NLTYPE_ANYCRLF
||
7006 md
->mark
= NULL
; /* Reset for start of next match attempt */
7007 } /* End of for(;;) "bumpalong" loop */
7009 /* ==========================================================================*/
7011 /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping
7014 (1) The pattern is anchored or the match was failed by (*COMMIT);
7016 (2) We are past the end of the subject;
7018 (3) PCRE_FIRSTLINE is set and we have failed to match at a newline, because
7019 this option requests that a match occur at or before the first newline in
7022 When we have a match and the offset vector is big enough to deal with any
7023 backreferences, captured substring offsets will already be set up. In the case
7024 where we had to get some local store to hold offsets for backreference
7025 processing, copy those that we can. In this case there need not be overflow if
7026 certain parts of the pattern were not used, even though there are more
7027 capturing parentheses than vector slots. */
7031 if (rc
== MATCH_MATCH
|| rc
== MATCH_ACCEPT
)
7033 if (using_temporary_offsets
)
7035 if (arg_offset_max
>= 4)
7037 memcpy(offsets
+ 2, md
->offset_vector
+ 2,
7038 (arg_offset_max
- 2) * sizeof(int));
7039 DPRINTF(("Copied offsets from temporary memory\n"));
7041 if (md
->end_offset_top
> arg_offset_max
) md
->offset_overflow
= TRUE
;
7042 DPRINTF(("Freeing temporary memory\n"));
7043 (PUBL(free
))(md
->offset_vector
);
7046 /* Set the return code to the number of captured strings, or 0 if there were
7047 too many to fit into the vector. */
7049 rc
= (md
->offset_overflow
&& md
->end_offset_top
>= arg_offset_max
)?
7050 0 : md
->end_offset_top
/2;
7052 /* If there is space in the offset vector, set any unused pairs at the end of
7053 the pattern to -1 for backwards compatibility. It is documented that this
7054 happens. In earlier versions, the whole set of potential capturing offsets
7055 was set to -1 each time round the loop, but this is handled differently now.
7056 "Gaps" are set to -1 dynamically instead (this fixes a bug). Thus, it is only
7057 those at the end that need unsetting here. We can't just unset them all at
7058 the start of the whole thing because they may get set in one branch that is
7059 not the final matching branch. */
7061 if (md
->end_offset_top
/2 <= re
->top_bracket
&& offsets
!= NULL
)
7064 int resetcount
= 2 + re
->top_bracket
* 2;
7065 if (resetcount
> offsetcount
) resetcount
= offsetcount
;
7066 iptr
= offsets
+ md
->end_offset_top
;
7067 iend
= offsets
+ resetcount
;
7068 while (iptr
< iend
) *iptr
++ = -1;
7071 /* If there is space, set up the whole thing as substring 0. The value of
7072 md->start_match_ptr might be modified if \K was encountered on the success
7075 if (offsetcount
< 2) rc
= 0; else
7077 offsets
[0] = (int)(md
->start_match_ptr
- md
->start_subject
);
7078 offsets
[1] = (int)(md
->end_match_ptr
- md
->start_subject
);
7081 /* Return MARK data if requested */
7083 if (extra_data
!= NULL
&& (extra_data
->flags
& PCRE_EXTRA_MARK
) != 0)
7084 *(extra_data
->mark
) = (pcre_uchar
*)md
->mark
;
7085 DPRINTF((">>>> returning %d\n", rc
));
7087 release_match_heapframes(&frame_zero
);
7092 /* Control gets here if there has been an error, or if the overall match
7093 attempt has failed at all permitted starting positions. */
7095 if (using_temporary_offsets
)
7097 DPRINTF(("Freeing temporary memory\n"));
7098 (PUBL(free
))(md
->offset_vector
);
7101 /* For anything other than nomatch or partial match, just return the code. */
7103 if (rc
!= MATCH_NOMATCH
&& rc
!= PCRE_ERROR_PARTIAL
)
7105 DPRINTF((">>>> error: returning %d\n", rc
));
7107 release_match_heapframes(&frame_zero
);
7112 /* Handle partial matches - disable any mark data */
7114 if (start_partial
!= NULL
)
7116 DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));
7118 if (offsetcount
> 1)
7120 offsets
[0] = (int)(start_partial
- (PCRE_PUCHAR
)subject
);
7121 offsets
[1] = (int)(end_subject
- (PCRE_PUCHAR
)subject
);
7123 rc
= PCRE_ERROR_PARTIAL
;
7126 /* This is the classic nomatch case */
7130 DPRINTF((">>>> returning PCRE_ERROR_NOMATCH\n"));
7131 rc
= PCRE_ERROR_NOMATCH
;
7134 /* Return the MARK data if it has been requested. */
7136 if (extra_data
!= NULL
&& (extra_data
->flags
& PCRE_EXTRA_MARK
) != 0)
7137 *(extra_data
->mark
) = (pcre_uchar
*)md
->nomatch_mark
;
7139 release_match_heapframes(&frame_zero
);
7144 /* End of pcre_exec.c */