Parent Directory
|
Revision Log
|
Patch
revision 123 by ph10, Mon Mar 12 15:19:06 2007 UTC | revision 608 by ph10, Sun Jun 12 16:25:55 2011 UTC | |
---|---|---|
# | Line 6 | Line 6 |
6 | and semantics are as close as possible to those of the Perl 5 language. | and semantics are as close as possible to those of the Perl 5 language. |
7 | ||
8 | Written by Philip Hazel | Written by Philip Hazel |
9 | Copyright (c) 1997-2007 University of Cambridge | Copyright (c) 1997-2011 University of Cambridge |
10 | ||
11 | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
12 | Redistribution and use in source and binary forms, with or without | Redistribution and use in source and binary forms, with or without |
# | Line 42 POSSIBILITY OF SUCH DAMAGE. | Line 42 POSSIBILITY OF SUCH DAMAGE. |
42 | pattern matching using an NFA algorithm, trying to mimic Perl as closely as | pattern matching using an NFA algorithm, trying to mimic Perl as closely as |
43 | possible. There are also some static supporting functions. */ | possible. There are also some static supporting functions. */ |
44 | ||
45 | #ifdef HAVE_CONFIG_H | |
46 | #include "config.h" | |
47 | #endif | |
48 | ||
49 | #define NLBLOCK md /* Block containing newline information */ | #define NLBLOCK md /* Block containing newline information */ |
50 | #define PSSTART start_subject /* Field containing processed string start */ | #define PSSTART start_subject /* Field containing processed string start */ |
51 | #define PSEND end_subject /* Field containing processed string end */ | #define PSEND end_subject /* Field containing processed string end */ |
52 | ||
53 | #include "pcre_internal.h" | #include "pcre_internal.h" |
54 | ||
55 | /* The chain of eptrblocks for tail recursions uses memory in stack workspace, | /* Undefine some potentially clashing cpp symbols */ |
obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */ | ||
56 | ||
57 | #define EPTR_WORK_SIZE (1000) | #undef min |
58 | #undef max | |
59 | ||
60 | /* Flag bits for the match() function */ | /* Values for setting in md->match_function_type to indicate two special types |
61 | of call to match(). We do it this way to save on using another stack variable, | |
62 | as stack usage is to be discouraged. */ | |
63 | ||
64 | #define match_condassert 0x01 /* Called to check a condition assertion */ | #define MATCH_CONDASSERT 1 /* Called to check a condition assertion */ |
65 | #define match_cbegroup 0x02 /* Could-be-empty unlimited repeat group */ | #define MATCH_CBEGROUP 2 /* Could-be-empty unlimited repeat group */ |
#define match_tail_recursed 0x04 /* Tail recursive call */ | ||
66 | ||
67 | /* Non-error returns from the match() function. Error returns are externally | /* Non-error returns from the match() function. Error returns are externally |
68 | defined PCRE_ERROR_xxx codes, which are all negative. */ | defined PCRE_ERROR_xxx codes, which are all negative. */ |
# | Line 65 defined PCRE_ERROR_xxx codes, which are | Line 70 defined PCRE_ERROR_xxx codes, which are |
70 | #define MATCH_MATCH 1 | #define MATCH_MATCH 1 |
71 | #define MATCH_NOMATCH 0 | #define MATCH_NOMATCH 0 |
72 | ||
73 | /* Special internal returns from the match() function. Make them sufficiently | |
74 | negative to avoid the external error codes. */ | |
75 | ||
76 | #define MATCH_ACCEPT (-999) | |
77 | #define MATCH_COMMIT (-998) | |
78 | #define MATCH_KETRPOS (-997) | |
79 | #define MATCH_PRUNE (-996) | |
80 | #define MATCH_SKIP (-995) | |
81 | #define MATCH_SKIP_ARG (-994) | |
82 | #define MATCH_THEN (-993) | |
83 | ||
84 | /* This is a convenience macro for code that occurs many times. */ | |
85 | ||
86 | #define MRRETURN(ra) \ | |
87 | { \ | |
88 | md->mark = markptr; \ | |
89 | RRETURN(ra); \ | |
90 | } | |
91 | ||
92 | /* Maximum number of ints of offset to save on the stack for recursive calls. | /* Maximum number of ints of offset to save on the stack for recursive calls. |
93 | If the offset vector is bigger, malloc is used. This should be a multiple of 3, | If the offset vector is bigger, malloc is used. This should be a multiple of 3, |
94 | because the offset vector is always a multiple of 3 long. */ | because the offset vector is always a multiple of 3 long. */ |
# | Line 78 static const char rep_max[] = { 0, 0, 0, | Line 102 static const char rep_max[] = { 0, 0, 0, |
102 | ||
103 | ||
104 | ||
105 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
106 | /************************************************* | /************************************************* |
107 | * Debugging function to print chars * | * Debugging function to print chars * |
108 | *************************************************/ | *************************************************/ |
# | Line 111 while (length-- > 0) | Line 135 while (length-- > 0) |
135 | * Match a back-reference * | * Match a back-reference * |
136 | *************************************************/ | *************************************************/ |
137 | ||
138 | /* If a back reference hasn't been set, the length that is passed is greater | /* Normally, if a back reference hasn't been set, the length that is passed is |
139 | than the number of characters left in the string, so the match fails. | negative, so the match always fails. However, in JavaScript compatibility mode, |
140 | the length passed is zero. Note that in caseless UTF-8 mode, the number of | |
141 | subject bytes matched may be different to the number of reference bytes. | |
142 | ||
143 | Arguments: | Arguments: |
144 | offset index into the offset vector | offset index into the offset vector |
145 | eptr points into the subject | eptr pointer into the subject |
146 | length length to be matched | length length of reference to be matched (number of bytes) |
147 | md points to match data block | md points to match data block |
148 | ims the ims flags | caseless TRUE if caseless |
149 | ||
150 | Returns: TRUE if matched | Returns: < 0 if not matched, otherwise the number of subject bytes matched |
151 | */ | */ |
152 | ||
153 | static BOOL | static int |
154 | match_ref(int offset, register USPTR eptr, int length, match_data *md, | match_ref(int offset, register USPTR eptr, int length, match_data *md, |
155 | unsigned long int ims) | BOOL caseless) |
156 | { | { |
157 | USPTR p = md->start_subject + md->offset_vector[offset]; | USPTR eptr_start = eptr; |
158 | register USPTR p = md->start_subject + md->offset_vector[offset]; | |
159 | ||
160 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
161 | if (eptr >= md->end_subject) | if (eptr >= md->end_subject) |
162 | printf("matching subject <null>"); | printf("matching subject <null>"); |
163 | else | else |
# | Line 143 pchars(p, length, FALSE, md); | Line 170 pchars(p, length, FALSE, md); |
170 | printf("\n"); | printf("\n"); |
171 | #endif | #endif |
172 | ||
173 | /* Always fail if not enough characters left */ | /* Always fail if reference not set (and not JavaScript compatible). */ |
174 | ||
175 | if (length > md->end_subject - eptr) return FALSE; | if (length < 0) return -1; |
176 | ||
177 | /* Separate the caselesss case for speed */ | /* Separate the caseless case for speed. In UTF-8 mode we can only do this |
178 | properly if Unicode properties are supported. Otherwise, we can check only | |
179 | ASCII characters. */ | |
180 | ||
181 | if ((ims & PCRE_CASELESS) != 0) | if (caseless) |
182 | { | { |
183 | while (length-- > 0) | #ifdef SUPPORT_UTF8 |
184 | if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; | #ifdef SUPPORT_UCP |
185 | if (md->utf8) | |
186 | { | |
187 | /* Match characters up to the end of the reference. NOTE: the number of | |
188 | bytes matched may differ, because there are some characters whose upper and | |
189 | lower case versions code as different numbers of bytes. For example, U+023A | |
190 | (2 bytes in UTF-8) is the upper case version of U+2C65 (3 bytes in UTF-8); | |
191 | a sequence of 3 of the former uses 6 bytes, as does a sequence of two of | |
192 | the latter. It is important, therefore, to check the length along the | |
193 | reference, not along the subject (earlier code did this wrong). */ | |
194 | ||
195 | USPTR endptr = p + length; | |
196 | while (p < endptr) | |
197 | { | |
198 | int c, d; | |
199 | if (eptr >= md->end_subject) return -1; | |
200 | GETCHARINC(c, eptr); | |
201 | GETCHARINC(d, p); | |
202 | if (c != d && c != UCD_OTHERCASE(d)) return -1; | |
203 | } | |
204 | } | |
205 | else | |
206 | #endif | |
207 | #endif | |
208 | ||
209 | /* The same code works when not in UTF-8 mode and in UTF-8 mode when there | |
210 | is no UCP support. */ | |
211 | { | |
212 | if (eptr + length > md->end_subject) return -1; | |
213 | while (length-- > 0) | |
214 | { if (md->lcc[*p++] != md->lcc[*eptr++]) return -1; } | |
215 | } | |
216 | } | } |
217 | ||
218 | /* In the caseful case, we can just compare the bytes, whether or not we | |
219 | are in UTF-8 mode. */ | |
220 | ||
221 | else | else |
222 | { while (length-- > 0) if (*p++ != *eptr++) return FALSE; } | { |
223 | if (eptr + length > md->end_subject) return -1; | |
224 | while (length-- > 0) if (*p++ != *eptr++) return -1; | |
225 | } | |
226 | ||
227 | return TRUE; | return eptr - eptr_start; |
228 | } | } |
229 | ||
230 | ||
# | Line 183 calls by keeping local variables that ne | Line 250 calls by keeping local variables that ne |
250 | obtained from malloc() instead instead of on the stack. Macros are used to | obtained from malloc() instead instead of on the stack. Macros are used to |
251 | achieve this so that the actual code doesn't look very different to what it | achieve this so that the actual code doesn't look very different to what it |
252 | always used to. | always used to. |
253 | ||
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. | |
260 | ||
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 | ***************************************************************************/ | ***************************************************************************/ |
269 | ||
270 | /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN | |
271 | below must be updated in sync. */ | |
272 | ||
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 }; | |
280 | ||
281 | /* These versions of the macros use the stack, as normal. There are debugging | /* These versions of the macros use the stack, as normal. There are debugging |
282 | versions and production versions. */ | versions and production versions. Note that the "rw" argument of RMATCH isn't |
283 | actually used in this definition. */ | |
284 | ||
285 | #ifndef NO_RECURSE | #ifndef NO_RECURSE |
286 | #define REGISTER register | #define REGISTER register |
287 | #ifdef DEBUG | |
288 | #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \ | #ifdef PCRE_DEBUG |
289 | #define RMATCH(ra,rb,rc,rd,re,rw) \ | |
290 | { \ | { \ |
291 | printf("match() called in line %d\n", __LINE__); \ | printf("match() called in line %d\n", __LINE__); \ |
292 | rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \ | rrc = match(ra,rb,mstart,markptr,rc,rd,re,rdepth+1); \ |
293 | printf("to line %d\n", __LINE__); \ | printf("to line %d\n", __LINE__); \ |
294 | } | } |
295 | #define RRETURN(ra) \ | #define RRETURN(ra) \ |
# | Line 205 versions and production versions. */ | Line 298 versions and production versions. */ |
298 | return ra; \ | return ra; \ |
299 | } | } |
300 | #else | #else |
301 | #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \ | #define RMATCH(ra,rb,rc,rd,re,rw) \ |
302 | rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1) | rrc = match(ra,rb,mstart,markptr,rc,rd,re,rdepth+1) |
303 | #define RRETURN(ra) return ra | #define RRETURN(ra) return ra |
304 | #endif | #endif |
305 | ||
306 | #else | #else |
307 | ||
308 | ||
309 | /* These versions of the macros manage a private stack on the heap. Note | /* These versions of the macros manage a private stack on the heap. Note that |
310 | that the rd argument of RMATCH isn't actually used. It's the md argument of | the "rd" argument of RMATCH isn't actually used in this definition. It's the md |
311 | match(), which never changes. */ | argument of match(), which never changes. */ |
312 | ||
313 | #define REGISTER | #define REGISTER |
314 | ||
315 | #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\ | #define RMATCH(ra,rb,rc,rd,re,rw)\ |
316 | {\ | {\ |
317 | heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\ | heapframe *newframe = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));\ |
318 | if (setjmp(frame->Xwhere) == 0)\ | if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\ |
319 | {\ | frame->Xwhere = rw; \ |
320 | newframe->Xeptr = ra;\ | newframe->Xeptr = ra;\ |
321 | newframe->Xecode = rb;\ | newframe->Xecode = rb;\ |
322 | newframe->Xoffset_top = rc;\ | newframe->Xmstart = mstart;\ |
323 | newframe->Xims = re;\ | newframe->Xmarkptr = markptr;\ |
324 | newframe->Xeptrb = rf;\ | newframe->Xoffset_top = rc;\ |
325 | newframe->Xflags = rg;\ | newframe->Xeptrb = re;\ |
326 | newframe->Xrdepth = frame->Xrdepth + 1;\ | newframe->Xrdepth = frame->Xrdepth + 1;\ |
327 | newframe->Xprevframe = frame;\ | newframe->Xprevframe = frame;\ |
328 | frame = newframe;\ | frame = newframe;\ |
329 | DPRINTF(("restarting from line %d\n", __LINE__));\ | DPRINTF(("restarting from line %d\n", __LINE__));\ |
330 | goto HEAP_RECURSE;\ | goto HEAP_RECURSE;\ |
331 | }\ | L_##rw:\ |
332 | else\ | DPRINTF(("jumped back to line %d\n", __LINE__));\ |
{\ | ||
DPRINTF(("longjumped back to line %d\n", __LINE__));\ | ||
frame = md->thisframe;\ | ||
rx = frame->Xresult;\ | ||
}\ | ||
333 | } | } |
334 | ||
335 | #define RRETURN(ra)\ | #define RRETURN(ra)\ |
336 | {\ | {\ |
337 | heapframe *newframe = frame;\ | heapframe *oldframe = frame;\ |
338 | frame = newframe->Xprevframe;\ | frame = oldframe->Xprevframe;\ |
339 | (pcre_stack_free)(newframe);\ | (pcre_stack_free)(oldframe);\ |
340 | if (frame != NULL)\ | if (frame != NULL)\ |
341 | {\ | {\ |
342 | frame->Xresult = ra;\ | rrc = ra;\ |
343 | md->thisframe = frame;\ | goto HEAP_RETURN;\ |
longjmp(frame->Xwhere, 1);\ | ||
344 | }\ | }\ |
345 | return ra;\ | return ra;\ |
346 | } | } |
# | Line 266 typedef struct heapframe { | Line 353 typedef struct heapframe { |
353 | ||
354 | /* Function arguments that may change */ | /* Function arguments that may change */ |
355 | ||
356 | const uschar *Xeptr; | USPTR Xeptr; |
357 | const uschar *Xecode; | const uschar *Xecode; |
358 | USPTR Xmstart; | |
359 | USPTR Xmarkptr; | |
360 | int Xoffset_top; | int Xoffset_top; |
long int Xims; | ||
361 | eptrblock *Xeptrb; | eptrblock *Xeptrb; |
int Xflags; | ||
362 | unsigned int Xrdepth; | unsigned int Xrdepth; |
363 | ||
364 | /* Function local variables */ | /* Function local variables */ |
365 | ||
366 | const uschar *Xcallpat; | USPTR Xcallpat; |
367 | const uschar *Xcharptr; | #ifdef SUPPORT_UTF8 |
368 | const uschar *Xdata; | USPTR Xcharptr; |
369 | const uschar *Xnext; | #endif |
370 | const uschar *Xpp; | USPTR Xdata; |
371 | const uschar *Xprev; | USPTR Xnext; |
372 | const uschar *Xsaved_eptr; | USPTR Xpp; |
373 | USPTR Xprev; | |
374 | USPTR Xsaved_eptr; | |
375 | ||
376 | recursion_info Xnew_recursive; | recursion_info Xnew_recursive; |
377 | ||
# | Line 290 typedef struct heapframe { | Line 379 typedef struct heapframe { |
379 | BOOL Xcondition; | BOOL Xcondition; |
380 | BOOL Xprev_is_word; | BOOL Xprev_is_word; |
381 | ||
unsigned long int Xoriginal_ims; | ||
382 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
383 | int Xprop_type; | int Xprop_type; |
384 | int Xprop_value; | int Xprop_value; |
# | Line 303 typedef struct heapframe { | Line 390 typedef struct heapframe { |
390 | uschar Xocchars[8]; | uschar Xocchars[8]; |
391 | #endif | #endif |
392 | ||
393 | int Xcodelink; | |
394 | int Xctype; | int Xctype; |
395 | unsigned int Xfc; | unsigned int Xfc; |
396 | int Xfi; | int Xfi; |
# | Line 318 typedef struct heapframe { | Line 406 typedef struct heapframe { |
406 | ||
407 | eptrblock Xnewptrb; | eptrblock Xnewptrb; |
408 | ||
409 | /* Place to pass back result, and where to jump back to */ | /* Where to jump back to */ |
410 | ||
411 | int Xresult; | int Xwhere; |
jmp_buf Xwhere; | ||
412 | ||
413 | } heapframe; | } heapframe; |
414 | ||
# | Line 339 typedef struct heapframe { | Line 426 typedef struct heapframe { |
426 | ||
427 | /* This function is called recursively in many circumstances. Whenever it | /* This function is called recursively in many circumstances. Whenever it |
428 | returns a negative (error) response, the outer incarnation must also return the | returns a negative (error) response, the outer incarnation must also return the |
429 | same response. | same response. */ |
430 | ||
431 | /* These macros pack up tests that are used for partial matching, and which | |
432 | appears several times in the code. We set the "hit end" flag if the pointer is | |
433 | at the end of the subject and also past the start of the subject (i.e. | |
434 | something has been matched). For hard partial matching, we then return | |
435 | immediately. The second one is used when we already know we are past the end of | |
436 | the subject. */ | |
437 | ||
438 | #define CHECK_PARTIAL()\ | |
439 | if (md->partial != 0 && eptr >= md->end_subject && \ | |
440 | eptr > md->start_used_ptr) \ | |
441 | { \ | |
442 | md->hitend = TRUE; \ | |
443 | if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \ | |
444 | } | |
445 | ||
446 | Performance note: It might be tempting to extract commonly used fields from the | #define SCHECK_PARTIAL()\ |
447 | md structure (e.g. utf8, end_subject) into individual variables to improve | if (md->partial != 0 && eptr > md->start_used_ptr) \ |
448 | { \ | |
449 | md->hitend = TRUE; \ | |
450 | if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \ | |
451 | } | |
452 | ||
453 | ||
454 | /* Performance note: It might be tempting to extract commonly used fields from | |
455 | the md structure (e.g. utf8, end_subject) into individual variables to improve | |
456 | performance. Tests using gcc on a SPARC disproved this; in the first case, it | performance. Tests using gcc on a SPARC disproved this; in the first case, it |
457 | made performance worse. | made performance worse. |
458 | ||
459 | Arguments: | Arguments: |
460 | eptr pointer to current character in subject | eptr pointer to current character in subject |
461 | ecode pointer to current position in compiled code | ecode pointer to current position in compiled code |
462 | mstart pointer to the current match start position (can be modified | |
463 | by encountering \K) | |
464 | markptr pointer to the most recent MARK name, or NULL | |
465 | offset_top current top pointer | offset_top current top pointer |
466 | md pointer to "static" info for the match | md pointer to "static" info for the match |
ims current /i, /m, and /s options | ||
467 | eptrb pointer to chain of blocks containing eptr at start of | eptrb pointer to chain of blocks containing eptr at start of |
468 | brackets - for testing for empty matches | brackets - for testing for empty matches |
flags can contain | ||
match_condassert - this is an assertion condition | ||
match_cbegroup - this is the start of an unlimited repeat | ||
group that can match an empty string | ||
match_tail_recursed - this is a tail_recursed group | ||
469 | rdepth the recursion depth | rdepth the recursion depth |
470 | ||
471 | Returns: MATCH_MATCH if matched ) these values are >= 0 | Returns: MATCH_MATCH if matched ) these values are >= 0 |
472 | MATCH_NOMATCH if failed to match ) | MATCH_NOMATCH if failed to match ) |
473 | a negative MATCH_xxx value for PRUNE, SKIP, etc | |
474 | a negative PCRE_ERROR_xxx value if aborted by an error condition | a negative PCRE_ERROR_xxx value if aborted by an error condition |
475 | (e.g. stopped by repeated call or recursion limit) | (e.g. stopped by repeated call or recursion limit) |
476 | */ | */ |
477 | ||
478 | static int | static int |
479 | match(REGISTER USPTR eptr, REGISTER const uschar *ecode, | match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart, |
480 | int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, | const uschar *markptr, int offset_top, match_data *md, eptrblock *eptrb, |
481 | int flags, unsigned int rdepth) | unsigned int rdepth) |
482 | { | { |
483 | /* These variables do not need to be preserved over recursion in this function, | /* These variables do not need to be preserved over recursion in this function, |
484 | so they can be ordinary variables in all cases. Mark some of them with | so they can be ordinary variables in all cases. Mark some of them with |
# | Line 382 register unsigned int c; /* Character | Line 490 register unsigned int c; /* Character |
490 | register BOOL utf8; /* Local copy of UTF-8 flag for speed */ | register BOOL utf8; /* Local copy of UTF-8 flag for speed */ |
491 | ||
492 | BOOL minimize, possessive; /* Quantifier options */ | BOOL minimize, possessive; /* Quantifier options */ |
493 | BOOL caseless; | |
494 | int condcode; | |
495 | ||
496 | /* When recursion is not being used, all "local" variables that have to be | /* When recursion is not being used, all "local" variables that have to be |
497 | preserved over calls to RMATCH() are part of a "frame" which is obtained from | preserved over calls to RMATCH() are part of a "frame" which is obtained from |
# | Line 389 heap storage. Set up the top-level frame | Line 499 heap storage. Set up the top-level frame |
499 | heap whenever RMATCH() does a "recursion". See the macro definitions above. */ | heap whenever RMATCH() does a "recursion". See the macro definitions above. */ |
500 | ||
501 | #ifdef NO_RECURSE | #ifdef NO_RECURSE |
502 | heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe)); | heapframe *frame = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe)); |
503 | if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY); | |
504 | frame->Xprevframe = NULL; /* Marks the top level */ | frame->Xprevframe = NULL; /* Marks the top level */ |
505 | ||
506 | /* Copy in the original argument variables */ | /* Copy in the original argument variables */ |
507 | ||
508 | frame->Xeptr = eptr; | frame->Xeptr = eptr; |
509 | frame->Xecode = ecode; | frame->Xecode = ecode; |
510 | frame->Xmstart = mstart; | |
511 | frame->Xmarkptr = markptr; | |
512 | frame->Xoffset_top = offset_top; | frame->Xoffset_top = offset_top; |
frame->Xims = ims; | ||
513 | frame->Xeptrb = eptrb; | frame->Xeptrb = eptrb; |
frame->Xflags = flags; | ||
514 | frame->Xrdepth = rdepth; | frame->Xrdepth = rdepth; |
515 | ||
516 | /* This is where control jumps back to to effect "recursion" */ | /* This is where control jumps back to to effect "recursion" */ |
# | Line 410 HEAP_RECURSE: | Line 521 HEAP_RECURSE: |
521 | ||
522 | #define eptr frame->Xeptr | #define eptr frame->Xeptr |
523 | #define ecode frame->Xecode | #define ecode frame->Xecode |
524 | #define mstart frame->Xmstart | |
525 | #define markptr frame->Xmarkptr | |
526 | #define offset_top frame->Xoffset_top | #define offset_top frame->Xoffset_top |
#define ims frame->Xims | ||
527 | #define eptrb frame->Xeptrb | #define eptrb frame->Xeptrb |
#define flags frame->Xflags | ||
528 | #define rdepth frame->Xrdepth | #define rdepth frame->Xrdepth |
529 | ||
530 | /* Ditto for the local variables */ | /* Ditto for the local variables */ |
# | Line 422 HEAP_RECURSE: | Line 533 HEAP_RECURSE: |
533 | #define charptr frame->Xcharptr | #define charptr frame->Xcharptr |
534 | #endif | #endif |
535 | #define callpat frame->Xcallpat | #define callpat frame->Xcallpat |
536 | #define codelink frame->Xcodelink | |
537 | #define data frame->Xdata | #define data frame->Xdata |
538 | #define next frame->Xnext | #define next frame->Xnext |
539 | #define pp frame->Xpp | #define pp frame->Xpp |
# | Line 434 HEAP_RECURSE: | Line 546 HEAP_RECURSE: |
546 | #define condition frame->Xcondition | #define condition frame->Xcondition |
547 | #define prev_is_word frame->Xprev_is_word | #define prev_is_word frame->Xprev_is_word |
548 | ||
#define original_ims frame->Xoriginal_ims | ||
549 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
550 | #define prop_type frame->Xprop_type | #define prop_type frame->Xprop_type |
551 | #define prop_value frame->Xprop_value | #define prop_value frame->Xprop_value |
# | Line 472 i, and fc and c, can be the same variabl | Line 582 i, and fc and c, can be the same variabl |
582 | #define fi i | #define fi i |
583 | #define fc c | #define fc c |
584 | ||
585 | /* Many of the following variables are used only in small blocks of the code. | |
586 | #ifdef SUPPORT_UTF8 /* Many of these variables are used only */ | My normal style of coding would have declared them within each of those blocks. |
587 | const uschar *charptr; /* in small blocks of the code. My normal */ | However, in order to accommodate the version of this code that uses an external |
588 | #endif /* style of coding would have declared */ | "stack" implemented on the heap, it is easier to declare them all here, so the |
589 | const uschar *callpat; /* them within each of those blocks. */ | declarations can be cut out in a block. The only declarations within blocks |
590 | const uschar *data; /* However, in order to accommodate the */ | below are for variables that do not have to be preserved over a recursive call |
591 | const uschar *next; /* version of this code that uses an */ | to RMATCH(). */ |
592 | USPTR pp; /* external "stack" implemented on the */ | |
593 | const uschar *prev; /* heap, it is easier to declare them all */ | #ifdef SUPPORT_UTF8 |
594 | USPTR saved_eptr; /* here, so the declarations can be cut */ | const uschar *charptr; |
595 | /* out in a block. The only declarations */ | #endif |
596 | recursion_info new_recursive; /* within blocks below are for variables */ | const uschar *callpat; |
597 | /* that do not have to be preserved over */ | const uschar *data; |
598 | BOOL cur_is_word; /* a recursive call to RMATCH(). */ | const uschar *next; |
599 | USPTR pp; | |
600 | const uschar *prev; | |
601 | USPTR saved_eptr; | |
602 | ||
603 | recursion_info new_recursive; | |
604 | ||
605 | BOOL cur_is_word; | |
606 | BOOL condition; | BOOL condition; |
607 | BOOL prev_is_word; | BOOL prev_is_word; |
608 | ||
unsigned long int original_ims; | ||
609 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
610 | int prop_type; | int prop_type; |
611 | int prop_value; | int prop_value; |
# | Line 502 int oclength; | Line 617 int oclength; |
617 | uschar occhars[8]; | uschar occhars[8]; |
618 | #endif | #endif |
619 | ||
620 | int codelink; | |
621 | int ctype; | int ctype; |
622 | int length; | int length; |
623 | int max; | int max; |
# | Line 516 int stacksave[REC_STACK_SAVE_MAX]; | Line 632 int stacksave[REC_STACK_SAVE_MAX]; |
632 | eptrblock newptrb; | eptrblock newptrb; |
633 | #endif /* NO_RECURSE */ | #endif /* NO_RECURSE */ |
634 | ||
635 | /* To save space on the stack and in the heap frame, I have doubled up on some | |
636 | of the local variables that are used only in localised parts of the code, but | |
637 | still need to be preserved over recursive calls of match(). These macros define | |
638 | the alternative names that are used. */ | |
639 | ||
640 | #define allow_zero cur_is_word | |
641 | #define cbegroup condition | |
642 | #define code_offset codelink | |
643 | #define condassert condition | |
644 | #define matched_once prev_is_word | |
645 | ||
646 | /* These statements are here to stop the compiler complaining about unitialized | /* These statements are here to stop the compiler complaining about unitialized |
647 | variables. */ | variables. */ |
648 | ||
# | Line 535 TAIL_RECURSE: | Line 662 TAIL_RECURSE: |
662 | /* OK, now we can get on with the real code of the function. Recursive calls | /* OK, now we can get on with the real code of the function. Recursive calls |
663 | are specified by the macro RMATCH and RRETURN is used to return. When | are specified by the macro RMATCH and RRETURN is used to return. When |
664 | NO_RECURSE is *not* defined, these just turn into a recursive call to match() | NO_RECURSE is *not* defined, these just turn into a recursive call to match() |
665 | and a "return", respectively (possibly with some debugging if DEBUG is | and a "return", respectively (possibly with some debugging if PCRE_DEBUG is |
666 | defined). However, RMATCH isn't like a function call because it's quite a | defined). However, RMATCH isn't like a function call because it's quite a |
667 | complicated macro. It has to be used in one particular way. This shouldn't, | complicated macro. It has to be used in one particular way. This shouldn't, |
668 | however, impact performance when true recursion is being used. */ | however, impact performance when true recursion is being used. */ |
669 | ||
/* First check that we haven't called match() too many times, or that we | ||
haven't exceeded the recursive call limit. */ | ||
if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT); | ||
if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); | ||
original_ims = ims; /* Save for resetting on ')' */ | ||
670 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
671 | utf8 = md->utf8; /* Local copy of the flag */ | utf8 = md->utf8; /* Local copy of the flag */ |
672 | #else | #else |
673 | utf8 = FALSE; | utf8 = FALSE; |
674 | #endif | #endif |
675 | ||
676 | /* First check that we haven't called match() too many times, or that we | |
677 | haven't exceeded the recursive call limit. */ | |
678 | ||
679 | if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT); | |
680 | if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); | |
681 | ||
682 | /* At the start of a group with an unlimited repeat that may match an empty | /* At the start of a group with an unlimited repeat that may match an empty |
683 | string, the match_cbegroup flag is set. When this is the case, add the current | string, the variable md->match_function_type is set to MATCH_CBEGROUP. It is |
684 | subject pointer to the chain of such remembered pointers, to be checked when we | done this way to save having to use another function argument, which would take |
685 | hit the closing ket, in order to break infinite loops that match no characters. | up space on the stack. See also MATCH_CONDASSERT below. |
686 | When match() is called in other circumstances, don't add to the chain. If this | |
687 | is a tail recursion, use a block from the workspace, as the one on the stack is | When MATCH_CBEGROUP is set, add the current subject pointer to the chain of |
688 | already used. */ | such remembered pointers, to be checked when we hit the closing ket, in order |
689 | to break infinite loops that match no characters. When match() is called in | |
690 | other circumstances, don't add to the chain. The MATCH_CBEGROUP feature must | |
691 | NOT be used with tail recursion, because the memory block that is used is on | |
692 | the stack, so a new one may be required for each match(). */ | |
693 | ||
694 | if ((flags & match_cbegroup) != 0) | if (md->match_function_type == MATCH_CBEGROUP) |
695 | { | { |
696 | eptrblock *p; | newptrb.epb_saved_eptr = eptr; |
697 | if ((flags & match_tail_recursed) != 0) | newptrb.epb_prev = eptrb; |
698 | { | eptrb = &newptrb; |
699 | if (md->eptrn >= EPTR_WORK_SIZE) RRETURN(PCRE_ERROR_NULLWSLIMIT); | md->match_function_type = 0; |
p = md->eptrchain + md->eptrn++; | ||
} | ||
else p = &newptrb; | ||
p->epb_saved_eptr = eptr; | ||
p->epb_prev = eptrb; | ||
eptrb = p; | ||
700 | } | } |
701 | ||
702 | /* Now start processing the opcodes. */ | /* Now start processing the opcodes. */ |
# | Line 582 for (;;) | Line 705 for (;;) |
705 | { | { |
706 | minimize = possessive = FALSE; | minimize = possessive = FALSE; |
707 | op = *ecode; | op = *ecode; |
708 | ||
/* For partial matching, remember if we ever hit the end of the subject after | ||
matching at least one subject character. */ | ||
if (md->partial && | ||
eptr >= md->end_subject && | ||
eptr > md->start_match) | ||
md->hitend = TRUE; | ||
709 | switch(op) | switch(op) |
710 | { | { |
711 | /* Handle a capturing bracket. If there is space in the offset vector, save | case OP_MARK: |
712 | the current subject position in the working slot at the top of the vector. | markptr = ecode + 2; |
713 | We mustn't change the current values of the data slot, because they may be | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md, |
714 | set from a previous iteration of this group, and be referred to by a | eptrb, RM55); |
715 | reference inside the group. | |
716 | /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an | |
717 | If the bracket fails to match, we need to restore this value and also the | argument, and we must check whether that argument matches this MARK's |
718 | argument. It is passed back in md->start_match_ptr (an overloading of that | |
719 | variable). If it does match, we reset that variable to the current subject | |
720 | position and return MATCH_SKIP. Otherwise, pass back the return code | |
721 | unaltered. */ | |
722 | ||
723 | if (rrc == MATCH_SKIP_ARG && | |
724 | strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0) | |
725 | { | |
726 | md->start_match_ptr = eptr; | |
727 | RRETURN(MATCH_SKIP); | |
728 | } | |
729 | ||
730 | if (md->mark == NULL) md->mark = markptr; | |
731 | RRETURN(rrc); | |
732 | ||
733 | case OP_FAIL: | |
734 | MRRETURN(MATCH_NOMATCH); | |
735 | ||
736 | /* COMMIT overrides PRUNE, SKIP, and THEN */ | |
737 | ||
738 | case OP_COMMIT: | |
739 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
740 | eptrb, RM52); | |
741 | if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && | |
742 | rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG && | |
743 | rrc != MATCH_THEN) | |
744 | RRETURN(rrc); | |
745 | MRRETURN(MATCH_COMMIT); | |
746 | ||
747 | /* PRUNE overrides THEN */ | |
748 | ||
749 | case OP_PRUNE: | |
750 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
751 | eptrb, RM51); | |
752 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); | |
753 | MRRETURN(MATCH_PRUNE); | |
754 | ||
755 | case OP_PRUNE_ARG: | |
756 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md, | |
757 | eptrb, RM56); | |
758 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); | |
759 | md->mark = ecode + 2; | |
760 | RRETURN(MATCH_PRUNE); | |
761 | ||
762 | /* SKIP overrides PRUNE and THEN */ | |
763 | ||
764 | case OP_SKIP: | |
765 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
766 | eptrb, RM53); | |
767 | if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN) | |
768 | RRETURN(rrc); | |
769 | md->start_match_ptr = eptr; /* Pass back current position */ | |
770 | MRRETURN(MATCH_SKIP); | |
771 | ||
772 | case OP_SKIP_ARG: | |
773 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md, | |
774 | eptrb, RM57); | |
775 | if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN) | |
776 | RRETURN(rrc); | |
777 | ||
778 | /* Pass back the current skip name by overloading md->start_match_ptr and | |
779 | returning the special MATCH_SKIP_ARG return code. This will either be | |
780 | caught by a matching MARK, or get to the top, where it is treated the same | |
781 | as PRUNE. */ | |
782 | ||
783 | md->start_match_ptr = ecode + 2; | |
784 | RRETURN(MATCH_SKIP_ARG); | |
785 | ||
786 | /* For THEN (and THEN_ARG) we pass back the address of the bracket or | |
787 | the alt that is at the start of the current branch. This makes it possible | |
788 | to skip back past alternatives that precede the THEN within the current | |
789 | branch. */ | |
790 | ||
791 | case OP_THEN: | |
792 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
793 | eptrb, RM54); | |
794 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
795 | md->start_match_ptr = ecode - GET(ecode, 1); | |
796 | MRRETURN(MATCH_THEN); | |
797 | ||
798 | case OP_THEN_ARG: | |
799 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE], | |
800 | offset_top, md, eptrb, RM58); | |
801 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
802 | md->start_match_ptr = ecode - GET(ecode, 1); | |
803 | md->mark = ecode + LINK_SIZE + 2; | |
804 | RRETURN(MATCH_THEN); | |
805 | ||
806 | /* Handle a capturing bracket, other than those that are possessive with an | |
807 | unlimited repeat. If there is space in the offset vector, save the current | |
808 | subject position in the working slot at the top of the vector. We mustn't | |
809 | change the current values of the data slot, because they may be set from a | |
810 | previous iteration of this group, and be referred to by a reference inside | |
811 | the group. If we fail to match, we need to restore this value and also the | |
812 | values of the final offsets, in case they were set by a previous iteration | values of the final offsets, in case they were set by a previous iteration |
813 | of the same bracket. | of the same bracket. |
814 | ||
# | Line 611 for (;;) | Line 820 for (;;) |
820 | case OP_SCBRA: | case OP_SCBRA: |
821 | number = GET2(ecode, 1+LINK_SIZE); | number = GET2(ecode, 1+LINK_SIZE); |
822 | offset = number << 1; | offset = number << 1; |
823 | ||
824 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
825 | printf("start bracket %d\n", number); | printf("start bracket %d\n", number); |
826 | printf("subject="); | printf("subject="); |
827 | pchars(eptr, 16, TRUE, md); | pchars(eptr, 16, TRUE, md); |
# | Line 627 for (;;) | Line 836 for (;;) |
836 | save_capture_last = md->capture_last; | save_capture_last = md->capture_last; |
837 | ||
838 | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); |
839 | md->offset_vector[md->offset_end - number] = eptr - md->start_subject; | md->offset_vector[md->offset_end - number] = |
840 | (int)(eptr - md->start_subject); | |
841 | ||
842 | flags = (op == OP_SCBRA)? match_cbegroup : 0; | for (;;) |
do | ||
843 | { | { |
844 | RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; |
845 | ims, eptrb, flags); | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, |
846 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | eptrb, RM1); |
847 | if (rrc != MATCH_NOMATCH && | |
848 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
849 | RRETURN(rrc); | |
850 | md->capture_last = save_capture_last; | md->capture_last = save_capture_last; |
851 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
852 | if (*ecode != OP_ALT) break; | |
853 | } | } |
while (*ecode == OP_ALT); | ||
854 | ||
855 | DPRINTF(("bracket %d failed\n", number)); | DPRINTF(("bracket %d failed\n", number)); |
856 | ||
# | Line 646 for (;;) | Line 858 for (;;) |
858 | md->offset_vector[offset+1] = save_offset2; | md->offset_vector[offset+1] = save_offset2; |
859 | md->offset_vector[md->offset_end - number] = save_offset3; | md->offset_vector[md->offset_end - number] = save_offset3; |
860 | ||
861 | if (rrc != MATCH_THEN) md->mark = markptr; | |
862 | RRETURN(MATCH_NOMATCH); | RRETURN(MATCH_NOMATCH); |
863 | } | } |
864 | ||
865 | /* Insufficient room for saving captured contents. Treat as a non-capturing | /* FALL THROUGH ... Insufficient room for saving captured contents. Treat |
866 | bracket. */ | as a non-capturing bracket. */ |
867 | ||
868 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
869 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
870 | ||
871 | DPRINTF(("insufficient capture room: treat as non-capturing\n")); | DPRINTF(("insufficient capture room: treat as non-capturing\n")); |
872 | ||
873 | /* Non-capturing bracket. Loop for all the alternatives. When we get to the | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
874 | final alternative within the brackets, we would return the result of a | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
875 | recursive call to match() whatever happened. We can reduce stack usage by | |
876 | turning this into a tail recursion. */ | /* Non-capturing bracket, except for possessive with unlimited repeat. Loop |
877 | for all the alternatives. When we get to the final alternative within the | |
878 | brackets, we would return the result of a recursive call to match() | |
879 | whatever happened. We can reduce stack usage by turning this into a tail | |
880 | recursion, except in the case of a possibly empty group.*/ | |
881 | ||
882 | case OP_BRA: | case OP_BRA: |
883 | case OP_SBRA: | case OP_SBRA: |
884 | DPRINTF(("start non-capturing bracket\n")); | DPRINTF(("start non-capturing bracket\n")); |
flags = (op >= OP_SBRA)? match_cbegroup : 0; | ||
885 | for (;;) | for (;;) |
886 | { | { |
887 | if (ecode[GET(ecode, 1)] != OP_ALT) | if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */ |
888 | { | { |
889 | if (op >= OP_SBRA) /* Possibly empty group */ | |
890 | { | |
891 | md->match_function_type = MATCH_CBEGROUP; | |
892 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, eptrb, | |
893 | RM48); | |
894 | if (rrc == MATCH_NOMATCH) md->mark = markptr; | |
895 | RRETURN(rrc); | |
896 | } | |
897 | /* Not a possibly empty group; use tail recursion */ | |
898 | ecode += _pcre_OP_lengths[*ecode]; | ecode += _pcre_OP_lengths[*ecode]; |
flags |= match_tail_recursed; | ||
899 | DPRINTF(("bracket 0 tail recursion\n")); | DPRINTF(("bracket 0 tail recursion\n")); |
900 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
901 | } | } |
# | Line 676 for (;;) | Line 903 for (;;) |
903 | /* For non-final alternatives, continue the loop for a NOMATCH result; | /* For non-final alternatives, continue the loop for a NOMATCH result; |
904 | otherwise return. */ | otherwise return. */ |
905 | ||
906 | RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; |
907 | eptrb, flags); | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, eptrb, |
908 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | RM2); |
909 | if (rrc != MATCH_NOMATCH && | |
910 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
911 | RRETURN(rrc); | |
912 | ecode += GET(ecode, 1); | |
913 | } | |
914 | /* Control never reaches here. */ | |
915 | ||
916 | /* Handle possessive capturing brackets with an unlimited repeat. We come | |
917 | here from BRAZERO with allow_zero set TRUE. The offset_vector values are | |
918 | handled similarly to the normal case above. However, the matching is | |
919 | different. The end of these brackets will always be OP_KETRPOS, which | |
920 | returns MATCH_KETRPOS without going further in the pattern. By this means | |
921 | we can handle the group by iteration rather than recursion, thereby | |
922 | reducing the amount of stack needed. */ | |
923 | ||
924 | case OP_CBRAPOS: | |
925 | case OP_SCBRAPOS: | |
926 | allow_zero = FALSE; | |
927 | ||
928 | POSSESSIVE_CAPTURE: | |
929 | number = GET2(ecode, 1+LINK_SIZE); | |
930 | offset = number << 1; | |
931 | ||
932 | #ifdef PCRE_DEBUG | |
933 | printf("start possessive bracket %d\n", number); | |
934 | printf("subject="); | |
935 | pchars(eptr, 16, TRUE, md); | |
936 | printf("\n"); | |
937 | #endif | |
938 | ||
939 | if (offset < md->offset_max) | |
940 | { | |
941 | matched_once = FALSE; | |
942 | code_offset = ecode - md->start_code; | |
943 | ||
944 | save_offset1 = md->offset_vector[offset]; | |
945 | save_offset2 = md->offset_vector[offset+1]; | |
946 | save_offset3 = md->offset_vector[md->offset_end - number]; | |
947 | save_capture_last = md->capture_last; | |
948 | ||
949 | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); | |
950 | ||
951 | /* Each time round the loop, save the current subject position for use | |
952 | when the group matches. For MATCH_MATCH, the group has matched, so we | |
953 | restart it with a new subject starting position, remembering that we had | |
954 | at least one match. For MATCH_NOMATCH, carry on with the alternatives, as | |
955 | usual. If we haven't matched any alternatives in any iteration, check to | |
956 | see if a previous iteration matched. If so, the group has matched; | |
957 | continue from afterwards. Otherwise it has failed; restore the previous | |
958 | capture values before returning NOMATCH. */ | |
959 | ||
960 | for (;;) | |
961 | { | |
962 | md->offset_vector[md->offset_end - number] = | |
963 | (int)(eptr - md->start_subject); | |
964 | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; | |
965 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
966 | eptrb, RM63); | |
967 | if (rrc == MATCH_KETRPOS) | |
968 | { | |
969 | offset_top = md->end_offset_top; | |
970 | eptr = md->end_match_ptr; | |
971 | ecode = md->start_code + code_offset; | |
972 | save_capture_last = md->capture_last; | |
973 | matched_once = TRUE; | |
974 | continue; | |
975 | } | |
976 | if (rrc != MATCH_NOMATCH && | |
977 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
978 | RRETURN(rrc); | |
979 | md->capture_last = save_capture_last; | |
980 | ecode += GET(ecode, 1); | |
981 | if (*ecode != OP_ALT) break; | |
982 | } | |
983 | ||
984 | if (!matched_once) | |
985 | { | |
986 | md->offset_vector[offset] = save_offset1; | |
987 | md->offset_vector[offset+1] = save_offset2; | |
988 | md->offset_vector[md->offset_end - number] = save_offset3; | |
989 | } | |
990 | ||
991 | if (rrc != MATCH_THEN) md->mark = markptr; | |
992 | if (allow_zero || matched_once) | |
993 | { | |
994 | ecode += 1 + LINK_SIZE; | |
995 | break; | |
996 | } | |
997 | ||
998 | RRETURN(MATCH_NOMATCH); | |
999 | } | |
1000 | ||
1001 | /* FALL THROUGH ... Insufficient room for saving captured contents. Treat | |
1002 | as a non-capturing bracket. */ | |
1003 | ||
1004 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
1005 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
1006 | ||
1007 | DPRINTF(("insufficient capture room: treat as non-capturing\n")); | |
1008 | ||
1009 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
1010 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ | |
1011 | ||
1012 | /* Non-capturing possessive bracket with unlimited repeat. We come here | |
1013 | from BRAZERO with allow_zero = TRUE. The code is similar to the above, | |
1014 | without the capturing complication. It is written out separately for speed | |
1015 | and cleanliness. */ | |
1016 | ||
1017 | case OP_BRAPOS: | |
1018 | case OP_SBRAPOS: | |
1019 | allow_zero = FALSE; | |
1020 | ||
1021 | POSSESSIVE_NON_CAPTURE: | |
1022 | matched_once = FALSE; | |
1023 | code_offset = ecode - md->start_code; | |
1024 | ||
1025 | for (;;) | |
1026 | { | |
1027 | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; | |
1028 | RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, | |
1029 | eptrb, RM64); | |
1030 | if (rrc == MATCH_KETRPOS) | |
1031 | { | |
1032 | eptr = md->end_match_ptr; | |
1033 | ecode = md->start_code + code_offset; | |
1034 | matched_once = TRUE; | |
1035 | continue; | |
1036 | } | |
1037 | if (rrc != MATCH_NOMATCH && | |
1038 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
1039 | RRETURN(rrc); | |
1040 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
1041 | if (*ecode != OP_ALT) break; | |
1042 | } | } |
1043 | ||
1044 | if (matched_once || allow_zero) | |
1045 | { | |
1046 | ecode += 1 + LINK_SIZE; | |
1047 | break; | |
1048 | } | |
1049 | RRETURN(MATCH_NOMATCH); | |
1050 | ||
1051 | /* Control never reaches here. */ | /* Control never reaches here. */ |
1052 | ||
1053 | /* Conditional group: compilation checked that there are no more than | /* Conditional group: compilation checked that there are no more than |
# | Line 691 for (;;) | Line 1058 for (;;) |
1058 | ||
1059 | case OP_COND: | case OP_COND: |
1060 | case OP_SCOND: | case OP_SCOND: |
1061 | if (ecode[LINK_SIZE+1] == OP_RREF) /* Recursion test */ | codelink = GET(ecode, 1); |
1062 | ||
1063 | /* Because of the way auto-callout works during compile, a callout item is | |
1064 | inserted between OP_COND and an assertion condition. */ | |
1065 | ||
1066 | if (ecode[LINK_SIZE+1] == OP_CALLOUT) | |
1067 | { | { |
1068 | offset = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ | if (pcre_callout != NULL) |
1069 | condition = md->recursive != NULL && | { |
1070 | (offset == RREF_ANY || offset == md->recursive->group_num); | pcre_callout_block cb; |
1071 | ecode += condition? 3 : GET(ecode, 1); | cb.version = 1; /* Version 1 of the callout block */ |
1072 | cb.callout_number = ecode[LINK_SIZE+2]; | |
1073 | cb.offset_vector = md->offset_vector; | |
1074 | cb.subject = (PCRE_SPTR)md->start_subject; | |
1075 | cb.subject_length = (int)(md->end_subject - md->start_subject); | |
1076 | cb.start_match = (int)(mstart - md->start_subject); | |
1077 | cb.current_position = (int)(eptr - md->start_subject); | |
1078 | cb.pattern_position = GET(ecode, LINK_SIZE + 3); | |
1079 | cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE); | |
1080 | cb.capture_top = offset_top/2; | |
1081 | cb.capture_last = md->capture_last; | |
1082 | cb.callout_data = md->callout_data; | |
1083 | if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH); | |
1084 | if (rrc < 0) RRETURN(rrc); | |
1085 | } | |
1086 | ecode += _pcre_OP_lengths[OP_CALLOUT]; | |
1087 | } | |
1088 | ||
1089 | condcode = ecode[LINK_SIZE+1]; | |
1090 | ||
1091 | /* Now see what the actual condition is */ | |
1092 | ||
1093 | if (condcode == OP_RREF || condcode == OP_NRREF) /* Recursion test */ | |
1094 | { | |
1095 | if (md->recursive == NULL) /* Not recursing => FALSE */ | |
1096 | { | |
1097 | condition = FALSE; | |
1098 | ecode += GET(ecode, 1); | |
1099 | } | |
1100 | else | |
1101 | { | |
1102 | int recno = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ | |
1103 | condition = (recno == RREF_ANY || recno == md->recursive->group_num); | |
1104 | ||
1105 | /* If the test is for recursion into a specific subpattern, and it is | |
1106 | false, but the test was set up by name, scan the table to see if the | |
1107 | name refers to any other numbers, and test them. The condition is true | |
1108 | if any one is set. */ | |
1109 | ||
1110 | if (!condition && condcode == OP_NRREF && recno != RREF_ANY) | |
1111 | { | |
1112 | uschar *slotA = md->name_table; | |
1113 | for (i = 0; i < md->name_count; i++) | |
1114 | { | |
1115 | if (GET2(slotA, 0) == recno) break; | |
1116 | slotA += md->name_entry_size; | |
1117 | } | |
1118 | ||
1119 | /* Found a name for the number - there can be only one; duplicate | |
1120 | names for different numbers are allowed, but not vice versa. First | |
1121 | scan down for duplicates. */ | |
1122 | ||
1123 | if (i < md->name_count) | |
1124 | { | |
1125 | uschar *slotB = slotA; | |
1126 | while (slotB > md->name_table) | |
1127 | { | |
1128 | slotB -= md->name_entry_size; | |
1129 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
1130 | { | |
1131 | condition = GET2(slotB, 0) == md->recursive->group_num; | |
1132 | if (condition) break; | |
1133 | } | |
1134 | else break; | |
1135 | } | |
1136 | ||
1137 | /* Scan up for duplicates */ | |
1138 | ||
1139 | if (!condition) | |
1140 | { | |
1141 | slotB = slotA; | |
1142 | for (i++; i < md->name_count; i++) | |
1143 | { | |
1144 | slotB += md->name_entry_size; | |
1145 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
1146 | { | |
1147 | condition = GET2(slotB, 0) == md->recursive->group_num; | |
1148 | if (condition) break; | |
1149 | } | |
1150 | else break; | |
1151 | } | |
1152 | } | |
1153 | } | |
1154 | } | |
1155 | ||
1156 | /* Chose branch according to the condition */ | |
1157 | ||
1158 | ecode += condition? 3 : GET(ecode, 1); | |
1159 | } | |
1160 | } | } |
1161 | ||
1162 | else if (ecode[LINK_SIZE+1] == OP_CREF) /* Group used test */ | else if (condcode == OP_CREF || condcode == OP_NCREF) /* Group used test */ |
1163 | { | { |
1164 | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ |
1165 | condition = offset < offset_top && md->offset_vector[offset] >= 0; | condition = offset < offset_top && md->offset_vector[offset] >= 0; |
1166 | ||
1167 | /* If the numbered capture is unset, but the reference was by name, | |
1168 | scan the table to see if the name refers to any other numbers, and test | |
1169 | them. The condition is true if any one is set. This is tediously similar | |
1170 | to the code above, but not close enough to try to amalgamate. */ | |
1171 | ||
1172 | if (!condition && condcode == OP_NCREF) | |
1173 | { | |
1174 | int refno = offset >> 1; | |
1175 | uschar *slotA = md->name_table; | |
1176 | ||
1177 | for (i = 0; i < md->name_count; i++) | |
1178 | { | |
1179 | if (GET2(slotA, 0) == refno) break; | |
1180 | slotA += md->name_entry_size; | |
1181 | } | |
1182 | ||
1183 | /* Found a name for the number - there can be only one; duplicate names | |
1184 | for different numbers are allowed, but not vice versa. First scan down | |
1185 | for duplicates. */ | |
1186 | ||
1187 | if (i < md->name_count) | |
1188 | { | |
1189 | uschar *slotB = slotA; | |
1190 | while (slotB > md->name_table) | |
1191 | { | |
1192 | slotB -= md->name_entry_size; | |
1193 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
1194 | { | |
1195 | offset = GET2(slotB, 0) << 1; | |
1196 | condition = offset < offset_top && | |
1197 | md->offset_vector[offset] >= 0; | |
1198 | if (condition) break; | |
1199 | } | |
1200 | else break; | |
1201 | } | |
1202 | ||
1203 | /* Scan up for duplicates */ | |
1204 | ||
1205 | if (!condition) | |
1206 | { | |
1207 | slotB = slotA; | |
1208 | for (i++; i < md->name_count; i++) | |
1209 | { | |
1210 | slotB += md->name_entry_size; | |
1211 | if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0) | |
1212 | { | |
1213 | offset = GET2(slotB, 0) << 1; | |
1214 | condition = offset < offset_top && | |
1215 | md->offset_vector[offset] >= 0; | |
1216 | if (condition) break; | |
1217 | } | |
1218 | else break; | |
1219 | } | |
1220 | } | |
1221 | } | |
1222 | } | |
1223 | ||
1224 | /* Chose branch according to the condition */ | |
1225 | ||
1226 | ecode += condition? 3 : GET(ecode, 1); | ecode += condition? 3 : GET(ecode, 1); |
1227 | } | } |
1228 | ||
1229 | else if (ecode[LINK_SIZE+1] == OP_DEF) /* DEFINE - always false */ | else if (condcode == OP_DEF) /* DEFINE - always false */ |
1230 | { | { |
1231 | condition = FALSE; | condition = FALSE; |
1232 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
1233 | } | } |
1234 | ||
1235 | /* The condition is an assertion. Call match() to evaluate it - setting | /* The condition is an assertion. Call match() to evaluate it - setting |
1236 | the final argument match_condassert causes it to stop at the end of an | md->match_function_type to MATCH_CONDASSERT causes it to stop at the end of |
1237 | assertion. */ | an assertion. */ |
1238 | ||
1239 | else | else |
1240 | { | { |
1241 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, | md->match_function_type = MATCH_CONDASSERT; |
1242 | match_condassert); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM3); |
1243 | if (rrc == MATCH_MATCH) | if (rrc == MATCH_MATCH) |
1244 | { | { |
1245 | condition = TRUE; | condition = TRUE; |
1246 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); |
1247 | while (*ecode == OP_ALT) ecode += GET(ecode, 1); | while (*ecode == OP_ALT) ecode += GET(ecode, 1); |
1248 | } | } |
1249 | else if (rrc != MATCH_NOMATCH) | else if (rrc != MATCH_NOMATCH && |
1250 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
1251 | { | { |
1252 | RRETURN(rrc); /* Need braces because of following else */ | RRETURN(rrc); /* Need braces because of following else */ |
1253 | } | } |
1254 | else | else |
1255 | { | { |
1256 | condition = FALSE; | condition = FALSE; |
1257 | ecode += GET(ecode, 1); | ecode += codelink; |
1258 | } | } |
1259 | } | } |
1260 | ||
1261 | /* We are now at the branch that is to be obeyed. As there is only one, | /* We are now at the branch that is to be obeyed. As there is only one, |
1262 | we can use tail recursion to avoid using another stack frame. If the second | we can use tail recursion to avoid using another stack frame, except when |
1263 | we have an unlimited repeat of a possibly empty group. If the second | |
1264 | alternative doesn't exist, we can just plough on. */ | alternative doesn't exist, we can just plough on. */ |
1265 | ||
1266 | if (condition || *ecode == OP_ALT) | if (condition || *ecode == OP_ALT) |
1267 | { | { |
1268 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
1269 | flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0); | if (op == OP_SCOND) /* Possibly empty group */ |
1270 | goto TAIL_RECURSE; | { |
1271 | md->match_function_type = MATCH_CBEGROUP; | |
1272 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM49); | |
1273 | RRETURN(rrc); | |
1274 | } | |
1275 | else goto TAIL_RECURSE; | |
1276 | } | } |
1277 | else | else /* Condition false & no alternative */ |
1278 | { | { |
1279 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
1280 | } | } |
1281 | break; | break; |
1282 | ||
1283 | ||
1284 | /* End of the pattern. If we are in a top-level recursion, we should | /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes, |
1285 | restore the offsets appropriately and continue from after the call. */ | to close any currently open capturing brackets. */ |
1286 | ||
1287 | case OP_CLOSE: | |
1288 | number = GET2(ecode, 1); | |
1289 | offset = number << 1; | |
1290 | ||
1291 | #ifdef PCRE_DEBUG | |
1292 | printf("end bracket %d at *ACCEPT", number); | |
1293 | printf("\n"); | |
1294 | #endif | |
1295 | ||
1296 | md->capture_last = number; | |
1297 | if (offset >= md->offset_max) md->offset_overflow = TRUE; else | |
1298 | { | |
1299 | md->offset_vector[offset] = | |
1300 | md->offset_vector[md->offset_end - number]; | |
1301 | md->offset_vector[offset+1] = (int)(eptr - md->start_subject); | |
1302 | if (offset_top <= offset) offset_top = offset + 2; | |
1303 | } | |
1304 | ecode += 3; | |
1305 | break; | |
1306 | ||
1307 | ||
1308 | /* End of the pattern, either real or forced. If we are in a recursion, we | |
1309 | should restore the offsets appropriately, and if it's a top-level | |
1310 | recursion, continue from after the call. */ | |
1311 | ||
1312 | case OP_ACCEPT: | |
1313 | case OP_END: | case OP_END: |
1314 | if (md->recursive != NULL && md->recursive->group_num == 0) | if (md->recursive != NULL) |
1315 | { | { |
1316 | recursion_info *rec = md->recursive; | recursion_info *rec = md->recursive; |
DPRINTF(("End of pattern in a (?0) recursion\n")); | ||
1317 | md->recursive = rec->prevrec; | md->recursive = rec->prevrec; |
1318 | memmove(md->offset_vector, rec->offset_save, | memmove(md->offset_vector, rec->offset_save, |
1319 | rec->saved_max * sizeof(int)); | rec->saved_max * sizeof(int)); |
1320 | md->start_match = rec->save_start; | offset_top = rec->save_offset_top; |
1321 | ims = original_ims; | if (rec->group_num == 0) |
1322 | ecode = rec->after_call; | { |
1323 | break; | ecode = rec->after_call; |
1324 | break; | |
1325 | } | |
1326 | } | } |
1327 | ||
1328 | /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty | /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is |
1329 | string - backtracking will then try other alternatives, if any. */ | set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of |
1330 | the subject. In both cases, backtracking will then try other alternatives, | |
1331 | if any. */ | |
1332 | ||
1333 | else if (eptr == mstart && | |
1334 | (md->notempty || | |
1335 | (md->notempty_atstart && | |
1336 | mstart == md->start_subject + md->start_offset))) | |
1337 | MRRETURN(MATCH_NOMATCH); | |
1338 | ||
1339 | /* Otherwise, we have a match. */ | |
1340 | ||
1341 | md->end_match_ptr = eptr; /* Record where we ended */ | |
1342 | md->end_offset_top = offset_top; /* and how many extracts were taken */ | |
1343 | md->start_match_ptr = mstart; /* and the start (\K can modify) */ | |
1344 | ||
1345 | if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH); | /* For some reason, the macros don't work properly if an expression is |
1346 | md->end_match_ptr = eptr; /* Record where we ended */ | given as the argument to MRRETURN when the heap is in use. */ |
1347 | md->end_offset_top = offset_top; /* and how many extracts were taken */ | |
1348 | RRETURN(MATCH_MATCH); | rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT; |
1349 | MRRETURN(rrc); | |
/* Change option settings */ | ||
case OP_OPT: | ||
ims = ecode[1]; | ||
ecode += 2; | ||
DPRINTF(("ims set to %02lx\n", ims)); | ||
break; | ||
1350 | ||
1351 | /* Assertion brackets. Check the alternative branches in turn - the | /* Assertion brackets. Check the alternative branches in turn - the |
1352 | matching won't pass the KET for an assertion. If any one branch matches, | matching won't pass the KET for an assertion. If any one branch matches, |
1353 | the assertion is true. Lookbehind assertions have an OP_REVERSE item at the | the assertion is true. Lookbehind assertions have an OP_REVERSE item at the |
1354 | start of each branch to move the current point backwards, so the code at | start of each branch to move the current point backwards, so the code at |
1355 | this level is identical to the lookahead case. */ | this level is identical to the lookahead case. When the assertion is part |
1356 | of a condition, we want to return immediately afterwards. The caller of | |
1357 | this incarnation of the match() function will have set MATCH_CONDASSERT in | |
1358 | md->match_function type, and one of these opcodes will be the first opcode | |
1359 | that is processed. We use a local variable that is preserved over calls to | |
1360 | match() to remember this case. */ | |
1361 | ||
1362 | case OP_ASSERT: | case OP_ASSERT: |
1363 | case OP_ASSERTBACK: | case OP_ASSERTBACK: |
1364 | if (md->match_function_type == MATCH_CONDASSERT) | |
1365 | { | |
1366 | condassert = TRUE; | |
1367 | md->match_function_type = 0; | |
1368 | } | |
1369 | else condassert = FALSE; | |
1370 | ||
1371 | do | do |
1372 | { | { |
1373 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM4); |
1374 | if (rrc == MATCH_MATCH) break; | if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) |
1375 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | { |
1376 | mstart = md->start_match_ptr; /* In case \K reset it */ | |
1377 | break; | |
1378 | } | |
1379 | if (rrc != MATCH_NOMATCH && | |
1380 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
1381 | RRETURN(rrc); | |
1382 | ecode += GET(ecode, 1); | ecode += GET(ecode, 1); |
1383 | } | } |
1384 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
1385 | if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH); | |
1386 | if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH); | |
1387 | ||
1388 | /* If checking an assertion for a condition, return MATCH_MATCH. */ | /* If checking an assertion for a condition, return MATCH_MATCH. */ |
1389 | ||
1390 | if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH); | if (condassert) RRETURN(MATCH_MATCH); |
1391 | ||
1392 | /* Continue from after the assertion, updating the offsets high water | /* Continue from after the assertion, updating the offsets high water |
1393 | mark, since extracts may have been taken during the assertion. */ | mark, since extracts may have been taken during the assertion. */ |
# | Line 817 for (;;) | Line 1397 for (;;) |
1397 | offset_top = md->end_offset_top; | offset_top = md->end_offset_top; |
1398 | continue; | continue; |
1399 | ||
1400 | /* Negative assertion: all branches must fail to match */ | /* Negative assertion: all branches must fail to match. Encountering SKIP, |
1401 | PRUNE, or COMMIT means we must assume failure without checking subsequent | |
1402 | branches. */ | |
1403 | ||
1404 | case OP_ASSERT_NOT: | case OP_ASSERT_NOT: |
1405 | case OP_ASSERTBACK_NOT: | case OP_ASSERTBACK_NOT: |
1406 | if (md->match_function_type == MATCH_CONDASSERT) | |
1407 | { | |
1408 | condassert = TRUE; | |
1409 | md->match_function_type = 0; | |
1410 | } | |
1411 | else condassert = FALSE; | |
1412 | ||
1413 | do | do |
1414 | { | { |
1415 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5); |
1416 | if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); | if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH); |
1417 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT) |
1418 | { | |
1419 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | |
1420 | break; | |
1421 | } | |
1422 | if (rrc != MATCH_NOMATCH && | |
1423 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
1424 | RRETURN(rrc); | |
1425 | ecode += GET(ecode,1); | ecode += GET(ecode,1); |
1426 | } | } |
1427 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
1428 | ||
1429 | if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH); | if (condassert) RRETURN(MATCH_MATCH); /* Condition assertion */ |
1430 | ||
1431 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
1432 | continue; | continue; |
1433 | ||
# | Line 848 for (;;) | Line 1444 for (;;) |
1444 | while (i-- > 0) | while (i-- > 0) |
1445 | { | { |
1446 | eptr--; | eptr--; |
1447 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH); |
1448 | BACKCHAR(eptr) | BACKCHAR(eptr); |
1449 | } | } |
1450 | } | } |
1451 | else | else |
# | Line 859 for (;;) | Line 1455 for (;;) |
1455 | ||
1456 | { | { |
1457 | eptr -= GET(ecode, 1); | eptr -= GET(ecode, 1); |
1458 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH); |
1459 | } | } |
1460 | ||
1461 | /* Skip to next op code */ | /* Save the earliest consulted character, then skip to next op code */ |
1462 | ||
1463 | if (eptr < md->start_used_ptr) md->start_used_ptr = eptr; | |
1464 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
1465 | break; | break; |
1466 | ||
# | Line 879 for (;;) | Line 1476 for (;;) |
1476 | cb.callout_number = ecode[1]; | cb.callout_number = ecode[1]; |
1477 | cb.offset_vector = md->offset_vector; | cb.offset_vector = md->offset_vector; |
1478 | cb.subject = (PCRE_SPTR)md->start_subject; | cb.subject = (PCRE_SPTR)md->start_subject; |
1479 | cb.subject_length = md->end_subject - md->start_subject; | cb.subject_length = (int)(md->end_subject - md->start_subject); |
1480 | cb.start_match = md->start_match - md->start_subject; | cb.start_match = (int)(mstart - md->start_subject); |
1481 | cb.current_position = eptr - md->start_subject; | cb.current_position = (int)(eptr - md->start_subject); |
1482 | cb.pattern_position = GET(ecode, 2); | cb.pattern_position = GET(ecode, 2); |
1483 | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); |
1484 | cb.capture_top = offset_top/2; | cb.capture_top = offset_top/2; |
1485 | cb.capture_last = md->capture_last; | cb.capture_last = md->capture_last; |
1486 | cb.callout_data = md->callout_data; | cb.callout_data = md->callout_data; |
1487 | if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH); | if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH); |
1488 | if (rrc < 0) RRETURN(rrc); | if (rrc < 0) RRETURN(rrc); |
1489 | } | } |
1490 | ecode += 2 + 2*LINK_SIZE; | ecode += 2 + 2*LINK_SIZE; |
# | Line 942 for (;;) | Line 1539 for (;;) |
1539 | ||
1540 | memcpy(new_recursive.offset_save, md->offset_vector, | memcpy(new_recursive.offset_save, md->offset_vector, |
1541 | new_recursive.saved_max * sizeof(int)); | new_recursive.saved_max * sizeof(int)); |
1542 | new_recursive.save_start = md->start_match; | new_recursive.save_offset_top = offset_top; |
1543 | md->start_match = eptr; | |
1544 | /* OK, now we can do the recursion. For each top-level alternative we | /* OK, now we can do the recursion. For each top-level alternative we |
1545 | restore the offset and recursion data. */ | restore the offset and recursion data. */ |
1546 | ||
1547 | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); |
1548 | flags = (*callpat >= OP_SBRA)? match_cbegroup : 0; | cbegroup = (*callpat >= OP_SBRA); |
1549 | do | do |
1550 | { | { |
1551 | RMATCH(rrc, eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, | if (cbegroup) md->match_function_type = MATCH_CBEGROUP; |
1552 | md, ims, eptrb, flags); | RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, |
1553 | if (rrc == MATCH_MATCH) | md, eptrb, RM6); |
1554 | if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) | |
1555 | { | { |
1556 | DPRINTF(("Recursion matched\n")); | DPRINTF(("Recursion matched\n")); |
1557 | md->recursive = new_recursive.prevrec; | md->recursive = new_recursive.prevrec; |
1558 | if (new_recursive.offset_save != stacksave) | if (new_recursive.offset_save != stacksave) |
1559 | (pcre_free)(new_recursive.offset_save); | (pcre_free)(new_recursive.offset_save); |
1560 | RRETURN(MATCH_MATCH); | MRRETURN(MATCH_MATCH); |
1561 | } | } |
1562 | else if (rrc != MATCH_NOMATCH) | else if (rrc != MATCH_NOMATCH && |
1563 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
1564 | { | { |
1565 | DPRINTF(("Recursion gave error %d\n", rrc)); | DPRINTF(("Recursion gave error %d\n", rrc)); |
1566 | if (new_recursive.offset_save != stacksave) | |
1567 | (pcre_free)(new_recursive.offset_save); | |
1568 | RRETURN(rrc); | RRETURN(rrc); |
1569 | } | } |
1570 | ||
# | Line 979 for (;;) | Line 1579 for (;;) |
1579 | md->recursive = new_recursive.prevrec; | md->recursive = new_recursive.prevrec; |
1580 | if (new_recursive.offset_save != stacksave) | if (new_recursive.offset_save != stacksave) |
1581 | (pcre_free)(new_recursive.offset_save); | (pcre_free)(new_recursive.offset_save); |
1582 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
1583 | } | } |
1584 | /* Control never reaches here */ | /* Control never reaches here */ |
1585 | ||
# | Line 988 for (;;) | Line 1588 for (;;) |
1588 | a move back into the brackets. Friedl calls these "atomic" subpatterns. | a move back into the brackets. Friedl calls these "atomic" subpatterns. |
1589 | Check the alternative branches in turn - the matching won't pass the KET | Check the alternative branches in turn - the matching won't pass the KET |
1590 | for this kind of subpattern. If any one branch matches, we carry on as at | for this kind of subpattern. If any one branch matches, we carry on as at |
1591 | the end of a normal bracket, leaving the subject pointer. */ | the end of a normal bracket, leaving the subject pointer, but resetting |
1592 | the start-of-match value in case it was changed by \K. */ | |
1593 | ||
1594 | case OP_ONCE: | case OP_ONCE: |
1595 | prev = ecode; | prev = ecode; |
# | Line 996 for (;;) | Line 1597 for (;;) |
1597 | ||
1598 | do | do |
1599 | { | { |
1600 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM7); |
1601 | eptrb, 0); | if (rrc == MATCH_MATCH) /* Note: _not_ MATCH_ACCEPT */ |
1602 | if (rrc == MATCH_MATCH) break; | { |
1603 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | mstart = md->start_match_ptr; |
1604 | break; | |
1605 | } | |
1606 | if (rrc != MATCH_NOMATCH && | |
1607 | (rrc != MATCH_THEN || md->start_match_ptr != ecode)) | |
1608 | RRETURN(rrc); | |
1609 | ecode += GET(ecode,1); | ecode += GET(ecode,1); |
1610 | } | } |
1611 | while (*ecode == OP_ALT); | while (*ecode == OP_ALT); |
# | Line 1030 for (;;) | Line 1636 for (;;) |
1636 | ||
1637 | /* The repeating kets try the rest of the pattern or restart from the | /* The repeating kets try the rest of the pattern or restart from the |
1638 | preceding bracket, in the appropriate order. The second "call" of match() | preceding bracket, in the appropriate order. The second "call" of match() |
1639 | uses tail recursion, to avoid using another stack frame. We need to reset | uses tail recursion, to avoid using another stack frame. */ |
any options that changed within the bracket before re-running it, so | ||
check the next opcode. */ | ||
if (ecode[1+LINK_SIZE] == OP_OPT) | ||
{ | ||
ims = (ims & ~PCRE_IMS) | ecode[4]; | ||
DPRINTF(("ims set to %02lx at group repeat\n", ims)); | ||
} | ||
1640 | ||
1641 | if (*ecode == OP_KETRMIN) | if (*ecode == OP_KETRMIN) |
1642 | { | { |
1643 | RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM8); |
1644 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1645 | ecode = prev; | ecode = prev; |
flags = match_tail_recursed; | ||
1646 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
1647 | } | } |
1648 | else /* OP_KETRMAX */ | else /* OP_KETRMAX */ |
1649 | { | { |
1650 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_cbegroup); | md->match_function_type = MATCH_CBEGROUP; |
1651 | RMATCH(eptr, prev, offset_top, md, eptrb, RM9); | |
1652 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1653 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
flags = match_tail_recursed; | ||
1654 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
1655 | } | } |
1656 | /* Control never gets here */ | /* Control never gets here */ |
# | Line 1065 for (;;) | Line 1662 for (;;) |
1662 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); | do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
1663 | break; | break; |
1664 | ||
1665 | /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating | /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group, |
1666 | that it may occur zero times. It may repeat infinitely, or not at all - | indicating that it may occur zero times. It may repeat infinitely, or not |
1667 | i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper | at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets |
1668 | repeat limits are compiled as a number of copies, with the optional ones | with fixed upper repeat limits are compiled as a number of copies, with the |
1669 | preceded by BRAZERO or BRAMINZERO. */ | optional ones preceded by BRAZERO or BRAMINZERO. */ |
1670 | ||
1671 | case OP_BRAZERO: | case OP_BRAZERO: |
1672 | { | next = ecode + 1; |
1673 | next = ecode+1; | RMATCH(eptr, next, offset_top, md, eptrb, RM10); |
1674 | RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, 0); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1675 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | do next += GET(next, 1); while (*next == OP_ALT); |
1676 | do next += GET(next,1); while (*next == OP_ALT); | ecode = next + 1 + LINK_SIZE; |
ecode = next + 1 + LINK_SIZE; | ||
} | ||
1677 | break; | break; |
1678 | ||
1679 | case OP_BRAMINZERO: | case OP_BRAMINZERO: |
1680 | { | next = ecode + 1; |
1681 | next = ecode+1; | do next += GET(next, 1); while (*next == OP_ALT); |
1682 | do next += GET(next, 1); while (*next == OP_ALT); | RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, eptrb, RM11); |
1683 | RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1684 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ecode++; |
1685 | ecode++; | break; |
1686 | } | |
1687 | case OP_SKIPZERO: | |
1688 | next = ecode+1; | |
1689 | do next += GET(next,1); while (*next == OP_ALT); | |
1690 | ecode = next + 1 + LINK_SIZE; | |
1691 | break; | break; |
1692 | ||
1693 | /* BRAPOSZERO occurs before a possessive bracket group. Don't do anything | |
1694 | here; just jump to the group, with allow_zero set TRUE. */ | |
1695 | ||
1696 | case OP_BRAPOSZERO: | |
1697 | op = *(++ecode); | |
1698 | allow_zero = TRUE; | |
1699 | if (op == OP_CBRAPOS || op == OP_SCBRAPOS) goto POSSESSIVE_CAPTURE; | |
1700 | goto POSSESSIVE_NON_CAPTURE; | |
1701 | ||
1702 | /* End of a group, repeated or non-repeating. */ | /* End of a group, repeated or non-repeating. */ |
1703 | ||
1704 | case OP_KET: | case OP_KET: |
1705 | case OP_KETRMIN: | case OP_KETRMIN: |
1706 | case OP_KETRMAX: | case OP_KETRMAX: |
1707 | case OP_KETRPOS: | |
1708 | prev = ecode - GET(ecode, 1); | prev = ecode - GET(ecode, 1); |
1709 | ||
1710 | /* If this was a group that remembered the subject start, in order to break | /* If this was a group that remembered the subject start, in order to break |
# | Line 1109 for (;;) | Line 1718 for (;;) |
1718 | } | } |
1719 | else saved_eptr = NULL; | else saved_eptr = NULL; |
1720 | ||
1721 | /* If we are at the end of an assertion group, stop matching and return | /* If we are at the end of an assertion group or an atomic group, stop |
1722 | MATCH_MATCH, but record the current high water mark for use by positive | matching and return MATCH_MATCH, but record the current high water mark for |
1723 | assertions. Do this also for the "once" (atomic) groups. */ | use by positive assertions. We also need to record the match start in case |
1724 | it was changed by \K. */ | |
1725 | ||
1726 | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || | if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || |
1727 | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || | *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || |
# | Line 1119 for (;;) | Line 1729 for (;;) |
1729 | { | { |
1730 | md->end_match_ptr = eptr; /* For ONCE */ | md->end_match_ptr = eptr; /* For ONCE */ |
1731 | md->end_offset_top = offset_top; | md->end_offset_top = offset_top; |
1732 | RRETURN(MATCH_MATCH); | md->start_match_ptr = mstart; |
1733 | MRRETURN(MATCH_MATCH); | |
1734 | } | } |
1735 | ||
1736 | /* For capturing groups we have to check the group number back at the start | /* For capturing groups we have to check the group number back at the start |
# | Line 1128 for (;;) | Line 1739 for (;;) |
1739 | a recurse into group 0, so it won't be picked up here. Instead, we catch it | a recurse into group 0, so it won't be picked up here. Instead, we catch it |
1740 | when the OP_END is reached. Other recursion is handled here. */ | when the OP_END is reached. Other recursion is handled here. */ |
1741 | ||
1742 | if (*prev == OP_CBRA || *prev == OP_SCBRA) | if (*prev == OP_CBRA || *prev == OP_SCBRA || |
1743 | *prev == OP_CBRAPOS || *prev == OP_SCBRAPOS) | |
1744 | { | { |
1745 | number = GET2(prev, 1+LINK_SIZE); | number = GET2(prev, 1+LINK_SIZE); |
1746 | offset = number << 1; | offset = number << 1; |
1747 | ||
1748 | #ifdef DEBUG | #ifdef PCRE_DEBUG |
1749 | printf("end bracket %d", number); | printf("end bracket %d", number); |
1750 | printf("\n"); | printf("\n"); |
1751 | #endif | #endif |
# | Line 1143 for (;;) | Line 1755 for (;;) |
1755 | { | { |
1756 | md->offset_vector[offset] = | md->offset_vector[offset] = |
1757 | md->offset_vector[md->offset_end - number]; | md->offset_vector[md->offset_end - number]; |
1758 | md->offset_vector[offset+1] = eptr - md->start_subject; | md->offset_vector[offset+1] = (int)(eptr - md->start_subject); |
1759 | if (offset_top <= offset) offset_top = offset + 2; | if (offset_top <= offset) offset_top = offset + 2; |
1760 | } | } |
1761 | ||
# | Line 1155 for (;;) | Line 1767 for (;;) |
1767 | recursion_info *rec = md->recursive; | recursion_info *rec = md->recursive; |
1768 | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); | DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); |
1769 | md->recursive = rec->prevrec; | md->recursive = rec->prevrec; |
md->start_match = rec->save_start; | ||
1770 | memcpy(md->offset_vector, rec->offset_save, | memcpy(md->offset_vector, rec->offset_save, |
1771 | rec->saved_max * sizeof(int)); | rec->saved_max * sizeof(int)); |
1772 | offset_top = rec->save_offset_top; | |
1773 | ecode = rec->after_call; | ecode = rec->after_call; |
ims = original_ims; | ||
1774 | break; | break; |
1775 | } | } |
1776 | } | } |
1777 | ||
/* For both capturing and non-capturing groups, reset the value of the ims | ||
flags, in case they got changed during the group. */ | ||
ims = original_ims; | ||
DPRINTF(("ims reset to %02lx\n", ims)); | ||
1778 | /* For a non-repeating ket, just continue at this level. This also | /* For a non-repeating ket, just continue at this level. This also |
1779 | happens for a repeating ket if no characters were matched in the group. | happens for a repeating ket if no characters were matched in the group. |
1780 | This is the forcible breaking of infinite loops as implemented in Perl | This is the forcible breaking of infinite loops as implemented in Perl |
# | Line 1181 for (;;) | Line 1786 for (;;) |
1786 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
1787 | break; | break; |
1788 | } | } |
1789 | ||
1790 | /* The repeating kets try the rest of the pattern or restart from the | /* OP_KETRPOS is a possessive repeating ket. Remember the current position, |
1791 | preceding bracket, in the appropriate order. In the second case, we can use | and return the MATCH_KETRPOS. This makes it possible to do the repeats one |
1792 | tail recursion to avoid using another stack frame. */ | at a time from the outer level, thus saving stack. */ |
1793 | ||
1794 | flags = (*prev >= OP_SBRA)? match_cbegroup : 0; | if (*ecode == OP_KETRPOS) |
1795 | { | |
1796 | md->end_match_ptr = eptr; | |
1797 | md->end_offset_top = offset_top; | |
1798 | RRETURN(MATCH_KETRPOS); | |
1799 | } | |
1800 | ||
1801 | /* The normal repeating kets try the rest of the pattern or restart from | |
1802 | the preceding bracket, in the appropriate order. In the second case, we can | |
1803 | use tail recursion to avoid using another stack frame, unless we have an | |
1804 | unlimited repeat of a group that can match an empty string. */ | |
1805 | ||
1806 | if (*ecode == OP_KETRMIN) | if (*ecode == OP_KETRMIN) |
1807 | { | { |
1808 | RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM12); |
1809 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1810 | if (*prev >= OP_SBRA) /* Could match an empty string */ | |
1811 | { | |
1812 | md->match_function_type = MATCH_CBEGROUP; | |
1813 | RMATCH(eptr, prev, offset_top, md, eptrb, RM50); | |
1814 | RRETURN(rrc); | |
1815 | } | |
1816 | ecode = prev; | ecode = prev; |
flags |= match_tail_recursed; | ||
1817 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
1818 | } | } |
1819 | else /* OP_KETRMAX */ | else /* OP_KETRMAX */ |
1820 | { | { |
1821 | RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, flags); | if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; |
1822 | RMATCH(eptr, prev, offset_top, md, eptrb, RM13); | |
1823 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
1824 | ecode += 1 + LINK_SIZE; | ecode += 1 + LINK_SIZE; |
flags = match_tail_recursed; | ||
1825 | goto TAIL_RECURSE; | goto TAIL_RECURSE; |
1826 | } | } |
1827 | /* Control never gets here */ | /* Control never gets here */ |
1828 | ||
1829 | /* Start of subject unless notbol, or after internal newline if multiline */ | /* Not multiline mode: start of subject assertion, unless notbol. */ |
1830 | ||
1831 | case OP_CIRC: | case OP_CIRC: |
1832 | if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); | if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH); |
1833 | if ((ims & PCRE_MULTILINE) != 0) | |
{ | ||
if (eptr != md->start_subject && | ||
(eptr == md->end_subject || !WAS_NEWLINE(eptr))) | ||
RRETURN(MATCH_NOMATCH); | ||
ecode++; | ||
break; | ||
} | ||
/* ... else fall through */ | ||
1834 | /* Start of subject assertion */ | /* Start of subject assertion */ |
1835 | ||
1836 | case OP_SOD: | case OP_SOD: |
1837 | if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH); | if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH); |
1838 | ecode++; | |
1839 | break; | |
1840 | ||
1841 | /* Multiline mode: start of subject unless notbol, or after any newline. */ | |
1842 | ||
1843 | case OP_CIRCM: | |
1844 | if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH); | |
1845 | if (eptr != md->start_subject && | |
1846 | (eptr == md->end_subject || !WAS_NEWLINE(eptr))) | |
1847 | MRRETURN(MATCH_NOMATCH); | |
1848 | ecode++; | ecode++; |
1849 | break; | break; |
1850 | ||
1851 | /* Start of match assertion */ | /* Start of match assertion */ |
1852 | ||
1853 | case OP_SOM: | case OP_SOM: |
1854 | if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH); | if (eptr != md->start_subject + md->start_offset) MRRETURN(MATCH_NOMATCH); |
1855 | ecode++; | ecode++; |
1856 | break; | break; |
1857 | ||
1858 | /* Assert before internal newline if multiline, or before a terminating | /* Reset the start of match point */ |
newline unless endonly is set, else end of subject unless noteol is set. */ | ||
1859 | ||
1860 | case OP_DOLL: | case OP_SET_SOM: |
1861 | if ((ims & PCRE_MULTILINE) != 0) | mstart = eptr; |
1862 | { | ecode++; |
1863 | if (eptr < md->end_subject) | break; |
1864 | { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); } | |
1865 | else | /* Multiline mode: assert before any newline, or before end of subject |
1866 | { if (md->noteol) RRETURN(MATCH_NOMATCH); } | unless noteol is set. */ |
1867 | ecode++; | |
1868 | break; | case OP_DOLLM: |
1869 | } | if (eptr < md->end_subject) |
1870 | { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); } | |
1871 | else | else |
1872 | { | { |
1873 | if (md->noteol) RRETURN(MATCH_NOMATCH); | if (md->noteol) MRRETURN(MATCH_NOMATCH); |
1874 | if (!md->endonly) | SCHECK_PARTIAL(); |
{ | ||
if (eptr != md->end_subject && | ||
(!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) | ||
RRETURN(MATCH_NOMATCH); | ||
ecode++; | ||
break; | ||
} | ||
1875 | } | } |
1876 | ecode++; | |
1877 | break; | |
1878 | ||
1879 | /* Not multiline mode: assert before a terminating newline or before end of | |
1880 | subject unless noteol is set. */ | |
1881 | ||
1882 | case OP_DOLL: | |
1883 | if (md->noteol) MRRETURN(MATCH_NOMATCH); | |
1884 | if (!md->endonly) goto ASSERT_NL_OR_EOS; | |
1885 | ||
1886 | /* ... else fall through for endonly */ | /* ... else fall through for endonly */ |
1887 | ||
1888 | /* End of subject assertion (\z) */ | /* End of subject assertion (\z) */ |
1889 | ||
1890 | case OP_EOD: | case OP_EOD: |
1891 | if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH); |
1892 | SCHECK_PARTIAL(); | |
1893 | ecode++; | ecode++; |
1894 | break; | break; |
1895 | ||
1896 | /* End of subject or ending \n assertion (\Z) */ | /* End of subject or ending \n assertion (\Z) */ |
1897 | ||
1898 | case OP_EODN: | case OP_EODN: |
1899 | if (eptr != md->end_subject && | ASSERT_NL_OR_EOS: |
1900 | if (eptr < md->end_subject && | |
1901 | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
1902 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
1903 | ||
1904 | /* Either at end of string or \n before end. */ | |
1905 | ||
1906 | SCHECK_PARTIAL(); | |
1907 | ecode++; | ecode++; |
1908 | break; | break; |
1909 | ||
# | Line 1285 for (;;) | Line 1915 for (;;) |
1915 | ||
1916 | /* Find out if the previous and current characters are "word" characters. | /* Find out if the previous and current characters are "word" characters. |
1917 | It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to | It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to |
1918 | be "non-word" characters. */ | be "non-word" characters. Remember the earliest consulted character for |
1919 | partial matching. */ | |
1920 | ||
1921 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
1922 | if (utf8) | if (utf8) |
1923 | { | { |
1924 | /* Get status of previous character */ | |
1925 | ||
1926 | if (eptr == md->start_subject) prev_is_word = FALSE; else | if (eptr == md->start_subject) prev_is_word = FALSE; else |
1927 | { | { |
1928 | const uschar *lastptr = eptr - 1; | USPTR lastptr = eptr - 1; |
1929 | while((*lastptr & 0xc0) == 0x80) lastptr--; | while((*lastptr & 0xc0) == 0x80) lastptr--; |
1930 | if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr; | |
1931 | GETCHAR(c, lastptr); | GETCHAR(c, lastptr); |
1932 | #ifdef SUPPORT_UCP | |
1933 | if (md->use_ucp) | |
1934 | { | |
1935 | if (c == '_') prev_is_word = TRUE; else | |
1936 | { | |
1937 | int cat = UCD_CATEGORY(c); | |
1938 | prev_is_word = (cat == ucp_L || cat == ucp_N); | |
1939 | } | |
1940 | } | |
1941 | else | |
1942 | #endif | |
1943 | prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; | prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
1944 | } | } |
1945 | if (eptr >= md->end_subject) cur_is_word = FALSE; else | |
1946 | /* Get status of next character */ | |
1947 | ||
1948 | if (eptr >= md->end_subject) | |
1949 | { | |
1950 | SCHECK_PARTIAL(); | |
1951 | cur_is_word = FALSE; | |
1952 | } | |
1953 | else | |
1954 | { | { |
1955 | GETCHAR(c, eptr); | GETCHAR(c, eptr); |
1956 | #ifdef SUPPORT_UCP | |
1957 | if (md->use_ucp) | |
1958 | { | |
1959 | if (c == '_') cur_is_word = TRUE; else | |
1960 | { | |
1961 | int cat = UCD_CATEGORY(c); | |
1962 | cur_is_word = (cat == ucp_L || cat == ucp_N); | |
1963 | } | |
1964 | } | |
1965 | else | |
1966 | #endif | |
1967 | cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; | cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
1968 | } | } |
1969 | } | } |
1970 | else | else |
1971 | #endif | #endif |
1972 | ||
1973 | /* More streamlined when not in UTF-8 mode */ | /* Not in UTF-8 mode, but we may still have PCRE_UCP set, and for |
1974 | consistency with the behaviour of \w we do use it in this case. */ | |
1975 | ||
1976 | { | { |
1977 | prev_is_word = (eptr != md->start_subject) && | /* Get status of previous character */ |
1978 | ((md->ctypes[eptr[-1]] & ctype_word) != 0); | |
1979 | cur_is_word = (eptr < md->end_subject) && | if (eptr == md->start_subject) prev_is_word = FALSE; else |
1980 | ((md->ctypes[*eptr] & ctype_word) != 0); | { |
1981 | if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1; | |
1982 | #ifdef SUPPORT_UCP | |
1983 | if (md->use_ucp) | |
1984 | { | |
1985 | c = eptr[-1]; | |
1986 | if (c == '_') prev_is_word = TRUE; else | |
1987 | { | |
1988 | int cat = UCD_CATEGORY(c); | |
1989 | prev_is_word = (cat == ucp_L || cat == ucp_N); | |
1990 | } | |
1991 | } | |
1992 | else | |
1993 | #endif | |
1994 | prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0); | |
1995 | } | |
1996 | ||
1997 | /* Get status of next character */ | |
1998 | ||
1999 | if (eptr >= md->end_subject) | |
2000 | { | |
2001 | SCHECK_PARTIAL(); | |
2002 | cur_is_word = FALSE; | |
2003 | } | |
2004 | else | |
2005 | #ifdef SUPPORT_UCP | |
2006 | if (md->use_ucp) | |
2007 | { | |
2008 | c = *eptr; | |
2009 | if (c == '_') cur_is_word = TRUE; else | |
2010 | { | |
2011 | int cat = UCD_CATEGORY(c); | |
2012 | cur_is_word = (cat == ucp_L || cat == ucp_N); | |
2013 | } | |
2014 | } | |
2015 | else | |
2016 | #endif | |
2017 | cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0); | |
2018 | } | } |
2019 | ||
2020 | /* Now see if the situation is what we want */ | /* Now see if the situation is what we want */ |
2021 | ||
2022 | if ((*ecode++ == OP_WORD_BOUNDARY)? | if ((*ecode++ == OP_WORD_BOUNDARY)? |
2023 | cur_is_word == prev_is_word : cur_is_word != prev_is_word) | cur_is_word == prev_is_word : cur_is_word != prev_is_word) |
2024 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2025 | } | } |
2026 | break; | break; |
2027 | ||
2028 | /* Match a single character type; inline for speed */ | /* Match a single character type; inline for speed */ |
2029 | ||
2030 | case OP_ANY: | case OP_ANY: |
2031 | if ((ims & PCRE_DOTALL) == 0) | if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); |
2032 | /* Fall through */ | |
2033 | ||
2034 | case OP_ALLANY: | |
2035 | if (eptr++ >= md->end_subject) | |
2036 | { | { |
2037 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); | SCHECK_PARTIAL(); |
2038 | MRRETURN(MATCH_NOMATCH); | |
2039 | } | } |
2040 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
if (utf8) | ||
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | ||
2041 | ecode++; | ecode++; |
2042 | break; | break; |
2043 | ||
# | Line 1340 for (;;) | Line 2045 for (;;) |
2045 | any byte, even newline, independent of the setting of PCRE_DOTALL. */ | any byte, even newline, independent of the setting of PCRE_DOTALL. */ |
2046 | ||
2047 | case OP_ANYBYTE: | case OP_ANYBYTE: |
2048 | if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr++ >= md->end_subject) |
2049 | { | |
2050 | SCHECK_PARTIAL(); | |
2051 | MRRETURN(MATCH_NOMATCH); | |
2052 | } | |
2053 | ecode++; | ecode++; |
2054 | break; | break; |
2055 | ||
2056 | case OP_NOT_DIGIT: | case OP_NOT_DIGIT: |
2057 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2058 | { | |
2059 | SCHECK_PARTIAL(); | |
2060 | MRRETURN(MATCH_NOMATCH); | |
2061 | } | |
2062 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
2063 | if ( | if ( |
2064 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
# | Line 1353 for (;;) | Line 2066 for (;;) |
2066 | #endif | #endif |
2067 | (md->ctypes[c] & ctype_digit) != 0 | (md->ctypes[c] & ctype_digit) != 0 |
2068 | ) | ) |
2069 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2070 | ecode++; | ecode++; |
2071 | break; | break; |
2072 | ||
2073 | case OP_DIGIT: | case OP_DIGIT: |
2074 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2075 | { | |
2076 | SCHECK_PARTIAL(); | |
2077 | MRRETURN(MATCH_NOMATCH); | |
2078 | } | |
2079 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
2080 | if ( | if ( |
2081 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
# | Line 1366 for (;;) | Line 2083 for (;;) |
2083 | #endif | #endif |
2084 | (md->ctypes[c] & ctype_digit) == 0 | (md->ctypes[c] & ctype_digit) == 0 |
2085 | ) | ) |
2086 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2087 | ecode++; | ecode++; |
2088 | break; | break; |
2089 | ||
2090 | case OP_NOT_WHITESPACE: | case OP_NOT_WHITESPACE: |
2091 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2092 | { | |
2093 | SCHECK_PARTIAL(); | |
2094 | MRRETURN(MATCH_NOMATCH); | |
2095 | } | |
2096 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
2097 | if ( | if ( |
2098 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
# | Line 1379 for (;;) | Line 2100 for (;;) |
2100 | #endif | #endif |
2101 | (md->ctypes[c] & ctype_space) != 0 | (md->ctypes[c] & ctype_space) != 0 |
2102 | ) | ) |
2103 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2104 | ecode++; | ecode++; |
2105 | break; | break; |
2106 | ||
2107 | case OP_WHITESPACE: | case OP_WHITESPACE: |
2108 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2109 | { | |
2110 | SCHECK_PARTIAL(); | |
2111 | MRRETURN(MATCH_NOMATCH); | |
2112 | } | |
2113 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
2114 | if ( | if ( |
2115 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
# | Line 1392 for (;;) | Line 2117 for (;;) |
2117 | #endif | #endif |
2118 | (md->ctypes[c] & ctype_space) == 0 | (md->ctypes[c] & ctype_space) == 0 |
2119 | ) | ) |
2120 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2121 | ecode++; | ecode++; |
2122 | break; | break; |
2123 | ||
2124 | case OP_NOT_WORDCHAR: | case OP_NOT_WORDCHAR: |
2125 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2126 | { | |
2127 | SCHECK_PARTIAL(); | |
2128 | MRRETURN(MATCH_NOMATCH); | |
2129 | } | |
2130 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
2131 | if ( | if ( |
2132 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
# | Line 1405 for (;;) | Line 2134 for (;;) |
2134 | #endif | #endif |
2135 | (md->ctypes[c] & ctype_word) != 0 | (md->ctypes[c] & ctype_word) != 0 |
2136 | ) | ) |
2137 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2138 | ecode++; | ecode++; |
2139 | break; | break; |
2140 | ||
2141 | case OP_WORDCHAR: | case OP_WORDCHAR: |
2142 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2143 | { | |
2144 | SCHECK_PARTIAL(); | |
2145 | MRRETURN(MATCH_NOMATCH); | |
2146 | } | |
2147 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
2148 | if ( | if ( |
2149 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
# | Line 1418 for (;;) | Line 2151 for (;;) |
2151 | #endif | #endif |
2152 | (md->ctypes[c] & ctype_word) == 0 | (md->ctypes[c] & ctype_word) == 0 |
2153 | ) | ) |
2154 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2155 | ecode++; | ecode++; |
2156 | break; | break; |
2157 | ||
2158 | case OP_ANYNL: | case OP_ANYNL: |
2159 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2160 | { | |
2161 | SCHECK_PARTIAL(); | |
2162 | MRRETURN(MATCH_NOMATCH); | |
2163 | } | |
2164 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
2165 | switch(c) | switch(c) |
2166 | { | { |
2167 | default: RRETURN(MATCH_NOMATCH); | default: MRRETURN(MATCH_NOMATCH); |
2168 | ||
2169 | case 0x000d: | case 0x000d: |
2170 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
2171 | break; | break; |
2172 | ||
2173 | case 0x000a: | case 0x000a: |
2174 | break; | |
2175 | ||
2176 | case 0x000b: | case 0x000b: |
2177 | case 0x000c: | case 0x000c: |
2178 | case 0x0085: | case 0x0085: |
2179 | case 0x2028: | case 0x2028: |
2180 | case 0x2029: | case 0x2029: |
2181 | if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH); | |
2182 | break; | |
2183 | } | |
2184 | ecode++; | |
2185 | break; | |
2186 | ||
2187 | case OP_NOT_HSPACE: | |
2188 | if (eptr >= md->end_subject) | |
2189 | { | |
2190 | SCHECK_PARTIAL(); | |
2191 | MRRETURN(MATCH_NOMATCH); | |
2192 | } | |
2193 | GETCHARINCTEST(c, eptr); | |
2194 | switch(c) | |
2195 | { | |
2196 | default: break; | |
2197 | case 0x09: /* HT */ | |
2198 | case 0x20: /* SPACE */ | |
2199 | case 0xa0: /* NBSP */ | |
2200 | case 0x1680: /* OGHAM SPACE MARK */ | |
2201 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
2202 | case 0x2000: /* EN QUAD */ | |
2203 | case 0x2001: /* EM QUAD */ | |
2204 | case 0x2002: /* EN SPACE */ | |
2205 | case 0x2003: /* EM SPACE */ | |
2206 | case 0x2004: /* THREE-PER-EM SPACE */ | |
2207 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
2208 | case 0x2006: /* SIX-PER-EM SPACE */ | |
2209 | case 0x2007: /* FIGURE SPACE */ | |
2210 | case 0x2008: /* PUNCTUATION SPACE */ | |
2211 | case 0x2009: /* THIN SPACE */ | |
2212 | case 0x200A: /* HAIR SPACE */ | |
2213 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
2214 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
2215 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
2216 | MRRETURN(MATCH_NOMATCH); | |
2217 | } | |
2218 | ecode++; | |
2219 | break; | |
2220 | ||
2221 | case OP_HSPACE: | |
2222 | if (eptr >= md->end_subject) | |
2223 | { | |
2224 | SCHECK_PARTIAL(); | |
2225 | MRRETURN(MATCH_NOMATCH); | |
2226 | } | |
2227 | GETCHARINCTEST(c, eptr); | |
2228 | switch(c) | |
2229 | { | |
2230 | default: MRRETURN(MATCH_NOMATCH); | |
2231 | case 0x09: /* HT */ | |
2232 | case 0x20: /* SPACE */ | |
2233 | case 0xa0: /* NBSP */ | |
2234 | case 0x1680: /* OGHAM SPACE MARK */ | |
2235 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ | |
2236 | case 0x2000: /* EN QUAD */ | |
2237 | case 0x2001: /* EM QUAD */ | |
2238 | case 0x2002: /* EN SPACE */ | |
2239 | case 0x2003: /* EM SPACE */ | |
2240 | case 0x2004: /* THREE-PER-EM SPACE */ | |
2241 | case 0x2005: /* FOUR-PER-EM SPACE */ | |
2242 | case 0x2006: /* SIX-PER-EM SPACE */ | |
2243 | case 0x2007: /* FIGURE SPACE */ | |
2244 | case 0x2008: /* PUNCTUATION SPACE */ | |
2245 | case 0x2009: /* THIN SPACE */ | |
2246 | case 0x200A: /* HAIR SPACE */ | |
2247 | case 0x202f: /* NARROW NO-BREAK SPACE */ | |
2248 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ | |
2249 | case 0x3000: /* IDEOGRAPHIC SPACE */ | |
2250 | break; | |
2251 | } | |
2252 | ecode++; | |
2253 | break; | |
2254 | ||
2255 | case OP_NOT_VSPACE: | |
2256 | if (eptr >= md->end_subject) | |
2257 | { | |
2258 | SCHECK_PARTIAL(); | |
2259 | MRRETURN(MATCH_NOMATCH); | |
2260 | } | |
2261 | GETCHARINCTEST(c, eptr); | |
2262 | switch(c) | |
2263 | { | |
2264 | default: break; | |
2265 | case 0x0a: /* LF */ | |
2266 | case 0x0b: /* VT */ | |
2267 | case 0x0c: /* FF */ | |
2268 | case 0x0d: /* CR */ | |
2269 | case 0x85: /* NEL */ | |
2270 | case 0x2028: /* LINE SEPARATOR */ | |
2271 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
2272 | MRRETURN(MATCH_NOMATCH); | |
2273 | } | |
2274 | ecode++; | |
2275 | break; | |
2276 | ||
2277 | case OP_VSPACE: | |
2278 | if (eptr >= md->end_subject) | |
2279 | { | |
2280 | SCHECK_PARTIAL(); | |
2281 | MRRETURN(MATCH_NOMATCH); | |
2282 | } | |
2283 | GETCHARINCTEST(c, eptr); | |
2284 | switch(c) | |
2285 | { | |
2286 | default: MRRETURN(MATCH_NOMATCH); | |
2287 | case 0x0a: /* LF */ | |
2288 | case 0x0b: /* VT */ | |
2289 | case 0x0c: /* FF */ | |
2290 | case 0x0d: /* CR */ | |
2291 | case 0x85: /* NEL */ | |
2292 | case 0x2028: /* LINE SEPARATOR */ | |
2293 | case 0x2029: /* PARAGRAPH SEPARATOR */ | |
2294 | break; | break; |
2295 | } | } |
2296 | ecode++; | ecode++; |
# | Line 1448 for (;;) | Line 2302 for (;;) |
2302 | ||
2303 | case OP_PROP: | case OP_PROP: |
2304 | case OP_NOTPROP: | case OP_NOTPROP: |
2305 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2306 | { | |
2307 | SCHECK_PARTIAL(); | |
2308 | MRRETURN(MATCH_NOMATCH); | |
2309 | } | |
2310 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
2311 | { | { |
2312 | int chartype, script; | const ucd_record *prop = GET_UCD(c); |
int category = _pcre_ucp_findprop(c, &chartype, &script); | ||
2313 | ||
2314 | switch(ecode[1]) | switch(ecode[1]) |
2315 | { | { |
2316 | case PT_ANY: | case PT_ANY: |
2317 | if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH); | if (op == OP_NOTPROP) MRRETURN(MATCH_NOMATCH); |
2318 | break; | break; |
2319 | ||
2320 | case PT_LAMP: | case PT_LAMP: |
2321 | if ((chartype == ucp_Lu || | if ((prop->chartype == ucp_Lu || |
2322 | chartype == ucp_Ll || | prop->chartype == ucp_Ll || |
2323 | chartype == ucp_Lt) == (op == OP_NOTPROP)) | prop->chartype == ucp_Lt) == (op == OP_NOTPROP)) |
2324 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2325 | break; | break; |
2326 | ||
2327 | case PT_GC: | case PT_GC: |
2328 | if ((ecode[2] != category) == (op == OP_PROP)) | if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP)) |
2329 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2330 | break; | break; |
2331 | ||
2332 | case PT_PC: | case PT_PC: |
2333 | if ((ecode[2] != chartype) == (op == OP_PROP)) | if ((ecode[2] != prop->chartype) == (op == OP_PROP)) |
2334 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2335 | break; | break; |
2336 | ||
2337 | case PT_SC: | case PT_SC: |
2338 | if ((ecode[2] != script) == (op == OP_PROP)) | if ((ecode[2] != prop->script) == (op == OP_PROP)) |
2339 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2340 | break; | |
2341 | ||
2342 | /* These are specials */ | |
2343 | ||
2344 | case PT_ALNUM: | |
2345 | if ((_pcre_ucp_gentype[prop->chartype] == ucp_L || | |
2346 | _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP)) | |
2347 | MRRETURN(MATCH_NOMATCH); | |
2348 | break; | |
2349 | ||
2350 | case PT_SPACE: /* Perl space */ | |
2351 | if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z || | |
2352 | c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR) | |
2353 | == (op == OP_NOTPROP)) | |
2354 | MRRETURN(MATCH_NOMATCH); | |
2355 | break; | |
2356 | ||
2357 | case PT_PXSPACE: /* POSIX space */ | |
2358 | if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z || | |
2359 | c == CHAR_HT || c == CHAR_NL || c == CHAR_VT || | |
2360 | c == CHAR_FF || c == CHAR_CR) | |
2361 | == (op == OP_NOTPROP)) | |
2362 | MRRETURN(MATCH_NOMATCH); | |
2363 | break; | |
2364 | ||
2365 | case PT_WORD: | |
2366 | if ((_pcre_ucp_gentype[prop->chartype] == ucp_L || | |
2367 | _pcre_ucp_gentype[prop->chartype] == ucp_N || | |
2368 | c == CHAR_UNDERSCORE) == (op == OP_NOTPROP)) | |
2369 | MRRETURN(MATCH_NOMATCH); | |
2370 | break; | break; |
2371 | ||
2372 | /* This should never occur */ | |
2373 | ||
2374 | default: | default: |
2375 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
2376 | } | } |
# | Line 1494 for (;;) | Line 2383 for (;;) |
2383 | is in the binary; otherwise a compile-time error occurs. */ | is in the binary; otherwise a compile-time error occurs. */ |
2384 | ||
2385 | case OP_EXTUNI: | case OP_EXTUNI: |
2386 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2387 | { | |
2388 | SCHECK_PARTIAL(); | |
2389 | MRRETURN(MATCH_NOMATCH); | |
2390 | } | |
2391 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
2392 | { | { |
2393 | int chartype, script; | int category = UCD_CATEGORY(c); |
2394 | int category = _pcre_ucp_findprop(c, &chartype, &script); | if (category == ucp_M) MRRETURN(MATCH_NOMATCH); |
if (category == ucp_M) RRETURN(MATCH_NOMATCH); | ||
2395 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
2396 | { | { |
2397 | int len = 1; | int len = 1; |
# | Line 1507 for (;;) | Line 2399 for (;;) |
2399 | { | { |
2400 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
2401 | } | } |
2402 | category = _pcre_ucp_findprop(c, &chartype, &script); | category = UCD_CATEGORY(c); |
2403 | if (category != ucp_M) break; | if (category != ucp_M) break; |
2404 | eptr += len; | eptr += len; |
2405 | } | } |
# | Line 1526 for (;;) | Line 2418 for (;;) |
2418 | loops). */ | loops). */ |
2419 | ||
2420 | case OP_REF: | case OP_REF: |
2421 | { | case OP_REFI: |
2422 | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ | caseless = op == OP_REFI; |
2423 | ecode += 3; /* Advance past item */ | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ |
2424 | ecode += 3; | |
2425 | ||
2426 | /* If the reference is unset, set the length to be longer than the amount | /* If the reference is unset, there are two possibilities: |
of subject left; this ensures that every attempt at a match fails. We | ||
can't just fail here, because of the possibility of quantifiers with zero | ||
minima. */ | ||
length = (offset >= offset_top || md->offset_vector[offset] < 0)? | ||
md->end_subject - eptr + 1 : | ||
md->offset_vector[offset+1] - md->offset_vector[offset]; | ||
2427 | ||
2428 | /* Set up for repetition, or handle the non-repeated case */ | (a) In the default, Perl-compatible state, set the length negative; |
2429 | this ensures that every attempt at a match fails. We can't just fail | |
2430 | here, because of the possibility of quantifiers with zero minima. | |
2431 | ||
2432 | switch (*ecode) | (b) If the JavaScript compatibility flag is set, set the length to zero |
2433 | { | so that the back reference matches an empty string. |
case OP_CRSTAR: | ||
case OP_CRMINSTAR: | ||
case OP_CRPLUS: | ||
case OP_CRMINPLUS: | ||
case OP_CRQUERY: | ||
case OP_CRMINQUERY: | ||
c = *ecode++ - OP_CRSTAR; | ||
minimize = (c & 1) != 0; | ||
min = rep_min[c]; /* Pick up values from tables; */ | ||
max = rep_max[c]; /* zero for max => infinity */ | ||
if (max == 0) max = INT_MAX; | ||
break; | ||
2434 | ||
2435 | case OP_CRRANGE: | Otherwise, set the length to the length of what was matched by the |
2436 | case OP_CRMINRANGE: | referenced subpattern. */ |
minimize = (*ecode == OP_CRMINRANGE); | ||
min = GET2(ecode, 1); | ||
max = GET2(ecode, 3); | ||
if (max == 0) max = INT_MAX; | ||
ecode += 5; | ||
break; | ||
2437 | ||
2438 | default: /* No repeat follows */ | if (offset >= offset_top || md->offset_vector[offset] < 0) |
2439 | if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH); | length = (md->jscript_compat)? 0 : -1; |
2440 | eptr += length; | else |
2441 | continue; /* With the main loop */ | length = md->offset_vector[offset+1] - md->offset_vector[offset]; |
2442 | ||
2443 | /* Set up for repetition, or handle the non-repeated case */ | |
2444 | ||
2445 | switch (*ecode) | |
2446 | { | |
2447 | case OP_CRSTAR: | |
2448 | case OP_CRMINSTAR: | |
2449 | case OP_CRPLUS: | |
2450 | case OP_CRMINPLUS: | |
2451 | case OP_CRQUERY: | |
2452 | case OP_CRMINQUERY: | |
2453 | c = *ecode++ - OP_CRSTAR; | |
2454 | minimize = (c & 1) != 0; | |
2455 | min = rep_min[c]; /* Pick up values from tables; */ | |
2456 | max = rep_max[c]; /* zero for max => infinity */ | |
2457 | if (max == 0) max = INT_MAX; | |
2458 | break; | |
2459 | ||
2460 | case OP_CRRANGE: | |
2461 | case OP_CRMINRANGE: | |
2462 | minimize = (*ecode == OP_CRMINRANGE); | |
2463 | min = GET2(ecode, 1); | |
2464 | max = GET2(ecode, 3); | |
2465 | if (max == 0) max = INT_MAX; | |
2466 | ecode += 5; | |
2467 | break; | |
2468 | ||
2469 | default: /* No repeat follows */ | |
2470 | if ((length = match_ref(offset, eptr, length, md, caseless)) < 0) | |
2471 | { | |
2472 | CHECK_PARTIAL(); | |
2473 | MRRETURN(MATCH_NOMATCH); | |
2474 | } | } |
2475 | eptr += length; | |
2476 | continue; /* With the main loop */ | |
2477 | } | |
2478 | ||
2479 | /* If the length of the reference is zero, just continue with the | /* Handle repeated back references. If the length of the reference is |
2480 | main loop. */ | zero, just continue with the main loop. */ |
2481 | ||
2482 | if (length == 0) continue; | if (length == 0) continue; |
2483 | ||
2484 | /* First, ensure the minimum number of matches are present. We get back | /* First, ensure the minimum number of matches are present. We get back |
2485 | the length of the reference string explicitly rather than passing the | the length of the reference string explicitly rather than passing the |
2486 | address of eptr, so that eptr can be a register variable. */ | address of eptr, so that eptr can be a register variable. */ |
2487 | ||
2488 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
2489 | { | |
2490 | int slength; | |
2491 | if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0) | |
2492 | { | { |
2493 | if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH); | CHECK_PARTIAL(); |
2494 | eptr += length; | MRRETURN(MATCH_NOMATCH); |
2495 | } | } |
2496 | eptr += slength; | |
2497 | } | |
2498 | ||
2499 | /* If min = max, continue at the same level without recursion. | /* If min = max, continue at the same level without recursion. |
2500 | They are not both allowed to be zero. */ | They are not both allowed to be zero. */ |
2501 | ||
2502 | if (min == max) continue; | if (min == max) continue; |
2503 | ||
2504 | /* If minimizing, keep trying and advancing the pointer */ | /* If minimizing, keep trying and advancing the pointer */ |
2505 | ||
2506 | if (minimize) | if (minimize) |
2507 | { | |
2508 | for (fi = min;; fi++) | |
2509 | { | { |
2510 | for (fi = min;; fi++) | int slength; |
2511 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM14); | |
2512 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
2513 | if (fi >= max) MRRETURN(MATCH_NOMATCH); | |
2514 | if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0) | |
2515 | { | { |
2516 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | CHECK_PARTIAL(); |
2517 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | MRRETURN(MATCH_NOMATCH); |
if (fi >= max || !match_ref(offset, eptr, length, md, ims)) | ||
RRETURN(MATCH_NOMATCH); | ||
eptr += length; | ||
2518 | } | } |
2519 | /* Control never gets here */ | eptr += slength; |
2520 | } | } |
2521 | /* Control never gets here */ | |
2522 | } | |
2523 | ||
2524 | /* If maximizing, find the longest string and work backwards */ | /* If maximizing, find the longest string and work backwards */ |
2525 | ||
2526 | else | else |
2527 | { | |
2528 | pp = eptr; | |
2529 | for (i = min; i < max; i++) | |
2530 | { | { |
2531 | pp = eptr; | int slength; |
2532 | for (i = min; i < max; i++) | if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0) |
2533 | { | { |
2534 | if (!match_ref(offset, eptr, length, md, ims)) break; | CHECK_PARTIAL(); |
2535 | eptr += length; | break; |
} | ||
while (eptr >= pp) | ||
{ | ||
RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | ||
if (rrc != MATCH_NOMATCH) RRETURN(rrc); | ||
eptr -= length; | ||
2536 | } | } |
2537 | RRETURN(MATCH_NOMATCH); | eptr += slength; |
2538 | } | |
2539 | while (eptr >= pp) | |
2540 | { | |
2541 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM15); | |
2542 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | |
2543 | eptr -= length; | |
2544 | } | } |
2545 | MRRETURN(MATCH_NOMATCH); | |
2546 | } | } |
2547 | /* Control never gets here */ | /* Control never gets here */ |
2548 | ||
2549 | /* Match a bit-mapped character class, possibly repeatedly. This op code is | /* Match a bit-mapped character class, possibly repeatedly. This op code is |
2550 | used when all the characters in the class have values in the range 0-255, | used when all the characters in the class have values in the range 0-255, |
2551 | and either the matching is caseful, or the characters are in the range | and either the matching is caseful, or the characters are in the range |
# | Line 1683 for (;;) | Line 2600 for (;;) |
2600 | { | { |
2601 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
2602 | { | { |
2603 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2604 | { | |
2605 | SCHECK_PARTIAL(); | |
2606 | MRRETURN(MATCH_NOMATCH); | |
2607 | } | |
2608 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
2609 | if (c > 255) | if (c > 255) |
2610 | { | { |
2611 | if (op == OP_CLASS) RRETURN(MATCH_NOMATCH); | if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH); |
2612 | } | } |
2613 | else | else |
2614 | { | { |
2615 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH); |
2616 | } | } |
2617 | } | } |
2618 | } | } |
# | Line 1701 for (;;) | Line 2622 for (;;) |
2622 | { | { |
2623 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
2624 | { | { |
2625 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2626 | { | |
2627 | SCHECK_PARTIAL(); | |
2628 | MRRETURN(MATCH_NOMATCH); | |
2629 | } | |
2630 | c = *eptr++; | c = *eptr++; |
2631 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH); |
2632 | } | } |
2633 | } | } |
2634 | ||
# | Line 1723 for (;;) | Line 2648 for (;;) |
2648 | { | { |
2649 | for (fi = min;; fi++) | for (fi = min;; fi++) |
2650 | { | { |
2651 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM16); |
2652 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2653 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
2654 | if (eptr >= md->end_subject) | |
2655 | { | |
2656 | SCHECK_PARTIAL(); | |
2657 | MRRETURN(MATCH_NOMATCH); | |
2658 | } | |
2659 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
2660 | if (c > 255) | if (c > 255) |
2661 | { | { |
2662 | if (op == OP_CLASS) RRETURN(MATCH_NOMATCH); | if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH); |
2663 | } | } |
2664 | else | else |
2665 | { | { |
2666 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH); |
2667 | } | } |
2668 | } | } |
2669 | } | } |
# | Line 1743 for (;;) | Line 2673 for (;;) |
2673 | { | { |
2674 | for (fi = min;; fi++) | for (fi = min;; fi++) |
2675 | { | { |
2676 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM17); |
2677 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2678 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
2679 | if (eptr >= md->end_subject) | |
2680 | { | |
2681 | SCHECK_PARTIAL(); | |
2682 | MRRETURN(MATCH_NOMATCH); | |
2683 | } | |
2684 | c = *eptr++; | c = *eptr++; |
2685 | if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); | if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH); |
2686 | } | } |
2687 | } | } |
2688 | /* Control never gets here */ | /* Control never gets here */ |
# | Line 1766 for (;;) | Line 2701 for (;;) |
2701 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
2702 | { | { |
2703 | int len = 1; | int len = 1; |
2704 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
2705 | { | |
2706 | SCHECK_PARTIAL(); | |
2707 | break; | |
2708 | } | |
2709 | GETCHARLEN(c, eptr, len); | GETCHARLEN(c, eptr, len); |
2710 | if (c > 255) | if (c > 255) |
2711 | { | { |
# | Line 1780 for (;;) | Line 2719 for (;;) |
2719 | } | } |
2720 | for (;;) | for (;;) |
2721 | { | { |
2722 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM18); |
2723 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2724 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
2725 | BACKCHAR(eptr); | BACKCHAR(eptr); |
# | Line 1792 for (;;) | Line 2731 for (;;) |
2731 | { | { |
2732 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
2733 | { | { |
2734 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
2735 | { | |
2736 | SCHECK_PARTIAL(); | |
2737 | break; | |
2738 | } | |
2739 | c = *eptr; | c = *eptr; |
2740 | if ((data[c/8] & (1 << (c&7))) == 0) break; | if ((data[c/8] & (1 << (c&7))) == 0) break; |
2741 | eptr++; | eptr++; |
2742 | } | } |
2743 | while (eptr >= pp) | while (eptr >= pp) |
2744 | { | { |
2745 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM19); |
2746 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2747 | eptr--; | eptr--; |
2748 | } | } |
2749 | } | } |
2750 | ||
2751 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2752 | } | } |
2753 | } | } |
2754 | /* Control never gets here */ | /* Control never gets here */ |
2755 | ||
2756 | ||
2757 | /* Match an extended character class. This opcode is encountered only | /* Match an extended character class. This opcode is encountered only |
2758 | in UTF-8 mode, because that's the only time it is compiled. */ | when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8 |
2759 | mode, because Unicode properties are supported in non-UTF-8 mode. */ | |
2760 | ||
2761 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
2762 | case OP_XCLASS: | case OP_XCLASS: |
# | Line 1853 for (;;) | Line 2797 for (;;) |
2797 | ||
2798 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
2799 | { | { |
2800 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
2801 | GETCHARINC(c, eptr); | { |
2802 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | SCHECK_PARTIAL(); |
2803 | MRRETURN(MATCH_NOMATCH); | |
2804 | } | |
2805 | GETCHARINCTEST(c, eptr); | |
2806 | if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH); | |
2807 | } | } |
2808 | ||
2809 | /* If max == min we can continue with the main loop without the | /* If max == min we can continue with the main loop without the |
# | Line 1870 for (;;) | Line 2818 for (;;) |
2818 | { | { |
2819 | for (fi = min;; fi++) | for (fi = min;; fi++) |
2820 | { | { |
2821 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM20); |
2822 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2823 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
2824 | GETCHARINC(c, eptr); | if (eptr >= md->end_subject) |
2825 | if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); | { |
2826 | SCHECK_PARTIAL(); | |
2827 | MRRETURN(MATCH_NOMATCH); | |
2828 | } | |
2829 | GETCHARINCTEST(c, eptr); | |
2830 | if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH); | |
2831 | } | } |
2832 | /* Control never gets here */ | /* Control never gets here */ |
2833 | } | } |
# | Line 1887 for (;;) | Line 2840 for (;;) |
2840 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
2841 | { | { |
2842 | int len = 1; | int len = 1; |
2843 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
2844 | GETCHARLEN(c, eptr, len); | { |
2845 | SCHECK_PARTIAL(); | |
2846 | break; | |
2847 | } | |
2848 | GETCHARLENTEST(c, eptr, len); | |
2849 | if (!_pcre_xclass(c, data)) break; | if (!_pcre_xclass(c, data)) break; |
2850 | eptr += len; | eptr += len; |
2851 | } | } |
2852 | for(;;) | for(;;) |
2853 | { | { |
2854 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM21); |
2855 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2856 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
2857 | BACKCHAR(eptr) | if (utf8) BACKCHAR(eptr); |
2858 | } | } |
2859 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2860 | } | } |
2861 | ||
2862 | /* Control never gets here */ | /* Control never gets here */ |
# | Line 1915 for (;;) | Line 2872 for (;;) |
2872 | length = 1; | length = 1; |
2873 | ecode++; | ecode++; |
2874 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
2875 | if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | if (length > md->end_subject - eptr) |
2876 | while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH); | { |
2877 | CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */ | |
2878 | MRRETURN(MATCH_NOMATCH); | |
2879 | } | |
2880 | while (length-- > 0) if (*ecode++ != *eptr++) MRRETURN(MATCH_NOMATCH); | |
2881 | } | } |
2882 | else | else |
2883 | #endif | #endif |
2884 | ||
2885 | /* Non-UTF-8 mode */ | /* Non-UTF-8 mode */ |
2886 | { | { |
2887 | if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH); | if (md->end_subject - eptr < 1) |
2888 | if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH); | { |
2889 | SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */ | |
2890 | MRRETURN(MATCH_NOMATCH); | |
2891 | } | |
2892 | if (ecode[1] != *eptr++) MRRETURN(MATCH_NOMATCH); | |
2893 | ecode += 2; | ecode += 2; |
2894 | } | } |
2895 | break; | break; |
2896 | ||
2897 | /* Match a single character, caselessly */ | /* Match a single character, caselessly */ |
2898 | ||
2899 | case OP_CHARNC: | case OP_CHARI: |
2900 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
2901 | if (utf8) | if (utf8) |
2902 | { | { |
# | Line 1939 for (;;) | Line 2904 for (;;) |
2904 | ecode++; | ecode++; |
2905 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
2906 | ||
2907 | if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | if (length > md->end_subject - eptr) |
2908 | { | |
2909 | CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */ | |
2910 | MRRETURN(MATCH_NOMATCH); | |
2911 | } | |
2912 | ||
2913 | /* If the pattern character's value is < 128, we have only one byte, and | /* If the pattern character's value is < 128, we have only one byte, and |
2914 | can use the fast lookup table. */ | can use the fast lookup table. */ |
2915 | ||
2916 | if (fc < 128) | if (fc < 128) |
2917 | { | { |
2918 | if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | if (md->lcc[*ecode++] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); |
2919 | } | } |
2920 | ||
2921 | /* Otherwise we must pick up the subject character */ | /* Otherwise we must pick up the subject character */ |
# | Line 1963 for (;;) | Line 2932 for (;;) |
2932 | if (fc != dc) | if (fc != dc) |
2933 | { | { |
2934 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
2935 | if (dc != _pcre_ucp_othercase(fc)) | if (dc != UCD_OTHERCASE(fc)) |
2936 | #endif | #endif |
2937 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
2938 | } | } |
2939 | } | } |
2940 | } | } |
# | Line 1974 for (;;) | Line 2943 for (;;) |
2943 | ||
2944 | /* Non-UTF-8 mode */ | /* Non-UTF-8 mode */ |
2945 | { | { |
2946 | if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH); | if (md->end_subject - eptr < 1) |
2947 | if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | { |
2948 | SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */ | |
2949 | MRRETURN(MATCH_NOMATCH); | |
2950 | } | |
2951 | if (md->lcc[ecode[1]] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); | |
2952 | ecode += 2; | ecode += 2; |
2953 | } | } |
2954 | break; | break; |
# | Line 1983 for (;;) | Line 2956 for (;;) |
2956 | /* Match a single character repeatedly. */ | /* Match a single character repeatedly. */ |
2957 | ||
2958 | case OP_EXACT: | case OP_EXACT: |
2959 | case OP_EXACTI: | |
2960 | min = max = GET2(ecode, 1); | min = max = GET2(ecode, 1); |
2961 | ecode += 3; | ecode += 3; |
2962 | goto REPEATCHAR; | goto REPEATCHAR; |
2963 | ||
2964 | case OP_POSUPTO: | case OP_POSUPTO: |
2965 | case OP_POSUPTOI: | |
2966 | possessive = TRUE; | possessive = TRUE; |
2967 | /* Fall through */ | /* Fall through */ |
2968 | ||
2969 | case OP_UPTO: | case OP_UPTO: |
2970 | case OP_UPTOI: | |
2971 | case OP_MINUPTO: | case OP_MINUPTO: |
2972 | case OP_MINUPTOI: | |
2973 | min = 0; | min = 0; |
2974 | max = GET2(ecode, 1); | max = GET2(ecode, 1); |
2975 | minimize = *ecode == OP_MINUPTO; | minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI; |
2976 | ecode += 3; | ecode += 3; |
2977 | goto REPEATCHAR; | goto REPEATCHAR; |
2978 | ||
2979 | case OP_POSSTAR: | case OP_POSSTAR: |
2980 | case OP_POSSTARI: | |
2981 | possessive = TRUE; | possessive = TRUE; |
2982 | min = 0; | min = 0; |
2983 | max = INT_MAX; | max = INT_MAX; |
# | Line 2007 for (;;) | Line 2985 for (;;) |
2985 | goto REPEATCHAR; | goto REPEATCHAR; |
2986 | ||
2987 | case OP_POSPLUS: | case OP_POSPLUS: |
2988 | case OP_POSPLUSI: | |
2989 | possessive = TRUE; | possessive = TRUE; |
2990 | min = 1; | min = 1; |
2991 | max = INT_MAX; | max = INT_MAX; |
# | Line 2014 for (;;) | Line 2993 for (;;) |
2993 | goto REPEATCHAR; | goto REPEATCHAR; |
2994 | ||
2995 | case OP_POSQUERY: | case OP_POSQUERY: |
2996 | case OP_POSQUERYI: | |
2997 | possessive = TRUE; | possessive = TRUE; |
2998 | min = 0; | min = 0; |
2999 | max = 1; | max = 1; |
# | Line 2021 for (;;) | Line 3001 for (;;) |
3001 | goto REPEATCHAR; | goto REPEATCHAR; |
3002 | ||
3003 | case OP_STAR: | case OP_STAR: |
3004 | case OP_STARI: | |
3005 | case OP_MINSTAR: | case OP_MINSTAR: |
3006 | case OP_MINSTARI: | |
3007 | case OP_PLUS: | case OP_PLUS: |
3008 | case OP_PLUSI: | |
3009 | case OP_MINPLUS: | case OP_MINPLUS: |
3010 | case OP_MINPLUSI: | |
3011 | case OP_QUERY: | case OP_QUERY: |
3012 | case OP_QUERYI: | |
3013 | case OP_MINQUERY: | case OP_MINQUERY: |
3014 | c = *ecode++ - OP_STAR; | case OP_MINQUERYI: |
3015 | c = *ecode++ - ((op < OP_STARI)? OP_STAR : OP_STARI); | |
3016 | minimize = (c & 1) != 0; | minimize = (c & 1) != 0; |
3017 | min = rep_min[c]; /* Pick up values from tables; */ | min = rep_min[c]; /* Pick up values from tables; */ |
3018 | max = rep_max[c]; /* zero for max => infinity */ | max = rep_max[c]; /* zero for max => infinity */ |
3019 | if (max == 0) max = INT_MAX; | if (max == 0) max = INT_MAX; |
3020 | ||
3021 | /* Common code for all repeated single-character matches. We can give | /* Common code for all repeated single-character matches. */ |
up quickly if there are fewer than the minimum number of characters left in | ||
the subject. */ | ||
3022 | ||
3023 | REPEATCHAR: | REPEATCHAR: |
3024 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
# | Line 2043 for (;;) | Line 3027 for (;;) |
3027 | length = 1; | length = 1; |
3028 | charptr = ecode; | charptr = ecode; |
3029 | GETCHARLEN(fc, ecode, length); | GETCHARLEN(fc, ecode, length); |
if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
3030 | ecode += length; | ecode += length; |
3031 | ||
3032 | /* Handle multibyte character matching specially here. There is | /* Handle multibyte character matching specially here. There is |
# | Line 2053 for (;;) | Line 3036 for (;;) |
3036 | { | { |
3037 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
3038 | unsigned int othercase; | unsigned int othercase; |
3039 | if ((ims & PCRE_CASELESS) != 0 && | if (op >= OP_STARI && /* Caseless */ |
3040 | (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR) | (othercase = UCD_OTHERCASE(fc)) != fc) |
3041 | oclength = _pcre_ord2utf8(othercase, occhars); | oclength = _pcre_ord2utf8(othercase, occhars); |
3042 | else oclength = 0; | else oclength = 0; |
3043 | #endif /* SUPPORT_UCP */ | #endif /* SUPPORT_UCP */ |
3044 | ||
3045 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3046 | { | { |
3047 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (eptr <= md->end_subject - length && |
3048 | memcmp(eptr, charptr, length) == 0) eptr += length; | |
3049 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
3050 | /* Need braces because of following else */ | else if (oclength > 0 && |
3051 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | eptr <= md->end_subject - oclength && |
3052 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
3053 | #endif /* SUPPORT_UCP */ | |
3054 | else | else |
3055 | { | { |
3056 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | CHECK_PARTIAL(); |
3057 | eptr += oclength; | MRRETURN(MATCH_NOMATCH); |
3058 | } | } |
#else /* without SUPPORT_UCP */ | ||
else { RRETURN(MATCH_NOMATCH); } | ||
#endif /* SUPPORT_UCP */ | ||
3059 | } | } |
3060 | ||
3061 | if (min == max) continue; | if (min == max) continue; |
# | Line 2081 for (;;) | Line 3064 for (;;) |
3064 | { | { |
3065 | for (fi = min;; fi++) | for (fi = min;; fi++) |
3066 | { | { |
3067 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM22); |
3068 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3069 | if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
3070 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | if (eptr <= md->end_subject - length && |
3071 | memcmp(eptr, charptr, length) == 0) eptr += length; | |
3072 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
3073 | /* Need braces because of following else */ | else if (oclength > 0 && |
3074 | else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } | eptr <= md->end_subject - oclength && |
3075 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
3076 | #endif /* SUPPORT_UCP */ | |
3077 | else | else |
3078 | { | { |
3079 | if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); | CHECK_PARTIAL(); |
3080 | eptr += oclength; | MRRETURN(MATCH_NOMATCH); |
3081 | } | } |
#else /* without SUPPORT_UCP */ | ||
else { RRETURN (MATCH_NOMATCH); } | ||
#endif /* SUPPORT_UCP */ | ||
3082 | } | } |
3083 | /* Control never gets here */ | /* Control never gets here */ |
3084 | } | } |
# | Line 2105 for (;;) | Line 3088 for (;;) |
3088 | pp = eptr; | pp = eptr; |
3089 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
3090 | { | { |
3091 | if (eptr > md->end_subject - length) break; | if (eptr <= md->end_subject - length && |
3092 | if (memcmp(eptr, charptr, length) == 0) eptr += length; | memcmp(eptr, charptr, length) == 0) eptr += length; |
3093 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
3094 | else if (oclength == 0) break; | else if (oclength > 0 && |
3095 | eptr <= md->end_subject - oclength && | |
3096 | memcmp(eptr, occhars, oclength) == 0) eptr += oclength; | |
3097 | #endif /* SUPPORT_UCP */ | |
3098 | else | else |
3099 | { | { |
3100 | if (memcmp(eptr, occhars, oclength) != 0) break; | CHECK_PARTIAL(); |
3101 | eptr += oclength; | break; |
3102 | } | } |
#else /* without SUPPORT_UCP */ | ||
else break; | ||
#endif /* SUPPORT_UCP */ | ||
3103 | } | } |
3104 | ||
3105 | if (possessive) continue; | if (possessive) continue; |
3106 | ||
3107 | for(;;) | for(;;) |
3108 | { | { |
3109 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM23); |
3110 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3111 | if (eptr == pp) RRETURN(MATCH_NOMATCH); | if (eptr == pp) { MRRETURN(MATCH_NOMATCH); } |
3112 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
3113 | eptr--; | eptr--; |
3114 | BACKCHAR(eptr); | BACKCHAR(eptr); |
3115 | #else /* without SUPPORT_UCP */ | #else /* without SUPPORT_UCP */ |
3116 | eptr -= length; | eptr -= length; |
3117 | #endif /* SUPPORT_UCP */ | #endif /* SUPPORT_UCP */ |
3118 | } | } |
3119 | } | } |
3120 | /* Control never gets here */ | /* Control never gets here */ |
3121 | } | } |
# | Line 2144 for (;;) | Line 3128 for (;;) |
3128 | #endif /* SUPPORT_UTF8 */ | #endif /* SUPPORT_UTF8 */ |
3129 | ||
3130 | /* When not in UTF-8 mode, load a single-byte character. */ | /* When not in UTF-8 mode, load a single-byte character. */ |
3131 | { | |
3132 | if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | fc = *ecode++; |
fc = *ecode++; | ||
} | ||
3133 | ||
3134 | /* The value of fc at this point is always less than 256, though we may or | /* The value of fc at this point is always less than 256, though we may or |
3135 | may not be in UTF-8 mode. The code is duplicated for the caseless and | may not be in UTF-8 mode. The code is duplicated for the caseless and |
# | Line 2161 for (;;) | Line 3143 for (;;) |
3143 | DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max, | DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max, |
3144 | max, eptr)); | max, eptr)); |
3145 | ||
3146 | if ((ims & PCRE_CASELESS) != 0) | if (op >= OP_STARI) /* Caseless */ |
3147 | { | { |
3148 | fc = md->lcc[fc]; | fc = md->lcc[fc]; |
3149 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3150 | if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | { |
3151 | if (eptr >= md->end_subject) | |
3152 | { | |
3153 | SCHECK_PARTIAL(); | |
3154 | MRRETURN(MATCH_NOMATCH); | |
3155 | } | |
3156 | if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); | |
3157 | } | |
3158 | if (min == max) continue; | if (min == max) continue; |
3159 | if (minimize) | if (minimize) |
3160 | { | { |
3161 | for (fi = min;; fi++) | for (fi = min;; fi++) |
3162 | { | { |
3163 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM24); |
3164 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3165 | if (fi >= max || eptr >= md->end_subject || | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
3166 | fc != md->lcc[*eptr++]) | if (eptr >= md->end_subject) |
3167 | RRETURN(MATCH_NOMATCH); | { |
3168 | SCHECK_PARTIAL(); | |
3169 | MRRETURN(MATCH_NOMATCH); | |
3170 | } | |
3171 | if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); | |
3172 | } | } |
3173 | /* Control never gets here */ | /* Control never gets here */ |
3174 | } | } |
# | Line 2184 for (;;) | Line 3177 for (;;) |
3177 | pp = eptr; | pp = eptr; |
3178 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
3179 | { | { |
3180 | if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break; | if (eptr >= md->end_subject) |
3181 | { | |
3182 | SCHECK_PARTIAL(); | |
3183 | break; | |
3184 | } | |
3185 | if (fc != md->lcc[*eptr]) break; | |
3186 | eptr++; | eptr++; |
3187 | } | } |
3188 | ||
3189 | if (possessive) continue; | if (possessive) continue; |
3190 | ||
3191 | while (eptr >= pp) | while (eptr >= pp) |
3192 | { | { |
3193 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM25); |
3194 | eptr--; | eptr--; |
3195 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3196 | } | } |
3197 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
3198 | } | } |
3199 | /* Control never gets here */ | /* Control never gets here */ |
3200 | } | } |
# | Line 2203 for (;;) | Line 3203 for (;;) |
3203 | ||
3204 | else | else |
3205 | { | { |
3206 | for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH); | for (i = 1; i <= min; i++) |
3207 | { | |
3208 | if (eptr >= md->end_subject) | |
3209 | { | |
3210 | SCHECK_PARTIAL(); | |
3211 | MRRETURN(MATCH_NOMATCH); | |
3212 | } | |
3213 | if (fc != *eptr++) MRRETURN(MATCH_NOMATCH); | |
3214 | } | |
3215 | ||
3216 | if (min == max) continue; | if (min == max) continue; |
3217 | ||
3218 | if (minimize) | if (minimize) |
3219 | { | { |
3220 | for (fi = min;; fi++) | for (fi = min;; fi++) |
3221 | { | { |
3222 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM26); |
3223 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3224 | if (fi >= max || eptr >= md->end_subject || fc != *eptr++) | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
3225 | RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3226 | { | |
3227 | SCHECK_PARTIAL(); | |
3228 | MRRETURN(MATCH_NOMATCH); | |
3229 | } | |
3230 | if (fc != *eptr++) MRRETURN(MATCH_NOMATCH); | |
3231 | } | } |
3232 | /* Control never gets here */ | /* Control never gets here */ |
3233 | } | } |
# | Line 2221 for (;;) | Line 3236 for (;;) |
3236 | pp = eptr; | pp = eptr; |
3237 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
3238 | { | { |
3239 | if (eptr >= md->end_subject || fc != *eptr) break; | if (eptr >= md->end_subject) |
3240 | { | |
3241 | SCHECK_PARTIAL(); | |
3242 | break; | |
3243 | } | |
3244 | if (fc != *eptr) break; | |
3245 | eptr++; | eptr++; |
3246 | } | } |
3247 | if (possessive) continue; | if (possessive) continue; |
3248 | ||
3249 | while (eptr >= pp) | while (eptr >= pp) |
3250 | { | { |
3251 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM27); |
3252 | eptr--; | eptr--; |
3253 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3254 | } | } |
3255 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
3256 | } | } |
3257 | } | } |
3258 | /* Control never gets here */ | /* Control never gets here */ |
# | Line 2240 for (;;) | Line 3261 for (;;) |
3261 | checking can be multibyte. */ | checking can be multibyte. */ |
3262 | ||
3263 | case OP_NOT: | case OP_NOT: |
3264 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | case OP_NOTI: |
3265 | if (eptr >= md->end_subject) | |
3266 | { | |
3267 | SCHECK_PARTIAL(); | |
3268 | MRRETURN(MATCH_NOMATCH); | |
3269 | } | |
3270 | ecode++; | ecode++; |
3271 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
3272 | if ((ims & PCRE_CASELESS) != 0) | if (op == OP_NOTI) /* The caseless case */ |
3273 | { | { |
3274 | #ifdef SUPPORT_UTF8 | #ifdef SUPPORT_UTF8 |
3275 | if (c < 256) | if (c < 256) |
3276 | #endif | #endif |
3277 | c = md->lcc[c]; | c = md->lcc[c]; |
3278 | if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH); | if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH); |
3279 | } | } |
3280 | else | else /* Caseful */ |
3281 | { | { |
3282 | if (*ecode++ == c) RRETURN(MATCH_NOMATCH); | if (*ecode++ == c) MRRETURN(MATCH_NOMATCH); |
3283 | } | } |
3284 | break; | break; |
3285 | ||
# | Line 2265 for (;;) | Line 3291 for (;;) |
3291 | about... */ | about... */ |
3292 | ||
3293 | case OP_NOTEXACT: | case OP_NOTEXACT: |
3294 | case OP_NOTEXACTI: | |
3295 | min = max = GET2(ecode, 1); | min = max = GET2(ecode, 1); |
3296 | ecode += 3; | ecode += 3; |
3297 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
3298 | ||
3299 | case OP_NOTUPTO: | case OP_NOTUPTO: |
3300 | case OP_NOTUPTOI: | |
3301 | case OP_NOTMINUPTO: | case OP_NOTMINUPTO: |
3302 | case OP_NOTMINUPTOI: | |
3303 | min = 0; | min = 0; |
3304 | max = GET2(ecode, 1); | max = GET2(ecode, 1); |
3305 | minimize = *ecode == OP_NOTMINUPTO; | minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI; |
3306 | ecode += 3; | ecode += 3; |
3307 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
3308 | ||
3309 | case OP_NOTPOSSTAR: | case OP_NOTPOSSTAR: |
3310 | case OP_NOTPOSSTARI: | |
3311 | possessive = TRUE; | possessive = TRUE; |
3312 | min = 0; | min = 0; |
3313 | max = INT_MAX; | max = INT_MAX; |
# | Line 2285 for (;;) | Line 3315 for (;;) |
3315 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
3316 | ||
3317 | case OP_NOTPOSPLUS: | case OP_NOTPOSPLUS: |
3318 | case OP_NOTPOSPLUSI: | |
3319 | possessive = TRUE; | possessive = TRUE; |
3320 | min = 1; | min = 1; |
3321 | max = INT_MAX; | max = INT_MAX; |
# | Line 2292 for (;;) | Line 3323 for (;;) |
3323 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
3324 | ||
3325 | case OP_NOTPOSQUERY: | case OP_NOTPOSQUERY: |
3326 | case OP_NOTPOSQUERYI: | |
3327 | possessive = TRUE; | possessive = TRUE; |
3328 | min = 0; | min = 0; |
3329 | max = 1; | max = 1; |
# | Line 2299 for (;;) | Line 3331 for (;;) |
3331 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
3332 | ||
3333 | case OP_NOTPOSUPTO: | case OP_NOTPOSUPTO: |
3334 | case OP_NOTPOSUPTOI: | |
3335 | possessive = TRUE; | possessive = TRUE; |
3336 | min = 0; | min = 0; |
3337 | max = GET2(ecode, 1); | max = GET2(ecode, 1); |
# | Line 2306 for (;;) | Line 3339 for (;;) |
3339 | goto REPEATNOTCHAR; | goto REPEATNOTCHAR; |
3340 | ||
3341 | case OP_NOTSTAR: | case OP_NOTSTAR: |
3342 | case OP_NOTSTARI: | |
3343 | case OP_NOTMINSTAR: | case OP_NOTMINSTAR: |
3344 | case OP_NOTMINSTARI: | |
3345 | case OP_NOTPLUS: | case OP_NOTPLUS: |
3346 | case OP_NOTPLUSI: | |
3347 | case OP_NOTMINPLUS: | case OP_NOTMINPLUS: |
3348 | case OP_NOTMINPLUSI: | |
3349 | case OP_NOTQUERY: | case OP_NOTQUERY: |
3350 | case OP_NOTQUERYI: | |
3351 | case OP_NOTMINQUERY: | case OP_NOTMINQUERY: |
3352 | c = *ecode++ - OP_NOTSTAR; | case OP_NOTMINQUERYI: |
3353 | c = *ecode++ - ((op >= OP_NOTSTARI)? OP_NOTSTARI: OP_NOTSTAR); | |
3354 | minimize = (c & 1) != 0; | minimize = (c & 1) != 0; |
3355 | min = rep_min[c]; /* Pick up values from tables; */ | min = rep_min[c]; /* Pick up values from tables; */ |
3356 | max = rep_max[c]; /* zero for max => infinity */ | max = rep_max[c]; /* zero for max => infinity */ |
3357 | if (max == 0) max = INT_MAX; | if (max == 0) max = INT_MAX; |
3358 | ||
3359 | /* Common code for all repeated single-byte matches. We can give up quickly | /* Common code for all repeated single-byte matches. */ |
if there are fewer than the minimum number of bytes left in the | ||
subject. */ | ||
3360 | ||
3361 | REPEATNOTCHAR: | REPEATNOTCHAR: |
if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
3362 | fc = *ecode++; | fc = *ecode++; |
3363 | ||
3364 | /* The code is duplicated for the caseless and caseful cases, for speed, | /* The code is duplicated for the caseless and caseful cases, for speed, |
# | Line 2336 for (;;) | Line 3372 for (;;) |
3372 | DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max, | DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max, |
3373 | max, eptr)); | max, eptr)); |
3374 | ||
3375 | if ((ims & PCRE_CASELESS) != 0) | if (op >= OP_NOTSTARI) /* Caseless */ |
3376 | { | { |
3377 | fc = md->lcc[fc]; | fc = md->lcc[fc]; |
3378 | ||
# | Line 2347 for (;;) | Line 3383 for (;;) |
3383 | register unsigned int d; | register unsigned int d; |
3384 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3385 | { | { |
3386 | if (eptr >= md->end_subject) | |
3387 | { | |
3388 | SCHECK_PARTIAL(); | |
3389 | MRRETURN(MATCH_NOMATCH); | |
3390 | } | |
3391 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
3392 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
3393 | if (fc == d) RRETURN(MATCH_NOMATCH); | if (fc == d) MRRETURN(MATCH_NOMATCH); |
3394 | } | } |
3395 | } | } |
3396 | else | else |
# | Line 2358 for (;;) | Line 3399 for (;;) |
3399 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
3400 | { | { |
3401 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3402 | if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); | { |
3403 | if (eptr >= md->end_subject) | |
3404 | { | |
3405 | SCHECK_PARTIAL(); | |
3406 | MRRETURN(MATCH_NOMATCH); | |
3407 | } | |
3408 | if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); | |
3409 | } | |
3410 | } | } |
3411 | ||
3412 | if (min == max) continue; | if (min == max) continue; |
# | Line 2372 for (;;) | Line 3420 for (;;) |
3420 | register unsigned int d; | register unsigned int d; |
3421 | for (fi = min;; fi++) | for (fi = min;; fi++) |
3422 | { | { |
3423 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM28); |
3424 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3425 | if (fi >= max) MRRETURN(MATCH_NOMATCH); | |
3426 | if (eptr >= md->end_subject) | |
3427 | { | |
3428 | SCHECK_PARTIAL(); | |
3429 | MRRETURN(MATCH_NOMATCH); | |
3430 | } | |
3431 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
3432 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
3433 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (fc == d) MRRETURN(MATCH_NOMATCH); |
RRETURN(MATCH_NOMATCH); | ||
3434 | } | } |
3435 | } | } |
3436 | else | else |
# | Line 2386 for (;;) | Line 3439 for (;;) |
3439 | { | { |
3440 | for (fi = min;; fi++) | for (fi = min;; fi++) |
3441 | { | { |
3442 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM29); |
3443 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3444 | if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++]) | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
3445 | RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3446 | { | |
3447 | SCHECK_PARTIAL(); | |
3448 | MRRETURN(MATCH_NOMATCH); | |
3449 | } | |
3450 | if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH); | |
3451 | } | } |
3452 | } | } |
3453 | /* Control never gets here */ | /* Control never gets here */ |
# | Line 2409 for (;;) | Line 3467 for (;;) |
3467 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
3468 | { | { |
3469 | int len = 1; | int len = 1; |
3470 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
3471 | { | |
3472 | SCHECK_PARTIAL(); | |
3473 | break; | |
3474 | } | |
3475 | GETCHARLEN(d, eptr, len); | GETCHARLEN(d, eptr, len); |
3476 | if (d < 256) d = md->lcc[d]; | if (d < 256) d = md->lcc[d]; |
3477 | if (fc == d) break; | if (fc == d) break; |
# | Line 2418 for (;;) | Line 3480 for (;;) |
3480 | if (possessive) continue; | if (possessive) continue; |
3481 | for(;;) | for(;;) |
3482 | { | { |
3483 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM30); |
3484 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3485 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
3486 | BACKCHAR(eptr); | BACKCHAR(eptr); |
# | Line 2430 for (;;) | Line 3492 for (;;) |
3492 | { | { |
3493 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
3494 | { | { |
3495 | if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break; | if (eptr >= md->end_subject) |
3496 | { | |
3497 | SCHECK_PARTIAL(); | |
3498 | break; | |
3499 | } | |
3500 | if (fc == md->lcc[*eptr]) break; | |
3501 | eptr++; | eptr++; |
3502 | } | } |
3503 | if (possessive) continue; | if (possessive) continue; |
3504 | while (eptr >= pp) | while (eptr >= pp) |
3505 | { | { |
3506 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM31); |
3507 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3508 | eptr--; | eptr--; |
3509 | } | } |
3510 | } | } |
3511 | ||
3512 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
3513 | } | } |
3514 | /* Control never gets here */ | /* Control never gets here */ |
3515 | } | } |
# | Line 2458 for (;;) | Line 3525 for (;;) |
3525 | register unsigned int d; | register unsigned int d; |
3526 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3527 | { | { |
3528 | if (eptr >= md->end_subject) | |
3529 | { | |
3530 | SCHECK_PARTIAL(); | |
3531 | MRRETURN(MATCH_NOMATCH); | |
3532 | } | |
3533 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
3534 | if (fc == d) RRETURN(MATCH_NOMATCH); | if (fc == d) MRRETURN(MATCH_NOMATCH); |
3535 | } | } |
3536 | } | } |
3537 | else | else |
# | Line 2467 for (;;) | Line 3539 for (;;) |
3539 | /* Not UTF-8 mode */ | /* Not UTF-8 mode */ |
3540 | { | { |
3541 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3542 | if (fc == *eptr++) RRETURN(MATCH_NOMATCH); | { |
3543 | if (eptr >= md->end_subject) | |
3544 | { | |
3545 | SCHECK_PARTIAL(); | |
3546 | MRRETURN(MATCH_NOMATCH); | |
3547 | } | |
3548 | if (fc == *eptr++) MRRETURN(MATCH_NOMATCH); | |
3549 | } | |
3550 | } | } |
3551 | ||
3552 | if (min == max) continue; | if (min == max) continue; |
# | Line 2481 for (;;) | Line 3560 for (;;) |
3560 | register unsigned int d; | register unsigned int d; |
3561 | for (fi = min;; fi++) | for (fi = min;; fi++) |
3562 | { | { |
3563 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM32); |
3564 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3565 | if (fi >= max) MRRETURN(MATCH_NOMATCH); | |
3566 | if (eptr >= md->end_subject) | |
3567 | { | |
3568 | SCHECK_PARTIAL(); | |
3569 | MRRETURN(MATCH_NOMATCH); | |
3570 | } | |
3571 | GETCHARINC(d, eptr); | GETCHARINC(d, eptr); |
3572 | if (fi >= max || eptr >= md->end_subject || fc == d) | if (fc == d) MRRETURN(MATCH_NOMATCH); |
RRETURN(MATCH_NOMATCH); | ||
3573 | } | } |
3574 | } | } |
3575 | else | else |
# | Line 2494 for (;;) | Line 3578 for (;;) |
3578 | { | { |
3579 | for (fi = min;; fi++) | for (fi = min;; fi++) |
3580 | { | { |
3581 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM33); |
3582 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3583 | if (fi >= max || eptr >= md->end_subject || fc == *eptr++) | if (fi >= max) MRRETURN(MATCH_NOMATCH); |
3584 | RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3585 | { | |
3586 | SCHECK_PARTIAL(); | |
3587 | MRRETURN(MATCH_NOMATCH); | |
3588 | } | |
3589 | if (fc == *eptr++) MRRETURN(MATCH_NOMATCH); | |
3590 | } | } |
3591 | } | } |
3592 | /* Control never gets here */ | /* Control never gets here */ |
# | Line 2517 for (;;) | Line 3606 for (;;) |
3606 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
3607 | { | { |
3608 | int len = 1; | int len = 1; |
3609 | if (eptr >= md->end_subject) break; | if (eptr >= md->end_subject) |
3610 | { | |
3611 | SCHECK_PARTIAL(); | |
3612 | break; | |
3613 | } | |
3614 | GETCHARLEN(d, eptr, len); | GETCHARLEN(d, eptr, len); |
3615 | if (fc == d) break; | if (fc == d) break; |
3616 | eptr += len; | eptr += len; |
# | Line 2525 for (;;) | Line 3618 for (;;) |
3618 | if (possessive) continue; | if (possessive) continue; |
3619 | for(;;) | for(;;) |
3620 | { | { |
3621 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM34); |
3622 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3623 | if (eptr-- == pp) break; /* Stop if tried at original pos */ | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
3624 | BACKCHAR(eptr); | BACKCHAR(eptr); |
# | Line 2537 for (;;) | Line 3630 for (;;) |
3630 | { | { |
3631 | for (i = min; i < max; i++) | for (i = min; i < max; i++) |
3632 | { | { |
3633 | if (eptr >= md->end_subject || fc == *eptr) break; | if (eptr >= md->end_subject) |
3634 | { | |
3635 | SCHECK_PARTIAL(); | |
3636 | break; | |
3637 | } | |
3638 | if (fc == *eptr) break; | |
3639 | eptr++; | eptr++; |
3640 | } | } |
3641 | if (possessive) continue; | if (possessive) continue; |
3642 | while (eptr >= pp) | while (eptr >= pp) |
3643 | { | { |
3644 | RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); | RMATCH(eptr, ecode, offset_top, md, eptrb, RM35); |
3645 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
3646 | eptr--; | eptr--; |
3647 | } | } |
3648 | } | } |
3649 | ||
3650 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
3651 | } | } |
3652 | } | } |
3653 | /* Control never gets here */ | /* Control never gets here */ |
# | Line 2631 for (;;) | Line 3729 for (;;) |
3729 | ||
3730 | /* First, ensure the minimum number of matches are present. Use inline | /* First, ensure the minimum number of matches are present. Use inline |
3731 | code for maximizing the speed, and do the type test once at the start | code for maximizing the speed, and do the type test once at the start |
3732 | (i.e. keep it out of the loop). Also we can test that there are at least | (i.e. keep it out of the loop). Separate the UTF-8 code completely as that |
the minimum number of bytes before we start. This isn't as effective in | ||
UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that | ||
3733 | is tidier. Also separate the UCP code, which can be the same for both UTF-8 | is tidier. Also separate the UCP code, which can be the same for both UTF-8 |
3734 | and single-bytes. */ | and single-bytes. */ |
3735 | ||
if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH); | ||
3736 | if (min > 0) | if (min > 0) |
3737 | { | { |
3738 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
# | Line 2646 for (;;) | Line 3741 for (;;) |
3741 | switch(prop_type) | switch(prop_type) |
3742 | { | { |
3743 | case PT_ANY: | case PT_ANY: |
3744 | if (prop_fail_result) RRETURN(MATCH_NOMATCH); | if (prop_fail_result) MRRETURN(MATCH_NOMATCH); |
3745 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3746 | { | { |
3747 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3748 | GETCHARINC(c, eptr); | { |
3749 | SCHECK_PARTIAL(); | |
3750 | MRRETURN(MATCH_NOMATCH); | |
3751 | } | |
3752 | GETCHARINCTEST(c, eptr); | |
3753 | } | } |
3754 | break; | break; |
3755 | ||
3756 | case PT_LAMP: | case PT_LAMP: |
3757 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3758 | { | { |
3759 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3760 | GETCHARINC(c, eptr); | { |
3761 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
3762 | MRRETURN(MATCH_NOMATCH); | |
3763 | } | |
3764 | GETCHARINCTEST(c, eptr); | |
3765 | prop_chartype = UCD_CHARTYPE(c); | |
3766 | if ((prop_chartype == ucp_Lu || | if ((prop_chartype == ucp_Lu || |
3767 | prop_chartype == ucp_Ll || | prop_chartype == ucp_Ll || |
3768 | prop_chartype == ucp_Lt) == prop_fail_result) | prop_chartype == ucp_Lt) == prop_fail_result) |
3769 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
3770 | } | } |
3771 | break; | break; |
3772 | ||
3773 | case PT_GC: | case PT_GC: |
3774 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3775 | { | { |
3776 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3777 | GETCHARINC(c, eptr); | { |
3778 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
3779 | MRRETURN(MATCH_NOMATCH); | |
3780 | } | |
3781 | GETCHARINCTEST(c, eptr); | |
3782 | prop_category = UCD_CATEGORY(c); | |
3783 | if ((prop_category == prop_value) == prop_fail_result) | if ((prop_category == prop_value) == prop_fail_result) |
3784 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
3785 | } | } |
3786 | break; | break; |
3787 | ||
3788 | case PT_PC: | case PT_PC: |
3789 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3790 | { | { |
3791 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3792 | GETCHARINC(c, eptr); | { |
3793 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
3794 | MRRETURN(MATCH_NOMATCH); | |
3795 | } | |
3796 | GETCHARINCTEST(c, eptr); | |
3797 | prop_chartype = UCD_CHARTYPE(c); | |
3798 | if ((prop_chartype == prop_value) == prop_fail_result) | if ((prop_chartype == prop_value) == prop_fail_result) |
3799 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
3800 | } | } |
3801 | break; | break; |
3802 | ||
3803 | case PT_SC: | case PT_SC: |
3804 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3805 | { | { |
3806 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3807 | GETCHARINC(c, eptr); | { |
3808 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | SCHECK_PARTIAL(); |
3809 | MRRETURN(MATCH_NOMATCH); | |
3810 | } | |
3811 | GETCHARINCTEST(c, eptr); | |
3812 | prop_script = UCD_SCRIPT(c); | |
3813 | if ((prop_script == prop_value) == prop_fail_result) | if ((prop_script == prop_value) == prop_fail_result) |
3814 | RRETURN(MATCH_NOMATCH); | MRRETURN(MATCH_NOMATCH); |
3815 | } | |
3816 | break; | |
3817 | ||
3818 | case PT_ALNUM: | |
3819 | for (i = 1; i <= min; i++) | |
3820 | { | |
3821 | if (eptr >= md->end_subject) | |
3822 | { | |
3823 | SCHECK_PARTIAL(); | |
3824 | MRRETURN(MATCH_NOMATCH); | |
3825 | } | |
3826 | GETCHARINCTEST(c, eptr); | |
3827 | prop_category = UCD_CATEGORY(c); | |
3828 | if ((prop_category == ucp_L || prop_category == ucp_N) | |
3829 | == prop_fail_result) | |
3830 | MRRETURN(MATCH_NOMATCH); | |
3831 | } | |
3832 | break; | |
3833 | ||
3834 | case PT_SPACE: /* Perl space */ | |
3835 | for (i = 1; i <= min; i++) | |
3836 | { | |
3837 | if (eptr >= md->end_subject) | |
3838 | { | |
3839 | SCHECK_PARTIAL(); | |
3840 | MRRETURN(MATCH_NOMATCH); | |
3841 | } | |
3842 | GETCHARINCTEST(c, eptr); | |
3843 | prop_category = UCD_CATEGORY(c); | |
3844 | if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL || | |
3845 | c == CHAR_FF || c == CHAR_CR) | |
3846 | == prop_fail_result) | |
3847 | MRRETURN(MATCH_NOMATCH); | |
3848 | } | |
3849 | break; | |
3850 | ||
3851 | case PT_PXSPACE: /* POSIX space */ | |
3852 | for (i = 1; i <= min; i++) | |
3853 | { | |
3854 | if (eptr >= md->end_subject) | |
3855 | { | |
3856 | SCHECK_PARTIAL(); | |
3857 | MRRETURN(MATCH_NOMATCH); | |
3858 | } | |
3859 | GETCHARINCTEST(c, eptr); | |
3860 | prop_category = UCD_CATEGORY(c); | |
3861 | if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL || | |
3862 | c == CHAR_VT || c == CHAR_FF || c == CHAR_CR) | |
3863 | == prop_fail_result) | |
3864 | MRRETURN(MATCH_NOMATCH); | |
3865 | } | |
3866 | break; | |
3867 | ||
3868 | case PT_WORD: | |
3869 | for (i = 1; i <= min; i++) | |
3870 | { | |
3871 | if (eptr >= md->end_subject) | |
3872 | { | |
3873 | SCHECK_PARTIAL(); | |
3874 | MRRETURN(MATCH_NOMATCH); | |
3875 | } | |
3876 | GETCHARINCTEST(c, eptr); | |
3877 | prop_category = UCD_CATEGORY(c); | |
3878 | if ((prop_category == ucp_L || prop_category == ucp_N || | |
3879 | c == CHAR_UNDERSCORE) | |
3880 | == prop_fail_result) | |
3881 | MRRETURN(MATCH_NOMATCH); | |
3882 | } | } |
3883 | break; | break; |
3884 | ||
3885 | /* This should not occur */ | |
3886 | ||
3887 | default: | default: |
3888 | RRETURN(PCRE_ERROR_INTERNAL); | RRETURN(PCRE_ERROR_INTERNAL); |
3889 | } | } |
# | Line 2712 for (;;) | Line 3896 for (;;) |
3896 | { | { |
3897 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3898 | { | { |
3899 | if (eptr >= md->end_subject) | |
3900 | { | |
3901 | SCHECK_PARTIAL(); | |
3902 | MRRETURN(MATCH_NOMATCH); | |
3903 | } | |
3904 | GETCHARINCTEST(c, eptr); | GETCHARINCTEST(c, eptr); |
3905 | prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | prop_category = UCD_CATEGORY(c); |
3906 | if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH); | if (prop_category == ucp_M) MRRETURN(MATCH_NOMATCH); |
3907 | while (eptr < md->end_subject) | while (eptr < md->end_subject) |
3908 | { | { |
3909 | int len = 1; | int len = 1; |
3910 | if (!utf8) c = *eptr; else | if (!utf8) c = *eptr; |
3911 | { | else { GETCHARLEN(c, eptr, len); } |
3912 | GETCHARLEN(c, eptr, len); | prop_category = UCD_CATEGORY(c); |
} | ||
prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); | ||
3913 | if (prop_category != ucp_M) break; | if (prop_category != ucp_M) break; |
3914 | eptr += len; | eptr += len; |
3915 | } | } |
# | Line 2740 for (;;) | Line 3927 for (;;) |
3927 | case OP_ANY: | case OP_ANY: |
3928 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3929 | { | { |
3930 | if (eptr >= md->end_subject || | if (eptr >= md->end_subject) |
3931 | ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr))) | { |
3932 | RRETURN(MATCH_NOMATCH); | SCHECK_PARTIAL(); |
3933 | MRRETURN(MATCH_NOMATCH); | |
3934 | } | |
3935 | if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); | |
3936 | eptr++; | |
3937 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | |
3938 | } | |
3939 | break; | |
3940 | ||
3941 | case OP_ALLANY: | |
3942 | for (i = 1; i <= min; i++) | |
3943 | { | |
3944 | if (eptr >= md->end_subject) | |
3945 | { | |
3946 | SCHECK_PARTIAL(); | |
3947 | MRRETURN(MATCH_NOMATCH); | |
3948 | } | |
3949 | eptr++; | eptr++; |
3950 | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; | while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; |
3951 | } | } |
3952 | break; | break; |
3953 | ||
3954 | case OP_ANYBYTE: | case OP_ANYBYTE: |
3955 | if (eptr > md->end_subject - min) MRRETURN(MATCH_NOMATCH); | |
3956 | eptr += min; | eptr += min; |
3957 | break; | break; |
3958 | ||
3959 | case OP_ANYNL: | case OP_ANYNL: |
3960 | for (i = 1; i <= min; i++) | for (i = 1; i <= min; i++) |
3961 | { | { |
3962 | if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); | if (eptr >= md->end_subject) |
3963 | { | |
3964 | SCHECK_PARTIAL(); | |
3965 | MRRETURN(MATCH_NOMATCH); | |
3966 | } | |
3967 | GETCHARINC(c, eptr); | GETCHARINC(c, eptr); |
3968 | switch(c) | switch(c) |
3969 | { |