Parent Directory
|
Revision Log
(*MARK) support, set_SOM optimization and other fixes in JIT
| 1 | /************************************************* |
| 2 | * Perl-Compatible Regular Expressions * |
| 3 | *************************************************/ |
| 4 | |
| 5 | /* PCRE is a library of functions to support regular expressions whose syntax |
| 6 | and semantics are as close as possible to those of the Perl 5 language. |
| 7 | |
| 8 | Written by Philip Hazel |
| 9 | Copyright (c) 1997-2012 University of Cambridge |
| 10 | |
| 11 | ----------------------------------------------------------------------------- |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions are met: |
| 14 | |
| 15 | * Redistributions of source code must retain the above copyright notice, |
| 16 | this list of conditions and the following disclaimer. |
| 17 | |
| 18 | * Redistributions in binary form must reproduce the above copyright |
| 19 | notice, this list of conditions and the following disclaimer in the |
| 20 | documentation and/or other materials provided with the distribution. |
| 21 | |
| 22 | * Neither the name of the University of Cambridge nor the names of its |
| 23 | contributors may be used to endorse or promote products derived from |
| 24 | this software without specific prior written permission. |
| 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 27 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 28 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 29 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 30 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 31 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 32 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 33 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 34 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 35 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | POSSIBILITY OF SUCH DAMAGE. |
| 37 | ----------------------------------------------------------------------------- |
| 38 | */ |
| 39 | |
| 40 | |
| 41 | /* This module contains pcre_exec(), the externally visible function that does |
| 42 | pattern matching using an NFA algorithm, trying to mimic Perl as closely as |
| 43 | possible. There are also some static supporting functions. */ |
| 44 | |
| 45 | #ifdef HAVE_CONFIG_H |
| 46 | #include "config.h" |
| 47 | #endif |
| 48 | |
| 49 | #define NLBLOCK md /* Block containing newline information */ |
| 50 | #define PSSTART start_subject /* Field containing processed string start */ |
| 51 | #define PSEND end_subject /* Field containing processed string end */ |
| 52 | |
| 53 | #include "pcre_internal.h" |
| 54 | |
| 55 | /* Undefine some potentially clashing cpp symbols */ |
| 56 | |
| 57 | #undef min |
| 58 | #undef max |
| 59 | |
| 60 | /* 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 1 /* Called to check a condition assertion */ |
| 65 | #define MATCH_CBEGROUP 2 /* Could-be-empty unlimited repeat group */ |
| 66 | |
| 67 | /* Non-error returns from the match() function. Error returns are externally |
| 68 | defined PCRE_ERROR_xxx codes, which are all negative. */ |
| 69 | |
| 70 | #define MATCH_MATCH 1 |
| 71 | #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_ONCE (-996) |
| 80 | #define MATCH_PRUNE (-995) |
| 81 | #define MATCH_SKIP (-994) |
| 82 | #define MATCH_SKIP_ARG (-993) |
| 83 | #define MATCH_THEN (-992) |
| 84 | |
| 85 | /* Maximum number of ints of offset to save on the stack for recursive calls. |
| 86 | If the offset vector is bigger, malloc is used. This should be a multiple of 3, |
| 87 | because the offset vector is always a multiple of 3 long. */ |
| 88 | |
| 89 | #define REC_STACK_SAVE_MAX 30 |
| 90 | |
| 91 | /* Min and max values for the common repeats; for the maxima, 0 => infinity */ |
| 92 | |
| 93 | static const char rep_min[] = { 0, 0, 1, 1, 0, 0 }; |
| 94 | static const char rep_max[] = { 0, 0, 0, 0, 1, 1 }; |
| 95 | |
| 96 | |
| 97 | |
| 98 | #ifdef PCRE_DEBUG |
| 99 | /************************************************* |
| 100 | * Debugging function to print chars * |
| 101 | *************************************************/ |
| 102 | |
| 103 | /* Print a sequence of chars in printable format, stopping at the end of the |
| 104 | subject if the requested. |
| 105 | |
| 106 | Arguments: |
| 107 | p points to characters |
| 108 | length number to print |
| 109 | is_subject TRUE if printing from within md->start_subject |
| 110 | md pointer to matching data block, if is_subject is TRUE |
| 111 | |
| 112 | Returns: nothing |
| 113 | */ |
| 114 | |
| 115 | static void |
| 116 | pchars(const pcre_uchar *p, int length, BOOL is_subject, match_data *md) |
| 117 | { |
| 118 | unsigned int c; |
| 119 | if (is_subject && length > md->end_subject - p) length = md->end_subject - p; |
| 120 | while (length-- > 0) |
| 121 | if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c); |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | |
| 126 | |
| 127 | /************************************************* |
| 128 | * Match a back-reference * |
| 129 | *************************************************/ |
| 130 | |
| 131 | /* Normally, if a back reference hasn't been set, the length that is passed is |
| 132 | negative, so the match always fails. However, in JavaScript compatibility mode, |
| 133 | the length passed is zero. Note that in caseless UTF-8 mode, the number of |
| 134 | subject bytes matched may be different to the number of reference bytes. |
| 135 | |
| 136 | Arguments: |
| 137 | offset index into the offset vector |
| 138 | eptr pointer into the subject |
| 139 | length length of reference to be matched (number of bytes) |
| 140 | md points to match data block |
| 141 | caseless TRUE if caseless |
| 142 | |
| 143 | Returns: >= 0 the number of subject bytes matched |
| 144 | -1 no match |
| 145 | -2 partial match; always given if at end subject |
| 146 | */ |
| 147 | |
| 148 | static int |
| 149 | match_ref(int offset, register PCRE_PUCHAR eptr, int length, match_data *md, |
| 150 | BOOL caseless) |
| 151 | { |
| 152 | PCRE_PUCHAR eptr_start = eptr; |
| 153 | register PCRE_PUCHAR p = md->start_subject + md->offset_vector[offset]; |
| 154 | |
| 155 | #ifdef PCRE_DEBUG |
| 156 | if (eptr >= md->end_subject) |
| 157 | printf("matching subject <null>"); |
| 158 | else |
| 159 | { |
| 160 | printf("matching subject "); |
| 161 | pchars(eptr, length, TRUE, md); |
| 162 | } |
| 163 | printf(" against backref "); |
| 164 | pchars(p, length, FALSE, md); |
| 165 | printf("\n"); |
| 166 | #endif |
| 167 | |
| 168 | /* Always fail if reference not set (and not JavaScript compatible - in that |
| 169 | case the length is passed as zero). */ |
| 170 | |
| 171 | if (length < 0) return -1; |
| 172 | |
| 173 | /* Separate the caseless case for speed. In UTF-8 mode we can only do this |
| 174 | properly if Unicode properties are supported. Otherwise, we can check only |
| 175 | ASCII characters. */ |
| 176 | |
| 177 | if (caseless) |
| 178 | { |
| 179 | #ifdef SUPPORT_UTF |
| 180 | #ifdef SUPPORT_UCP |
| 181 | if (md->utf) |
| 182 | { |
| 183 | /* Match characters up to the end of the reference. NOTE: the number of |
| 184 | bytes matched may differ, because there are some characters whose upper and |
| 185 | lower case versions code as different numbers of bytes. For example, U+023A |
| 186 | (2 bytes in UTF-8) is the upper case version of U+2C65 (3 bytes in UTF-8); |
| 187 | a sequence of 3 of the former uses 6 bytes, as does a sequence of two of |
| 188 | the latter. It is important, therefore, to check the length along the |
| 189 | reference, not along the subject (earlier code did this wrong). */ |
| 190 | |
| 191 | PCRE_PUCHAR endptr = p + length; |
| 192 | while (p < endptr) |
| 193 | { |
| 194 | int c, d; |
| 195 | if (eptr >= md->end_subject) return -2; /* Partial match */ |
| 196 | GETCHARINC(c, eptr); |
| 197 | GETCHARINC(d, p); |
| 198 | if (c != d && c != UCD_OTHERCASE(d)) return -1; |
| 199 | } |
| 200 | } |
| 201 | else |
| 202 | #endif |
| 203 | #endif |
| 204 | |
| 205 | /* The same code works when not in UTF-8 mode and in UTF-8 mode when there |
| 206 | is no UCP support. */ |
| 207 | { |
| 208 | while (length-- > 0) |
| 209 | { |
| 210 | if (eptr >= md->end_subject) return -2; /* Partial match */ |
| 211 | if (TABLE_GET(*p, md->lcc, *p) != TABLE_GET(*eptr, md->lcc, *eptr)) return -1; |
| 212 | p++; |
| 213 | eptr++; |
| 214 | } |
| 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 |
| 222 | { |
| 223 | while (length-- > 0) |
| 224 | { |
| 225 | if (eptr >= md->end_subject) return -2; /* Partial match */ |
| 226 | if (*p++ != *eptr++) return -1; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return (int)(eptr - eptr_start); |
| 231 | } |
| 232 | |
| 233 | |
| 234 | |
| 235 | /*************************************************************************** |
| 236 | **************************************************************************** |
| 237 | RECURSION IN THE match() FUNCTION |
| 238 | |
| 239 | The match() function is highly recursive, though not every recursive call |
| 240 | increases the recursive depth. Nevertheless, some regular expressions can cause |
| 241 | it to recurse to a great depth. I was writing for Unix, so I just let it call |
| 242 | itself recursively. This uses the stack for saving everything that has to be |
| 243 | saved for a recursive call. On Unix, the stack can be large, and this works |
| 244 | fine. |
| 245 | |
| 246 | It turns out that on some non-Unix-like systems there are problems with |
| 247 | programs that use a lot of stack. (This despite the fact that every last chip |
| 248 | has oodles of memory these days, and techniques for extending the stack have |
| 249 | been known for decades.) So.... |
| 250 | |
| 251 | There is a fudge, triggered by defining NO_RECURSE, which avoids recursive |
| 252 | calls by keeping local variables that need to be preserved in blocks of memory |
| 253 | obtained from malloc() instead instead of on the stack. Macros are used to |
| 254 | achieve this so that the actual code doesn't look very different to what it |
| 255 | always used to. |
| 256 | |
| 257 | The original heap-recursive code used longjmp(). However, it seems that this |
| 258 | can be very slow on some operating systems. Following a suggestion from Stan |
| 259 | Switzer, the use of longjmp() has been abolished, at the cost of having to |
| 260 | provide a unique number for each call to RMATCH. There is no way of generating |
| 261 | a sequence of numbers at compile time in C. I have given them names, to make |
| 262 | them stand out more clearly. |
| 263 | |
| 264 | Crude tests on x86 Linux show a small speedup of around 5-8%. However, on |
| 265 | FreeBSD, avoiding longjmp() more than halves the time taken to run the standard |
| 266 | tests. Furthermore, not using longjmp() means that local dynamic variables |
| 267 | don't have indeterminate values; this has meant that the frame size can be |
| 268 | reduced because the result can be "passed back" by straight setting of the |
| 269 | variable instead of being passed in the frame. |
| 270 | **************************************************************************** |
| 271 | ***************************************************************************/ |
| 272 | |
| 273 | /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN |
| 274 | below must be updated in sync. */ |
| 275 | |
| 276 | enum { RM1=1, RM2, RM3, RM4, RM5, RM6, RM7, RM8, RM9, RM10, |
| 277 | RM11, RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20, |
| 278 | RM21, RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30, |
| 279 | RM31, RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40, |
| 280 | RM41, RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50, |
| 281 | RM51, RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60, |
| 282 | RM61, RM62, RM63, RM64, RM65, RM66 }; |
| 283 | |
| 284 | /* These versions of the macros use the stack, as normal. There are debugging |
| 285 | versions and production versions. Note that the "rw" argument of RMATCH isn't |
| 286 | actually used in this definition. */ |
| 287 | |
| 288 | #ifndef NO_RECURSE |
| 289 | #define REGISTER register |
| 290 | |
| 291 | #ifdef PCRE_DEBUG |
| 292 | #define RMATCH(ra,rb,rc,rd,re,rw) \ |
| 293 | { \ |
| 294 | printf("match() called in line %d\n", __LINE__); \ |
| 295 | rrc = match(ra,rb,mstart,rc,rd,re,rdepth+1); \ |
| 296 | printf("to line %d\n", __LINE__); \ |
| 297 | } |
| 298 | #define RRETURN(ra) \ |
| 299 | { \ |
| 300 | printf("match() returned %d from line %d ", ra, __LINE__); \ |
| 301 | return ra; \ |
| 302 | } |
| 303 | #else |
| 304 | #define RMATCH(ra,rb,rc,rd,re,rw) \ |
| 305 | rrc = match(ra,rb,mstart,rc,rd,re,rdepth+1) |
| 306 | #define RRETURN(ra) return ra |
| 307 | #endif |
| 308 | |
| 309 | #else |
| 310 | |
| 311 | |
| 312 | /* These versions of the macros manage a private stack on the heap. Note that |
| 313 | the "rd" argument of RMATCH isn't actually used in this definition. It's the md |
| 314 | argument of match(), which never changes. */ |
| 315 | |
| 316 | #define REGISTER |
| 317 | |
| 318 | #define RMATCH(ra,rb,rc,rd,re,rw)\ |
| 319 | {\ |
| 320 | heapframe *newframe = (heapframe *)(PUBL(stack_malloc))(sizeof(heapframe));\ |
| 321 | if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\ |
| 322 | frame->Xwhere = rw; \ |
| 323 | newframe->Xeptr = ra;\ |
| 324 | newframe->Xecode = rb;\ |
| 325 | newframe->Xmstart = mstart;\ |
| 326 | newframe->Xoffset_top = rc;\ |
| 327 | newframe->Xeptrb = re;\ |
| 328 | newframe->Xrdepth = frame->Xrdepth + 1;\ |
| 329 | newframe->Xprevframe = frame;\ |
| 330 | frame = newframe;\ |
| 331 | DPRINTF(("restarting from line %d\n", __LINE__));\ |
| 332 | goto HEAP_RECURSE;\ |
| 333 | L_##rw:\ |
| 334 | DPRINTF(("jumped back to line %d\n", __LINE__));\ |
| 335 | } |
| 336 | |
| 337 | #define RRETURN(ra)\ |
| 338 | {\ |
| 339 | heapframe *oldframe = frame;\ |
| 340 | frame = oldframe->Xprevframe;\ |
| 341 | if (oldframe != &frame_zero) (PUBL(stack_free))(oldframe);\ |
| 342 | if (frame != NULL)\ |
| 343 | {\ |
| 344 | rrc = ra;\ |
| 345 | goto HEAP_RETURN;\ |
| 346 | }\ |
| 347 | return ra;\ |
| 348 | } |
| 349 | |
| 350 | |
| 351 | /* Structure for remembering the local variables in a private frame */ |
| 352 | |
| 353 | typedef struct heapframe { |
| 354 | struct heapframe *Xprevframe; |
| 355 | |
| 356 | /* Function arguments that may change */ |
| 357 | |
| 358 | PCRE_PUCHAR Xeptr; |
| 359 | const pcre_uchar *Xecode; |
| 360 | PCRE_PUCHAR Xmstart; |
| 361 | int Xoffset_top; |
| 362 | eptrblock *Xeptrb; |
| 363 | unsigned int Xrdepth; |
| 364 | |
| 365 | /* Function local variables */ |
| 366 | |
| 367 | PCRE_PUCHAR Xcallpat; |
| 368 | #ifdef SUPPORT_UTF |
| 369 | PCRE_PUCHAR Xcharptr; |
| 370 | #endif |
| 371 | PCRE_PUCHAR Xdata; |
| 372 | PCRE_PUCHAR Xnext; |
| 373 | PCRE_PUCHAR Xpp; |
| 374 | PCRE_PUCHAR Xprev; |
| 375 | PCRE_PUCHAR Xsaved_eptr; |
| 376 | |
| 377 | recursion_info Xnew_recursive; |
| 378 | |
| 379 | BOOL Xcur_is_word; |
| 380 | BOOL Xcondition; |
| 381 | BOOL Xprev_is_word; |
| 382 | |
| 383 | #ifdef SUPPORT_UCP |
| 384 | int Xprop_type; |
| 385 | int Xprop_value; |
| 386 | int Xprop_fail_result; |
| 387 | int Xoclength; |
| 388 | pcre_uchar Xocchars[6]; |
| 389 | #endif |
| 390 | |
| 391 | int Xcodelink; |
| 392 | int Xctype; |
| 393 | unsigned int Xfc; |
| 394 | int Xfi; |
| 395 | int Xlength; |
| 396 | int Xmax; |
| 397 | int Xmin; |
| 398 | int Xnumber; |
| 399 | int Xoffset; |
| 400 | int Xop; |
| 401 | int Xsave_capture_last; |
| 402 | int Xsave_offset1, Xsave_offset2, Xsave_offset3; |
| 403 | int Xstacksave[REC_STACK_SAVE_MAX]; |
| 404 | |
| 405 | eptrblock Xnewptrb; |
| 406 | |
| 407 | /* Where to jump back to */ |
| 408 | |
| 409 | int Xwhere; |
| 410 | |
| 411 | } heapframe; |
| 412 | |
| 413 | #endif |
| 414 | |
| 415 | |
| 416 | /*************************************************************************** |
| 417 | ***************************************************************************/ |
| 418 | |
| 419 | |
| 420 | |
| 421 | /************************************************* |
| 422 | * Match from current position * |
| 423 | *************************************************/ |
| 424 | |
| 425 | /* This function is called recursively in many circumstances. Whenever it |
| 426 | returns a negative (error) response, the outer incarnation must also return the |
| 427 | same response. */ |
| 428 | |
| 429 | /* These macros pack up tests that are used for partial matching, and which |
| 430 | appear several times in the code. We set the "hit end" flag if the pointer is |
| 431 | at the end of the subject and also past the start of the subject (i.e. |
| 432 | something has been matched). For hard partial matching, we then return |
| 433 | immediately. The second one is used when we already know we are past the end of |
| 434 | the subject. */ |
| 435 | |
| 436 | #define CHECK_PARTIAL()\ |
| 437 | if (md->partial != 0 && eptr >= md->end_subject && \ |
| 438 | eptr > md->start_used_ptr) \ |
| 439 | { \ |
| 440 | md->hitend = TRUE; \ |
| 441 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); \ |
| 442 | } |
| 443 | |
| 444 | #define SCHECK_PARTIAL()\ |
| 445 | if (md->partial != 0 && eptr > md->start_used_ptr) \ |
| 446 | { \ |
| 447 | md->hitend = TRUE; \ |
| 448 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); \ |
| 449 | } |
| 450 | |
| 451 | |
| 452 | /* Performance note: It might be tempting to extract commonly used fields from |
| 453 | the md structure (e.g. utf, end_subject) into individual variables to improve |
| 454 | performance. Tests using gcc on a SPARC disproved this; in the first case, it |
| 455 | made performance worse. |
| 456 | |
| 457 | Arguments: |
| 458 | eptr pointer to current character in subject |
| 459 | ecode pointer to current position in compiled code |
| 460 | mstart pointer to the current match start position (can be modified |
| 461 | by encountering \K) |
| 462 | offset_top current top pointer |
| 463 | md pointer to "static" info for the match |
| 464 | eptrb pointer to chain of blocks containing eptr at start of |
| 465 | brackets - for testing for empty matches |
| 466 | rdepth the recursion depth |
| 467 | |
| 468 | Returns: MATCH_MATCH if matched ) these values are >= 0 |
| 469 | MATCH_NOMATCH if failed to match ) |
| 470 | a negative MATCH_xxx value for PRUNE, SKIP, etc |
| 471 | a negative PCRE_ERROR_xxx value if aborted by an error condition |
| 472 | (e.g. stopped by repeated call or recursion limit) |
| 473 | */ |
| 474 | |
| 475 | static int |
| 476 | match(REGISTER PCRE_PUCHAR eptr, REGISTER const pcre_uchar *ecode, |
| 477 | PCRE_PUCHAR mstart, int offset_top, match_data *md, eptrblock *eptrb, |
| 478 | unsigned int rdepth) |
| 479 | { |
| 480 | /* These variables do not need to be preserved over recursion in this function, |
| 481 | so they can be ordinary variables in all cases. Mark some of them with |
| 482 | "register" because they are used a lot in loops. */ |
| 483 | |
| 484 | register int rrc; /* Returns from recursive calls */ |
| 485 | register int i; /* Used for loops not involving calls to RMATCH() */ |
| 486 | register unsigned int c; /* Character values not kept over RMATCH() calls */ |
| 487 | register BOOL utf; /* Local copy of UTF flag for speed */ |
| 488 | |
| 489 | BOOL minimize, possessive; /* Quantifier options */ |
| 490 | BOOL caseless; |
| 491 | int condcode; |
| 492 | |
| 493 | /* When recursion is not being used, all "local" variables that have to be |
| 494 | preserved over calls to RMATCH() are part of a "frame". We set up the top-level |
| 495 | frame on the stack here; subsequent instantiations are obtained from the heap |
| 496 | whenever RMATCH() does a "recursion". See the macro definitions above. Putting |
| 497 | the top-level on the stack rather than malloc-ing them all gives a performance |
| 498 | boost in many cases where there is not much "recursion". */ |
| 499 | |
| 500 | #ifdef NO_RECURSE |
| 501 | heapframe frame_zero; |
| 502 | heapframe *frame = &frame_zero; |
| 503 | frame->Xprevframe = NULL; /* Marks the top level */ |
| 504 | |
| 505 | /* Copy in the original argument variables */ |
| 506 | |
| 507 | frame->Xeptr = eptr; |
| 508 | frame->Xecode = ecode; |
| 509 | frame->Xmstart = mstart; |
| 510 | frame->Xoffset_top = offset_top; |
| 511 | frame->Xeptrb = eptrb; |
| 512 | frame->Xrdepth = rdepth; |
| 513 | |
| 514 | /* This is where control jumps back to to effect "recursion" */ |
| 515 | |
| 516 | HEAP_RECURSE: |
| 517 | |
| 518 | /* Macros make the argument variables come from the current frame */ |
| 519 | |
| 520 | #define eptr frame->Xeptr |
| 521 | #define ecode frame->Xecode |
| 522 | #define mstart frame->Xmstart |
| 523 | #define offset_top frame->Xoffset_top |
| 524 | #define eptrb frame->Xeptrb |
| 525 | #define rdepth frame->Xrdepth |
| 526 | |
| 527 | /* Ditto for the local variables */ |
| 528 | |
| 529 | #ifdef SUPPORT_UTF |
| 530 | #define charptr frame->Xcharptr |
| 531 | #endif |
| 532 | #define callpat frame->Xcallpat |
| 533 | #define codelink frame->Xcodelink |
| 534 | #define data frame->Xdata |
| 535 | #define next frame->Xnext |
| 536 | #define pp frame->Xpp |
| 537 | #define prev frame->Xprev |
| 538 | #define saved_eptr frame->Xsaved_eptr |
| 539 | |
| 540 | #define new_recursive frame->Xnew_recursive |
| 541 | |
| 542 | #define cur_is_word frame->Xcur_is_word |
| 543 | #define condition frame->Xcondition |
| 544 | #define prev_is_word frame->Xprev_is_word |
| 545 | |
| 546 | #ifdef SUPPORT_UCP |
| 547 | #define prop_type frame->Xprop_type |
| 548 | #define prop_value frame->Xprop_value |
| 549 | #define prop_fail_result frame->Xprop_fail_result |
| 550 | #define oclength frame->Xoclength |
| 551 | #define occhars frame->Xocchars |
| 552 | #endif |
| 553 | |
| 554 | #define ctype frame->Xctype |
| 555 | #define fc frame->Xfc |
| 556 | #define fi frame->Xfi |
| 557 | #define length frame->Xlength |
| 558 | #define max frame->Xmax |
| 559 | #define min frame->Xmin |
| 560 | #define number frame->Xnumber |
| 561 | #define offset frame->Xoffset |
| 562 | #define op frame->Xop |
| 563 | #define save_capture_last frame->Xsave_capture_last |
| 564 | #define save_offset1 frame->Xsave_offset1 |
| 565 | #define save_offset2 frame->Xsave_offset2 |
| 566 | #define save_offset3 frame->Xsave_offset3 |
| 567 | #define stacksave frame->Xstacksave |
| 568 | |
| 569 | #define newptrb frame->Xnewptrb |
| 570 | |
| 571 | /* When recursion is being used, local variables are allocated on the stack and |
| 572 | get preserved during recursion in the normal way. In this environment, fi and |
| 573 | i, and fc and c, can be the same variables. */ |
| 574 | |
| 575 | #else /* NO_RECURSE not defined */ |
| 576 | #define fi i |
| 577 | #define fc c |
| 578 | |
| 579 | /* Many of the following variables are used only in small blocks of the code. |
| 580 | My normal style of coding would have declared them within each of those blocks. |
| 581 | However, in order to accommodate the version of this code that uses an external |
| 582 | "stack" implemented on the heap, it is easier to declare them all here, so the |
| 583 | declarations can be cut out in a block. The only declarations within blocks |
| 584 | below are for variables that do not have to be preserved over a recursive call |
| 585 | to RMATCH(). */ |
| 586 | |
| 587 | #ifdef SUPPORT_UTF |
| 588 | const pcre_uchar *charptr; |
| 589 | #endif |
| 590 | const pcre_uchar *callpat; |
| 591 | const pcre_uchar *data; |
| 592 | const pcre_uchar *next; |
| 593 | PCRE_PUCHAR pp; |
| 594 | const pcre_uchar *prev; |
| 595 | PCRE_PUCHAR saved_eptr; |
| 596 | |
| 597 | recursion_info new_recursive; |
| 598 | |
| 599 | BOOL cur_is_word; |
| 600 | BOOL condition; |
| 601 | BOOL prev_is_word; |
| 602 | |
| 603 | #ifdef SUPPORT_UCP |
| 604 | int prop_type; |
| 605 | int prop_value; |
| 606 | int prop_fail_result; |
| 607 | int oclength; |
| 608 | pcre_uchar occhars[6]; |
| 609 | #endif |
| 610 | |
| 611 | int codelink; |
| 612 | int ctype; |
| 613 | int length; |
| 614 | int max; |
| 615 | int min; |
| 616 | int number; |
| 617 | int offset; |
| 618 | int op; |
| 619 | int save_capture_last; |
| 620 | int save_offset1, save_offset2, save_offset3; |
| 621 | int stacksave[REC_STACK_SAVE_MAX]; |
| 622 | |
| 623 | eptrblock newptrb; |
| 624 | |
| 625 | /* There is a special fudge for calling match() in a way that causes it to |
| 626 | measure the size of its basic stack frame when the stack is being used for |
| 627 | recursion. The second argument (ecode) being NULL triggers this behaviour. It |
| 628 | cannot normally ever be NULL. The return is the negated value of the frame |
| 629 | size. */ |
| 630 | |
| 631 | if (ecode == NULL) |
| 632 | { |
| 633 | if (rdepth == 0) |
| 634 | return match((PCRE_PUCHAR)&rdepth, NULL, NULL, 0, NULL, NULL, 1); |
| 635 | else |
| 636 | { |
| 637 | int len = (char *)&rdepth - (char *)eptr; |
| 638 | return (len > 0)? -len : len; |
| 639 | } |
| 640 | } |
| 641 | #endif /* NO_RECURSE */ |
| 642 | |
| 643 | /* To save space on the stack and in the heap frame, I have doubled up on some |
| 644 | of the local variables that are used only in localised parts of the code, but |
| 645 | still need to be preserved over recursive calls of match(). These macros define |
| 646 | the alternative names that are used. */ |
| 647 | |
| 648 | #define allow_zero cur_is_word |
| 649 | #define cbegroup condition |
| 650 | #define code_offset codelink |
| 651 | #define condassert condition |
| 652 | #define matched_once prev_is_word |
| 653 | #define foc number |
| 654 | #define save_mark data |
| 655 | |
| 656 | /* These statements are here to stop the compiler complaining about unitialized |
| 657 | variables. */ |
| 658 | |
| 659 | #ifdef SUPPORT_UCP |
| 660 | prop_value = 0; |
| 661 | prop_fail_result = 0; |
| 662 | #endif |
| 663 | |
| 664 | |
| 665 | /* This label is used for tail recursion, which is used in a few cases even |
| 666 | when NO_RECURSE is not defined, in order to reduce the amount of stack that is |
| 667 | used. Thanks to Ian Taylor for noticing this possibility and sending the |
| 668 | original patch. */ |
| 669 | |
| 670 | TAIL_RECURSE: |
| 671 | |
| 672 | /* OK, now we can get on with the real code of the function. Recursive calls |
| 673 | are specified by the macro RMATCH and RRETURN is used to return. When |
| 674 | NO_RECURSE is *not* defined, these just turn into a recursive call to match() |
| 675 | and a "return", respectively (possibly with some debugging if PCRE_DEBUG is |
| 676 | defined). However, RMATCH isn't like a function call because it's quite a |
| 677 | complicated macro. It has to be used in one particular way. This shouldn't, |
| 678 | however, impact performance when true recursion is being used. */ |
| 679 | |
| 680 | #ifdef SUPPORT_UTF |
| 681 | utf = md->utf; /* Local copy of the flag */ |
| 682 | #else |
| 683 | utf = FALSE; |
| 684 | #endif |
| 685 | |
| 686 | /* First check that we haven't called match() too many times, or that we |
| 687 | haven't exceeded the recursive call limit. */ |
| 688 | |
| 689 | if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT); |
| 690 | if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT); |
| 691 | |
| 692 | /* At the start of a group with an unlimited repeat that may match an empty |
| 693 | string, the variable md->match_function_type is set to MATCH_CBEGROUP. It is |
| 694 | done this way to save having to use another function argument, which would take |
| 695 | up space on the stack. See also MATCH_CONDASSERT below. |
| 696 | |
| 697 | When MATCH_CBEGROUP is set, add the current subject pointer to the chain of |
| 698 | such remembered pointers, to be checked when we hit the closing ket, in order |
| 699 | to break infinite loops that match no characters. When match() is called in |
| 700 | other circumstances, don't add to the chain. The MATCH_CBEGROUP feature must |
| 701 | NOT be used with tail recursion, because the memory block that is used is on |
| 702 | the stack, so a new one may be required for each match(). */ |
| 703 | |
| 704 | if (md->match_function_type == MATCH_CBEGROUP) |
| 705 | { |
| 706 | newptrb.epb_saved_eptr = eptr; |
| 707 | newptrb.epb_prev = eptrb; |
| 708 | eptrb = &newptrb; |
| 709 | md->match_function_type = 0; |
| 710 | } |
| 711 | |
| 712 | /* Now start processing the opcodes. */ |
| 713 | |
| 714 | for (;;) |
| 715 | { |
| 716 | minimize = possessive = FALSE; |
| 717 | op = *ecode; |
| 718 | |
| 719 | switch(op) |
| 720 | { |
| 721 | case OP_MARK: |
| 722 | md->nomatch_mark = ecode + 2; |
| 723 | md->mark = NULL; /* In case previously set by assertion */ |
| 724 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md, |
| 725 | eptrb, RM55); |
| 726 | if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) && |
| 727 | md->mark == NULL) md->mark = ecode + 2; |
| 728 | |
| 729 | /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an |
| 730 | argument, and we must check whether that argument matches this MARK's |
| 731 | argument. It is passed back in md->start_match_ptr (an overloading of that |
| 732 | variable). If it does match, we reset that variable to the current subject |
| 733 | position and return MATCH_SKIP. Otherwise, pass back the return code |
| 734 | unaltered. */ |
| 735 | |
| 736 | else if (rrc == MATCH_SKIP_ARG && |
| 737 | STRCMP_UC_UC(ecode + 2, md->start_match_ptr) == 0) |
| 738 | { |
| 739 | md->start_match_ptr = eptr; |
| 740 | RRETURN(MATCH_SKIP); |
| 741 | } |
| 742 | RRETURN(rrc); |
| 743 | |
| 744 | case OP_FAIL: |
| 745 | RRETURN(MATCH_NOMATCH); |
| 746 | |
| 747 | /* COMMIT overrides PRUNE, SKIP, and THEN */ |
| 748 | |
| 749 | case OP_COMMIT: |
| 750 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, |
| 751 | eptrb, RM52); |
| 752 | if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && |
| 753 | rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG && |
| 754 | rrc != MATCH_THEN) |
| 755 | RRETURN(rrc); |
| 756 | RRETURN(MATCH_COMMIT); |
| 757 | |
| 758 | /* PRUNE overrides THEN */ |
| 759 | |
| 760 | case OP_PRUNE: |
| 761 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, |
| 762 | eptrb, RM51); |
| 763 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 764 | RRETURN(MATCH_PRUNE); |
| 765 | |
| 766 | case OP_PRUNE_ARG: |
| 767 | md->nomatch_mark = ecode + 2; |
| 768 | md->mark = NULL; /* In case previously set by assertion */ |
| 769 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md, |
| 770 | eptrb, RM56); |
| 771 | if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) && |
| 772 | md->mark == NULL) md->mark = ecode + 2; |
| 773 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 774 | RRETURN(MATCH_PRUNE); |
| 775 | |
| 776 | /* SKIP overrides PRUNE and THEN */ |
| 777 | |
| 778 | case OP_SKIP: |
| 779 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, |
| 780 | eptrb, RM53); |
| 781 | if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN) |
| 782 | RRETURN(rrc); |
| 783 | md->start_match_ptr = eptr; /* Pass back current position */ |
| 784 | RRETURN(MATCH_SKIP); |
| 785 | |
| 786 | /* Note that, for Perl compatibility, SKIP with an argument does NOT set |
| 787 | nomatch_mark. There is a flag that disables this opcode when re-matching a |
| 788 | pattern that ended with a SKIP for which there was not a matching MARK. */ |
| 789 | |
| 790 | case OP_SKIP_ARG: |
| 791 | if (md->ignore_skip_arg) |
| 792 | { |
| 793 | ecode += PRIV(OP_lengths)[*ecode] + ecode[1]; |
| 794 | break; |
| 795 | } |
| 796 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md, |
| 797 | eptrb, RM57); |
| 798 | if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN) |
| 799 | RRETURN(rrc); |
| 800 | |
| 801 | /* Pass back the current skip name by overloading md->start_match_ptr and |
| 802 | returning the special MATCH_SKIP_ARG return code. This will either be |
| 803 | caught by a matching MARK, or get to the top, where it causes a rematch |
| 804 | with the md->ignore_skip_arg flag set. */ |
| 805 | |
| 806 | md->start_match_ptr = ecode + 2; |
| 807 | RRETURN(MATCH_SKIP_ARG); |
| 808 | |
| 809 | /* For THEN (and THEN_ARG) we pass back the address of the opcode, so that |
| 810 | the branch in which it occurs can be determined. Overload the start of |
| 811 | match pointer to do this. */ |
| 812 | |
| 813 | case OP_THEN: |
| 814 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, |
| 815 | eptrb, RM54); |
| 816 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 817 | md->start_match_ptr = ecode; |
| 818 | RRETURN(MATCH_THEN); |
| 819 | |
| 820 | case OP_THEN_ARG: |
| 821 | md->nomatch_mark = ecode + 2; |
| 822 | md->mark = NULL; /* In case previously set by assertion */ |
| 823 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, |
| 824 | md, eptrb, RM58); |
| 825 | if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) && |
| 826 | md->mark == NULL) md->mark = ecode + 2; |
| 827 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 828 | md->start_match_ptr = ecode; |
| 829 | RRETURN(MATCH_THEN); |
| 830 | |
| 831 | /* Handle an atomic group that does not contain any capturing parentheses. |
| 832 | This can be handled like an assertion. Prior to 8.13, all atomic groups |
| 833 | were handled this way. In 8.13, the code was changed as below for ONCE, so |
| 834 | that backups pass through the group and thereby reset captured values. |
| 835 | However, this uses a lot more stack, so in 8.20, atomic groups that do not |
| 836 | contain any captures generate OP_ONCE_NC, which can be handled in the old, |
| 837 | less stack intensive way. |
| 838 | |
| 839 | Check the alternative branches in turn - the matching won't pass the KET |
| 840 | for this kind of subpattern. If any one branch matches, we carry on as at |
| 841 | the end of a normal bracket, leaving the subject pointer, but resetting |
| 842 | the start-of-match value in case it was changed by \K. */ |
| 843 | |
| 844 | case OP_ONCE_NC: |
| 845 | prev = ecode; |
| 846 | saved_eptr = eptr; |
| 847 | save_mark = md->mark; |
| 848 | do |
| 849 | { |
| 850 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64); |
| 851 | if (rrc == MATCH_MATCH) /* Note: _not_ MATCH_ACCEPT */ |
| 852 | { |
| 853 | mstart = md->start_match_ptr; |
| 854 | break; |
| 855 | } |
| 856 | if (rrc == MATCH_THEN) |
| 857 | { |
| 858 | next = ecode + GET(ecode,1); |
| 859 | if (md->start_match_ptr < next && |
| 860 | (*ecode == OP_ALT || *next == OP_ALT)) |
| 861 | rrc = MATCH_NOMATCH; |
| 862 | } |
| 863 | |
| 864 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 865 | ecode += GET(ecode,1); |
| 866 | md->mark = save_mark; |
| 867 | } |
| 868 | while (*ecode == OP_ALT); |
| 869 | |
| 870 | /* If hit the end of the group (which could be repeated), fail */ |
| 871 | |
| 872 | if (*ecode != OP_ONCE_NC && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH); |
| 873 | |
| 874 | /* Continue as from after the group, updating the offsets high water |
| 875 | mark, since extracts may have been taken. */ |
| 876 | |
| 877 | do ecode += GET(ecode, 1); while (*ecode == OP_ALT); |
| 878 | |
| 879 | offset_top = md->end_offset_top; |
| 880 | eptr = md->end_match_ptr; |
| 881 | |
| 882 | /* For a non-repeating ket, just continue at this level. This also |
| 883 | happens for a repeating ket if no characters were matched in the group. |
| 884 | This is the forcible breaking of infinite loops as implemented in Perl |
| 885 | 5.005. */ |
| 886 | |
| 887 | if (*ecode == OP_KET || eptr == saved_eptr) |
| 888 | { |
| 889 | ecode += 1+LINK_SIZE; |
| 890 | break; |
| 891 | } |
| 892 | |
| 893 | /* The repeating kets try the rest of the pattern or restart from the |
| 894 | preceding bracket, in the appropriate order. The second "call" of match() |
| 895 | uses tail recursion, to avoid using another stack frame. */ |
| 896 | |
| 897 | if (*ecode == OP_KETRMIN) |
| 898 | { |
| 899 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM65); |
| 900 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 901 | ecode = prev; |
| 902 | goto TAIL_RECURSE; |
| 903 | } |
| 904 | else /* OP_KETRMAX */ |
| 905 | { |
| 906 | md->match_function_type = MATCH_CBEGROUP; |
| 907 | RMATCH(eptr, prev, offset_top, md, eptrb, RM66); |
| 908 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 909 | ecode += 1 + LINK_SIZE; |
| 910 | goto TAIL_RECURSE; |
| 911 | } |
| 912 | /* Control never gets here */ |
| 913 | |
| 914 | /* Handle a capturing bracket, other than those that are possessive with an |
| 915 | unlimited repeat. If there is space in the offset vector, save the current |
| 916 | subject position in the working slot at the top of the vector. We mustn't |
| 917 | change the current values of the data slot, because they may be set from a |
| 918 | previous iteration of this group, and be referred to by a reference inside |
| 919 | the group. A failure to match might occur after the group has succeeded, |
| 920 | if something later on doesn't match. For this reason, we need to restore |
| 921 | the working value and also the values of the final offsets, in case they |
| 922 | were set by a previous iteration of the same bracket. |
| 923 | |
| 924 | If there isn't enough space in the offset vector, treat this as if it were |
| 925 | a non-capturing bracket. Don't worry about setting the flag for the error |
| 926 | case here; that is handled in the code for KET. */ |
| 927 | |
| 928 | case OP_CBRA: |
| 929 | case OP_SCBRA: |
| 930 | number = GET2(ecode, 1+LINK_SIZE); |
| 931 | offset = number << 1; |
| 932 | |
| 933 | #ifdef PCRE_DEBUG |
| 934 | printf("start bracket %d\n", number); |
| 935 | printf("subject="); |
| 936 | pchars(eptr, 16, TRUE, md); |
| 937 | printf("\n"); |
| 938 | #endif |
| 939 | |
| 940 | if (offset < md->offset_max) |
| 941 | { |
| 942 | save_offset1 = md->offset_vector[offset]; |
| 943 | save_offset2 = md->offset_vector[offset+1]; |
| 944 | save_offset3 = md->offset_vector[md->offset_end - number]; |
| 945 | save_capture_last = md->capture_last; |
| 946 | save_mark = md->mark; |
| 947 | |
| 948 | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); |
| 949 | md->offset_vector[md->offset_end - number] = |
| 950 | (int)(eptr - md->start_subject); |
| 951 | |
| 952 | for (;;) |
| 953 | { |
| 954 | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; |
| 955 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, |
| 956 | eptrb, RM1); |
| 957 | if (rrc == MATCH_ONCE) break; /* Backing up through an atomic group */ |
| 958 | |
| 959 | /* If we backed up to a THEN, check whether it is within the current |
| 960 | branch by comparing the address of the THEN that is passed back with |
| 961 | the end of the branch. If it is within the current branch, and the |
| 962 | branch is one of two or more alternatives (it either starts or ends |
| 963 | with OP_ALT), we have reached the limit of THEN's action, so convert |
| 964 | the return code to NOMATCH, which will cause normal backtracking to |
| 965 | happen from now on. Otherwise, THEN is passed back to an outer |
| 966 | alternative. This implements Perl's treatment of parenthesized groups, |
| 967 | where a group not containing | does not affect the current alternative, |
| 968 | that is, (X) is NOT the same as (X|(*F)). */ |
| 969 | |
| 970 | if (rrc == MATCH_THEN) |
| 971 | { |
| 972 | next = ecode + GET(ecode,1); |
| 973 | if (md->start_match_ptr < next && |
| 974 | (*ecode == OP_ALT || *next == OP_ALT)) |
| 975 | rrc = MATCH_NOMATCH; |
| 976 | } |
| 977 | |
| 978 | /* Anything other than NOMATCH is passed back. */ |
| 979 | |
| 980 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 981 | md->capture_last = save_capture_last; |
| 982 | ecode += GET(ecode, 1); |
| 983 | md->mark = save_mark; |
| 984 | if (*ecode != OP_ALT) break; |
| 985 | } |
| 986 | |
| 987 | DPRINTF(("bracket %d failed\n", number)); |
| 988 | md->offset_vector[offset] = save_offset1; |
| 989 | md->offset_vector[offset+1] = save_offset2; |
| 990 | md->offset_vector[md->offset_end - number] = save_offset3; |
| 991 | |
| 992 | /* At this point, rrc will be one of MATCH_ONCE or MATCH_NOMATCH. */ |
| 993 | |
| 994 | RRETURN(rrc); |
| 995 | } |
| 996 | |
| 997 | /* FALL THROUGH ... Insufficient room for saving captured contents. Treat |
| 998 | as a non-capturing bracket. */ |
| 999 | |
| 1000 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 1001 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 1002 | |
| 1003 | DPRINTF(("insufficient capture room: treat as non-capturing\n")); |
| 1004 | |
| 1005 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 1006 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 1007 | |
| 1008 | /* Non-capturing or atomic group, except for possessive with unlimited |
| 1009 | repeat and ONCE group with no captures. Loop for all the alternatives. |
| 1010 | |
| 1011 | When we get to the final alternative within the brackets, we used to return |
| 1012 | the result of a recursive call to match() whatever happened so it was |
| 1013 | possible to reduce stack usage by turning this into a tail recursion, |
| 1014 | except in the case of a possibly empty group. However, now that there is |
| 1015 | the possiblity of (*THEN) occurring in the final alternative, this |
| 1016 | optimization is no longer always possible. |
| 1017 | |
| 1018 | We can optimize if we know there are no (*THEN)s in the pattern; at present |
| 1019 | this is the best that can be done. |
| 1020 | |
| 1021 | MATCH_ONCE is returned when the end of an atomic group is successfully |
| 1022 | reached, but subsequent matching fails. It passes back up the tree (causing |
| 1023 | captured values to be reset) until the original atomic group level is |
| 1024 | reached. This is tested by comparing md->once_target with the start of the |
| 1025 | group. At this point, the return is converted into MATCH_NOMATCH so that |
| 1026 | previous backup points can be taken. */ |
| 1027 | |
| 1028 | case OP_ONCE: |
| 1029 | case OP_BRA: |
| 1030 | case OP_SBRA: |
| 1031 | DPRINTF(("start non-capturing bracket\n")); |
| 1032 | |
| 1033 | for (;;) |
| 1034 | { |
| 1035 | if (op >= OP_SBRA || op == OP_ONCE) md->match_function_type = MATCH_CBEGROUP; |
| 1036 | |
| 1037 | /* If this is not a possibly empty group, and there are no (*THEN)s in |
| 1038 | the pattern, and this is the final alternative, optimize as described |
| 1039 | above. */ |
| 1040 | |
| 1041 | else if (!md->hasthen && ecode[GET(ecode, 1)] != OP_ALT) |
| 1042 | { |
| 1043 | ecode += PRIV(OP_lengths)[*ecode]; |
| 1044 | goto TAIL_RECURSE; |
| 1045 | } |
| 1046 | |
| 1047 | /* In all other cases, we have to make another call to match(). */ |
| 1048 | |
| 1049 | save_mark = md->mark; |
| 1050 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, eptrb, |
| 1051 | RM2); |
| 1052 | |
| 1053 | /* See comment in the code for capturing groups above about handling |
| 1054 | THEN. */ |
| 1055 | |
| 1056 | if (rrc == MATCH_THEN) |
| 1057 | { |
| 1058 | next = ecode + GET(ecode,1); |
| 1059 | if (md->start_match_ptr < next && |
| 1060 | (*ecode == OP_ALT || *next == OP_ALT)) |
| 1061 | rrc = MATCH_NOMATCH; |
| 1062 | } |
| 1063 | |
| 1064 | if (rrc != MATCH_NOMATCH) |
| 1065 | { |
| 1066 | if (rrc == MATCH_ONCE) |
| 1067 | { |
| 1068 | const pcre_uchar *scode = ecode; |
| 1069 | if (*scode != OP_ONCE) /* If not at start, find it */ |
| 1070 | { |
| 1071 | while (*scode == OP_ALT) scode += GET(scode, 1); |
| 1072 | scode -= GET(scode, 1); |
| 1073 | } |
| 1074 | if (md->once_target == scode) rrc = MATCH_NOMATCH; |
| 1075 | } |
| 1076 | RRETURN(rrc); |
| 1077 | } |
| 1078 | ecode += GET(ecode, 1); |
| 1079 | md->mark = save_mark; |
| 1080 | if (*ecode != OP_ALT) break; |
| 1081 | } |
| 1082 | |
| 1083 | RRETURN(MATCH_NOMATCH); |
| 1084 | |
| 1085 | /* Handle possessive capturing brackets with an unlimited repeat. We come |
| 1086 | here from BRAZERO with allow_zero set TRUE. The offset_vector values are |
| 1087 | handled similarly to the normal case above. However, the matching is |
| 1088 | different. The end of these brackets will always be OP_KETRPOS, which |
| 1089 | returns MATCH_KETRPOS without going further in the pattern. By this means |
| 1090 | we can handle the group by iteration rather than recursion, thereby |
| 1091 | reducing the amount of stack needed. */ |
| 1092 | |
| 1093 | case OP_CBRAPOS: |
| 1094 | case OP_SCBRAPOS: |
| 1095 | allow_zero = FALSE; |
| 1096 | |
| 1097 | POSSESSIVE_CAPTURE: |
| 1098 | number = GET2(ecode, 1+LINK_SIZE); |
| 1099 | offset = number << 1; |
| 1100 | |
| 1101 | #ifdef PCRE_DEBUG |
| 1102 | printf("start possessive bracket %d\n", number); |
| 1103 | printf("subject="); |
| 1104 | pchars(eptr, 16, TRUE, md); |
| 1105 | printf("\n"); |
| 1106 | #endif |
| 1107 | |
| 1108 | if (offset < md->offset_max) |
| 1109 | { |
| 1110 | matched_once = FALSE; |
| 1111 | code_offset = (int)(ecode - md->start_code); |
| 1112 | |
| 1113 | save_offset1 = md->offset_vector[offset]; |
| 1114 | save_offset2 = md->offset_vector[offset+1]; |
| 1115 | save_offset3 = md->offset_vector[md->offset_end - number]; |
| 1116 | save_capture_last = md->capture_last; |
| 1117 | |
| 1118 | DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); |
| 1119 | |
| 1120 | /* Each time round the loop, save the current subject position for use |
| 1121 | when the group matches. For MATCH_MATCH, the group has matched, so we |
| 1122 | restart it with a new subject starting position, remembering that we had |
| 1123 | at least one match. For MATCH_NOMATCH, carry on with the alternatives, as |
| 1124 | usual. If we haven't matched any alternatives in any iteration, check to |
| 1125 | see if a previous iteration matched. If so, the group has matched; |
| 1126 | continue from afterwards. Otherwise it has failed; restore the previous |
| 1127 | capture values before returning NOMATCH. */ |
| 1128 | |
| 1129 | for (;;) |
| 1130 | { |
| 1131 | md->offset_vector[md->offset_end - number] = |
| 1132 | (int)(eptr - md->start_subject); |
| 1133 | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; |
| 1134 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, |
| 1135 | eptrb, RM63); |
| 1136 | if (rrc == MATCH_KETRPOS) |
| 1137 | { |
| 1138 | offset_top = md->end_offset_top; |
| 1139 | eptr = md->end_match_ptr; |
| 1140 | ecode = md->start_code + code_offset; |
| 1141 | save_capture_last = md->capture_last; |
| 1142 | matched_once = TRUE; |
| 1143 | continue; |
| 1144 | } |
| 1145 | |
| 1146 | /* See comment in the code for capturing groups above about handling |
| 1147 | THEN. */ |
| 1148 | |
| 1149 | if (rrc == MATCH_THEN) |
| 1150 | { |
| 1151 | next = ecode + GET(ecode,1); |
| 1152 | if (md->start_match_ptr < next && |
| 1153 | (*ecode == OP_ALT || *next == OP_ALT)) |
| 1154 | rrc = MATCH_NOMATCH; |
| 1155 | } |
| 1156 | |
| 1157 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1158 | md->capture_last = save_capture_last; |
| 1159 | ecode += GET(ecode, 1); |
| 1160 | if (*ecode != OP_ALT) break; |
| 1161 | } |
| 1162 | |
| 1163 | if (!matched_once) |
| 1164 | { |
| 1165 | md->offset_vector[offset] = save_offset1; |
| 1166 | md->offset_vector[offset+1] = save_offset2; |
| 1167 | md->offset_vector[md->offset_end - number] = save_offset3; |
| 1168 | } |
| 1169 | |
| 1170 | if (allow_zero || matched_once) |
| 1171 | { |
| 1172 | ecode += 1 + LINK_SIZE; |
| 1173 | break; |
| 1174 | } |
| 1175 | |
| 1176 | RRETURN(MATCH_NOMATCH); |
| 1177 | } |
| 1178 | |
| 1179 | /* FALL THROUGH ... Insufficient room for saving captured contents. Treat |
| 1180 | as a non-capturing bracket. */ |
| 1181 | |
| 1182 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 1183 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 1184 | |
| 1185 | DPRINTF(("insufficient capture room: treat as non-capturing\n")); |
| 1186 | |
| 1187 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 1188 | /* VVVVVVVVVVVVVVVVVVVVVVVVV */ |
| 1189 | |
| 1190 | /* Non-capturing possessive bracket with unlimited repeat. We come here |
| 1191 | from BRAZERO with allow_zero = TRUE. The code is similar to the above, |
| 1192 | without the capturing complication. It is written out separately for speed |
| 1193 | and cleanliness. */ |
| 1194 | |
| 1195 | case OP_BRAPOS: |
| 1196 | case OP_SBRAPOS: |
| 1197 | allow_zero = FALSE; |
| 1198 | |
| 1199 | POSSESSIVE_NON_CAPTURE: |
| 1200 | matched_once = FALSE; |
| 1201 | code_offset = (int)(ecode - md->start_code); |
| 1202 | |
| 1203 | for (;;) |
| 1204 | { |
| 1205 | if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; |
| 1206 | RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, |
| 1207 | eptrb, RM48); |
| 1208 | if (rrc == MATCH_KETRPOS) |
| 1209 | { |
| 1210 | offset_top = md->end_offset_top; |
| 1211 | eptr = md->end_match_ptr; |
| 1212 | ecode = md->start_code + code_offset; |
| 1213 | matched_once = TRUE; |
| 1214 | continue; |
| 1215 | } |
| 1216 | |
| 1217 | /* See comment in the code for capturing groups above about handling |
| 1218 | THEN. */ |
| 1219 | |
| 1220 | if (rrc == MATCH_THEN) |
| 1221 | { |
| 1222 | next = ecode + GET(ecode,1); |
| 1223 | if (md->start_match_ptr < next && |
| 1224 | (*ecode == OP_ALT || *next == OP_ALT)) |
| 1225 | rrc = MATCH_NOMATCH; |
| 1226 | } |
| 1227 | |
| 1228 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1229 | ecode += GET(ecode, 1); |
| 1230 | if (*ecode != OP_ALT) break; |
| 1231 | } |
| 1232 | |
| 1233 | if (matched_once || allow_zero) |
| 1234 | { |
| 1235 | ecode += 1 + LINK_SIZE; |
| 1236 | break; |
| 1237 | } |
| 1238 | RRETURN(MATCH_NOMATCH); |
| 1239 | |
| 1240 | /* Control never reaches here. */ |
| 1241 | |
| 1242 | /* Conditional group: compilation checked that there are no more than |
| 1243 | two branches. If the condition is false, skipping the first branch takes us |
| 1244 | past the end if there is only one branch, but that's OK because that is |
| 1245 | exactly what going to the ket would do. */ |
| 1246 | |
| 1247 | case OP_COND: |
| 1248 | case OP_SCOND: |
| 1249 | codelink = GET(ecode, 1); |
| 1250 | |
| 1251 | /* Because of the way auto-callout works during compile, a callout item is |
| 1252 | inserted between OP_COND and an assertion condition. */ |
| 1253 | |
| 1254 | if (ecode[LINK_SIZE+1] == OP_CALLOUT) |
| 1255 | { |
| 1256 | if (PUBL(callout) != NULL) |
| 1257 | { |
| 1258 | PUBL(callout_block) cb; |
| 1259 | cb.version = 2; /* Version 1 of the callout block */ |
| 1260 | cb.callout_number = ecode[LINK_SIZE+2]; |
| 1261 | cb.offset_vector = md->offset_vector; |
| 1262 | #ifdef COMPILE_PCRE8 |
| 1263 | cb.subject = (PCRE_SPTR)md->start_subject; |
| 1264 | #else |
| 1265 | cb.subject = (PCRE_SPTR16)md->start_subject; |
| 1266 | #endif |
| 1267 | cb.subject_length = (int)(md->end_subject - md->start_subject); |
| 1268 | cb.start_match = (int)(mstart - md->start_subject); |
| 1269 | cb.current_position = (int)(eptr - md->start_subject); |
| 1270 | cb.pattern_position = GET(ecode, LINK_SIZE + 3); |
| 1271 | cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE); |
| 1272 | cb.capture_top = offset_top/2; |
| 1273 | cb.capture_last = md->capture_last; |
| 1274 | cb.callout_data = md->callout_data; |
| 1275 | cb.mark = md->nomatch_mark; |
| 1276 | if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH); |
| 1277 | if (rrc < 0) RRETURN(rrc); |
| 1278 | } |
| 1279 | ecode += PRIV(OP_lengths)[OP_CALLOUT]; |
| 1280 | } |
| 1281 | |
| 1282 | condcode = ecode[LINK_SIZE+1]; |
| 1283 | |
| 1284 | /* Now see what the actual condition is */ |
| 1285 | |
| 1286 | if (condcode == OP_RREF || condcode == OP_NRREF) /* Recursion test */ |
| 1287 | { |
| 1288 | if (md->recursive == NULL) /* Not recursing => FALSE */ |
| 1289 | { |
| 1290 | condition = FALSE; |
| 1291 | ecode += GET(ecode, 1); |
| 1292 | } |
| 1293 | else |
| 1294 | { |
| 1295 | int recno = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ |
| 1296 | condition = (recno == RREF_ANY || recno == md->recursive->group_num); |
| 1297 | |
| 1298 | /* If the test is for recursion into a specific subpattern, and it is |
| 1299 | false, but the test was set up by name, scan the table to see if the |
| 1300 | name refers to any other numbers, and test them. The condition is true |
| 1301 | if any one is set. */ |
| 1302 | |
| 1303 | if (!condition && condcode == OP_NRREF) |
| 1304 | { |
| 1305 | pcre_uchar *slotA = md->name_table; |
| 1306 | for (i = 0; i < md->name_count; i++) |
| 1307 | { |
| 1308 | if (GET2(slotA, 0) == recno) break; |
| 1309 | slotA += md->name_entry_size; |
| 1310 | } |
| 1311 | |
| 1312 | /* Found a name for the number - there can be only one; duplicate |
| 1313 | names for different numbers are allowed, but not vice versa. First |
| 1314 | scan down for duplicates. */ |
| 1315 | |
| 1316 | if (i < md->name_count) |
| 1317 | { |
| 1318 | pcre_uchar *slotB = slotA; |
| 1319 | while (slotB > md->name_table) |
| 1320 | { |
| 1321 | slotB -= md->name_entry_size; |
| 1322 | if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0) |
| 1323 | { |
| 1324 | condition = GET2(slotB, 0) == md->recursive->group_num; |
| 1325 | if (condition) break; |
| 1326 | } |
| 1327 | else break; |
| 1328 | } |
| 1329 | |
| 1330 | /* Scan up for duplicates */ |
| 1331 | |
| 1332 | if (!condition) |
| 1333 | { |
| 1334 | slotB = slotA; |
| 1335 | for (i++; i < md->name_count; i++) |
| 1336 | { |
| 1337 | slotB += md->name_entry_size; |
| 1338 | if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0) |
| 1339 | { |
| 1340 | condition = GET2(slotB, 0) == md->recursive->group_num; |
| 1341 | if (condition) break; |
| 1342 | } |
| 1343 | else break; |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | /* Chose branch according to the condition */ |
| 1350 | |
| 1351 | ecode += condition? 1 + IMM2_SIZE : GET(ecode, 1); |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | else if (condcode == OP_CREF || condcode == OP_NCREF) /* Group used test */ |
| 1356 | { |
| 1357 | offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ |
| 1358 | condition = offset < offset_top && md->offset_vector[offset] >= 0; |
| 1359 | |
| 1360 | /* If the numbered capture is unset, but the reference was by name, |
| 1361 | scan the table to see if the name refers to any other numbers, and test |
| 1362 | them. The condition is true if any one is set. This is tediously similar |
| 1363 | to the code above, but not close enough to try to amalgamate. */ |
| 1364 | |
| 1365 | if (!condition && condcode == OP_NCREF) |
| 1366 | { |
| 1367 | int refno = offset >> 1; |
| 1368 | pcre_uchar *slotA = md->name_table; |
| 1369 | |
| 1370 | for (i = 0; i < md->name_count; i++) |
| 1371 | { |
| 1372 | if (GET2(slotA, 0) == refno) break; |
| 1373 | slotA += md->name_entry_size; |
| 1374 | } |
| 1375 | |
| 1376 | /* Found a name for the number - there can be only one; duplicate names |
| 1377 | for different numbers are allowed, but not vice versa. First scan down |
| 1378 | for duplicates. */ |
| 1379 | |
| 1380 | if (i < md->name_count) |
| 1381 | { |
| 1382 | pcre_uchar *slotB = slotA; |
| 1383 | while (slotB > md->name_table) |
| 1384 | { |
| 1385 | slotB -= md->name_entry_size; |
| 1386 | if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0) |
| 1387 | { |
| 1388 | offset = GET2(slotB, 0) << 1; |
| 1389 | condition = offset < offset_top && |
| 1390 | md->offset_vector[offset] >= 0; |
| 1391 | if (condition) break; |
| 1392 | } |
| 1393 | else break; |
| 1394 | } |
| 1395 | |
| 1396 | /* Scan up for duplicates */ |
| 1397 | |
| 1398 | if (!condition) |
| 1399 | { |
| 1400 | slotB = slotA; |
| 1401 | for (i++; i < md->name_count; i++) |
| 1402 | { |
| 1403 | slotB += md->name_entry_size; |
| 1404 | if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0) |
| 1405 | { |
| 1406 | offset = GET2(slotB, 0) << 1; |
| 1407 | condition = offset < offset_top && |
| 1408 | md->offset_vector[offset] >= 0; |
| 1409 | if (condition) break; |
| 1410 | } |
| 1411 | else break; |
| 1412 | } |
| 1413 | } |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | /* Chose branch according to the condition */ |
| 1418 | |
| 1419 | ecode += condition? 1 + IMM2_SIZE : GET(ecode, 1); |
| 1420 | } |
| 1421 | |
| 1422 | else if (condcode == OP_DEF) /* DEFINE - always false */ |
| 1423 | { |
| 1424 | condition = FALSE; |
| 1425 | ecode += GET(ecode, 1); |
| 1426 | } |
| 1427 | |
| 1428 | /* The condition is an assertion. Call match() to evaluate it - setting |
| 1429 | md->match_function_type to MATCH_CONDASSERT causes it to stop at the end of |
| 1430 | an assertion. */ |
| 1431 | |
| 1432 | else |
| 1433 | { |
| 1434 | md->match_function_type = MATCH_CONDASSERT; |
| 1435 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM3); |
| 1436 | if (rrc == MATCH_MATCH) |
| 1437 | { |
| 1438 | if (md->end_offset_top > offset_top) |
| 1439 | offset_top = md->end_offset_top; /* Captures may have happened */ |
| 1440 | condition = TRUE; |
| 1441 | ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); |
| 1442 | while (*ecode == OP_ALT) ecode += GET(ecode, 1); |
| 1443 | } |
| 1444 | |
| 1445 | /* PCRE doesn't allow the effect of (*THEN) to escape beyond an |
| 1446 | assertion; it is therefore treated as NOMATCH. */ |
| 1447 | |
| 1448 | else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
| 1449 | { |
| 1450 | RRETURN(rrc); /* Need braces because of following else */ |
| 1451 | } |
| 1452 | else |
| 1453 | { |
| 1454 | condition = FALSE; |
| 1455 | ecode += codelink; |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | /* We are now at the branch that is to be obeyed. As there is only one, can |
| 1460 | use tail recursion to avoid using another stack frame, except when there is |
| 1461 | unlimited repeat of a possibly empty group. In the latter case, a recursive |
| 1462 | call to match() is always required, unless the second alternative doesn't |
| 1463 | exist, in which case we can just plough on. Note that, for compatibility |
| 1464 | with Perl, the | in a conditional group is NOT treated as creating two |
| 1465 | alternatives. If a THEN is encountered in the branch, it propagates out to |
| 1466 | the enclosing alternative (unless nested in a deeper set of alternatives, |
| 1467 | of course). */ |
| 1468 | |
| 1469 | if (condition || *ecode == OP_ALT) |
| 1470 | { |
| 1471 | if (op != OP_SCOND) |
| 1472 | { |
| 1473 | ecode += 1 + LINK_SIZE; |
| 1474 | goto TAIL_RECURSE; |
| 1475 | } |
| 1476 | |
| 1477 | md->match_function_type = MATCH_CBEGROUP; |
| 1478 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM49); |
| 1479 | RRETURN(rrc); |
| 1480 | } |
| 1481 | |
| 1482 | /* Condition false & no alternative; continue after the group. */ |
| 1483 | |
| 1484 | else |
| 1485 | { |
| 1486 | ecode += 1 + LINK_SIZE; |
| 1487 | } |
| 1488 | break; |
| 1489 | |
| 1490 | |
| 1491 | /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes, |
| 1492 | to close any currently open capturing brackets. */ |
| 1493 | |
| 1494 | case OP_CLOSE: |
| 1495 | number = GET2(ecode, 1); |
| 1496 | offset = number << 1; |
| 1497 | |
| 1498 | #ifdef PCRE_DEBUG |
| 1499 | printf("end bracket %d at *ACCEPT", number); |
| 1500 | printf("\n"); |
| 1501 | #endif |
| 1502 | |
| 1503 | md->capture_last = number; |
| 1504 | if (offset >= md->offset_max) md->offset_overflow = TRUE; else |
| 1505 | { |
| 1506 | md->offset_vector[offset] = |
| 1507 | md->offset_vector[md->offset_end - number]; |
| 1508 | md->offset_vector[offset+1] = (int)(eptr - md->start_subject); |
| 1509 | if (offset_top <= offset) offset_top = offset + 2; |
| 1510 | } |
| 1511 | ecode += 1 + IMM2_SIZE; |
| 1512 | break; |
| 1513 | |
| 1514 | |
| 1515 | /* End of the pattern, either real or forced. */ |
| 1516 | |
| 1517 | case OP_END: |
| 1518 | case OP_ACCEPT: |
| 1519 | case OP_ASSERT_ACCEPT: |
| 1520 | |
| 1521 | /* If we have matched an empty string, fail if not in an assertion and not |
| 1522 | in a recursion if either PCRE_NOTEMPTY is set, or if PCRE_NOTEMPTY_ATSTART |
| 1523 | is set and we have matched at the start of the subject. In both cases, |
| 1524 | backtracking will then try other alternatives, if any. */ |
| 1525 | |
| 1526 | if (eptr == mstart && op != OP_ASSERT_ACCEPT && |
| 1527 | md->recursive == NULL && |
| 1528 | (md->notempty || |
| 1529 | (md->notempty_atstart && |
| 1530 | mstart == md->start_subject + md->start_offset))) |
| 1531 | RRETURN(MATCH_NOMATCH); |
| 1532 | |
| 1533 | /* Otherwise, we have a match. */ |
| 1534 | |
| 1535 | md->end_match_ptr = eptr; /* Record where we ended */ |
| 1536 | md->end_offset_top = offset_top; /* and how many extracts were taken */ |
| 1537 | md->start_match_ptr = mstart; /* and the start (\K can modify) */ |
| 1538 | |
| 1539 | /* For some reason, the macros don't work properly if an expression is |
| 1540 | given as the argument to RRETURN when the heap is in use. */ |
| 1541 | |
| 1542 | rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT; |
| 1543 | RRETURN(rrc); |
| 1544 | |
| 1545 | /* Assertion brackets. Check the alternative branches in turn - the |
| 1546 | matching won't pass the KET for an assertion. If any one branch matches, |
| 1547 | the assertion is true. Lookbehind assertions have an OP_REVERSE item at the |
| 1548 | start of each branch to move the current point backwards, so the code at |
| 1549 | this level is identical to the lookahead case. When the assertion is part |
| 1550 | of a condition, we want to return immediately afterwards. The caller of |
| 1551 | this incarnation of the match() function will have set MATCH_CONDASSERT in |
| 1552 | md->match_function type, and one of these opcodes will be the first opcode |
| 1553 | that is processed. We use a local variable that is preserved over calls to |
| 1554 | match() to remember this case. */ |
| 1555 | |
| 1556 | case OP_ASSERT: |
| 1557 | case OP_ASSERTBACK: |
| 1558 | save_mark = md->mark; |
| 1559 | if (md->match_function_type == MATCH_CONDASSERT) |
| 1560 | { |
| 1561 | condassert = TRUE; |
| 1562 | md->match_function_type = 0; |
| 1563 | } |
| 1564 | else condassert = FALSE; |
| 1565 | |
| 1566 | do |
| 1567 | { |
| 1568 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM4); |
| 1569 | if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) |
| 1570 | { |
| 1571 | mstart = md->start_match_ptr; /* In case \K reset it */ |
| 1572 | break; |
| 1573 | } |
| 1574 | |
| 1575 | /* PCRE does not allow THEN to escape beyond an assertion; it is treated |
| 1576 | as NOMATCH. */ |
| 1577 | |
| 1578 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 1579 | ecode += GET(ecode, 1); |
| 1580 | md->mark = save_mark; |
| 1581 | } |
| 1582 | while (*ecode == OP_ALT); |
| 1583 | |
| 1584 | if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH); |
| 1585 | |
| 1586 | /* If checking an assertion for a condition, return MATCH_MATCH. */ |
| 1587 | |
| 1588 | if (condassert) RRETURN(MATCH_MATCH); |
| 1589 | |
| 1590 | /* Continue from after the assertion, updating the offsets high water |
| 1591 | mark, since extracts may have been taken during the assertion. */ |
| 1592 | |
| 1593 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
| 1594 | ecode += 1 + LINK_SIZE; |
| 1595 | offset_top = md->end_offset_top; |
| 1596 | continue; |
| 1597 | |
| 1598 | /* Negative assertion: all branches must fail to match. Encountering SKIP, |
| 1599 | PRUNE, or COMMIT means we must assume failure without checking subsequent |
| 1600 | branches. */ |
| 1601 | |
| 1602 | case OP_ASSERT_NOT: |
| 1603 | case OP_ASSERTBACK_NOT: |
| 1604 | save_mark = md->mark; |
| 1605 | if (md->match_function_type == MATCH_CONDASSERT) |
| 1606 | { |
| 1607 | condassert = TRUE; |
| 1608 | md->match_function_type = 0; |
| 1609 | } |
| 1610 | else condassert = FALSE; |
| 1611 | |
| 1612 | do |
| 1613 | { |
| 1614 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5); |
| 1615 | md->mark = save_mark; |
| 1616 | if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH); |
| 1617 | if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT) |
| 1618 | { |
| 1619 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
| 1620 | break; |
| 1621 | } |
| 1622 | |
| 1623 | /* PCRE does not allow THEN to escape beyond an assertion; it is treated |
| 1624 | as NOMATCH. */ |
| 1625 | |
| 1626 | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); |
| 1627 | ecode += GET(ecode,1); |
| 1628 | } |
| 1629 | while (*ecode == OP_ALT); |
| 1630 | |
| 1631 | if (condassert) RRETURN(MATCH_MATCH); /* Condition assertion */ |
| 1632 | |
| 1633 | ecode += 1 + LINK_SIZE; |
| 1634 | continue; |
| 1635 | |
| 1636 | /* Move the subject pointer back. This occurs only at the start of |
| 1637 | each branch of a lookbehind assertion. If we are too close to the start to |
| 1638 | move back, this match function fails. When working with UTF-8 we move |
| 1639 | back a number of characters, not bytes. */ |
| 1640 | |
| 1641 | case OP_REVERSE: |
| 1642 | #ifdef SUPPORT_UTF |
| 1643 | if (utf) |
| 1644 | { |
| 1645 | i = GET(ecode, 1); |
| 1646 | while (i-- > 0) |
| 1647 | { |
| 1648 | eptr--; |
| 1649 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1650 | BACKCHAR(eptr); |
| 1651 | } |
| 1652 | } |
| 1653 | else |
| 1654 | #endif |
| 1655 | |
| 1656 | /* No UTF-8 support, or not in UTF-8 mode: count is byte count */ |
| 1657 | |
| 1658 | { |
| 1659 | eptr -= GET(ecode, 1); |
| 1660 | if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); |
| 1661 | } |
| 1662 | |
| 1663 | /* Save the earliest consulted character, then skip to next op code */ |
| 1664 | |
| 1665 | if (eptr < md->start_used_ptr) md->start_used_ptr = eptr; |
| 1666 | ecode += 1 + LINK_SIZE; |
| 1667 | break; |
| 1668 | |
| 1669 | /* The callout item calls an external function, if one is provided, passing |
| 1670 | details of the match so far. This is mainly for debugging, though the |
| 1671 | function is able to force a failure. */ |
| 1672 | |
| 1673 | case OP_CALLOUT: |
| 1674 | if (PUBL(callout) != NULL) |
| 1675 | { |
| 1676 | PUBL(callout_block) cb; |
| 1677 | cb.version = 2; /* Version 1 of the callout block */ |
| 1678 | cb.callout_number = ecode[1]; |
| 1679 | cb.offset_vector = md->offset_vector; |
| 1680 | #ifdef COMPILE_PCRE8 |
| 1681 | cb.subject = (PCRE_SPTR)md->start_subject; |
| 1682 | #else |
| 1683 | cb.subject = (PCRE_SPTR16)md->start_subject; |
| 1684 | #endif |
| 1685 | cb.subject_length = (int)(md->end_subject - md->start_subject); |
| 1686 | cb.start_match = (int)(mstart - md->start_subject); |
| 1687 | cb.current_position = (int)(eptr - md->start_subject); |
| 1688 | cb.pattern_position = GET(ecode, 2); |
| 1689 | cb.next_item_length = GET(ecode, 2 + LINK_SIZE); |
| 1690 | cb.capture_top = offset_top/2; |
| 1691 | cb.capture_last = md->capture_last; |
| 1692 | cb.callout_data = md->callout_data; |
| 1693 | cb.mark = md->nomatch_mark; |
| 1694 | if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH); |
| 1695 | if (rrc < 0) RRETURN(rrc); |
| 1696 | } |
| 1697 | ecode += 2 + 2*LINK_SIZE; |
| 1698 | break; |
| 1699 | |
| 1700 | /* Recursion either matches the current regex, or some subexpression. The |
| 1701 | offset data is the offset to the starting bracket from the start of the |
| 1702 | whole pattern. (This is so that it works from duplicated subpatterns.) |
| 1703 | |
| 1704 | The state of the capturing groups is preserved over recursion, and |
| 1705 | re-instated afterwards. We don't know how many are started and not yet |
| 1706 | finished (offset_top records the completed total) so we just have to save |
| 1707 | all the potential data. There may be up to 65535 such values, which is too |
| 1708 | large to put on the stack, but using malloc for small numbers seems |
| 1709 | expensive. As a compromise, the stack is used when there are no more than |
| 1710 | REC_STACK_SAVE_MAX values to store; otherwise malloc is used. |
| 1711 | |
| 1712 | There are also other values that have to be saved. We use a chained |
| 1713 | sequence of blocks that actually live on the stack. Thanks to Robin Houston |
| 1714 | for the original version of this logic. It has, however, been hacked around |
| 1715 | a lot, so he is not to blame for the current way it works. */ |
| 1716 | |
| 1717 | case OP_RECURSE: |
| 1718 | { |
| 1719 | recursion_info *ri; |
| 1720 | int recno; |
| 1721 | |
| 1722 | callpat = md->start_code + GET(ecode, 1); |
| 1723 | recno = (callpat == md->start_code)? 0 : |
| 1724 | GET2(callpat, 1 + LINK_SIZE); |
| 1725 | |
| 1726 | /* Check for repeating a recursion without advancing the subject pointer. |
| 1727 | This should catch convoluted mutual recursions. (Some simple cases are |
| 1728 | caught at compile time.) */ |
| 1729 | |
| 1730 | for (ri = md->recursive; ri != NULL; ri = ri->prevrec) |
| 1731 | if (recno == ri->group_num && eptr == ri->subject_position) |
| 1732 | RRETURN(PCRE_ERROR_RECURSELOOP); |
| 1733 | |
| 1734 | /* Add to "recursing stack" */ |
| 1735 | |
| 1736 | new_recursive.group_num = recno; |
| 1737 | new_recursive.subject_position = eptr; |
| 1738 | new_recursive.prevrec = md->recursive; |
| 1739 | md->recursive = &new_recursive; |
| 1740 | |
| 1741 | /* Where to continue from afterwards */ |
| 1742 | |
| 1743 | ecode += 1 + LINK_SIZE; |
| 1744 | |
| 1745 | /* Now save the offset data */ |
| 1746 | |
| 1747 | new_recursive.saved_max = md->offset_end; |
| 1748 | if (new_recursive.saved_max <= REC_STACK_SAVE_MAX) |
| 1749 | new_recursive.offset_save = stacksave; |
| 1750 | else |
| 1751 | { |
| 1752 | new_recursive.offset_save = |
| 1753 | (int *)(PUBL(malloc))(new_recursive.saved_max * sizeof(int)); |
| 1754 | if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY); |
| 1755 | } |
| 1756 | memcpy(new_recursive.offset_save, md->offset_vector, |
| 1757 | new_recursive.saved_max * sizeof(int)); |
| 1758 | |
| 1759 | /* OK, now we can do the recursion. After processing each alternative, |
| 1760 | restore the offset data. If there were nested recursions, md->recursive |
| 1761 | might be changed, so reset it before looping. */ |
| 1762 | |
| 1763 | DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); |
| 1764 | cbegroup = (*callpat >= OP_SBRA); |
| 1765 | do |
| 1766 | { |
| 1767 | if (cbegroup) md->match_function_type = MATCH_CBEGROUP; |
| 1768 | RMATCH(eptr, callpat + PRIV(OP_lengths)[*callpat], offset_top, |
| 1769 | md, eptrb, RM6); |
| 1770 | memcpy(md->offset_vector, new_recursive.offset_save, |
| 1771 | new_recursive.saved_max * sizeof(int)); |
| 1772 | md->recursive = new_recursive.prevrec; |
| 1773 | if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) |
| 1774 | { |
| 1775 | DPRINTF(("Recursion matched\n")); |
| 1776 | if (new_recursive.offset_save != stacksave) |
| 1777 | (PUBL(free))(new_recursive.offset_save); |
| 1778 | |
| 1779 | /* Set where we got to in the subject, and reset the start in case |
| 1780 | it was changed by \K. This *is* propagated back out of a recursion, |
| 1781 | for Perl compatibility. */ |
| 1782 | |
| 1783 | eptr = md->end_match_ptr; |
| 1784 | mstart = md->start_match_ptr; |
| 1785 | goto RECURSION_MATCHED; /* Exit loop; end processing */ |
| 1786 | } |
| 1787 | |
| 1788 | /* PCRE does not allow THEN to escape beyond a recursion; it is treated |
| 1789 | as NOMATCH. */ |
| 1790 | |
| 1791 | else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
| 1792 | { |
| 1793 | DPRINTF(("Recursion gave error %d\n", rrc)); |
| 1794 | if (new_recursive.offset_save != stacksave) |
| 1795 | (PUBL(free))(new_recursive.offset_save); |
| 1796 | RRETURN(rrc); |
| 1797 | } |
| 1798 | |
| 1799 | md->recursive = &new_recursive; |
| 1800 | callpat += GET(callpat, 1); |
| 1801 | } |
| 1802 | while (*callpat == OP_ALT); |
| 1803 | |
| 1804 | DPRINTF(("Recursion didn't match\n")); |
| 1805 | md->recursive = new_recursive.prevrec; |
| 1806 | if (new_recursive.offset_save != stacksave) |
| 1807 | (PUBL(free))(new_recursive.offset_save); |
| 1808 | RRETURN(MATCH_NOMATCH); |
| 1809 | } |
| 1810 | |
| 1811 | RECURSION_MATCHED: |
| 1812 | break; |
| 1813 | |
| 1814 | /* An alternation is the end of a branch; scan along to find the end of the |
| 1815 | bracketed group and go to there. */ |
| 1816 | |
| 1817 | case OP_ALT: |
| 1818 | do ecode += GET(ecode,1); while (*ecode == OP_ALT); |
| 1819 | break; |
| 1820 | |
| 1821 | /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group, |
| 1822 | indicating that it may occur zero times. It may repeat infinitely, or not |
| 1823 | at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets |
| 1824 | with fixed upper repeat limits are compiled as a number of copies, with the |
| 1825 | optional ones preceded by BRAZERO or BRAMINZERO. */ |
| 1826 | |
| 1827 | case OP_BRAZERO: |
| 1828 | next = ecode + 1; |
| 1829 | RMATCH(eptr, next, offset_top, md, eptrb, RM10); |
| 1830 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1831 | do next += GET(next, 1); while (*next == OP_ALT); |
| 1832 | ecode = next + 1 + LINK_SIZE; |
| 1833 | break; |
| 1834 | |
| 1835 | case OP_BRAMINZERO: |
| 1836 | next = ecode + 1; |
| 1837 | do next += GET(next, 1); while (*next == OP_ALT); |
| 1838 | RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, eptrb, RM11); |
| 1839 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1840 | ecode++; |
| 1841 | break; |
| 1842 | |
| 1843 | case OP_SKIPZERO: |
| 1844 | next = ecode+1; |
| 1845 | do next += GET(next,1); while (*next == OP_ALT); |
| 1846 | ecode = next + 1 + LINK_SIZE; |
| 1847 | break; |
| 1848 | |
| 1849 | /* BRAPOSZERO occurs before a possessive bracket group. Don't do anything |
| 1850 | here; just jump to the group, with allow_zero set TRUE. */ |
| 1851 | |
| 1852 | case OP_BRAPOSZERO: |
| 1853 | op = *(++ecode); |
| 1854 | allow_zero = TRUE; |
| 1855 | if (op == OP_CBRAPOS || op == OP_SCBRAPOS) goto POSSESSIVE_CAPTURE; |
| 1856 | goto POSSESSIVE_NON_CAPTURE; |
| 1857 | |
| 1858 | /* End of a group, repeated or non-repeating. */ |
| 1859 | |
| 1860 | case OP_KET: |
| 1861 | case OP_KETRMIN: |
| 1862 | case OP_KETRMAX: |
| 1863 | case OP_KETRPOS: |
| 1864 | prev = ecode - GET(ecode, 1); |
| 1865 | |
| 1866 | /* If this was a group that remembered the subject start, in order to break |
| 1867 | infinite repeats of empty string matches, retrieve the subject start from |
| 1868 | the chain. Otherwise, set it NULL. */ |
| 1869 | |
| 1870 | if (*prev >= OP_SBRA || *prev == OP_ONCE) |
| 1871 | { |
| 1872 | saved_eptr = eptrb->epb_saved_eptr; /* Value at start of group */ |
| 1873 | eptrb = eptrb->epb_prev; /* Backup to previous group */ |
| 1874 | } |
| 1875 | else saved_eptr = NULL; |
| 1876 | |
| 1877 | /* If we are at the end of an assertion group or a non-capturing atomic |
| 1878 | group, stop matching and return MATCH_MATCH, but record the current high |
| 1879 | water mark for use by positive assertions. We also need to record the match |
| 1880 | start in case it was changed by \K. */ |
| 1881 | |
| 1882 | if ((*prev >= OP_ASSERT && *prev <= OP_ASSERTBACK_NOT) || |
| 1883 | *prev == OP_ONCE_NC) |
| 1884 | { |
| 1885 | md->end_match_ptr = eptr; /* For ONCE_NC */ |
| 1886 | md->end_offset_top = offset_top; |
| 1887 | md->start_match_ptr = mstart; |
| 1888 | RRETURN(MATCH_MATCH); /* Sets md->mark */ |
| 1889 | } |
| 1890 | |
| 1891 | /* For capturing groups we have to check the group number back at the start |
| 1892 | and if necessary complete handling an extraction by setting the offsets and |
| 1893 | bumping the high water mark. Whole-pattern recursion is coded as a recurse |
| 1894 | into group 0, so it won't be picked up here. Instead, we catch it when the |
| 1895 | OP_END is reached. Other recursion is handled here. We just have to record |
| 1896 | the current subject position and start match pointer and give a MATCH |
| 1897 | return. */ |
| 1898 | |
| 1899 | if (*prev == OP_CBRA || *prev == OP_SCBRA || |
| 1900 | *prev == OP_CBRAPOS || *prev == OP_SCBRAPOS) |
| 1901 | { |
| 1902 | number = GET2(prev, 1+LINK_SIZE); |
| 1903 | offset = number << 1; |
| 1904 | |
| 1905 | #ifdef PCRE_DEBUG |
| 1906 | printf("end bracket %d", number); |
| 1907 | printf("\n"); |
| 1908 | #endif |
| 1909 | |
| 1910 | /* Handle a recursively called group. */ |
| 1911 | |
| 1912 | if (md->recursive != NULL && md->recursive->group_num == number) |
| 1913 | { |
| 1914 | md->end_match_ptr = eptr; |
| 1915 | md->start_match_ptr = mstart; |
| 1916 | RRETURN(MATCH_MATCH); |
| 1917 | } |
| 1918 | |
| 1919 | /* Deal with capturing */ |
| 1920 | |
| 1921 | md->capture_last = number; |
| 1922 | if (offset >= md->offset_max) md->offset_overflow = TRUE; else |
| 1923 | { |
| 1924 | /* If offset is greater than offset_top, it means that we are |
| 1925 | "skipping" a capturing group, and that group's offsets must be marked |
| 1926 | unset. In earlier versions of PCRE, all the offsets were unset at the |
| 1927 | start of matching, but this doesn't work because atomic groups and |
| 1928 | assertions can cause a value to be set that should later be unset. |
| 1929 | Example: matching /(?>(a))b|(a)c/ against "ac". This sets group 1 as |
| 1930 | part of the atomic group, but this is not on the final matching path, |
| 1931 | so must be unset when 2 is set. (If there is no group 2, there is no |
| 1932 | problem, because offset_top will then be 2, indicating no capture.) */ |
| 1933 | |
| 1934 | if (offset > offset_top) |
| 1935 | { |
| 1936 | register int *iptr = md->offset_vector + offset_top; |
| 1937 | register int *iend = md->offset_vector + offset; |
| 1938 | while (iptr < iend) *iptr++ = -1; |
| 1939 | } |
| 1940 | |
| 1941 | /* Now make the extraction */ |
| 1942 | |
| 1943 | md->offset_vector[offset] = |
| 1944 | md->offset_vector[md->offset_end - number]; |
| 1945 | md->offset_vector[offset+1] = (int)(eptr - md->start_subject); |
| 1946 | if (offset_top <= offset) offset_top = offset + 2; |
| 1947 | } |
| 1948 | } |
| 1949 | |
| 1950 | /* For an ordinary non-repeating ket, just continue at this level. This |
| 1951 | also happens for a repeating ket if no characters were matched in the |
| 1952 | group. This is the forcible breaking of infinite loops as implemented in |
| 1953 | Perl 5.005. For a non-repeating atomic group that includes captures, |
| 1954 | establish a backup point by processing the rest of the pattern at a lower |
| 1955 | level. If this results in a NOMATCH return, pass MATCH_ONCE back to the |
| 1956 | original OP_ONCE level, thereby bypassing intermediate backup points, but |
| 1957 | resetting any captures that happened along the way. */ |
| 1958 | |
| 1959 | if (*ecode == OP_KET || eptr == saved_eptr) |
| 1960 | { |
| 1961 | if (*prev == OP_ONCE) |
| 1962 | { |
| 1963 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM12); |
| 1964 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1965 | md->once_target = prev; /* Level at which to change to MATCH_NOMATCH */ |
| 1966 | RRETURN(MATCH_ONCE); |
| 1967 | } |
| 1968 | ecode += 1 + LINK_SIZE; /* Carry on at this level */ |
| 1969 | break; |
| 1970 | } |
| 1971 | |
| 1972 | /* OP_KETRPOS is a possessive repeating ket. Remember the current position, |
| 1973 | and return the MATCH_KETRPOS. This makes it possible to do the repeats one |
| 1974 | at a time from the outer level, thus saving stack. */ |
| 1975 | |
| 1976 | if (*ecode == OP_KETRPOS) |
| 1977 | { |
| 1978 | md->end_match_ptr = eptr; |
| 1979 | md->end_offset_top = offset_top; |
| 1980 | RRETURN(MATCH_KETRPOS); |
| 1981 | } |
| 1982 | |
| 1983 | /* The normal repeating kets try the rest of the pattern or restart from |
| 1984 | the preceding bracket, in the appropriate order. In the second case, we can |
| 1985 | use tail recursion to avoid using another stack frame, unless we have an |
| 1986 | an atomic group or an unlimited repeat of a group that can match an empty |
| 1987 | string. */ |
| 1988 | |
| 1989 | if (*ecode == OP_KETRMIN) |
| 1990 | { |
| 1991 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM7); |
| 1992 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1993 | if (*prev == OP_ONCE) |
| 1994 | { |
| 1995 | RMATCH(eptr, prev, offset_top, md, eptrb, RM8); |
| 1996 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 1997 | md->once_target = prev; /* Level at which to change to MATCH_NOMATCH */ |
| 1998 | RRETURN(MATCH_ONCE); |
| 1999 | } |
| 2000 | if (*prev >= OP_SBRA) /* Could match an empty string */ |
| 2001 | { |
| 2002 | md->match_function_type = MATCH_CBEGROUP; |
| 2003 | RMATCH(eptr, prev, offset_top, md, eptrb, RM50); |
| 2004 | RRETURN(rrc); |
| 2005 | } |
| 2006 | ecode = prev; |
| 2007 | goto TAIL_RECURSE; |
| 2008 | } |
| 2009 | else /* OP_KETRMAX */ |
| 2010 | { |
| 2011 | if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP; |
| 2012 | RMATCH(eptr, prev, offset_top, md, eptrb, RM13); |
| 2013 | if (rrc == MATCH_ONCE && md->once_target == prev) rrc = MATCH_NOMATCH; |
| 2014 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2015 | if (*prev == OP_ONCE) |
| 2016 | { |
| 2017 | RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM9); |
| 2018 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2019 | md->once_target = prev; |
| 2020 | RRETURN(MATCH_ONCE); |
| 2021 | } |
| 2022 | ecode += 1 + LINK_SIZE; |
| 2023 | goto TAIL_RECURSE; |
| 2024 | } |
| 2025 | /* Control never gets here */ |
| 2026 | |
| 2027 | /* Not multiline mode: start of subject assertion, unless notbol. */ |
| 2028 | |
| 2029 | case OP_CIRC: |
| 2030 | if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); |
| 2031 | |
| 2032 | /* Start of subject assertion */ |
| 2033 | |
| 2034 | case OP_SOD: |
| 2035 | if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH); |
| 2036 | ecode++; |
| 2037 | break; |
| 2038 | |
| 2039 | /* Multiline mode: start of subject unless notbol, or after any newline. */ |
| 2040 | |
| 2041 | case OP_CIRCM: |
| 2042 | if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH); |
| 2043 | if (eptr != md->start_subject && |
| 2044 | (eptr == md->end_subject || !WAS_NEWLINE(eptr))) |
| 2045 | RRETURN(MATCH_NOMATCH); |
| 2046 | ecode++; |
| 2047 | break; |
| 2048 | |
| 2049 | /* Start of match assertion */ |
| 2050 | |
| 2051 | case OP_SOM: |
| 2052 | if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH); |
| 2053 | ecode++; |
| 2054 | break; |
| 2055 | |
| 2056 | /* Reset the start of match point */ |
| 2057 | |
| 2058 | case OP_SET_SOM: |
| 2059 | mstart = eptr; |
| 2060 | ecode++; |
| 2061 | break; |
| 2062 | |
| 2063 | /* Multiline mode: assert before any newline, or before end of subject |
| 2064 | unless noteol is set. */ |
| 2065 | |
| 2066 | case OP_DOLLM: |
| 2067 | if (eptr < md->end_subject) |
| 2068 | { |
| 2069 | if (!IS_NEWLINE(eptr)) |
| 2070 | { |
| 2071 | if (md->partial != 0 && |
| 2072 | eptr + 1 >= md->end_subject && |
| 2073 | NLBLOCK->nltype == NLTYPE_FIXED && |
| 2074 | NLBLOCK->nllen == 2 && |
| 2075 | *eptr == NLBLOCK->nl[0]) |
| 2076 | { |
| 2077 | md->hitend = TRUE; |
| 2078 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 2079 | } |
| 2080 | RRETURN(MATCH_NOMATCH); |
| 2081 | } |
| 2082 | } |
| 2083 | else |
| 2084 | { |
| 2085 | if (md->noteol) RRETURN(MATCH_NOMATCH); |
| 2086 | SCHECK_PARTIAL(); |
| 2087 | } |
| 2088 | ecode++; |
| 2089 | break; |
| 2090 | |
| 2091 | /* Not multiline mode: assert before a terminating newline or before end of |
| 2092 | subject unless noteol is set. */ |
| 2093 | |
| 2094 | case OP_DOLL: |
| 2095 | if (md->noteol) RRETURN(MATCH_NOMATCH); |
| 2096 | if (!md->endonly) goto ASSERT_NL_OR_EOS; |
| 2097 | |
| 2098 | /* ... else fall through for endonly */ |
| 2099 | |
| 2100 | /* End of subject assertion (\z) */ |
| 2101 | |
| 2102 | case OP_EOD: |
| 2103 | if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH); |
| 2104 | SCHECK_PARTIAL(); |
| 2105 | ecode++; |
| 2106 | break; |
| 2107 | |
| 2108 | /* End of subject or ending \n assertion (\Z) */ |
| 2109 | |
| 2110 | case OP_EODN: |
| 2111 | ASSERT_NL_OR_EOS: |
| 2112 | if (eptr < md->end_subject && |
| 2113 | (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) |
| 2114 | { |
| 2115 | if (md->partial != 0 && |
| 2116 | eptr + 1 >= md->end_subject && |
| 2117 | NLBLOCK->nltype == NLTYPE_FIXED && |
| 2118 | NLBLOCK->nllen == 2 && |
| 2119 | *eptr == NLBLOCK->nl[0]) |
| 2120 | { |
| 2121 | md->hitend = TRUE; |
| 2122 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 2123 | } |
| 2124 | RRETURN(MATCH_NOMATCH); |
| 2125 | } |
| 2126 | |
| 2127 | /* Either at end of string or \n before end. */ |
| 2128 | |
| 2129 | SCHECK_PARTIAL(); |
| 2130 | ecode++; |
| 2131 | break; |
| 2132 | |
| 2133 | /* Word boundary assertions */ |
| 2134 | |
| 2135 | case OP_NOT_WORD_BOUNDARY: |
| 2136 | case OP_WORD_BOUNDARY: |
| 2137 | { |
| 2138 | |
| 2139 | /* Find out if the previous and current characters are "word" characters. |
| 2140 | It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to |
| 2141 | be "non-word" characters. Remember the earliest consulted character for |
| 2142 | partial matching. */ |
| 2143 | |
| 2144 | #ifdef SUPPORT_UTF |
| 2145 | if (utf) |
| 2146 | { |
| 2147 | /* Get status of previous character */ |
| 2148 | |
| 2149 | if (eptr == md->start_subject) prev_is_word = FALSE; else |
| 2150 | { |
| 2151 | PCRE_PUCHAR lastptr = eptr - 1; |
| 2152 | BACKCHAR(lastptr); |
| 2153 | if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr; |
| 2154 | GETCHAR(c, lastptr); |
| 2155 | #ifdef SUPPORT_UCP |
| 2156 | if (md->use_ucp) |
| 2157 | { |
| 2158 | if (c == '_') prev_is_word = TRUE; else |
| 2159 | { |
| 2160 | int cat = UCD_CATEGORY(c); |
| 2161 | prev_is_word = (cat == ucp_L || cat == ucp_N); |
| 2162 | } |
| 2163 | } |
| 2164 | else |
| 2165 | #endif |
| 2166 | prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
| 2167 | } |
| 2168 | |
| 2169 | /* Get status of next character */ |
| 2170 | |
| 2171 | if (eptr >= md->end_subject) |
| 2172 | { |
| 2173 | SCHECK_PARTIAL(); |
| 2174 | cur_is_word = FALSE; |
| 2175 | } |
| 2176 | else |
| 2177 | { |
| 2178 | GETCHAR(c, eptr); |
| 2179 | #ifdef SUPPORT_UCP |
| 2180 | if (md->use_ucp) |
| 2181 | { |
| 2182 | if (c == '_') cur_is_word = TRUE; else |
| 2183 | { |
| 2184 | int cat = UCD_CATEGORY(c); |
| 2185 | cur_is_word = (cat == ucp_L || cat == ucp_N); |
| 2186 | } |
| 2187 | } |
| 2188 | else |
| 2189 | #endif |
| 2190 | cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
| 2191 | } |
| 2192 | } |
| 2193 | else |
| 2194 | #endif |
| 2195 | |
| 2196 | /* Not in UTF-8 mode, but we may still have PCRE_UCP set, and for |
| 2197 | consistency with the behaviour of \w we do use it in this case. */ |
| 2198 | |
| 2199 | { |
| 2200 | /* Get status of previous character */ |
| 2201 | |
| 2202 | if (eptr == md->start_subject) prev_is_word = FALSE; else |
| 2203 | { |
| 2204 | if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1; |
| 2205 | #ifdef SUPPORT_UCP |
| 2206 | if (md->use_ucp) |
| 2207 | { |
| 2208 | c = eptr[-1]; |
| 2209 | if (c == '_') prev_is_word = TRUE; else |
| 2210 | { |
| 2211 | int cat = UCD_CATEGORY(c); |
| 2212 | prev_is_word = (cat == ucp_L || cat == ucp_N); |
| 2213 | } |
| 2214 | } |
| 2215 | else |
| 2216 | #endif |
| 2217 | prev_is_word = MAX_255(eptr[-1]) |
| 2218 | && ((md->ctypes[eptr[-1]] & ctype_word) != 0); |
| 2219 | } |
| 2220 | |
| 2221 | /* Get status of next character */ |
| 2222 | |
| 2223 | if (eptr >= md->end_subject) |
| 2224 | { |
| 2225 | SCHECK_PARTIAL(); |
| 2226 | cur_is_word = FALSE; |
| 2227 | } |
| 2228 | else |
| 2229 | #ifdef SUPPORT_UCP |
| 2230 | if (md->use_ucp) |
| 2231 | { |
| 2232 | c = *eptr; |
| 2233 | if (c == '_') cur_is_word = TRUE; else |
| 2234 | { |
| 2235 | int cat = UCD_CATEGORY(c); |
| 2236 | cur_is_word = (cat == ucp_L || cat == ucp_N); |
| 2237 | } |
| 2238 | } |
| 2239 | else |
| 2240 | #endif |
| 2241 | cur_is_word = MAX_255(*eptr) |
| 2242 | && ((md->ctypes[*eptr] & ctype_word) != 0); |
| 2243 | } |
| 2244 | |
| 2245 | /* Now see if the situation is what we want */ |
| 2246 | |
| 2247 | if ((*ecode++ == OP_WORD_BOUNDARY)? |
| 2248 | cur_is_word == prev_is_word : cur_is_word != prev_is_word) |
| 2249 | RRETURN(MATCH_NOMATCH); |
| 2250 | } |
| 2251 | break; |
| 2252 | |
| 2253 | /* Match any single character type except newline; have to take care with |
| 2254 | CRLF newlines and partial matching. */ |
| 2255 | |
| 2256 | case OP_ANY: |
| 2257 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); |
| 2258 | if (md->partial != 0 && |
| 2259 | eptr + 1 >= md->end_subject && |
| 2260 | NLBLOCK->nltype == NLTYPE_FIXED && |
| 2261 | NLBLOCK->nllen == 2 && |
| 2262 | *eptr == NLBLOCK->nl[0]) |
| 2263 | { |
| 2264 | md->hitend = TRUE; |
| 2265 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 2266 | } |
| 2267 | |
| 2268 | /* Fall through */ |
| 2269 | |
| 2270 | /* Match any single character whatsoever. */ |
| 2271 | |
| 2272 | case OP_ALLANY: |
| 2273 | if (eptr >= md->end_subject) /* DO NOT merge the eptr++ here; it must */ |
| 2274 | { /* not be updated before SCHECK_PARTIAL. */ |
| 2275 | SCHECK_PARTIAL(); |
| 2276 | RRETURN(MATCH_NOMATCH); |
| 2277 | } |
| 2278 | eptr++; |
| 2279 | #ifdef SUPPORT_UTF |
| 2280 | if (utf) ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++); |
| 2281 | #endif |
| 2282 | ecode++; |
| 2283 | break; |
| 2284 | |
| 2285 | /* Match a single byte, even in UTF-8 mode. This opcode really does match |
| 2286 | any byte, even newline, independent of the setting of PCRE_DOTALL. */ |
| 2287 | |
| 2288 | case OP_ANYBYTE: |
| 2289 | if (eptr >= md->end_subject) /* DO NOT merge the eptr++ here; it must */ |
| 2290 | { /* not be updated before SCHECK_PARTIAL. */ |
| 2291 | SCHECK_PARTIAL(); |
| 2292 | RRETURN(MATCH_NOMATCH); |
| 2293 | } |
| 2294 | eptr++; |
| 2295 | ecode++; |
| 2296 | break; |
| 2297 | |
| 2298 | case OP_NOT_DIGIT: |
| 2299 | if (eptr >= md->end_subject) |
| 2300 | { |
| 2301 | SCHECK_PARTIAL(); |
| 2302 | RRETURN(MATCH_NOMATCH); |
| 2303 | } |
| 2304 | GETCHARINCTEST(c, eptr); |
| 2305 | if ( |
| 2306 | #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8) |
| 2307 | c < 256 && |
| 2308 | #endif |
| 2309 | (md->ctypes[c] & ctype_digit) != 0 |
| 2310 | ) |
| 2311 | RRETURN(MATCH_NOMATCH); |
| 2312 | ecode++; |
| 2313 | break; |
| 2314 | |
| 2315 | case OP_DIGIT: |
| 2316 | if (eptr >= md->end_subject) |
| 2317 | { |
| 2318 | SCHECK_PARTIAL(); |
| 2319 | RRETURN(MATCH_NOMATCH); |
| 2320 | } |
| 2321 | GETCHARINCTEST(c, eptr); |
| 2322 | if ( |
| 2323 | #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8) |
| 2324 | c > 255 || |
| 2325 | #endif |
| 2326 | (md->ctypes[c] & ctype_digit) == 0 |
| 2327 | ) |
| 2328 | RRETURN(MATCH_NOMATCH); |
| 2329 | ecode++; |
| 2330 | break; |
| 2331 | |
| 2332 | case OP_NOT_WHITESPACE: |
| 2333 | if (eptr >= md->end_subject) |
| 2334 | { |
| 2335 | SCHECK_PARTIAL(); |
| 2336 | RRETURN(MATCH_NOMATCH); |
| 2337 | } |
| 2338 | GETCHARINCTEST(c, eptr); |
| 2339 | if ( |
| 2340 | #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8) |
| 2341 | c < 256 && |
| 2342 | #endif |
| 2343 | (md->ctypes[c] & ctype_space) != 0 |
| 2344 | ) |
| 2345 | RRETURN(MATCH_NOMATCH); |
| 2346 | ecode++; |
| 2347 | break; |
| 2348 | |
| 2349 | case OP_WHITESPACE: |
| 2350 | if (eptr >= md->end_subject) |
| 2351 | { |
| 2352 | SCHECK_PARTIAL(); |
| 2353 | RRETURN(MATCH_NOMATCH); |
| 2354 | } |
| 2355 | GETCHARINCTEST(c, eptr); |
| 2356 | if ( |
| 2357 | #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8) |
| 2358 | c > 255 || |
| 2359 | #endif |
| 2360 | (md->ctypes[c] & ctype_space) == 0 |
| 2361 | ) |
| 2362 | RRETURN(MATCH_NOMATCH); |
| 2363 | ecode++; |
| 2364 | break; |
| 2365 | |
| 2366 | case OP_NOT_WORDCHAR: |
| 2367 | if (eptr >= md->end_subject) |
| 2368 | { |
| 2369 | SCHECK_PARTIAL(); |
| 2370 | RRETURN(MATCH_NOMATCH); |
| 2371 | } |
| 2372 | GETCHARINCTEST(c, eptr); |
| 2373 | if ( |
| 2374 | #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8) |
| 2375 | c < 256 && |
| 2376 | #endif |
| 2377 | (md->ctypes[c] & ctype_word) != 0 |
| 2378 | ) |
| 2379 | RRETURN(MATCH_NOMATCH); |
| 2380 | ecode++; |
| 2381 | break; |
| 2382 | |
| 2383 | case OP_WORDCHAR: |
| 2384 | if (eptr >= md->end_subject) |
| 2385 | { |
| 2386 | SCHECK_PARTIAL(); |
| 2387 | RRETURN(MATCH_NOMATCH); |
| 2388 | } |
| 2389 | GETCHARINCTEST(c, eptr); |
| 2390 | if ( |
| 2391 | #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8) |
| 2392 | c > 255 || |
| 2393 | #endif |
| 2394 | (md->ctypes[c] & ctype_word) == 0 |
| 2395 | ) |
| 2396 | RRETURN(MATCH_NOMATCH); |
| 2397 | ecode++; |
| 2398 | break; |
| 2399 | |
| 2400 | case OP_ANYNL: |
| 2401 | if (eptr >= md->end_subject) |
| 2402 | { |
| 2403 | SCHECK_PARTIAL(); |
| 2404 | RRETURN(MATCH_NOMATCH); |
| 2405 | } |
| 2406 | GETCHARINCTEST(c, eptr); |
| 2407 | switch(c) |
| 2408 | { |
| 2409 | default: RRETURN(MATCH_NOMATCH); |
| 2410 | |
| 2411 | case 0x000d: |
| 2412 | if (eptr >= md->end_subject) |
| 2413 | { |
| 2414 | SCHECK_PARTIAL(); |
| 2415 | } |
| 2416 | else if (*eptr == 0x0a) eptr++; |
| 2417 | break; |
| 2418 | |
| 2419 | case 0x000a: |
| 2420 | break; |
| 2421 | |
| 2422 | case 0x000b: |
| 2423 | case 0x000c: |
| 2424 | case 0x0085: |
| 2425 | case 0x2028: |
| 2426 | case 0x2029: |
| 2427 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); |
| 2428 | break; |
| 2429 | } |
| 2430 | ecode++; |
| 2431 | break; |
| 2432 | |
| 2433 | case OP_NOT_HSPACE: |
| 2434 | if (eptr >= md->end_subject) |
| 2435 | { |
| 2436 | SCHECK_PARTIAL(); |
| 2437 | RRETURN(MATCH_NOMATCH); |
| 2438 | } |
| 2439 | GETCHARINCTEST(c, eptr); |
| 2440 | switch(c) |
| 2441 | { |
| 2442 | default: break; |
| 2443 | case 0x09: /* HT */ |
| 2444 | case 0x20: /* SPACE */ |
| 2445 | case 0xa0: /* NBSP */ |
| 2446 | case 0x1680: /* OGHAM SPACE MARK */ |
| 2447 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 2448 | case 0x2000: /* EN QUAD */ |
| 2449 | case 0x2001: /* EM QUAD */ |
| 2450 | case 0x2002: /* EN SPACE */ |
| 2451 | case 0x2003: /* EM SPACE */ |
| 2452 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 2453 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 2454 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 2455 | case 0x2007: /* FIGURE SPACE */ |
| 2456 | case 0x2008: /* PUNCTUATION SPACE */ |
| 2457 | case 0x2009: /* THIN SPACE */ |
| 2458 | case 0x200A: /* HAIR SPACE */ |
| 2459 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 2460 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 2461 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 2462 | RRETURN(MATCH_NOMATCH); |
| 2463 | } |
| 2464 | ecode++; |
| 2465 | break; |
| 2466 | |
| 2467 | case OP_HSPACE: |
| 2468 | if (eptr >= md->end_subject) |
| 2469 | { |
| 2470 | SCHECK_PARTIAL(); |
| 2471 | RRETURN(MATCH_NOMATCH); |
| 2472 | } |
| 2473 | GETCHARINCTEST(c, eptr); |
| 2474 | switch(c) |
| 2475 | { |
| 2476 | default: RRETURN(MATCH_NOMATCH); |
| 2477 | case 0x09: /* HT */ |
| 2478 | case 0x20: /* SPACE */ |
| 2479 | case 0xa0: /* NBSP */ |
| 2480 | case 0x1680: /* OGHAM SPACE MARK */ |
| 2481 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 2482 | case 0x2000: /* EN QUAD */ |
| 2483 | case 0x2001: /* EM QUAD */ |
| 2484 | case 0x2002: /* EN SPACE */ |
| 2485 | case 0x2003: /* EM SPACE */ |
| 2486 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 2487 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 2488 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 2489 | case 0x2007: /* FIGURE SPACE */ |
| 2490 | case 0x2008: /* PUNCTUATION SPACE */ |
| 2491 | case 0x2009: /* THIN SPACE */ |
| 2492 | case 0x200A: /* HAIR SPACE */ |
| 2493 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 2494 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 2495 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 2496 | break; |
| 2497 | } |
| 2498 | ecode++; |
| 2499 | break; |
| 2500 | |
| 2501 | case OP_NOT_VSPACE: |
| 2502 | if (eptr >= md->end_subject) |
| 2503 | { |
| 2504 | SCHECK_PARTIAL(); |
| 2505 | RRETURN(MATCH_NOMATCH); |
| 2506 | } |
| 2507 | GETCHARINCTEST(c, eptr); |
| 2508 | switch(c) |
| 2509 | { |
| 2510 | default: break; |
| 2511 | case 0x0a: /* LF */ |
| 2512 | case 0x0b: /* VT */ |
| 2513 | case 0x0c: /* FF */ |
| 2514 | case 0x0d: /* CR */ |
| 2515 | case 0x85: /* NEL */ |
| 2516 | case 0x2028: /* LINE SEPARATOR */ |
| 2517 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 2518 | RRETURN(MATCH_NOMATCH); |
| 2519 | } |
| 2520 | ecode++; |
| 2521 | break; |
| 2522 | |
| 2523 | case OP_VSPACE: |
| 2524 | if (eptr >= md->end_subject) |
| 2525 | { |
| 2526 | SCHECK_PARTIAL(); |
| 2527 | RRETURN(MATCH_NOMATCH); |
| 2528 | } |
| 2529 | GETCHARINCTEST(c, eptr); |
| 2530 | switch(c) |
| 2531 | { |
| 2532 | default: RRETURN(MATCH_NOMATCH); |
| 2533 | case 0x0a: /* LF */ |
| 2534 | case 0x0b: /* VT */ |
| 2535 | case 0x0c: /* FF */ |
| 2536 | case 0x0d: /* CR */ |
| 2537 | case 0x85: /* NEL */ |
| 2538 | case 0x2028: /* LINE SEPARATOR */ |
| 2539 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 2540 | break; |
| 2541 | } |
| 2542 | ecode++; |
| 2543 | break; |
| 2544 | |
| 2545 | #ifdef SUPPORT_UCP |
| 2546 | /* Check the next character by Unicode property. We will get here only |
| 2547 | if the support is in the binary; otherwise a compile-time error occurs. */ |
| 2548 | |
| 2549 | case OP_PROP: |
| 2550 | case OP_NOTPROP: |
| 2551 | if (eptr >= md->end_subject) |
| 2552 | { |
| 2553 | SCHECK_PARTIAL(); |
| 2554 | RRETURN(MATCH_NOMATCH); |
| 2555 | } |
| 2556 | GETCHARINCTEST(c, eptr); |
| 2557 | { |
| 2558 | const ucd_record *prop = GET_UCD(c); |
| 2559 | |
| 2560 | switch(ecode[1]) |
| 2561 | { |
| 2562 | case PT_ANY: |
| 2563 | if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH); |
| 2564 | break; |
| 2565 | |
| 2566 | case PT_LAMP: |
| 2567 | if ((prop->chartype == ucp_Lu || |
| 2568 | prop->chartype == ucp_Ll || |
| 2569 | prop->chartype == ucp_Lt) == (op == OP_NOTPROP)) |
| 2570 | RRETURN(MATCH_NOMATCH); |
| 2571 | break; |
| 2572 | |
| 2573 | case PT_GC: |
| 2574 | if ((ecode[2] != PRIV(ucp_gentype)[prop->chartype]) == (op == OP_PROP)) |
| 2575 | RRETURN(MATCH_NOMATCH); |
| 2576 | break; |
| 2577 | |
| 2578 | case PT_PC: |
| 2579 | if ((ecode[2] != prop->chartype) == (op == OP_PROP)) |
| 2580 | RRETURN(MATCH_NOMATCH); |
| 2581 | break; |
| 2582 | |
| 2583 | case PT_SC: |
| 2584 | if ((ecode[2] != prop->script) == (op == OP_PROP)) |
| 2585 | RRETURN(MATCH_NOMATCH); |
| 2586 | break; |
| 2587 | |
| 2588 | /* These are specials */ |
| 2589 | |
| 2590 | case PT_ALNUM: |
| 2591 | if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L || |
| 2592 | PRIV(ucp_gentype)[prop->chartype] == ucp_N) == (op == OP_NOTPROP)) |
| 2593 | RRETURN(MATCH_NOMATCH); |
| 2594 | break; |
| 2595 | |
| 2596 | case PT_SPACE: /* Perl space */ |
| 2597 | if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z || |
| 2598 | c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR) |
| 2599 | == (op == OP_NOTPROP)) |
| 2600 | RRETURN(MATCH_NOMATCH); |
| 2601 | break; |
| 2602 | |
| 2603 | case PT_PXSPACE: /* POSIX space */ |
| 2604 | if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z || |
| 2605 | c == CHAR_HT || c == CHAR_NL || c == CHAR_VT || |
| 2606 | c == CHAR_FF || c == CHAR_CR) |
| 2607 | == (op == OP_NOTPROP)) |
| 2608 | RRETURN(MATCH_NOMATCH); |
| 2609 | break; |
| 2610 | |
| 2611 | case PT_WORD: |
| 2612 | if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L || |
| 2613 | PRIV(ucp_gentype)[prop->chartype] == ucp_N || |
| 2614 | c == CHAR_UNDERSCORE) == (op == OP_NOTPROP)) |
| 2615 | RRETURN(MATCH_NOMATCH); |
| 2616 | break; |
| 2617 | |
| 2618 | /* This should never occur */ |
| 2619 | |
| 2620 | default: |
| 2621 | RRETURN(PCRE_ERROR_INTERNAL); |
| 2622 | } |
| 2623 | |
| 2624 | ecode += 3; |
| 2625 | } |
| 2626 | break; |
| 2627 | |
| 2628 | /* Match an extended Unicode sequence. We will get here only if the support |
| 2629 | is in the binary; otherwise a compile-time error occurs. */ |
| 2630 | |
| 2631 | case OP_EXTUNI: |
| 2632 | if (eptr >= md->end_subject) |
| 2633 | { |
| 2634 | SCHECK_PARTIAL(); |
| 2635 | RRETURN(MATCH_NOMATCH); |
| 2636 | } |
| 2637 | GETCHARINCTEST(c, eptr); |
| 2638 | if (UCD_CATEGORY(c) == ucp_M) RRETURN(MATCH_NOMATCH); |
| 2639 | while (eptr < md->end_subject) |
| 2640 | { |
| 2641 | int len = 1; |
| 2642 | if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); } |
| 2643 | if (UCD_CATEGORY(c) != ucp_M) break; |
| 2644 | eptr += len; |
| 2645 | } |
| 2646 | CHECK_PARTIAL(); |
| 2647 | ecode++; |
| 2648 | break; |
| 2649 | #endif |
| 2650 | |
| 2651 | |
| 2652 | /* Match a back reference, possibly repeatedly. Look past the end of the |
| 2653 | item to see if there is repeat information following. The code is similar |
| 2654 | to that for character classes, but repeated for efficiency. Then obey |
| 2655 | similar code to character type repeats - written out again for speed. |
| 2656 | However, if the referenced string is the empty string, always treat |
| 2657 | it as matched, any number of times (otherwise there could be infinite |
| 2658 | loops). */ |
| 2659 | |
| 2660 | case OP_REF: |
| 2661 | case OP_REFI: |
| 2662 | caseless = op == OP_REFI; |
| 2663 | offset = GET2(ecode, 1) << 1; /* Doubled ref number */ |
| 2664 | ecode += 1 + IMM2_SIZE; |
| 2665 | |
| 2666 | /* If the reference is unset, there are two possibilities: |
| 2667 | |
| 2668 | (a) In the default, Perl-compatible state, set the length negative; |
| 2669 | this ensures that every attempt at a match fails. We can't just fail |
| 2670 | here, because of the possibility of quantifiers with zero minima. |
| 2671 | |
| 2672 | (b) If the JavaScript compatibility flag is set, set the length to zero |
| 2673 | so that the back reference matches an empty string. |
| 2674 | |
| 2675 | Otherwise, set the length to the length of what was matched by the |
| 2676 | referenced subpattern. */ |
| 2677 | |
| 2678 | if (offset >= offset_top || md->offset_vector[offset] < 0) |
| 2679 | length = (md->jscript_compat)? 0 : -1; |
| 2680 | else |
| 2681 | length = md->offset_vector[offset+1] - md->offset_vector[offset]; |
| 2682 | |
| 2683 | /* Set up for repetition, or handle the non-repeated case */ |
| 2684 | |
| 2685 | switch (*ecode) |
| 2686 | { |
| 2687 | case OP_CRSTAR: |
| 2688 | case OP_CRMINSTAR: |
| 2689 | case OP_CRPLUS: |
| 2690 | case OP_CRMINPLUS: |
| 2691 | case OP_CRQUERY: |
| 2692 | case OP_CRMINQUERY: |
| 2693 | c = *ecode++ - OP_CRSTAR; |
| 2694 | minimize = (c & 1) != 0; |
| 2695 | min = rep_min[c]; /* Pick up values from tables; */ |
| 2696 | max = rep_max[c]; /* zero for max => infinity */ |
| 2697 | if (max == 0) max = INT_MAX; |
| 2698 | break; |
| 2699 | |
| 2700 | case OP_CRRANGE: |
| 2701 | case OP_CRMINRANGE: |
| 2702 | minimize = (*ecode == OP_CRMINRANGE); |
| 2703 | min = GET2(ecode, 1); |
| 2704 | max = GET2(ecode, 1 + IMM2_SIZE); |
| 2705 | if (max == 0) max = INT_MAX; |
| 2706 | ecode += 1 + 2 * IMM2_SIZE; |
| 2707 | break; |
| 2708 | |
| 2709 | default: /* No repeat follows */ |
| 2710 | if ((length = match_ref(offset, eptr, length, md, caseless)) < 0) |
| 2711 | { |
| 2712 | if (length == -2) eptr = md->end_subject; /* Partial match */ |
| 2713 | CHECK_PARTIAL(); |
| 2714 | RRETURN(MATCH_NOMATCH); |
| 2715 | } |
| 2716 | eptr += length; |
| 2717 | continue; /* With the main loop */ |
| 2718 | } |
| 2719 | |
| 2720 | /* Handle repeated back references. If the length of the reference is |
| 2721 | zero, just continue with the main loop. If the length is negative, it |
| 2722 | means the reference is unset in non-Java-compatible mode. If the minimum is |
| 2723 | zero, we can continue at the same level without recursion. For any other |
| 2724 | minimum, carrying on will result in NOMATCH. */ |
| 2725 | |
| 2726 | if (length == 0) continue; |
| 2727 | if (length < 0 && min == 0) continue; |
| 2728 | |
| 2729 | /* First, ensure the minimum number of matches are present. We get back |
| 2730 | the length of the reference string explicitly rather than passing the |
| 2731 | address of eptr, so that eptr can be a register variable. */ |
| 2732 | |
| 2733 | for (i = 1; i <= min; i++) |
| 2734 | { |
| 2735 | int slength; |
| 2736 | if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0) |
| 2737 | { |
| 2738 | if (slength == -2) eptr = md->end_subject; /* Partial match */ |
| 2739 | CHECK_PARTIAL(); |
| 2740 | RRETURN(MATCH_NOMATCH); |
| 2741 | } |
| 2742 | eptr += slength; |
| 2743 | } |
| 2744 | |
| 2745 | /* If min = max, continue at the same level without recursion. |
| 2746 | They are not both allowed to be zero. */ |
| 2747 | |
| 2748 | if (min == max) continue; |
| 2749 | |
| 2750 | /* If minimizing, keep trying and advancing the pointer */ |
| 2751 | |
| 2752 | if (minimize) |
| 2753 | { |
| 2754 | for (fi = min;; fi++) |
| 2755 | { |
| 2756 | int slength; |
| 2757 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM14); |
| 2758 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2759 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2760 | if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0) |
| 2761 | { |
| 2762 | if (slength == -2) eptr = md->end_subject; /* Partial match */ |
| 2763 | CHECK_PARTIAL(); |
| 2764 | RRETURN(MATCH_NOMATCH); |
| 2765 | } |
| 2766 | eptr += slength; |
| 2767 | } |
| 2768 | /* Control never gets here */ |
| 2769 | } |
| 2770 | |
| 2771 | /* If maximizing, find the longest string and work backwards */ |
| 2772 | |
| 2773 | else |
| 2774 | { |
| 2775 | pp = eptr; |
| 2776 | for (i = min; i < max; i++) |
| 2777 | { |
| 2778 | int slength; |
| 2779 | if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0) |
| 2780 | { |
| 2781 | /* Can't use CHECK_PARTIAL because we don't want to update eptr in |
| 2782 | the soft partial matching case. */ |
| 2783 | |
| 2784 | if (slength == -2 && md->partial != 0 && |
| 2785 | md->end_subject > md->start_used_ptr) |
| 2786 | { |
| 2787 | md->hitend = TRUE; |
| 2788 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 2789 | } |
| 2790 | break; |
| 2791 | } |
| 2792 | eptr += slength; |
| 2793 | } |
| 2794 | |
| 2795 | while (eptr >= pp) |
| 2796 | { |
| 2797 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM15); |
| 2798 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2799 | eptr -= length; |
| 2800 | } |
| 2801 | RRETURN(MATCH_NOMATCH); |
| 2802 | } |
| 2803 | /* Control never gets here */ |
| 2804 | |
| 2805 | /* Match a bit-mapped character class, possibly repeatedly. This op code is |
| 2806 | used when all the characters in the class have values in the range 0-255, |
| 2807 | and either the matching is caseful, or the characters are in the range |
| 2808 | 0-127 when UTF-8 processing is enabled. The only difference between |
| 2809 | OP_CLASS and OP_NCLASS occurs when a data character outside the range is |
| 2810 | encountered. |
| 2811 | |
| 2812 | First, look past the end of the item to see if there is repeat information |
| 2813 | following. Then obey similar code to character type repeats - written out |
| 2814 | again for speed. */ |
| 2815 | |
| 2816 | case OP_NCLASS: |
| 2817 | case OP_CLASS: |
| 2818 | { |
| 2819 | /* The data variable is saved across frames, so the byte map needs to |
| 2820 | be stored there. */ |
| 2821 | #define BYTE_MAP ((pcre_uint8 *)data) |
| 2822 | data = ecode + 1; /* Save for matching */ |
| 2823 | ecode += 1 + (32 / sizeof(pcre_uchar)); /* Advance past the item */ |
| 2824 | |
| 2825 | switch (*ecode) |
| 2826 | { |
| 2827 | case OP_CRSTAR: |
| 2828 | case OP_CRMINSTAR: |
| 2829 | case OP_CRPLUS: |
| 2830 | case OP_CRMINPLUS: |
| 2831 | case OP_CRQUERY: |
| 2832 | case OP_CRMINQUERY: |
| 2833 | c = *ecode++ - OP_CRSTAR; |
| 2834 | minimize = (c & 1) != 0; |
| 2835 | min = rep_min[c]; /* Pick up values from tables; */ |
| 2836 | max = rep_max[c]; /* zero for max => infinity */ |
| 2837 | if (max == 0) max = INT_MAX; |
| 2838 | break; |
| 2839 | |
| 2840 | case OP_CRRANGE: |
| 2841 | case OP_CRMINRANGE: |
| 2842 | minimize = (*ecode == OP_CRMINRANGE); |
| 2843 | min = GET2(ecode, 1); |
| 2844 | max = GET2(ecode, 1 + IMM2_SIZE); |
| 2845 | if (max == 0) max = INT_MAX; |
| 2846 | ecode += 1 + 2 * IMM2_SIZE; |
| 2847 | break; |
| 2848 | |
| 2849 | default: /* No repeat follows */ |
| 2850 | min = max = 1; |
| 2851 | break; |
| 2852 | } |
| 2853 | |
| 2854 | /* First, ensure the minimum number of matches are present. */ |
| 2855 | |
| 2856 | #ifdef SUPPORT_UTF |
| 2857 | if (utf) |
| 2858 | { |
| 2859 | for (i = 1; i <= min; i++) |
| 2860 | { |
| 2861 | if (eptr >= md->end_subject) |
| 2862 | { |
| 2863 | SCHECK_PARTIAL(); |
| 2864 | RRETURN(MATCH_NOMATCH); |
| 2865 | } |
| 2866 | GETCHARINC(c, eptr); |
| 2867 | if (c > 255) |
| 2868 | { |
| 2869 | if (op == OP_CLASS) RRETURN(MATCH_NOMATCH); |
| 2870 | } |
| 2871 | else |
| 2872 | if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); |
| 2873 | } |
| 2874 | } |
| 2875 | else |
| 2876 | #endif |
| 2877 | /* Not UTF mode */ |
| 2878 | { |
| 2879 | for (i = 1; i <= min; i++) |
| 2880 | { |
| 2881 | if (eptr >= md->end_subject) |
| 2882 | { |
| 2883 | SCHECK_PARTIAL(); |
| 2884 | RRETURN(MATCH_NOMATCH); |
| 2885 | } |
| 2886 | c = *eptr++; |
| 2887 | #ifndef COMPILE_PCRE8 |
| 2888 | if (c > 255) |
| 2889 | { |
| 2890 | if (op == OP_CLASS) RRETURN(MATCH_NOMATCH); |
| 2891 | } |
| 2892 | else |
| 2893 | #endif |
| 2894 | if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | /* If max == min we can continue with the main loop without the |
| 2899 | need to recurse. */ |
| 2900 | |
| 2901 | if (min == max) continue; |
| 2902 | |
| 2903 | /* If minimizing, keep testing the rest of the expression and advancing |
| 2904 | the pointer while it matches the class. */ |
| 2905 | |
| 2906 | if (minimize) |
| 2907 | { |
| 2908 | #ifdef SUPPORT_UTF |
| 2909 | if (utf) |
| 2910 | { |
| 2911 | for (fi = min;; fi++) |
| 2912 | { |
| 2913 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM16); |
| 2914 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2915 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2916 | if (eptr >= md->end_subject) |
| 2917 | { |
| 2918 | SCHECK_PARTIAL(); |
| 2919 | RRETURN(MATCH_NOMATCH); |
| 2920 | } |
| 2921 | GETCHARINC(c, eptr); |
| 2922 | if (c > 255) |
| 2923 | { |
| 2924 | if (op == OP_CLASS) RRETURN(MATCH_NOMATCH); |
| 2925 | } |
| 2926 | else |
| 2927 | if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); |
| 2928 | } |
| 2929 | } |
| 2930 | else |
| 2931 | #endif |
| 2932 | /* Not UTF mode */ |
| 2933 | { |
| 2934 | for (fi = min;; fi++) |
| 2935 | { |
| 2936 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM17); |
| 2937 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2938 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 2939 | if (eptr >= md->end_subject) |
| 2940 | { |
| 2941 | SCHECK_PARTIAL(); |
| 2942 | RRETURN(MATCH_NOMATCH); |
| 2943 | } |
| 2944 | c = *eptr++; |
| 2945 | #ifndef COMPILE_PCRE8 |
| 2946 | if (c > 255) |
| 2947 | { |
| 2948 | if (op == OP_CLASS) RRETURN(MATCH_NOMATCH); |
| 2949 | } |
| 2950 | else |
| 2951 | #endif |
| 2952 | if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH); |
| 2953 | } |
| 2954 | } |
| 2955 | /* Control never gets here */ |
| 2956 | } |
| 2957 | |
| 2958 | /* If maximizing, find the longest possible run, then work backwards. */ |
| 2959 | |
| 2960 | else |
| 2961 | { |
| 2962 | pp = eptr; |
| 2963 | |
| 2964 | #ifdef SUPPORT_UTF |
| 2965 | if (utf) |
| 2966 | { |
| 2967 | for (i = min; i < max; i++) |
| 2968 | { |
| 2969 | int len = 1; |
| 2970 | if (eptr >= md->end_subject) |
| 2971 | { |
| 2972 | SCHECK_PARTIAL(); |
| 2973 | break; |
| 2974 | } |
| 2975 | GETCHARLEN(c, eptr, len); |
| 2976 | if (c > 255) |
| 2977 | { |
| 2978 | if (op == OP_CLASS) break; |
| 2979 | } |
| 2980 | else |
| 2981 | if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) break; |
| 2982 | eptr += len; |
| 2983 | } |
| 2984 | for (;;) |
| 2985 | { |
| 2986 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM18); |
| 2987 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 2988 | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 2989 | BACKCHAR(eptr); |
| 2990 | } |
| 2991 | } |
| 2992 | else |
| 2993 | #endif |
| 2994 | /* Not UTF mode */ |
| 2995 | { |
| 2996 | for (i = min; i < max; i++) |
| 2997 | { |
| 2998 | if (eptr >= md->end_subject) |
| 2999 | { |
| 3000 | SCHECK_PARTIAL(); |
| 3001 | break; |
| 3002 | } |
| 3003 | c = *eptr; |
| 3004 | #ifndef COMPILE_PCRE8 |
| 3005 | if (c > 255) |
| 3006 | { |
| 3007 | if (op == OP_CLASS) break; |
| 3008 | } |
| 3009 | else |
| 3010 | #endif |
| 3011 | if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) break; |
| 3012 | eptr++; |
| 3013 | } |
| 3014 | while (eptr >= pp) |
| 3015 | { |
| 3016 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM19); |
| 3017 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3018 | eptr--; |
| 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | RRETURN(MATCH_NOMATCH); |
| 3023 | } |
| 3024 | #undef BYTE_MAP |
| 3025 | } |
| 3026 | /* Control never gets here */ |
| 3027 | |
| 3028 | |
| 3029 | /* Match an extended character class. This opcode is encountered only |
| 3030 | when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8 |
| 3031 | mode, because Unicode properties are supported in non-UTF-8 mode. */ |
| 3032 | |
| 3033 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 |
| 3034 | case OP_XCLASS: |
| 3035 | { |
| 3036 | data = ecode + 1 + LINK_SIZE; /* Save for matching */ |
| 3037 | ecode += GET(ecode, 1); /* Advance past the item */ |
| 3038 | |
| 3039 | switch (*ecode) |
| 3040 | { |
| 3041 | case OP_CRSTAR: |
| 3042 | case OP_CRMINSTAR: |
| 3043 | case OP_CRPLUS: |
| 3044 | case OP_CRMINPLUS: |
| 3045 | case OP_CRQUERY: |
| 3046 | case OP_CRMINQUERY: |
| 3047 | c = *ecode++ - OP_CRSTAR; |
| 3048 | minimize = (c & 1) != 0; |
| 3049 | min = rep_min[c]; /* Pick up values from tables; */ |
| 3050 | max = rep_max[c]; /* zero for max => infinity */ |
| 3051 | if (max == 0) max = INT_MAX; |
| 3052 | break; |
| 3053 | |
| 3054 | case OP_CRRANGE: |
| 3055 | case OP_CRMINRANGE: |
| 3056 | minimize = (*ecode == OP_CRMINRANGE); |
| 3057 | min = GET2(ecode, 1); |
| 3058 | max = GET2(ecode, 1 + IMM2_SIZE); |
| 3059 | if (max == 0) max = INT_MAX; |
| 3060 | ecode += 1 + 2 * IMM2_SIZE; |
| 3061 | break; |
| 3062 | |
| 3063 | default: /* No repeat follows */ |
| 3064 | min = max = 1; |
| 3065 | break; |
| 3066 | } |
| 3067 | |
| 3068 | /* First, ensure the minimum number of matches are present. */ |
| 3069 | |
| 3070 | for (i = 1; i <= min; i++) |
| 3071 | { |
| 3072 | if (eptr >= md->end_subject) |
| 3073 | { |
| 3074 | SCHECK_PARTIAL(); |
| 3075 | RRETURN(MATCH_NOMATCH); |
| 3076 | } |
| 3077 | GETCHARINCTEST(c, eptr); |
| 3078 | if (!PRIV(xclass)(c, data, utf)) RRETURN(MATCH_NOMATCH); |
| 3079 | } |
| 3080 | |
| 3081 | /* If max == min we can continue with the main loop without the |
| 3082 | need to recurse. */ |
| 3083 | |
| 3084 | if (min == max) continue; |
| 3085 | |
| 3086 | /* If minimizing, keep testing the rest of the expression and advancing |
| 3087 | the pointer while it matches the class. */ |
| 3088 | |
| 3089 | if (minimize) |
| 3090 | { |
| 3091 | for (fi = min;; fi++) |
| 3092 | { |
| 3093 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM20); |
| 3094 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3095 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3096 | if (eptr >= md->end_subject) |
| 3097 | { |
| 3098 | SCHECK_PARTIAL(); |
| 3099 | RRETURN(MATCH_NOMATCH); |
| 3100 | } |
| 3101 | GETCHARINCTEST(c, eptr); |
| 3102 | if (!PRIV(xclass)(c, data, utf)) RRETURN(MATCH_NOMATCH); |
| 3103 | } |
| 3104 | /* Control never gets here */ |
| 3105 | } |
| 3106 | |
| 3107 | /* If maximizing, find the longest possible run, then work backwards. */ |
| 3108 | |
| 3109 | else |
| 3110 | { |
| 3111 | pp = eptr; |
| 3112 | for (i = min; i < max; i++) |
| 3113 | { |
| 3114 | int len = 1; |
| 3115 | if (eptr >= md->end_subject) |
| 3116 | { |
| 3117 | SCHECK_PARTIAL(); |
| 3118 | break; |
| 3119 | } |
| 3120 | #ifdef SUPPORT_UTF |
| 3121 | GETCHARLENTEST(c, eptr, len); |
| 3122 | #else |
| 3123 | c = *eptr; |
| 3124 | #endif |
| 3125 | if (!PRIV(xclass)(c, data, utf)) break; |
| 3126 | eptr += len; |
| 3127 | } |
| 3128 | for(;;) |
| 3129 | { |
| 3130 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM21); |
| 3131 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3132 | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3133 | #ifdef SUPPORT_UTF |
| 3134 | if (utf) BACKCHAR(eptr); |
| 3135 | #endif |
| 3136 | } |
| 3137 | RRETURN(MATCH_NOMATCH); |
| 3138 | } |
| 3139 | |
| 3140 | /* Control never gets here */ |
| 3141 | } |
| 3142 | #endif /* End of XCLASS */ |
| 3143 | |
| 3144 | /* Match a single character, casefully */ |
| 3145 | |
| 3146 | case OP_CHAR: |
| 3147 | #ifdef SUPPORT_UTF |
| 3148 | if (utf) |
| 3149 | { |
| 3150 | length = 1; |
| 3151 | ecode++; |
| 3152 | GETCHARLEN(fc, ecode, length); |
| 3153 | if (length > md->end_subject - eptr) |
| 3154 | { |
| 3155 | CHECK_PARTIAL(); /* Not SCHECK_PARTIAL() */ |
| 3156 | RRETURN(MATCH_NOMATCH); |
| 3157 | } |
| 3158 | while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH); |
| 3159 | } |
| 3160 | else |
| 3161 | #endif |
| 3162 | /* Not UTF mode */ |
| 3163 | { |
| 3164 | if (md->end_subject - eptr < 1) |
| 3165 | { |
| 3166 | SCHECK_PARTIAL(); /* This one can use SCHECK_PARTIAL() */ |
| 3167 | RRETURN(MATCH_NOMATCH); |
| 3168 | } |
| 3169 | if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH); |
| 3170 | ecode += 2; |
| 3171 | } |
| 3172 | break; |
| 3173 | |
| 3174 | /* Match a single character, caselessly. If we are at the end of the |
| 3175 | subject, give up immediately. */ |
| 3176 | |
| 3177 | case OP_CHARI: |
| 3178 | if (eptr >= md->end_subject) |
| 3179 | { |
| 3180 | SCHECK_PARTIAL(); |
| 3181 | RRETURN(MATCH_NOMATCH); |
| 3182 | } |
| 3183 | |
| 3184 | #ifdef SUPPORT_UTF |
| 3185 | if (utf) |
| 3186 | { |
| 3187 | length = 1; |
| 3188 | ecode++; |
| 3189 | GETCHARLEN(fc, ecode, length); |
| 3190 | |
| 3191 | /* If the pattern character's value is < 128, we have only one byte, and |
| 3192 | we know that its other case must also be one byte long, so we can use the |
| 3193 | fast lookup table. We know that there is at least one byte left in the |
| 3194 | subject. */ |
| 3195 | |
| 3196 | if (fc < 128) |
| 3197 | { |
| 3198 | if (md->lcc[fc] |
| 3199 | != TABLE_GET(*eptr, md->lcc, *eptr)) RRETURN(MATCH_NOMATCH); |
| 3200 | ecode++; |
| 3201 | eptr++; |
| 3202 | } |
| 3203 | |
| 3204 | /* Otherwise we must pick up the subject character. Note that we cannot |
| 3205 | use the value of "length" to check for sufficient bytes left, because the |
| 3206 | other case of the character may have more or fewer bytes. */ |
| 3207 | |
| 3208 | else |
| 3209 | { |
| 3210 | unsigned int dc; |
| 3211 | GETCHARINC(dc, eptr); |
| 3212 | ecode += length; |
| 3213 | |
| 3214 | /* If we have Unicode property support, we can use it to test the other |
| 3215 | case of the character, if there is one. */ |
| 3216 | |
| 3217 | if (fc != dc) |
| 3218 | { |
| 3219 | #ifdef SUPPORT_UCP |
| 3220 | if (dc != UCD_OTHERCASE(fc)) |
| 3221 | #endif |
| 3222 | RRETURN(MATCH_NOMATCH); |
| 3223 | } |
| 3224 | } |
| 3225 | } |
| 3226 | else |
| 3227 | #endif /* SUPPORT_UTF */ |
| 3228 | |
| 3229 | /* Not UTF mode */ |
| 3230 | { |
| 3231 | if (TABLE_GET(ecode[1], md->lcc, ecode[1]) |
| 3232 | != TABLE_GET(*eptr, md->lcc, *eptr)) RRETURN(MATCH_NOMATCH); |
| 3233 | eptr++; |
| 3234 | ecode += 2; |
| 3235 | } |
| 3236 | break; |
| 3237 | |
| 3238 | /* Match a single character repeatedly. */ |
| 3239 | |
| 3240 | case OP_EXACT: |
| 3241 | case OP_EXACTI: |
| 3242 | min = max = GET2(ecode, 1); |
| 3243 | ecode += 1 + IMM2_SIZE; |
| 3244 | goto REPEATCHAR; |
| 3245 | |
| 3246 | case OP_POSUPTO: |
| 3247 | case OP_POSUPTOI: |
| 3248 | possessive = TRUE; |
| 3249 | /* Fall through */ |
| 3250 | |
| 3251 | case OP_UPTO: |
| 3252 | case OP_UPTOI: |
| 3253 | case OP_MINUPTO: |
| 3254 | case OP_MINUPTOI: |
| 3255 | min = 0; |
| 3256 | max = GET2(ecode, 1); |
| 3257 | minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI; |
| 3258 | ecode += 1 + IMM2_SIZE; |
| 3259 | goto REPEATCHAR; |
| 3260 | |
| 3261 | case OP_POSSTAR: |
| 3262 | case OP_POSSTARI: |
| 3263 | possessive = TRUE; |
| 3264 | min = 0; |
| 3265 | max = INT_MAX; |
| 3266 | ecode++; |
| 3267 | goto REPEATCHAR; |
| 3268 | |
| 3269 | case OP_POSPLUS: |
| 3270 | case OP_POSPLUSI: |
| 3271 | possessive = TRUE; |
| 3272 | min = 1; |
| 3273 | max = INT_MAX; |
| 3274 | ecode++; |
| 3275 | goto REPEATCHAR; |
| 3276 | |
| 3277 | case OP_POSQUERY: |
| 3278 | case OP_POSQUERYI: |
| 3279 | possessive = TRUE; |
| 3280 | min = 0; |
| 3281 | max = 1; |
| 3282 | ecode++; |
| 3283 | goto REPEATCHAR; |
| 3284 | |
| 3285 | case OP_STAR: |
| 3286 | case OP_STARI: |
| 3287 | case OP_MINSTAR: |
| 3288 | case OP_MINSTARI: |
| 3289 | case OP_PLUS: |
| 3290 | case OP_PLUSI: |
| 3291 | case OP_MINPLUS: |
| 3292 | case OP_MINPLUSI: |
| 3293 | case OP_QUERY: |
| 3294 | case OP_QUERYI: |
| 3295 | case OP_MINQUERY: |
| 3296 | case OP_MINQUERYI: |
| 3297 | c = *ecode++ - ((op < OP_STARI)? OP_STAR : OP_STARI); |
| 3298 | minimize = (c & 1) != 0; |
| 3299 | min = rep_min[c]; /* Pick up values from tables; */ |
| 3300 | max = rep_max[c]; /* zero for max => infinity */ |
| 3301 | if (max == 0) max = INT_MAX; |
| 3302 | |
| 3303 | /* Common code for all repeated single-character matches. */ |
| 3304 | |
| 3305 | REPEATCHAR: |
| 3306 | #ifdef SUPPORT_UTF |
| 3307 | if (utf) |
| 3308 | { |
| 3309 | length = 1; |
| 3310 | charptr = ecode; |
| 3311 | GETCHARLEN(fc, ecode, length); |
| 3312 | ecode += length; |
| 3313 | |
| 3314 | /* Handle multibyte character matching specially here. There is |
| 3315 | support for caseless matching if UCP support is present. */ |
| 3316 | |
| 3317 | if (length > 1) |
| 3318 | { |
| 3319 | #ifdef SUPPORT_UCP |
| 3320 | unsigned int othercase; |
| 3321 | if (op >= OP_STARI && /* Caseless */ |
| 3322 | (othercase = UCD_OTHERCASE(fc)) != fc) |
| 3323 | oclength = PRIV(ord2utf)(othercase, occhars); |
| 3324 | else oclength = 0; |
| 3325 | #endif /* SUPPORT_UCP */ |
| 3326 | |
| 3327 | for (i = 1; i <= min; i++) |
| 3328 | { |
| 3329 | if (eptr <= md->end_subject - length && |
| 3330 | memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length; |
| 3331 | #ifdef SUPPORT_UCP |
| 3332 | else if (oclength > 0 && |
| 3333 | eptr <= md->end_subject - oclength && |
| 3334 | memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength; |
| 3335 | #endif /* SUPPORT_UCP */ |
| 3336 | else |
| 3337 | { |
| 3338 | CHECK_PARTIAL(); |
| 3339 | RRETURN(MATCH_NOMATCH); |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | if (min == max) continue; |
| 3344 | |
| 3345 | if (minimize) |
| 3346 | { |
| 3347 | for (fi = min;; fi++) |
| 3348 | { |
| 3349 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM22); |
| 3350 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3351 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3352 | if (eptr <= md->end_subject - length && |
| 3353 | memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length; |
| 3354 | #ifdef SUPPORT_UCP |
| 3355 | else if (oclength > 0 && |
| 3356 | eptr <= md->end_subject - oclength && |
| 3357 | memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength; |
| 3358 | #endif /* SUPPORT_UCP */ |
| 3359 | else |
| 3360 | { |
| 3361 | CHECK_PARTIAL(); |
| 3362 | RRETURN(MATCH_NOMATCH); |
| 3363 | } |
| 3364 | } |
| 3365 | /* Control never gets here */ |
| 3366 | } |
| 3367 | |
| 3368 | else /* Maximize */ |
| 3369 | { |
| 3370 | pp = eptr; |
| 3371 | for (i = min; i < max; i++) |
| 3372 | { |
| 3373 | if (eptr <= md->end_subject - length && |
| 3374 | memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length; |
| 3375 | #ifdef SUPPORT_UCP |
| 3376 | else if (oclength > 0 && |
| 3377 | eptr <= md->end_subject - oclength && |
| 3378 | memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength; |
| 3379 | #endif /* SUPPORT_UCP */ |
| 3380 | else |
| 3381 | { |
| 3382 | CHECK_PARTIAL(); |
| 3383 | break; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | if (possessive) continue; |
| 3388 | |
| 3389 | for(;;) |
| 3390 | { |
| 3391 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM23); |
| 3392 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3393 | if (eptr == pp) { RRETURN(MATCH_NOMATCH); } |
| 3394 | #ifdef SUPPORT_UCP |
| 3395 | eptr--; |
| 3396 | BACKCHAR(eptr); |
| 3397 | #else /* without SUPPORT_UCP */ |
| 3398 | eptr -= length; |
| 3399 | #endif /* SUPPORT_UCP */ |
| 3400 | } |
| 3401 | } |
| 3402 | /* Control never gets here */ |
| 3403 | } |
| 3404 | |
| 3405 | /* If the length of a UTF-8 character is 1, we fall through here, and |
| 3406 | obey the code as for non-UTF-8 characters below, though in this case the |
| 3407 | value of fc will always be < 128. */ |
| 3408 | } |
| 3409 | else |
| 3410 | #endif /* SUPPORT_UTF */ |
| 3411 | /* When not in UTF-8 mode, load a single-byte character. */ |
| 3412 | fc = *ecode++; |
| 3413 | |
| 3414 | /* The value of fc at this point is always one character, though we may |
| 3415 | or may not be in UTF mode. The code is duplicated for the caseless and |
| 3416 | caseful cases, for speed, since matching characters is likely to be quite |
| 3417 | common. First, ensure the minimum number of matches are present. If min = |
| 3418 | max, continue at the same level without recursing. Otherwise, if |
| 3419 | minimizing, keep trying the rest of the expression and advancing one |
| 3420 | matching character if failing, up to the maximum. Alternatively, if |
| 3421 | maximizing, find the maximum number of characters and work backwards. */ |
| 3422 | |
| 3423 | DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max, |
| 3424 | max, eptr)); |
| 3425 | |
| 3426 | if (op >= OP_STARI) /* Caseless */ |
| 3427 | { |
| 3428 | #ifdef COMPILE_PCRE8 |
| 3429 | /* fc must be < 128 if UTF is enabled. */ |
| 3430 | foc = md->fcc[fc]; |
| 3431 | #else |
| 3432 | #ifdef SUPPORT_UTF |
| 3433 | #ifdef SUPPORT_UCP |
| 3434 | if (utf && fc > 127) |
| 3435 | foc = UCD_OTHERCASE(fc); |
| 3436 | #else |
| 3437 | if (utf && fc > 127) |
| 3438 | foc = fc; |
| 3439 | #endif /* SUPPORT_UCP */ |
| 3440 | else |
| 3441 | #endif /* SUPPORT_UTF */ |
| 3442 | foc = TABLE_GET(fc, md->fcc, fc); |
| 3443 | #endif /* COMPILE_PCRE8 */ |
| 3444 | |
| 3445 | for (i = 1; i <= min; i++) |
| 3446 | { |
| 3447 | if (eptr >= md->end_subject) |
| 3448 | { |
| 3449 | SCHECK_PARTIAL(); |
| 3450 | RRETURN(MATCH_NOMATCH); |
| 3451 | } |
| 3452 | if (fc != *eptr && foc != *eptr) RRETURN(MATCH_NOMATCH); |
| 3453 | eptr++; |
| 3454 | } |
| 3455 | if (min == max) continue; |
| 3456 | if (minimize) |
| 3457 | { |
| 3458 | for (fi = min;; fi++) |
| 3459 | { |
| 3460 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM24); |
| 3461 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3462 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3463 | if (eptr >= md->end_subject) |
| 3464 | { |
| 3465 | SCHECK_PARTIAL(); |
| 3466 | RRETURN(MATCH_NOMATCH); |
| 3467 | } |
| 3468 | if (fc != *eptr && foc != *eptr) RRETURN(MATCH_NOMATCH); |
| 3469 | eptr++; |
| 3470 | } |
| 3471 | /* Control never gets here */ |
| 3472 | } |
| 3473 | else /* Maximize */ |
| 3474 | { |
| 3475 | pp = eptr; |
| 3476 | for (i = min; i < max; i++) |
| 3477 | { |
| 3478 | if (eptr >= md->end_subject) |
| 3479 | { |
| 3480 | SCHECK_PARTIAL(); |
| 3481 | break; |
| 3482 | } |
| 3483 | if (fc != *eptr && foc != *eptr) break; |
| 3484 | eptr++; |
| 3485 | } |
| 3486 | |
| 3487 | if (possessive) continue; |
| 3488 | |
| 3489 | while (eptr >= pp) |
| 3490 | { |
| 3491 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM25); |
| 3492 | eptr--; |
| 3493 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3494 | } |
| 3495 | RRETURN(MATCH_NOMATCH); |
| 3496 | } |
| 3497 | /* Control never gets here */ |
| 3498 | } |
| 3499 | |
| 3500 | /* Caseful comparisons (includes all multi-byte characters) */ |
| 3501 | |
| 3502 | else |
| 3503 | { |
| 3504 | for (i = 1; i <= min; i++) |
| 3505 | { |
| 3506 | if (eptr >= md->end_subject) |
| 3507 | { |
| 3508 | SCHECK_PARTIAL(); |
| 3509 | RRETURN(MATCH_NOMATCH); |
| 3510 | } |
| 3511 | if (fc != *eptr++) RRETURN(MATCH_NOMATCH); |
| 3512 | } |
| 3513 | |
| 3514 | if (min == max) continue; |
| 3515 | |
| 3516 | if (minimize) |
| 3517 | { |
| 3518 | for (fi = min;; fi++) |
| 3519 | { |
| 3520 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM26); |
| 3521 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3522 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3523 | if (eptr >= md->end_subject) |
| 3524 | { |
| 3525 | SCHECK_PARTIAL(); |
| 3526 | RRETURN(MATCH_NOMATCH); |
| 3527 | } |
| 3528 | if (fc != *eptr++) RRETURN(MATCH_NOMATCH); |
| 3529 | } |
| 3530 | /* Control never gets here */ |
| 3531 | } |
| 3532 | else /* Maximize */ |
| 3533 | { |
| 3534 | pp = eptr; |
| 3535 | for (i = min; i < max; i++) |
| 3536 | { |
| 3537 | if (eptr >= md->end_subject) |
| 3538 | { |
| 3539 | SCHECK_PARTIAL(); |
| 3540 | break; |
| 3541 | } |
| 3542 | if (fc != *eptr) break; |
| 3543 | eptr++; |
| 3544 | } |
| 3545 | if (possessive) continue; |
| 3546 | |
| 3547 | while (eptr >= pp) |
| 3548 | { |
| 3549 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM27); |
| 3550 | eptr--; |
| 3551 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3552 | } |
| 3553 | RRETURN(MATCH_NOMATCH); |
| 3554 | } |
| 3555 | } |
| 3556 | /* Control never gets here */ |
| 3557 | |
| 3558 | /* Match a negated single one-byte character. The character we are |
| 3559 | checking can be multibyte. */ |
| 3560 | |
| 3561 | case OP_NOT: |
| 3562 | case OP_NOTI: |
| 3563 | if (eptr >= md->end_subject) |
| 3564 | { |
| 3565 | SCHECK_PARTIAL(); |
| 3566 | RRETURN(MATCH_NOMATCH); |
| 3567 | } |
| 3568 | #ifdef SUPPORT_UTF |
| 3569 | if (utf) |
| 3570 | { |
| 3571 | register unsigned int ch, och; |
| 3572 | |
| 3573 | ecode++; |
| 3574 | GETCHARINC(ch, ecode); |
| 3575 | GETCHARINC(c, eptr); |
| 3576 | |
| 3577 | if (op == OP_NOT) |
| 3578 | { |
| 3579 | if (ch == c) RRETURN(MATCH_NOMATCH); |
| 3580 | } |
| 3581 | else |
| 3582 | { |
| 3583 | #ifdef SUPPORT_UCP |
| 3584 | if (ch > 127) |
| 3585 | och = UCD_OTHERCASE(ch); |
| 3586 | #else |
| 3587 | if (ch > 127) |
| 3588 | och = ch; |
| 3589 | #endif /* SUPPORT_UCP */ |
| 3590 | else |
| 3591 | och = TABLE_GET(ch, md->fcc, ch); |
| 3592 | if (ch == c || och == c) RRETURN(MATCH_NOMATCH); |
| 3593 | } |
| 3594 | } |
| 3595 | else |
| 3596 | #endif |
| 3597 | { |
| 3598 | register unsigned int ch = ecode[1]; |
| 3599 | c = *eptr++; |
| 3600 | if (ch == c || (op == OP_NOTI && TABLE_GET(ch, md->fcc, ch) == c)) |
| 3601 | RRETURN(MATCH_NOMATCH); |
| 3602 | ecode += 2; |
| 3603 | } |
| 3604 | break; |
| 3605 | |
| 3606 | /* Match a negated single one-byte character repeatedly. This is almost a |
| 3607 | repeat of the code for a repeated single character, but I haven't found a |
| 3608 | nice way of commoning these up that doesn't require a test of the |
| 3609 | positive/negative option for each character match. Maybe that wouldn't add |
| 3610 | very much to the time taken, but character matching *is* what this is all |
| 3611 | about... */ |
| 3612 | |
| 3613 | case OP_NOTEXACT: |
| 3614 | case OP_NOTEXACTI: |
| 3615 | min = max = GET2(ecode, 1); |
| 3616 | ecode += 1 + IMM2_SIZE; |
| 3617 | goto REPEATNOTCHAR; |
| 3618 | |
| 3619 | case OP_NOTUPTO: |
| 3620 | case OP_NOTUPTOI: |
| 3621 | case OP_NOTMINUPTO: |
| 3622 | case OP_NOTMINUPTOI: |
| 3623 | min = 0; |
| 3624 | max = GET2(ecode, 1); |
| 3625 | minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI; |
| 3626 | ecode += 1 + IMM2_SIZE; |
| 3627 | goto REPEATNOTCHAR; |
| 3628 | |
| 3629 | case OP_NOTPOSSTAR: |
| 3630 | case OP_NOTPOSSTARI: |
| 3631 | possessive = TRUE; |
| 3632 | min = 0; |
| 3633 | max = INT_MAX; |
| 3634 | ecode++; |
| 3635 | goto REPEATNOTCHAR; |
| 3636 | |
| 3637 | case OP_NOTPOSPLUS: |
| 3638 | case OP_NOTPOSPLUSI: |
| 3639 | possessive = TRUE; |
| 3640 | min = 1; |
| 3641 | max = INT_MAX; |
| 3642 | ecode++; |
| 3643 | goto REPEATNOTCHAR; |
| 3644 | |
| 3645 | case OP_NOTPOSQUERY: |
| 3646 | case OP_NOTPOSQUERYI: |
| 3647 | possessive = TRUE; |
| 3648 | min = 0; |
| 3649 | max = 1; |
| 3650 | ecode++; |
| 3651 | goto REPEATNOTCHAR; |
| 3652 | |
| 3653 | case OP_NOTPOSUPTO: |
| 3654 | case OP_NOTPOSUPTOI: |
| 3655 | possessive = TRUE; |
| 3656 | min = 0; |
| 3657 | max = GET2(ecode, 1); |
| 3658 | ecode += 1 + IMM2_SIZE; |
| 3659 | goto REPEATNOTCHAR; |
| 3660 | |
| 3661 | case OP_NOTSTAR: |
| 3662 | case OP_NOTSTARI: |
| 3663 | case OP_NOTMINSTAR: |
| 3664 | case OP_NOTMINSTARI: |
| 3665 | case OP_NOTPLUS: |
| 3666 | case OP_NOTPLUSI: |
| 3667 | case OP_NOTMINPLUS: |
| 3668 | case OP_NOTMINPLUSI: |
| 3669 | case OP_NOTQUERY: |
| 3670 | case OP_NOTQUERYI: |
| 3671 | case OP_NOTMINQUERY: |
| 3672 | case OP_NOTMINQUERYI: |
| 3673 | c = *ecode++ - ((op >= OP_NOTSTARI)? OP_NOTSTARI: OP_NOTSTAR); |
| 3674 | minimize = (c & 1) != 0; |
| 3675 | min = rep_min[c]; /* Pick up values from tables; */ |
| 3676 | max = rep_max[c]; /* zero for max => infinity */ |
| 3677 | if (max == 0) max = INT_MAX; |
| 3678 | |
| 3679 | /* Common code for all repeated single-byte matches. */ |
| 3680 | |
| 3681 | REPEATNOTCHAR: |
| 3682 | GETCHARINCTEST(fc, ecode); |
| 3683 | |
| 3684 | /* The code is duplicated for the caseless and caseful cases, for speed, |
| 3685 | since matching characters is likely to be quite common. First, ensure the |
| 3686 | minimum number of matches are present. If min = max, continue at the same |
| 3687 | level without recursing. Otherwise, if minimizing, keep trying the rest of |
| 3688 | the expression and advancing one matching character if failing, up to the |
| 3689 | maximum. Alternatively, if maximizing, find the maximum number of |
| 3690 | characters and work backwards. */ |
| 3691 | |
| 3692 | DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max, |
| 3693 | max, eptr)); |
| 3694 | |
| 3695 | if (op >= OP_NOTSTARI) /* Caseless */ |
| 3696 | { |
| 3697 | #ifdef SUPPORT_UTF |
| 3698 | #ifdef SUPPORT_UCP |
| 3699 | if (utf && fc > 127) |
| 3700 | foc = UCD_OTHERCASE(fc); |
| 3701 | #else |
| 3702 | if (utf && fc > 127) |
| 3703 | foc = fc; |
| 3704 | #endif /* SUPPORT_UCP */ |
| 3705 | else |
| 3706 | #endif /* SUPPORT_UTF */ |
| 3707 | foc = TABLE_GET(fc, md->fcc, fc); |
| 3708 | |
| 3709 | #ifdef SUPPORT_UTF |
| 3710 | if (utf) |
| 3711 | { |
| 3712 | register unsigned int d; |
| 3713 | for (i = 1; i <= min; i++) |
| 3714 | { |
| 3715 | if (eptr >= md->end_subject) |
| 3716 | { |
| 3717 | SCHECK_PARTIAL(); |
| 3718 | RRETURN(MATCH_NOMATCH); |
| 3719 | } |
| 3720 | GETCHARINC(d, eptr); |
| 3721 | if (fc == d || (unsigned int)foc == d) RRETURN(MATCH_NOMATCH); |
| 3722 | } |
| 3723 | } |
| 3724 | else |
| 3725 | #endif |
| 3726 | /* Not UTF mode */ |
| 3727 | { |
| 3728 | for (i = 1; i <= min; i++) |
| 3729 | { |
| 3730 | if (eptr >= md->end_subject) |
| 3731 | { |
| 3732 | SCHECK_PARTIAL(); |
| 3733 | RRETURN(MATCH_NOMATCH); |
| 3734 | } |
| 3735 | if (fc == *eptr || foc == *eptr) RRETURN(MATCH_NOMATCH); |
| 3736 | eptr++; |
| 3737 | } |
| 3738 | } |
| 3739 | |
| 3740 | if (min == max) continue; |
| 3741 | |
| 3742 | if (minimize) |
| 3743 | { |
| 3744 | #ifdef SUPPORT_UTF |
| 3745 | if (utf) |
| 3746 | { |
| 3747 | register unsigned int d; |
| 3748 | for (fi = min;; fi++) |
| 3749 | { |
| 3750 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM28); |
| 3751 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3752 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3753 | if (eptr >= md->end_subject) |
| 3754 | { |
| 3755 | SCHECK_PARTIAL(); |
| 3756 | RRETURN(MATCH_NOMATCH); |
| 3757 | } |
| 3758 | GETCHARINC(d, eptr); |
| 3759 | if (fc == d || (unsigned int)foc == d) RRETURN(MATCH_NOMATCH); |
| 3760 | } |
| 3761 | } |
| 3762 | else |
| 3763 | #endif |
| 3764 | /* Not UTF mode */ |
| 3765 | { |
| 3766 | for (fi = min;; fi++) |
| 3767 | { |
| 3768 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM29); |
| 3769 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3770 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3771 | if (eptr >= md->end_subject) |
| 3772 | { |
| 3773 | SCHECK_PARTIAL(); |
| 3774 | RRETURN(MATCH_NOMATCH); |
| 3775 | } |
| 3776 | if (fc == *eptr || foc == *eptr) RRETURN(MATCH_NOMATCH); |
| 3777 | eptr++; |
| 3778 | } |
| 3779 | } |
| 3780 | /* Control never gets here */ |
| 3781 | } |
| 3782 | |
| 3783 | /* Maximize case */ |
| 3784 | |
| 3785 | else |
| 3786 | { |
| 3787 | pp = eptr; |
| 3788 | |
| 3789 | #ifdef SUPPORT_UTF |
| 3790 | if (utf) |
| 3791 | { |
| 3792 | register unsigned int d; |
| 3793 | for (i = min; i < max; i++) |
| 3794 | { |
| 3795 | int len = 1; |
| 3796 | if (eptr >= md->end_subject) |
| 3797 | { |
| 3798 | SCHECK_PARTIAL(); |
| 3799 | break; |
| 3800 | } |
| 3801 | GETCHARLEN(d, eptr, len); |
| 3802 | if (fc == d || (unsigned int)foc == d) break; |
| 3803 | eptr += len; |
| 3804 | } |
| 3805 | if (possessive) continue; |
| 3806 | for(;;) |
| 3807 | { |
| 3808 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM30); |
| 3809 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3810 | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3811 | BACKCHAR(eptr); |
| 3812 | } |
| 3813 | } |
| 3814 | else |
| 3815 | #endif |
| 3816 | /* Not UTF mode */ |
| 3817 | { |
| 3818 | for (i = min; i < max; i++) |
| 3819 | { |
| 3820 | if (eptr >= md->end_subject) |
| 3821 | { |
| 3822 | SCHECK_PARTIAL(); |
| 3823 | break; |
| 3824 | } |
| 3825 | if (fc == *eptr || foc == *eptr) break; |
| 3826 | eptr++; |
| 3827 | } |
| 3828 | if (possessive) continue; |
| 3829 | while (eptr >= pp) |
| 3830 | { |
| 3831 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM31); |
| 3832 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3833 | eptr--; |
| 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | RRETURN(MATCH_NOMATCH); |
| 3838 | } |
| 3839 | /* Control never gets here */ |
| 3840 | } |
| 3841 | |
| 3842 | /* Caseful comparisons */ |
| 3843 | |
| 3844 | else |
| 3845 | { |
| 3846 | #ifdef SUPPORT_UTF |
| 3847 | if (utf) |
| 3848 | { |
| 3849 | register unsigned int d; |
| 3850 | for (i = 1; i <= min; i++) |
| 3851 | { |
| 3852 | if (eptr >= md->end_subject) |
| 3853 | { |
| 3854 | SCHECK_PARTIAL(); |
| 3855 | RRETURN(MATCH_NOMATCH); |
| 3856 | } |
| 3857 | GETCHARINC(d, eptr); |
| 3858 | if (fc == d) RRETURN(MATCH_NOMATCH); |
| 3859 | } |
| 3860 | } |
| 3861 | else |
| 3862 | #endif |
| 3863 | /* Not UTF mode */ |
| 3864 | { |
| 3865 | for (i = 1; i <= min; i++) |
| 3866 | { |
| 3867 | if (eptr >= md->end_subject) |
| 3868 | { |
| 3869 | SCHECK_PARTIAL(); |
| 3870 | RRETURN(MATCH_NOMATCH); |
| 3871 | } |
| 3872 | if (fc == *eptr++) RRETURN(MATCH_NOMATCH); |
| 3873 | } |
| 3874 | } |
| 3875 | |
| 3876 | if (min == max) continue; |
| 3877 | |
| 3878 | if (minimize) |
| 3879 | { |
| 3880 | #ifdef SUPPORT_UTF |
| 3881 | if (utf) |
| 3882 | { |
| 3883 | register unsigned int d; |
| 3884 | for (fi = min;; fi++) |
| 3885 | { |
| 3886 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM32); |
| 3887 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3888 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3889 | if (eptr >= md->end_subject) |
| 3890 | { |
| 3891 | SCHECK_PARTIAL(); |
| 3892 | RRETURN(MATCH_NOMATCH); |
| 3893 | } |
| 3894 | GETCHARINC(d, eptr); |
| 3895 | if (fc == d) RRETURN(MATCH_NOMATCH); |
| 3896 | } |
| 3897 | } |
| 3898 | else |
| 3899 | #endif |
| 3900 | /* Not UTF mode */ |
| 3901 | { |
| 3902 | for (fi = min;; fi++) |
| 3903 | { |
| 3904 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM33); |
| 3905 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3906 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 3907 | if (eptr >= md->end_subject) |
| 3908 | { |
| 3909 | SCHECK_PARTIAL(); |
| 3910 | RRETURN(MATCH_NOMATCH); |
| 3911 | } |
| 3912 | if (fc == *eptr++) RRETURN(MATCH_NOMATCH); |
| 3913 | } |
| 3914 | } |
| 3915 | /* Control never gets here */ |
| 3916 | } |
| 3917 | |
| 3918 | /* Maximize case */ |
| 3919 | |
| 3920 | else |
| 3921 | { |
| 3922 | pp = eptr; |
| 3923 | |
| 3924 | #ifdef SUPPORT_UTF |
| 3925 | if (utf) |
| 3926 | { |
| 3927 | register unsigned int d; |
| 3928 | for (i = min; i < max; i++) |
| 3929 | { |
| 3930 | int len = 1; |
| 3931 | if (eptr >= md->end_subject) |
| 3932 | { |
| 3933 | SCHECK_PARTIAL(); |
| 3934 | break; |
| 3935 | } |
| 3936 | GETCHARLEN(d, eptr, len); |
| 3937 | if (fc == d) break; |
| 3938 | eptr += len; |
| 3939 | } |
| 3940 | if (possessive) continue; |
| 3941 | for(;;) |
| 3942 | { |
| 3943 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM34); |
| 3944 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3945 | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 3946 | BACKCHAR(eptr); |
| 3947 | } |
| 3948 | } |
| 3949 | else |
| 3950 | #endif |
| 3951 | /* Not UTF mode */ |
| 3952 | { |
| 3953 | for (i = min; i < max; i++) |
| 3954 | { |
| 3955 | if (eptr >= md->end_subject) |
| 3956 | { |
| 3957 | SCHECK_PARTIAL(); |
| 3958 | break; |
| 3959 | } |
| 3960 | if (fc == *eptr) break; |
| 3961 | eptr++; |
| 3962 | } |
| 3963 | if (possessive) continue; |
| 3964 | while (eptr >= pp) |
| 3965 | { |
| 3966 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM35); |
| 3967 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 3968 | eptr--; |
| 3969 | } |
| 3970 | } |
| 3971 | |
| 3972 | RRETURN(MATCH_NOMATCH); |
| 3973 | } |
| 3974 | } |
| 3975 | /* Control never gets here */ |
| 3976 | |
| 3977 | /* Match a single character type repeatedly; several different opcodes |
| 3978 | share code. This is very similar to the code for single characters, but we |
| 3979 | repeat it in the interests of efficiency. */ |
| 3980 | |
| 3981 | case OP_TYPEEXACT: |
| 3982 | min = max = GET2(ecode, 1); |
| 3983 | minimize = TRUE; |
| 3984 | ecode += 1 + IMM2_SIZE; |
| 3985 | goto REPEATTYPE; |
| 3986 | |
| 3987 | case OP_TYPEUPTO: |
| 3988 | case OP_TYPEMINUPTO: |
| 3989 | min = 0; |
| 3990 | max = GET2(ecode, 1); |
| 3991 | minimize = *ecode == OP_TYPEMINUPTO; |
| 3992 | ecode += 1 + IMM2_SIZE; |
| 3993 | goto REPEATTYPE; |
| 3994 | |
| 3995 | case OP_TYPEPOSSTAR: |
| 3996 | possessive = TRUE; |
| 3997 | min = 0; |
| 3998 | max = INT_MAX; |
| 3999 | ecode++; |
| 4000 | goto REPEATTYPE; |
| 4001 | |
| 4002 | case OP_TYPEPOSPLUS: |
| 4003 | possessive = TRUE; |
| 4004 | min = 1; |
| 4005 | max = INT_MAX; |
| 4006 | ecode++; |
| 4007 | goto REPEATTYPE; |
| 4008 | |
| 4009 | case OP_TYPEPOSQUERY: |
| 4010 | possessive = TRUE; |
| 4011 | min = 0; |
| 4012 | max = 1; |
| 4013 | ecode++; |
| 4014 | goto REPEATTYPE; |
| 4015 | |
| 4016 | case OP_TYPEPOSUPTO: |
| 4017 | possessive = TRUE; |
| 4018 | min = 0; |
| 4019 | max = GET2(ecode, 1); |
| 4020 | ecode += 1 + IMM2_SIZE; |
| 4021 | goto REPEATTYPE; |
| 4022 | |
| 4023 | case OP_TYPESTAR: |
| 4024 | case OP_TYPEMINSTAR: |
| 4025 | case OP_TYPEPLUS: |
| 4026 | case OP_TYPEMINPLUS: |
| 4027 | case OP_TYPEQUERY: |
| 4028 | case OP_TYPEMINQUERY: |
| 4029 | c = *ecode++ - OP_TYPESTAR; |
| 4030 | minimize = (c & 1) != 0; |
| 4031 | min = rep_min[c]; /* Pick up values from tables; */ |
| 4032 | max = rep_max[c]; /* zero for max => infinity */ |
| 4033 | if (max == 0) max = INT_MAX; |
| 4034 | |
| 4035 | /* Common code for all repeated single character type matches. Note that |
| 4036 | in UTF-8 mode, '.' matches a character of any length, but for the other |
| 4037 | character types, the valid characters are all one-byte long. */ |
| 4038 | |
| 4039 | REPEATTYPE: |
| 4040 | ctype = *ecode++; /* Code for the character type */ |
| 4041 | |
| 4042 | #ifdef SUPPORT_UCP |
| 4043 | if (ctype == OP_PROP || ctype == OP_NOTPROP) |
| 4044 | { |
| 4045 | prop_fail_result = ctype == OP_NOTPROP; |
| 4046 | prop_type = *ecode++; |
| 4047 | prop_value = *ecode++; |
| 4048 | } |
| 4049 | else prop_type = -1; |
| 4050 | #endif |
| 4051 | |
| 4052 | /* First, ensure the minimum number of matches are present. Use inline |
| 4053 | code for maximizing the speed, and do the type test once at the start |
| 4054 | (i.e. keep it out of the loop). Separate the UTF-8 code completely as that |
| 4055 | is tidier. Also separate the UCP code, which can be the same for both UTF-8 |
| 4056 | and single-bytes. */ |
| 4057 | |
| 4058 | if (min > 0) |
| 4059 | { |
| 4060 | #ifdef SUPPORT_UCP |
| 4061 | if (prop_type >= 0) |
| 4062 | { |
| 4063 | switch(prop_type) |
| 4064 | { |
| 4065 | case PT_ANY: |
| 4066 | if (prop_fail_result) RRETURN(MATCH_NOMATCH); |
| 4067 | for (i = 1; i <= min; i++) |
| 4068 | { |
| 4069 | if (eptr >= md->end_subject) |
| 4070 | { |
| 4071 | SCHECK_PARTIAL(); |
| 4072 | RRETURN(MATCH_NOMATCH); |
| 4073 | } |
| 4074 | GETCHARINCTEST(c, eptr); |
| 4075 | } |
| 4076 | break; |
| 4077 | |
| 4078 | case PT_LAMP: |
| 4079 | for (i = 1; i <= min; i++) |
| 4080 | { |
| 4081 | int chartype; |
| 4082 | if (eptr >= md->end_subject) |
| 4083 | { |
| 4084 | SCHECK_PARTIAL(); |
| 4085 | RRETURN(MATCH_NOMATCH); |
| 4086 | } |
| 4087 | GETCHARINCTEST(c, eptr); |
| 4088 | chartype = UCD_CHARTYPE(c); |
| 4089 | if ((chartype == ucp_Lu || |
| 4090 | chartype == ucp_Ll || |
| 4091 | chartype == ucp_Lt) == prop_fail_result) |
| 4092 | RRETURN(MATCH_NOMATCH); |
| 4093 | } |
| 4094 | break; |
| 4095 | |
| 4096 | case PT_GC: |
| 4097 | for (i = 1; i <= min; i++) |
| 4098 | { |
| 4099 | if (eptr >= md->end_subject) |
| 4100 | { |
| 4101 | SCHECK_PARTIAL(); |
| 4102 | RRETURN(MATCH_NOMATCH); |
| 4103 | } |
| 4104 | GETCHARINCTEST(c, eptr); |
| 4105 | if ((UCD_CATEGORY(c) == prop_value) == prop_fail_result) |
| 4106 | RRETURN(MATCH_NOMATCH); |
| 4107 | } |
| 4108 | break; |
| 4109 | |
| 4110 | case PT_PC: |
| 4111 | for (i = 1; i <= min; i++) |
| 4112 | { |
| 4113 | if (eptr >= md->end_subject) |
| 4114 | { |
| 4115 | SCHECK_PARTIAL(); |
| 4116 | RRETURN(MATCH_NOMATCH); |
| 4117 | } |
| 4118 | GETCHARINCTEST(c, eptr); |
| 4119 | if ((UCD_CHARTYPE(c) == prop_value) == prop_fail_result) |
| 4120 | RRETURN(MATCH_NOMATCH); |
| 4121 | } |
| 4122 | break; |
| 4123 | |
| 4124 | case PT_SC: |
| 4125 | for (i = 1; i <= min; i++) |
| 4126 | { |
| 4127 | if (eptr >= md->end_subject) |
| 4128 | { |
| 4129 | SCHECK_PARTIAL(); |
| 4130 | RRETURN(MATCH_NOMATCH); |
| 4131 | } |
| 4132 | GETCHARINCTEST(c, eptr); |
| 4133 | if ((UCD_SCRIPT(c) == prop_value) == prop_fail_result) |
| 4134 | RRETURN(MATCH_NOMATCH); |
| 4135 | } |
| 4136 | break; |
| 4137 | |
| 4138 | case PT_ALNUM: |
| 4139 | for (i = 1; i <= min; i++) |
| 4140 | { |
| 4141 | int category; |
| 4142 | if (eptr >= md->end_subject) |
| 4143 | { |
| 4144 | SCHECK_PARTIAL(); |
| 4145 | RRETURN(MATCH_NOMATCH); |
| 4146 | } |
| 4147 | GETCHARINCTEST(c, eptr); |
| 4148 | category = UCD_CATEGORY(c); |
| 4149 | if ((category == ucp_L || category == ucp_N) == prop_fail_result) |
| 4150 | RRETURN(MATCH_NOMATCH); |
| 4151 | } |
| 4152 | break; |
| 4153 | |
| 4154 | case PT_SPACE: /* Perl space */ |
| 4155 | for (i = 1; i <= min; i++) |
| 4156 | { |
| 4157 | if (eptr >= md->end_subject) |
| 4158 | { |
| 4159 | SCHECK_PARTIAL(); |
| 4160 | RRETURN(MATCH_NOMATCH); |
| 4161 | } |
| 4162 | GETCHARINCTEST(c, eptr); |
| 4163 | if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL || |
| 4164 | c == CHAR_FF || c == CHAR_CR) |
| 4165 | == prop_fail_result) |
| 4166 | RRETURN(MATCH_NOMATCH); |
| 4167 | } |
| 4168 | break; |
| 4169 | |
| 4170 | case PT_PXSPACE: /* POSIX space */ |
| 4171 | for (i = 1; i <= min; i++) |
| 4172 | { |
| 4173 | if (eptr >= md->end_subject) |
| 4174 | { |
| 4175 | SCHECK_PARTIAL(); |
| 4176 | RRETURN(MATCH_NOMATCH); |
| 4177 | } |
| 4178 | GETCHARINCTEST(c, eptr); |
| 4179 | if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL || |
| 4180 | c == CHAR_VT || c == CHAR_FF || c == CHAR_CR) |
| 4181 | == prop_fail_result) |
| 4182 | RRETURN(MATCH_NOMATCH); |
| 4183 | } |
| 4184 | break; |
| 4185 | |
| 4186 | case PT_WORD: |
| 4187 | for (i = 1; i <= min; i++) |
| 4188 | { |
| 4189 | int category; |
| 4190 | if (eptr >= md->end_subject) |
| 4191 | { |
| 4192 | SCHECK_PARTIAL(); |
| 4193 | RRETURN(MATCH_NOMATCH); |
| 4194 | } |
| 4195 | GETCHARINCTEST(c, eptr); |
| 4196 | category = UCD_CATEGORY(c); |
| 4197 | if ((category == ucp_L || category == ucp_N || c == CHAR_UNDERSCORE) |
| 4198 | == prop_fail_result) |
| 4199 | RRETURN(MATCH_NOMATCH); |
| 4200 | } |
| 4201 | break; |
| 4202 | |
| 4203 | /* This should not occur */ |
| 4204 | |
| 4205 | default: |
| 4206 | RRETURN(PCRE_ERROR_INTERNAL); |
| 4207 | } |
| 4208 | } |
| 4209 | |
| 4210 | /* Match extended Unicode sequences. We will get here only if the |
| 4211 | support is in the binary; otherwise a compile-time error occurs. */ |
| 4212 | |
| 4213 | else if (ctype == OP_EXTUNI) |
| 4214 | { |
| 4215 | for (i = 1; i <= min; i++) |
| 4216 | { |
| 4217 | if (eptr >= md->end_subject) |
| 4218 | { |
| 4219 | SCHECK_PARTIAL(); |
| 4220 | RRETURN(MATCH_NOMATCH); |
| 4221 | } |
| 4222 | GETCHARINCTEST(c, eptr); |
| 4223 | if (UCD_CATEGORY(c) == ucp_M) RRETURN(MATCH_NOMATCH); |
| 4224 | while (eptr < md->end_subject) |
| 4225 | { |
| 4226 | int len = 1; |
| 4227 | if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); } |
| 4228 | if (UCD_CATEGORY(c) != ucp_M) break; |
| 4229 | eptr += len; |
| 4230 | } |
| 4231 | CHECK_PARTIAL(); |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | else |
| 4236 | #endif /* SUPPORT_UCP */ |
| 4237 | |
| 4238 | /* Handle all other cases when the coding is UTF-8 */ |
| 4239 | |
| 4240 | #ifdef SUPPORT_UTF |
| 4241 | if (utf) switch(ctype) |
| 4242 | { |
| 4243 | case OP_ANY: |
| 4244 | for (i = 1; i <= min; i++) |
| 4245 | { |
| 4246 | if (eptr >= md->end_subject) |
| 4247 | { |
| 4248 | SCHECK_PARTIAL(); |
| 4249 | RRETURN(MATCH_NOMATCH); |
| 4250 | } |
| 4251 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); |
| 4252 | if (md->partial != 0 && |
| 4253 | eptr + 1 >= md->end_subject && |
| 4254 | NLBLOCK->nltype == NLTYPE_FIXED && |
| 4255 | NLBLOCK->nllen == 2 && |
| 4256 | *eptr == NLBLOCK->nl[0]) |
| 4257 | { |
| 4258 | md->hitend = TRUE; |
| 4259 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 4260 | } |
| 4261 | eptr++; |
| 4262 | ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++); |
| 4263 | } |
| 4264 | break; |
| 4265 | |
| 4266 | case OP_ALLANY: |
| 4267 | for (i = 1; i <= min; i++) |
| 4268 | { |
| 4269 | if (eptr >= md->end_subject) |
| 4270 | { |
| 4271 | SCHECK_PARTIAL(); |
| 4272 | RRETURN(MATCH_NOMATCH); |
| 4273 | } |
| 4274 | eptr++; |
| 4275 | ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++); |
| 4276 | } |
| 4277 | break; |
| 4278 | |
| 4279 | case OP_ANYBYTE: |
| 4280 | if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH); |
| 4281 | eptr += min; |
| 4282 | break; |
| 4283 | |
| 4284 | case OP_ANYNL: |
| 4285 | for (i = 1; i <= min; i++) |
| 4286 | { |
| 4287 | if (eptr >= md->end_subject) |
| 4288 | { |
| 4289 | SCHECK_PARTIAL(); |
| 4290 | RRETURN(MATCH_NOMATCH); |
| 4291 | } |
| 4292 | GETCHARINC(c, eptr); |
| 4293 | switch(c) |
| 4294 | { |
| 4295 | default: RRETURN(MATCH_NOMATCH); |
| 4296 | |
| 4297 | case 0x000d: |
| 4298 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
| 4299 | break; |
| 4300 | |
| 4301 | case 0x000a: |
| 4302 | break; |
| 4303 | |
| 4304 | case 0x000b: |
| 4305 | case 0x000c: |
| 4306 | case 0x0085: |
| 4307 | case 0x2028: |
| 4308 | case 0x2029: |
| 4309 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); |
| 4310 | break; |
| 4311 | } |
| 4312 | } |
| 4313 | break; |
| 4314 | |
| 4315 | case OP_NOT_HSPACE: |
| 4316 | for (i = 1; i <= min; i++) |
| 4317 | { |
| 4318 | if (eptr >= md->end_subject) |
| 4319 | { |
| 4320 | SCHECK_PARTIAL(); |
| 4321 | RRETURN(MATCH_NOMATCH); |
| 4322 | } |
| 4323 | GETCHARINC(c, eptr); |
| 4324 | switch(c) |
| 4325 | { |
| 4326 | default: break; |
| 4327 | case 0x09: /* HT */ |
| 4328 | case 0x20: /* SPACE */ |
| 4329 | case 0xa0: /* NBSP */ |
| 4330 | case 0x1680: /* OGHAM SPACE MARK */ |
| 4331 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 4332 | case 0x2000: /* EN QUAD */ |
| 4333 | case 0x2001: /* EM QUAD */ |
| 4334 | case 0x2002: /* EN SPACE */ |
| 4335 | case 0x2003: /* EM SPACE */ |
| 4336 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 4337 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 4338 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 4339 | case 0x2007: /* FIGURE SPACE */ |
| 4340 | case 0x2008: /* PUNCTUATION SPACE */ |
| 4341 | case 0x2009: /* THIN SPACE */ |
| 4342 | case 0x200A: /* HAIR SPACE */ |
| 4343 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 4344 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 4345 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 4346 | RRETURN(MATCH_NOMATCH); |
| 4347 | } |
| 4348 | } |
| 4349 | break; |
| 4350 | |
| 4351 | case OP_HSPACE: |
| 4352 | for (i = 1; i <= min; i++) |
| 4353 | { |
| 4354 | if (eptr >= md->end_subject) |
| 4355 | { |
| 4356 | SCHECK_PARTIAL(); |
| 4357 | RRETURN(MATCH_NOMATCH); |
| 4358 | } |
| 4359 | GETCHARINC(c, eptr); |
| 4360 | switch(c) |
| 4361 | { |
| 4362 | default: RRETURN(MATCH_NOMATCH); |
| 4363 | case 0x09: /* HT */ |
| 4364 | case 0x20: /* SPACE */ |
| 4365 | case 0xa0: /* NBSP */ |
| 4366 | case 0x1680: /* OGHAM SPACE MARK */ |
| 4367 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 4368 | case 0x2000: /* EN QUAD */ |
| 4369 | case 0x2001: /* EM QUAD */ |
| 4370 | case 0x2002: /* EN SPACE */ |
| 4371 | case 0x2003: /* EM SPACE */ |
| 4372 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 4373 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 4374 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 4375 | case 0x2007: /* FIGURE SPACE */ |
| 4376 | case 0x2008: /* PUNCTUATION SPACE */ |
| 4377 | case 0x2009: /* THIN SPACE */ |
| 4378 | case 0x200A: /* HAIR SPACE */ |
| 4379 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 4380 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 4381 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 4382 | break; |
| 4383 | } |
| 4384 | } |
| 4385 | break; |
| 4386 | |
| 4387 | case OP_NOT_VSPACE: |
| 4388 | for (i = 1; i <= min; i++) |
| 4389 | { |
| 4390 | if (eptr >= md->end_subject) |
| 4391 | { |
| 4392 | SCHECK_PARTIAL(); |
| 4393 | RRETURN(MATCH_NOMATCH); |
| 4394 | } |
| 4395 | GETCHARINC(c, eptr); |
| 4396 | switch(c) |
| 4397 | { |
| 4398 | default: break; |
| 4399 | case 0x0a: /* LF */ |
| 4400 | case 0x0b: /* VT */ |
| 4401 | case 0x0c: /* FF */ |
| 4402 | case 0x0d: /* CR */ |
| 4403 | case 0x85: /* NEL */ |
| 4404 | case 0x2028: /* LINE SEPARATOR */ |
| 4405 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 4406 | RRETURN(MATCH_NOMATCH); |
| 4407 | } |
| 4408 | } |
| 4409 | break; |
| 4410 | |
| 4411 | case OP_VSPACE: |
| 4412 | for (i = 1; i <= min; i++) |
| 4413 | { |
| 4414 | if (eptr >= md->end_subject) |
| 4415 | { |
| 4416 | SCHECK_PARTIAL(); |
| 4417 | RRETURN(MATCH_NOMATCH); |
| 4418 | } |
| 4419 | GETCHARINC(c, eptr); |
| 4420 | switch(c) |
| 4421 | { |
| 4422 | default: RRETURN(MATCH_NOMATCH); |
| 4423 | case 0x0a: /* LF */ |
| 4424 | case 0x0b: /* VT */ |
| 4425 | case 0x0c: /* FF */ |
| 4426 | case 0x0d: /* CR */ |
| 4427 | case 0x85: /* NEL */ |
| 4428 | case 0x2028: /* LINE SEPARATOR */ |
| 4429 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 4430 | break; |
| 4431 | } |
| 4432 | } |
| 4433 | break; |
| 4434 | |
| 4435 | case OP_NOT_DIGIT: |
| 4436 | for (i = 1; i <= min; i++) |
| 4437 | { |
| 4438 | if (eptr >= md->end_subject) |
| 4439 | { |
| 4440 | SCHECK_PARTIAL(); |
| 4441 | RRETURN(MATCH_NOMATCH); |
| 4442 | } |
| 4443 | GETCHARINC(c, eptr); |
| 4444 | if (c < 128 && (md->ctypes[c] & ctype_digit) != 0) |
| 4445 | RRETURN(MATCH_NOMATCH); |
| 4446 | } |
| 4447 | break; |
| 4448 | |
| 4449 | case OP_DIGIT: |
| 4450 | for (i = 1; i <= min; i++) |
| 4451 | { |
| 4452 | if (eptr >= md->end_subject) |
| 4453 | { |
| 4454 | SCHECK_PARTIAL(); |
| 4455 | RRETURN(MATCH_NOMATCH); |
| 4456 | } |
| 4457 | if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_digit) == 0) |
| 4458 | RRETURN(MATCH_NOMATCH); |
| 4459 | eptr++; |
| 4460 | /* No need to skip more bytes - we know it's a 1-byte character */ |
| 4461 | } |
| 4462 | break; |
| 4463 | |
| 4464 | case OP_NOT_WHITESPACE: |
| 4465 | for (i = 1; i <= min; i++) |
| 4466 | { |
| 4467 | if (eptr >= md->end_subject) |
| 4468 | { |
| 4469 | SCHECK_PARTIAL(); |
| 4470 | RRETURN(MATCH_NOMATCH); |
| 4471 | } |
| 4472 | if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0) |
| 4473 | RRETURN(MATCH_NOMATCH); |
| 4474 | eptr++; |
| 4475 | ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++); |
| 4476 | } |
| 4477 | break; |
| 4478 | |
| 4479 | case OP_WHITESPACE: |
| 4480 | for (i = 1; i <= min; i++) |
| 4481 | { |
| 4482 | if (eptr >= md->end_subject) |
| 4483 | { |
| 4484 | SCHECK_PARTIAL(); |
| 4485 | RRETURN(MATCH_NOMATCH); |
| 4486 | } |
| 4487 | if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_space) == 0) |
| 4488 | RRETURN(MATCH_NOMATCH); |
| 4489 | eptr++; |
| 4490 | /* No need to skip more bytes - we know it's a 1-byte character */ |
| 4491 | } |
| 4492 | break; |
| 4493 | |
| 4494 | case OP_NOT_WORDCHAR: |
| 4495 | for (i = 1; i <= min; i++) |
| 4496 | { |
| 4497 | if (eptr >= md->end_subject) |
| 4498 | { |
| 4499 | SCHECK_PARTIAL(); |
| 4500 | RRETURN(MATCH_NOMATCH); |
| 4501 | } |
| 4502 | if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0) |
| 4503 | RRETURN(MATCH_NOMATCH); |
| 4504 | eptr++; |
| 4505 | ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++); |
| 4506 | } |
| 4507 | break; |
| 4508 | |
| 4509 | case OP_WORDCHAR: |
| 4510 | for (i = 1; i <= min; i++) |
| 4511 | { |
| 4512 | if (eptr >= md->end_subject) |
| 4513 | { |
| 4514 | SCHECK_PARTIAL(); |
| 4515 | RRETURN(MATCH_NOMATCH); |
| 4516 | } |
| 4517 | if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_word) == 0) |
| 4518 | RRETURN(MATCH_NOMATCH); |
| 4519 | eptr++; |
| 4520 | /* No need to skip more bytes - we know it's a 1-byte character */ |
| 4521 | } |
| 4522 | break; |
| 4523 | |
| 4524 | default: |
| 4525 | RRETURN(PCRE_ERROR_INTERNAL); |
| 4526 | } /* End switch(ctype) */ |
| 4527 | |
| 4528 | else |
| 4529 | #endif /* SUPPORT_UTF */ |
| 4530 | |
| 4531 | /* Code for the non-UTF-8 case for minimum matching of operators other |
| 4532 | than OP_PROP and OP_NOTPROP. */ |
| 4533 | |
| 4534 | switch(ctype) |
| 4535 | { |
| 4536 | case OP_ANY: |
| 4537 | for (i = 1; i <= min; i++) |
| 4538 | { |
| 4539 | if (eptr >= md->end_subject) |
| 4540 | { |
| 4541 | SCHECK_PARTIAL(); |
| 4542 | RRETURN(MATCH_NOMATCH); |
| 4543 | } |
| 4544 | if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); |
| 4545 | if (md->partial != 0 && |
| 4546 | eptr + 1 >= md->end_subject && |
| 4547 | NLBLOCK->nltype == NLTYPE_FIXED && |
| 4548 | NLBLOCK->nllen == 2 && |
| 4549 | *eptr == NLBLOCK->nl[0]) |
| 4550 | { |
| 4551 | md->hitend = TRUE; |
| 4552 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 4553 | } |
| 4554 | eptr++; |
| 4555 | } |
| 4556 | break; |
| 4557 | |
| 4558 | case OP_ALLANY: |
| 4559 | if (eptr > md->end_subject - min) |
| 4560 | { |
| 4561 | SCHECK_PARTIAL(); |
| 4562 | RRETURN(MATCH_NOMATCH); |
| 4563 | } |
| 4564 | eptr += min; |
| 4565 | break; |
| 4566 | |
| 4567 | case OP_ANYBYTE: |
| 4568 | if (eptr > md->end_subject - min) |
| 4569 | { |
| 4570 | SCHECK_PARTIAL(); |
| 4571 | RRETURN(MATCH_NOMATCH); |
| 4572 | } |
| 4573 | eptr += min; |
| 4574 | break; |
| 4575 | |
| 4576 | case OP_ANYNL: |
| 4577 | for (i = 1; i <= min; i++) |
| 4578 | { |
| 4579 | if (eptr >= md->end_subject) |
| 4580 | { |
| 4581 | SCHECK_PARTIAL(); |
| 4582 | RRETURN(MATCH_NOMATCH); |
| 4583 | } |
| 4584 | switch(*eptr++) |
| 4585 | { |
| 4586 | default: RRETURN(MATCH_NOMATCH); |
| 4587 | |
| 4588 | case 0x000d: |
| 4589 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
| 4590 | break; |
| 4591 | |
| 4592 | case 0x000a: |
| 4593 | break; |
| 4594 | |
| 4595 | case 0x000b: |
| 4596 | case 0x000c: |
| 4597 | case 0x0085: |
| 4598 | #ifdef COMPILE_PCRE16 |
| 4599 | case 0x2028: |
| 4600 | case 0x2029: |
| 4601 | #endif |
| 4602 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); |
| 4603 | break; |
| 4604 | } |
| 4605 | } |
| 4606 | break; |
| 4607 | |
| 4608 | case OP_NOT_HSPACE: |
| 4609 | for (i = 1; i <= min; i++) |
| 4610 | { |
| 4611 | if (eptr >= md->end_subject) |
| 4612 | { |
| 4613 | SCHECK_PARTIAL(); |
| 4614 | RRETURN(MATCH_NOMATCH); |
| 4615 | } |
| 4616 | switch(*eptr++) |
| 4617 | { |
| 4618 | default: break; |
| 4619 | case 0x09: /* HT */ |
| 4620 | case 0x20: /* SPACE */ |
| 4621 | case 0xa0: /* NBSP */ |
| 4622 | #ifdef COMPILE_PCRE16 |
| 4623 | case 0x1680: /* OGHAM SPACE MARK */ |
| 4624 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 4625 | case 0x2000: /* EN QUAD */ |
| 4626 | case 0x2001: /* EM QUAD */ |
| 4627 | case 0x2002: /* EN SPACE */ |
| 4628 | case 0x2003: /* EM SPACE */ |
| 4629 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 4630 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 4631 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 4632 | case 0x2007: /* FIGURE SPACE */ |
| 4633 | case 0x2008: /* PUNCTUATION SPACE */ |
| 4634 | case 0x2009: /* THIN SPACE */ |
| 4635 | case 0x200A: /* HAIR SPACE */ |
| 4636 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 4637 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 4638 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 4639 | #endif |
| 4640 | RRETURN(MATCH_NOMATCH); |
| 4641 | } |
| 4642 | } |
| 4643 | break; |
| 4644 | |
| 4645 | case OP_HSPACE: |
| 4646 | for (i = 1; i <= min; i++) |
| 4647 | { |
| 4648 | if (eptr >= md->end_subject) |
| 4649 | { |
| 4650 | SCHECK_PARTIAL(); |
| 4651 | RRETURN(MATCH_NOMATCH); |
| 4652 | } |
| 4653 | switch(*eptr++) |
| 4654 | { |
| 4655 | default: RRETURN(MATCH_NOMATCH); |
| 4656 | case 0x09: /* HT */ |
| 4657 | case 0x20: /* SPACE */ |
| 4658 | case 0xa0: /* NBSP */ |
| 4659 | #ifdef COMPILE_PCRE16 |
| 4660 | case 0x1680: /* OGHAM SPACE MARK */ |
| 4661 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 4662 | case 0x2000: /* EN QUAD */ |
| 4663 | case 0x2001: /* EM QUAD */ |
| 4664 | case 0x2002: /* EN SPACE */ |
| 4665 | case 0x2003: /* EM SPACE */ |
| 4666 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 4667 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 4668 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 4669 | case 0x2007: /* FIGURE SPACE */ |
| 4670 | case 0x2008: /* PUNCTUATION SPACE */ |
| 4671 | case 0x2009: /* THIN SPACE */ |
| 4672 | case 0x200A: /* HAIR SPACE */ |
| 4673 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 4674 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 4675 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 4676 | #endif |
| 4677 | break; |
| 4678 | } |
| 4679 | } |
| 4680 | break; |
| 4681 | |
| 4682 | case OP_NOT_VSPACE: |
| 4683 | for (i = 1; i <= min; i++) |
| 4684 | { |
| 4685 | if (eptr >= md->end_subject) |
| 4686 | { |
| 4687 | SCHECK_PARTIAL(); |
| 4688 | RRETURN(MATCH_NOMATCH); |
| 4689 | } |
| 4690 | switch(*eptr++) |
| 4691 | { |
| 4692 | default: break; |
| 4693 | case 0x0a: /* LF */ |
| 4694 | case 0x0b: /* VT */ |
| 4695 | case 0x0c: /* FF */ |
| 4696 | case 0x0d: /* CR */ |
| 4697 | case 0x85: /* NEL */ |
| 4698 | #ifdef COMPILE_PCRE16 |
| 4699 | case 0x2028: /* LINE SEPARATOR */ |
| 4700 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 4701 | #endif |
| 4702 | RRETURN(MATCH_NOMATCH); |
| 4703 | } |
| 4704 | } |
| 4705 | break; |
| 4706 | |
| 4707 | case OP_VSPACE: |
| 4708 | for (i = 1; i <= min; i++) |
| 4709 | { |
| 4710 | if (eptr >= md->end_subject) |
| 4711 | { |
| 4712 | SCHECK_PARTIAL(); |
| 4713 | RRETURN(MATCH_NOMATCH); |
| 4714 | } |
| 4715 | switch(*eptr++) |
| 4716 | { |
| 4717 | default: RRETURN(MATCH_NOMATCH); |
| 4718 | case 0x0a: /* LF */ |
| 4719 | case 0x0b: /* VT */ |
| 4720 | case 0x0c: /* FF */ |
| 4721 | case 0x0d: /* CR */ |
| 4722 | case 0x85: /* NEL */ |
| 4723 | #ifdef COMPILE_PCRE16 |
| 4724 | case 0x2028: /* LINE SEPARATOR */ |
| 4725 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 4726 | #endif |
| 4727 | break; |
| 4728 | } |
| 4729 | } |
| 4730 | break; |
| 4731 | |
| 4732 | case OP_NOT_DIGIT: |
| 4733 | for (i = 1; i <= min; i++) |
| 4734 | { |
| 4735 | if (eptr >= md->end_subject) |
| 4736 | { |
| 4737 | SCHECK_PARTIAL(); |
| 4738 | RRETURN(MATCH_NOMATCH); |
| 4739 | } |
| 4740 | if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_digit) != 0) |
| 4741 | RRETURN(MATCH_NOMATCH); |
| 4742 | eptr++; |
| 4743 | } |
| 4744 | break; |
| 4745 | |
| 4746 | case OP_DIGIT: |
| 4747 | for (i = 1; i <= min; i++) |
| 4748 | { |
| 4749 | if (eptr >= md->end_subject) |
| 4750 | { |
| 4751 | SCHECK_PARTIAL(); |
| 4752 | RRETURN(MATCH_NOMATCH); |
| 4753 | } |
| 4754 | if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_digit) == 0) |
| 4755 | RRETURN(MATCH_NOMATCH); |
| 4756 | eptr++; |
| 4757 | } |
| 4758 | break; |
| 4759 | |
| 4760 | case OP_NOT_WHITESPACE: |
| 4761 | for (i = 1; i <= min; i++) |
| 4762 | { |
| 4763 | if (eptr >= md->end_subject) |
| 4764 | { |
| 4765 | SCHECK_PARTIAL(); |
| 4766 | RRETURN(MATCH_NOMATCH); |
| 4767 | } |
| 4768 | if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_space) != 0) |
| 4769 | RRETURN(MATCH_NOMATCH); |
| 4770 | eptr++; |
| 4771 | } |
| 4772 | break; |
| 4773 | |
| 4774 | case OP_WHITESPACE: |
| 4775 | for (i = 1; i <= min; i++) |
| 4776 | { |
| 4777 | if (eptr >= md->end_subject) |
| 4778 | { |
| 4779 | SCHECK_PARTIAL(); |
| 4780 | RRETURN(MATCH_NOMATCH); |
| 4781 | } |
| 4782 | if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_space) == 0) |
| 4783 | RRETURN(MATCH_NOMATCH); |
| 4784 | eptr++; |
| 4785 | } |
| 4786 | break; |
| 4787 | |
| 4788 | case OP_NOT_WORDCHAR: |
| 4789 | for (i = 1; i <= min; i++) |
| 4790 | { |
| 4791 | if (eptr >= md->end_subject) |
| 4792 | { |
| 4793 | SCHECK_PARTIAL(); |
| 4794 | RRETURN(MATCH_NOMATCH); |
| 4795 | } |
| 4796 | if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_word) != 0) |
| 4797 | RRETURN(MATCH_NOMATCH); |
| 4798 | eptr++; |
| 4799 | } |
| 4800 | break; |
| 4801 | |
| 4802 | case OP_WORDCHAR: |
| 4803 | for (i = 1; i <= min; i++) |
| 4804 | { |
| 4805 | if (eptr >= md->end_subject) |
| 4806 | { |
| 4807 | SCHECK_PARTIAL(); |
| 4808 | RRETURN(MATCH_NOMATCH); |
| 4809 | } |
| 4810 | if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_word) == 0) |
| 4811 | RRETURN(MATCH_NOMATCH); |
| 4812 | eptr++; |
| 4813 | } |
| 4814 | break; |
| 4815 | |
| 4816 | default: |
| 4817 | RRETURN(PCRE_ERROR_INTERNAL); |
| 4818 | } |
| 4819 | } |
| 4820 | |
| 4821 | /* If min = max, continue at the same level without recursing */ |
| 4822 | |
| 4823 | if (min == max) continue; |
| 4824 | |
| 4825 | /* If minimizing, we have to test the rest of the pattern before each |
| 4826 | subsequent match. Again, separate the UTF-8 case for speed, and also |
| 4827 | separate the UCP cases. */ |
| 4828 | |
| 4829 | if (minimize) |
| 4830 | { |
| 4831 | #ifdef SUPPORT_UCP |
| 4832 | if (prop_type >= 0) |
| 4833 | { |
| 4834 | switch(prop_type) |
| 4835 | { |
| 4836 | case PT_ANY: |
| 4837 | for (fi = min;; fi++) |
| 4838 | { |
| 4839 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM36); |
| 4840 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4841 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4842 | if (eptr >= md->end_subject) |
| 4843 | { |
| 4844 | SCHECK_PARTIAL(); |
| 4845 | RRETURN(MATCH_NOMATCH); |
| 4846 | } |
| 4847 | GETCHARINCTEST(c, eptr); |
| 4848 | if (prop_fail_result) RRETURN(MATCH_NOMATCH); |
| 4849 | } |
| 4850 | /* Control never gets here */ |
| 4851 | |
| 4852 | case PT_LAMP: |
| 4853 | for (fi = min;; fi++) |
| 4854 | { |
| 4855 | int chartype; |
| 4856 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM37); |
| 4857 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4858 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4859 | if (eptr >= md->end_subject) |
| 4860 | { |
| 4861 | SCHECK_PARTIAL(); |
| 4862 | RRETURN(MATCH_NOMATCH); |
| 4863 | } |
| 4864 | GETCHARINCTEST(c, eptr); |
| 4865 | chartype = UCD_CHARTYPE(c); |
| 4866 | if ((chartype == ucp_Lu || |
| 4867 | chartype == ucp_Ll || |
| 4868 | chartype == ucp_Lt) == prop_fail_result) |
| 4869 | RRETURN(MATCH_NOMATCH); |
| 4870 | } |
| 4871 | /* Control never gets here */ |
| 4872 | |
| 4873 | case PT_GC: |
| 4874 | for (fi = min;; fi++) |
| 4875 | { |
| 4876 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM38); |
| 4877 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4878 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4879 | if (eptr >= md->end_subject) |
| 4880 | { |
| 4881 | SCHECK_PARTIAL(); |
| 4882 | RRETURN(MATCH_NOMATCH); |
| 4883 | } |
| 4884 | GETCHARINCTEST(c, eptr); |
| 4885 | if ((UCD_CATEGORY(c) == prop_value) == prop_fail_result) |
| 4886 | RRETURN(MATCH_NOMATCH); |
| 4887 | } |
| 4888 | /* Control never gets here */ |
| 4889 | |
| 4890 | case PT_PC: |
| 4891 | for (fi = min;; fi++) |
| 4892 | { |
| 4893 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM39); |
| 4894 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4895 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4896 | if (eptr >= md->end_subject) |
| 4897 | { |
| 4898 | SCHECK_PARTIAL(); |
| 4899 | RRETURN(MATCH_NOMATCH); |
| 4900 | } |
| 4901 | GETCHARINCTEST(c, eptr); |
| 4902 | if ((UCD_CHARTYPE(c) == prop_value) == prop_fail_result) |
| 4903 | RRETURN(MATCH_NOMATCH); |
| 4904 | } |
| 4905 | /* Control never gets here */ |
| 4906 | |
| 4907 | case PT_SC: |
| 4908 | for (fi = min;; fi++) |
| 4909 | { |
| 4910 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM40); |
| 4911 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4912 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4913 | if (eptr >= md->end_subject) |
| 4914 | { |
| 4915 | SCHECK_PARTIAL(); |
| 4916 | RRETURN(MATCH_NOMATCH); |
| 4917 | } |
| 4918 | GETCHARINCTEST(c, eptr); |
| 4919 | if ((UCD_SCRIPT(c) == prop_value) == prop_fail_result) |
| 4920 | RRETURN(MATCH_NOMATCH); |
| 4921 | } |
| 4922 | /* Control never gets here */ |
| 4923 | |
| 4924 | case PT_ALNUM: |
| 4925 | for (fi = min;; fi++) |
| 4926 | { |
| 4927 | int category; |
| 4928 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM59); |
| 4929 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4930 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4931 | if (eptr >= md->end_subject) |
| 4932 | { |
| 4933 | SCHECK_PARTIAL(); |
| 4934 | RRETURN(MATCH_NOMATCH); |
| 4935 | } |
| 4936 | GETCHARINCTEST(c, eptr); |
| 4937 | category = UCD_CATEGORY(c); |
| 4938 | if ((category == ucp_L || category == ucp_N) == prop_fail_result) |
| 4939 | RRETURN(MATCH_NOMATCH); |
| 4940 | } |
| 4941 | /* Control never gets here */ |
| 4942 | |
| 4943 | case PT_SPACE: /* Perl space */ |
| 4944 | for (fi = min;; fi++) |
| 4945 | { |
| 4946 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM60); |
| 4947 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4948 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4949 | if (eptr >= md->end_subject) |
| 4950 | { |
| 4951 | SCHECK_PARTIAL(); |
| 4952 | RRETURN(MATCH_NOMATCH); |
| 4953 | } |
| 4954 | GETCHARINCTEST(c, eptr); |
| 4955 | if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL || |
| 4956 | c == CHAR_FF || c == CHAR_CR) |
| 4957 | == prop_fail_result) |
| 4958 | RRETURN(MATCH_NOMATCH); |
| 4959 | } |
| 4960 | /* Control never gets here */ |
| 4961 | |
| 4962 | case PT_PXSPACE: /* POSIX space */ |
| 4963 | for (fi = min;; fi++) |
| 4964 | { |
| 4965 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM61); |
| 4966 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4967 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4968 | if (eptr >= md->end_subject) |
| 4969 | { |
| 4970 | SCHECK_PARTIAL(); |
| 4971 | RRETURN(MATCH_NOMATCH); |
| 4972 | } |
| 4973 | GETCHARINCTEST(c, eptr); |
| 4974 | if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL || |
| 4975 | c == CHAR_VT || c == CHAR_FF || c == CHAR_CR) |
| 4976 | == prop_fail_result) |
| 4977 | RRETURN(MATCH_NOMATCH); |
| 4978 | } |
| 4979 | /* Control never gets here */ |
| 4980 | |
| 4981 | case PT_WORD: |
| 4982 | for (fi = min;; fi++) |
| 4983 | { |
| 4984 | int category; |
| 4985 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM62); |
| 4986 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 4987 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 4988 | if (eptr >= md->end_subject) |
| 4989 | { |
| 4990 | SCHECK_PARTIAL(); |
| 4991 | RRETURN(MATCH_NOMATCH); |
| 4992 | } |
| 4993 | GETCHARINCTEST(c, eptr); |
| 4994 | category = UCD_CATEGORY(c); |
| 4995 | if ((category == ucp_L || |
| 4996 | category == ucp_N || |
| 4997 | c == CHAR_UNDERSCORE) |
| 4998 | == prop_fail_result) |
| 4999 | RRETURN(MATCH_NOMATCH); |
| 5000 | } |
| 5001 | /* Control never gets here */ |
| 5002 | |
| 5003 | /* This should never occur */ |
| 5004 | |
| 5005 | default: |
| 5006 | RRETURN(PCRE_ERROR_INTERNAL); |
| 5007 | } |
| 5008 | } |
| 5009 | |
| 5010 | /* Match extended Unicode sequences. We will get here only if the |
| 5011 | support is in the binary; otherwise a compile-time error occurs. */ |
| 5012 | |
| 5013 | else if (ctype == OP_EXTUNI) |
| 5014 | { |
| 5015 | for (fi = min;; fi++) |
| 5016 | { |
| 5017 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM41); |
| 5018 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 5019 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 5020 | if (eptr >= md->end_subject) |
| 5021 | { |
| 5022 | SCHECK_PARTIAL(); |
| 5023 | RRETURN(MATCH_NOMATCH); |
| 5024 | } |
| 5025 | GETCHARINCTEST(c, eptr); |
| 5026 | if (UCD_CATEGORY(c) == ucp_M) RRETURN(MATCH_NOMATCH); |
| 5027 | while (eptr < md->end_subject) |
| 5028 | { |
| 5029 | int len = 1; |
| 5030 | if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); } |
| 5031 | if (UCD_CATEGORY(c) != ucp_M) break; |
| 5032 | eptr += len; |
| 5033 | } |
| 5034 | CHECK_PARTIAL(); |
| 5035 | } |
| 5036 | } |
| 5037 | else |
| 5038 | #endif /* SUPPORT_UCP */ |
| 5039 | |
| 5040 | #ifdef SUPPORT_UTF |
| 5041 | if (utf) |
| 5042 | { |
| 5043 | for (fi = min;; fi++) |
| 5044 | { |
| 5045 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM42); |
| 5046 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 5047 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 5048 | if (eptr >= md->end_subject) |
| 5049 | { |
| 5050 | SCHECK_PARTIAL(); |
| 5051 | RRETURN(MATCH_NOMATCH); |
| 5052 | } |
| 5053 | if (ctype == OP_ANY && IS_NEWLINE(eptr)) |
| 5054 | RRETURN(MATCH_NOMATCH); |
| 5055 | GETCHARINC(c, eptr); |
| 5056 | switch(ctype) |
| 5057 | { |
| 5058 | case OP_ANY: /* This is the non-NL case */ |
| 5059 | if (md->partial != 0 && /* Take care with CRLF partial */ |
| 5060 | eptr >= md->end_subject && |
| 5061 | NLBLOCK->nltype == NLTYPE_FIXED && |
| 5062 | NLBLOCK->nllen == 2 && |
| 5063 | c == NLBLOCK->nl[0]) |
| 5064 | { |
| 5065 | md->hitend = TRUE; |
| 5066 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 5067 | } |
| 5068 | break; |
| 5069 | |
| 5070 | case OP_ALLANY: |
| 5071 | case OP_ANYBYTE: |
| 5072 | break; |
| 5073 | |
| 5074 | case OP_ANYNL: |
| 5075 | switch(c) |
| 5076 | { |
| 5077 | default: RRETURN(MATCH_NOMATCH); |
| 5078 | case 0x000d: |
| 5079 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
| 5080 | break; |
| 5081 | case 0x000a: |
| 5082 | break; |
| 5083 | |
| 5084 | case 0x000b: |
| 5085 | case 0x000c: |
| 5086 | case 0x0085: |
| 5087 | case 0x2028: |
| 5088 | case 0x2029: |
| 5089 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); |
| 5090 | break; |
| 5091 | } |
| 5092 | break; |
| 5093 | |
| 5094 | case OP_NOT_HSPACE: |
| 5095 | switch(c) |
| 5096 | { |
| 5097 | default: break; |
| 5098 | case 0x09: /* HT */ |
| 5099 | case 0x20: /* SPACE */ |
| 5100 | case 0xa0: /* NBSP */ |
| 5101 | case 0x1680: /* OGHAM SPACE MARK */ |
| 5102 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 5103 | case 0x2000: /* EN QUAD */ |
| 5104 | case 0x2001: /* EM QUAD */ |
| 5105 | case 0x2002: /* EN SPACE */ |
| 5106 | case 0x2003: /* EM SPACE */ |
| 5107 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 5108 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 5109 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 5110 | case 0x2007: /* FIGURE SPACE */ |
| 5111 | case 0x2008: /* PUNCTUATION SPACE */ |
| 5112 | case 0x2009: /* THIN SPACE */ |
| 5113 | case 0x200A: /* HAIR SPACE */ |
| 5114 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 5115 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 5116 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 5117 | RRETURN(MATCH_NOMATCH); |
| 5118 | } |
| 5119 | break; |
| 5120 | |
| 5121 | case OP_HSPACE: |
| 5122 | switch(c) |
| 5123 | { |
| 5124 | default: RRETURN(MATCH_NOMATCH); |
| 5125 | case 0x09: /* HT */ |
| 5126 | case 0x20: /* SPACE */ |
| 5127 | case 0xa0: /* NBSP */ |
| 5128 | case 0x1680: /* OGHAM SPACE MARK */ |
| 5129 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 5130 | case 0x2000: /* EN QUAD */ |
| 5131 | case 0x2001: /* EM QUAD */ |
| 5132 | case 0x2002: /* EN SPACE */ |
| 5133 | case 0x2003: /* EM SPACE */ |
| 5134 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 5135 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 5136 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 5137 | case 0x2007: /* FIGURE SPACE */ |
| 5138 | case 0x2008: /* PUNCTUATION SPACE */ |
| 5139 | case 0x2009: /* THIN SPACE */ |
| 5140 | case 0x200A: /* HAIR SPACE */ |
| 5141 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 5142 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 5143 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 5144 | break; |
| 5145 | } |
| 5146 | break; |
| 5147 | |
| 5148 | case OP_NOT_VSPACE: |
| 5149 | switch(c) |
| 5150 | { |
| 5151 | default: break; |
| 5152 | case 0x0a: /* LF */ |
| 5153 | case 0x0b: /* VT */ |
| 5154 | case 0x0c: /* FF */ |
| 5155 | case 0x0d: /* CR */ |
| 5156 | case 0x85: /* NEL */ |
| 5157 | case 0x2028: /* LINE SEPARATOR */ |
| 5158 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 5159 | RRETURN(MATCH_NOMATCH); |
| 5160 | } |
| 5161 | break; |
| 5162 | |
| 5163 | case OP_VSPACE: |
| 5164 | switch(c) |
| 5165 | { |
| 5166 | default: RRETURN(MATCH_NOMATCH); |
| 5167 | case 0x0a: /* LF */ |
| 5168 | case 0x0b: /* VT */ |
| 5169 | case 0x0c: /* FF */ |
| 5170 | case 0x0d: /* CR */ |
| 5171 | case 0x85: /* NEL */ |
| 5172 | case 0x2028: /* LINE SEPARATOR */ |
| 5173 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 5174 | break; |
| 5175 | } |
| 5176 | break; |
| 5177 | |
| 5178 | case OP_NOT_DIGIT: |
| 5179 | if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) |
| 5180 | RRETURN(MATCH_NOMATCH); |
| 5181 | break; |
| 5182 | |
| 5183 | case OP_DIGIT: |
| 5184 | if (c >= 256 || (md->ctypes[c] & ctype_digit) == 0) |
| 5185 | RRETURN(MATCH_NOMATCH); |
| 5186 | break; |
| 5187 | |
| 5188 | case OP_NOT_WHITESPACE: |
| 5189 | if (c < 256 && (md->ctypes[c] & ctype_space) != 0) |
| 5190 | RRETURN(MATCH_NOMATCH); |
| 5191 | break; |
| 5192 | |
| 5193 | case OP_WHITESPACE: |
| 5194 | if (c >= 256 || (md->ctypes[c] & ctype_space) == 0) |
| 5195 | RRETURN(MATCH_NOMATCH); |
| 5196 | break; |
| 5197 | |
| 5198 | case OP_NOT_WORDCHAR: |
| 5199 | if (c < 256 && (md->ctypes[c] & ctype_word) != 0) |
| 5200 | RRETURN(MATCH_NOMATCH); |
| 5201 | break; |
| 5202 | |
| 5203 | case OP_WORDCHAR: |
| 5204 | if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) |
| 5205 | RRETURN(MATCH_NOMATCH); |
| 5206 | break; |
| 5207 | |
| 5208 | default: |
| 5209 | RRETURN(PCRE_ERROR_INTERNAL); |
| 5210 | } |
| 5211 | } |
| 5212 | } |
| 5213 | else |
| 5214 | #endif |
| 5215 | /* Not UTF mode */ |
| 5216 | { |
| 5217 | for (fi = min;; fi++) |
| 5218 | { |
| 5219 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM43); |
| 5220 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 5221 | if (fi >= max) RRETURN(MATCH_NOMATCH); |
| 5222 | if (eptr >= md->end_subject) |
| 5223 | { |
| 5224 | SCHECK_PARTIAL(); |
| 5225 | RRETURN(MATCH_NOMATCH); |
| 5226 | } |
| 5227 | if (ctype == OP_ANY && IS_NEWLINE(eptr)) |
| 5228 | RRETURN(MATCH_NOMATCH); |
| 5229 | c = *eptr++; |
| 5230 | switch(ctype) |
| 5231 | { |
| 5232 | case OP_ANY: /* This is the non-NL case */ |
| 5233 | if (md->partial != 0 && /* Take care with CRLF partial */ |
| 5234 | eptr >= md->end_subject && |
| 5235 | NLBLOCK->nltype == NLTYPE_FIXED && |
| 5236 | NLBLOCK->nllen == 2 && |
| 5237 | c == NLBLOCK->nl[0]) |
| 5238 | { |
| 5239 | md->hitend = TRUE; |
| 5240 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 5241 | } |
| 5242 | break; |
| 5243 | |
| 5244 | case OP_ALLANY: |
| 5245 | case OP_ANYBYTE: |
| 5246 | break; |
| 5247 | |
| 5248 | case OP_ANYNL: |
| 5249 | switch(c) |
| 5250 | { |
| 5251 | default: RRETURN(MATCH_NOMATCH); |
| 5252 | case 0x000d: |
| 5253 | if (eptr < md->end_subject && *eptr == 0x0a) eptr++; |
| 5254 | break; |
| 5255 | |
| 5256 | case 0x000a: |
| 5257 | break; |
| 5258 | |
| 5259 | case 0x000b: |
| 5260 | case 0x000c: |
| 5261 | case 0x0085: |
| 5262 | #ifdef COMPILE_PCRE16 |
| 5263 | case 0x2028: |
| 5264 | case 0x2029: |
| 5265 | #endif |
| 5266 | if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); |
| 5267 | break; |
| 5268 | } |
| 5269 | break; |
| 5270 | |
| 5271 | case OP_NOT_HSPACE: |
| 5272 | switch(c) |
| 5273 | { |
| 5274 | default: break; |
| 5275 | case 0x09: /* HT */ |
| 5276 | case 0x20: /* SPACE */ |
| 5277 | case 0xa0: /* NBSP */ |
| 5278 | #ifdef COMPILE_PCRE16 |
| 5279 | case 0x1680: /* OGHAM SPACE MARK */ |
| 5280 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 5281 | case 0x2000: /* EN QUAD */ |
| 5282 | case 0x2001: /* EM QUAD */ |
| 5283 | case 0x2002: /* EN SPACE */ |
| 5284 | case 0x2003: /* EM SPACE */ |
| 5285 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 5286 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 5287 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 5288 | case 0x2007: /* FIGURE SPACE */ |
| 5289 | case 0x2008: /* PUNCTUATION SPACE */ |
| 5290 | case 0x2009: /* THIN SPACE */ |
| 5291 | case 0x200A: /* HAIR SPACE */ |
| 5292 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 5293 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 5294 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 5295 | #endif |
| 5296 | RRETURN(MATCH_NOMATCH); |
| 5297 | } |
| 5298 | break; |
| 5299 | |
| 5300 | case OP_HSPACE: |
| 5301 | switch(c) |
| 5302 | { |
| 5303 | default: RRETURN(MATCH_NOMATCH); |
| 5304 | case 0x09: /* HT */ |
| 5305 | case 0x20: /* SPACE */ |
| 5306 | case 0xa0: /* NBSP */ |
| 5307 | #ifdef COMPILE_PCRE16 |
| 5308 | case 0x1680: /* OGHAM SPACE MARK */ |
| 5309 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 5310 | case 0x2000: /* EN QUAD */ |
| 5311 | case 0x2001: /* EM QUAD */ |
| 5312 | case 0x2002: /* EN SPACE */ |
| 5313 | case 0x2003: /* EM SPACE */ |
| 5314 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 5315 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 5316 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 5317 | case 0x2007: /* FIGURE SPACE */ |
| 5318 | case 0x2008: /* PUNCTUATION SPACE */ |
| 5319 | case 0x2009: /* THIN SPACE */ |
| 5320 | case 0x200A: /* HAIR SPACE */ |
| 5321 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 5322 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 5323 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 5324 | #endif |
| 5325 | break; |
| 5326 | } |
| 5327 | break; |
| 5328 | |
| 5329 | case OP_NOT_VSPACE: |
| 5330 | switch(c) |
| 5331 | { |
| 5332 | default: break; |
| 5333 | case 0x0a: /* LF */ |
| 5334 | case 0x0b: /* VT */ |
| 5335 | case 0x0c: /* FF */ |
| 5336 | case 0x0d: /* CR */ |
| 5337 | case 0x85: /* NEL */ |
| 5338 | #ifdef COMPILE_PCRE16 |
| 5339 | case 0x2028: /* LINE SEPARATOR */ |
| 5340 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 5341 | #endif |
| 5342 | RRETURN(MATCH_NOMATCH); |
| 5343 | } |
| 5344 | break; |
| 5345 | |
| 5346 | case OP_VSPACE: |
| 5347 | switch(c) |
| 5348 | { |
| 5349 | default: RRETURN(MATCH_NOMATCH); |
| 5350 | case 0x0a: /* LF */ |
| 5351 | case 0x0b: /* VT */ |
| 5352 | case 0x0c: /* FF */ |
| 5353 | case 0x0d: /* CR */ |
| 5354 | case 0x85: /* NEL */ |
| 5355 | #ifdef COMPILE_PCRE16 |
| 5356 | case 0x2028: /* LINE SEPARATOR */ |
| 5357 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 5358 | #endif |
| 5359 | break; |
| 5360 | } |
| 5361 | break; |
| 5362 | |
| 5363 | case OP_NOT_DIGIT: |
| 5364 | if (MAX_255(c) && (md->ctypes[c] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); |
| 5365 | break; |
| 5366 | |
| 5367 | case OP_DIGIT: |
| 5368 | if (!MAX_255(c) || (md->ctypes[c] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH); |
| 5369 | break; |
| 5370 | |
| 5371 | case OP_NOT_WHITESPACE: |
| 5372 | if (MAX_255(c) && (md->ctypes[c] & ctype_space) != 0) RRETURN(MATCH_NOMATCH); |
| 5373 | break; |
| 5374 | |
| 5375 | case OP_WHITESPACE: |
| 5376 | if (!MAX_255(c) || (md->ctypes[c] & ctype_space) == 0) RRETURN(MATCH_NOMATCH); |
| 5377 | break; |
| 5378 | |
| 5379 | case OP_NOT_WORDCHAR: |
| 5380 | if (MAX_255(c) && (md->ctypes[c] & ctype_word) != 0) RRETURN(MATCH_NOMATCH); |
| 5381 | break; |
| 5382 | |
| 5383 | case OP_WORDCHAR: |
| 5384 | if (!MAX_255(c) || (md->ctypes[c] & ctype_word) == 0) RRETURN(MATCH_NOMATCH); |
| 5385 | break; |
| 5386 | |
| 5387 | default: |
| 5388 | RRETURN(PCRE_ERROR_INTERNAL); |
| 5389 | } |
| 5390 | } |
| 5391 | } |
| 5392 | /* Control never gets here */ |
| 5393 | } |
| 5394 | |
| 5395 | /* If maximizing, it is worth using inline code for speed, doing the type |
| 5396 | test once at the start (i.e. keep it out of the loop). Again, keep the |
| 5397 | UTF-8 and UCP stuff separate. */ |
| 5398 | |
| 5399 | else |
| 5400 | { |
| 5401 | pp = eptr; /* Remember where we started */ |
| 5402 | |
| 5403 | #ifdef SUPPORT_UCP |
| 5404 | if (prop_type >= 0) |
| 5405 | { |
| 5406 | switch(prop_type) |
| 5407 | { |
| 5408 | case PT_ANY: |
| 5409 | for (i = min; i < max; i++) |
| 5410 | { |
| 5411 | int len = 1; |
| 5412 | if (eptr >= md->end_subject) |
| 5413 | { |
| 5414 | SCHECK_PARTIAL(); |
| 5415 | break; |
| 5416 | } |
| 5417 | GETCHARLENTEST(c, eptr, len); |
| 5418 | if (prop_fail_result) break; |
| 5419 | eptr+= len; |
| 5420 | } |
| 5421 | break; |
| 5422 | |
| 5423 | case PT_LAMP: |
| 5424 | for (i = min; i < max; i++) |
| 5425 | { |
| 5426 | int chartype; |
| 5427 | int len = 1; |
| 5428 | if (eptr >= md->end_subject) |
| 5429 | { |
| 5430 | SCHECK_PARTIAL(); |
| 5431 | break; |
| 5432 | } |
| 5433 | GETCHARLENTEST(c, eptr, len); |
| 5434 | chartype = UCD_CHARTYPE(c); |
| 5435 | if ((chartype == ucp_Lu || |
| 5436 | chartype == ucp_Ll || |
| 5437 | chartype == ucp_Lt) == prop_fail_result) |
| 5438 | break; |
| 5439 | eptr+= len; |
| 5440 | } |
| 5441 | break; |
| 5442 | |
| 5443 | case PT_GC: |
| 5444 | for (i = min; i < max; i++) |
| 5445 | { |
| 5446 | int len = 1; |
| 5447 | if (eptr >= md->end_subject) |
| 5448 | { |
| 5449 | SCHECK_PARTIAL(); |
| 5450 | break; |
| 5451 | } |
| 5452 | GETCHARLENTEST(c, eptr, len); |
| 5453 | if ((UCD_CATEGORY(c) == prop_value) == prop_fail_result) break; |
| 5454 | eptr+= len; |
| 5455 | } |
| 5456 | break; |
| 5457 | |
| 5458 | case PT_PC: |
| 5459 | for (i = min; i < max; i++) |
| 5460 | { |
| 5461 | int len = 1; |
| 5462 | if (eptr >= md->end_subject) |
| 5463 | { |
| 5464 | SCHECK_PARTIAL(); |
| 5465 | break; |
| 5466 | } |
| 5467 | GETCHARLENTEST(c, eptr, len); |
| 5468 | if ((UCD_CHARTYPE(c) == prop_value) == prop_fail_result) break; |
| 5469 | eptr+= len; |
| 5470 | } |
| 5471 | break; |
| 5472 | |
| 5473 | case PT_SC: |
| 5474 | for (i = min; i < max; i++) |
| 5475 | { |
| 5476 | int len = 1; |
| 5477 | if (eptr >= md->end_subject) |
| 5478 | { |
| 5479 | SCHECK_PARTIAL(); |
| 5480 | break; |
| 5481 | } |
| 5482 | GETCHARLENTEST(c, eptr, len); |
| 5483 | if ((UCD_SCRIPT(c) == prop_value) == prop_fail_result) break; |
| 5484 | eptr+= len; |
| 5485 | } |
| 5486 | break; |
| 5487 | |
| 5488 | case PT_ALNUM: |
| 5489 | for (i = min; i < max; i++) |
| 5490 | { |
| 5491 | int category; |
| 5492 | int len = 1; |
| 5493 | if (eptr >= md->end_subject) |
| 5494 | { |
| 5495 | SCHECK_PARTIAL(); |
| 5496 | break; |
| 5497 | } |
| 5498 | GETCHARLENTEST(c, eptr, len); |
| 5499 | category = UCD_CATEGORY(c); |
| 5500 | if ((category == ucp_L || category == ucp_N) == prop_fail_result) |
| 5501 | break; |
| 5502 | eptr+= len; |
| 5503 | } |
| 5504 | break; |
| 5505 | |
| 5506 | case PT_SPACE: /* Perl space */ |
| 5507 | for (i = min; i < max; i++) |
| 5508 | { |
| 5509 | int len = 1; |
| 5510 | if (eptr >= md->end_subject) |
| 5511 | { |
| 5512 | SCHECK_PARTIAL(); |
| 5513 | break; |
| 5514 | } |
| 5515 | GETCHARLENTEST(c, eptr, len); |
| 5516 | if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL || |
| 5517 | c == CHAR_FF || c == CHAR_CR) |
| 5518 | == prop_fail_result) |
| 5519 | break; |
| 5520 | eptr+= len; |
| 5521 | } |
| 5522 | break; |
| 5523 | |
| 5524 | case PT_PXSPACE: /* POSIX space */ |
| 5525 | for (i = min; i < max; i++) |
| 5526 | { |
| 5527 | int len = 1; |
| 5528 | if (eptr >= md->end_subject) |
| 5529 | { |
| 5530 | SCHECK_PARTIAL(); |
| 5531 | break; |
| 5532 | } |
| 5533 | GETCHARLENTEST(c, eptr, len); |
| 5534 | if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL || |
| 5535 | c == CHAR_VT || c == CHAR_FF || c == CHAR_CR) |
| 5536 | == prop_fail_result) |
| 5537 | break; |
| 5538 | eptr+= len; |
| 5539 | } |
| 5540 | break; |
| 5541 | |
| 5542 | case PT_WORD: |
| 5543 | for (i = min; i < max; i++) |
| 5544 | { |
| 5545 | int category; |
| 5546 | int len = 1; |
| 5547 | if (eptr >= md->end_subject) |
| 5548 | { |
| 5549 | SCHECK_PARTIAL(); |
| 5550 | break; |
| 5551 | } |
| 5552 | GETCHARLENTEST(c, eptr, len); |
| 5553 | category = UCD_CATEGORY(c); |
| 5554 | if ((category == ucp_L || category == ucp_N || |
| 5555 | c == CHAR_UNDERSCORE) == prop_fail_result) |
| 5556 | break; |
| 5557 | eptr+= len; |
| 5558 | } |
| 5559 | break; |
| 5560 | |
| 5561 | default: |
| 5562 | RRETURN(PCRE_ERROR_INTERNAL); |
| 5563 | } |
| 5564 | |
| 5565 | /* eptr is now past the end of the maximum run */ |
| 5566 | |
| 5567 | if (possessive) continue; |
| 5568 | for(;;) |
| 5569 | { |
| 5570 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM44); |
| 5571 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 5572 | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 5573 | if (utf) BACKCHAR(eptr); |
| 5574 | } |
| 5575 | } |
| 5576 | |
| 5577 | /* Match extended Unicode sequences. We will get here only if the |
| 5578 | support is in the binary; otherwise a compile-time error occurs. */ |
| 5579 | |
| 5580 | else if (ctype == OP_EXTUNI) |
| 5581 | { |
| 5582 | for (i = min; i < max; i++) |
| 5583 | { |
| 5584 | int len = 1; |
| 5585 | if (eptr >= md->end_subject) |
| 5586 | { |
| 5587 | SCHECK_PARTIAL(); |
| 5588 | break; |
| 5589 | } |
| 5590 | if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); } |
| 5591 | if (UCD_CATEGORY(c) == ucp_M) break; |
| 5592 | eptr += len; |
| 5593 | while (eptr < md->end_subject) |
| 5594 | { |
| 5595 | len = 1; |
| 5596 | if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); } |
| 5597 | if (UCD_CATEGORY(c) != ucp_M) break; |
| 5598 | eptr += len; |
| 5599 | } |
| 5600 | CHECK_PARTIAL(); |
| 5601 | } |
| 5602 | |
| 5603 | /* eptr is now past the end of the maximum run */ |
| 5604 | |
| 5605 | if (possessive) continue; |
| 5606 | |
| 5607 | for(;;) |
| 5608 | { |
| 5609 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM45); |
| 5610 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 5611 | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 5612 | for (;;) /* Move back over one extended */ |
| 5613 | { |
| 5614 | if (!utf) c = *eptr; else |
| 5615 | { |
| 5616 | BACKCHAR(eptr); |
| 5617 | GETCHAR(c, eptr); |
| 5618 | } |
| 5619 | if (UCD_CATEGORY(c) != ucp_M) break; |
| 5620 | eptr--; |
| 5621 | } |
| 5622 | } |
| 5623 | } |
| 5624 | |
| 5625 | else |
| 5626 | #endif /* SUPPORT_UCP */ |
| 5627 | |
| 5628 | #ifdef SUPPORT_UTF |
| 5629 | if (utf) |
| 5630 | { |
| 5631 | switch(ctype) |
| 5632 | { |
| 5633 | case OP_ANY: |
| 5634 | if (max < INT_MAX) |
| 5635 | { |
| 5636 | for (i = min; i < max; i++) |
| 5637 | { |
| 5638 | if (eptr >= md->end_subject) |
| 5639 | { |
| 5640 | SCHECK_PARTIAL(); |
| 5641 | break; |
| 5642 | } |
| 5643 | if (IS_NEWLINE(eptr)) break; |
| 5644 | if (md->partial != 0 && /* Take care with CRLF partial */ |
| 5645 | eptr + 1 >= md->end_subject && |
| 5646 | NLBLOCK->nltype == NLTYPE_FIXED && |
| 5647 | NLBLOCK->nllen == 2 && |
| 5648 | *eptr == NLBLOCK->nl[0]) |
| 5649 | { |
| 5650 | md->hitend = TRUE; |
| 5651 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 5652 | } |
| 5653 | eptr++; |
| 5654 | ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++); |
| 5655 | } |
| 5656 | } |
| 5657 | |
| 5658 | /* Handle unlimited UTF-8 repeat */ |
| 5659 | |
| 5660 | else |
| 5661 | { |
| 5662 | for (i = min; i < max; i++) |
| 5663 | { |
| 5664 | if (eptr >= md->end_subject) |
| 5665 | { |
| 5666 | SCHECK_PARTIAL(); |
| 5667 | break; |
| 5668 | } |
| 5669 | if (IS_NEWLINE(eptr)) break; |
| 5670 | if (md->partial != 0 && /* Take care with CRLF partial */ |
| 5671 | eptr + 1 >= md->end_subject && |
| 5672 | NLBLOCK->nltype == NLTYPE_FIXED && |
| 5673 | NLBLOCK->nllen == 2 && |
| 5674 | *eptr == NLBLOCK->nl[0]) |
| 5675 | { |
| 5676 | md->hitend = TRUE; |
| 5677 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 5678 | } |
| 5679 | eptr++; |
| 5680 | ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++); |
| 5681 | } |
| 5682 | } |
| 5683 | break; |
| 5684 | |
| 5685 | case OP_ALLANY: |
| 5686 | if (max < INT_MAX) |
| 5687 | { |
| 5688 | for (i = min; i < max; i++) |
| 5689 | { |
| 5690 | if (eptr >= md->end_subject) |
| 5691 | { |
| 5692 | SCHECK_PARTIAL(); |
| 5693 | break; |
| 5694 | } |
| 5695 | eptr++; |
| 5696 | ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++); |
| 5697 | } |
| 5698 | } |
| 5699 | else |
| 5700 | { |
| 5701 | eptr = md->end_subject; /* Unlimited UTF-8 repeat */ |
| 5702 | SCHECK_PARTIAL(); |
| 5703 | } |
| 5704 | break; |
| 5705 | |
| 5706 | /* The byte case is the same as non-UTF8 */ |
| 5707 | |
| 5708 | case OP_ANYBYTE: |
| 5709 | c = max - min; |
| 5710 | if (c > (unsigned int)(md->end_subject - eptr)) |
| 5711 | { |
| 5712 | eptr = md->end_subject; |
| 5713 | SCHECK_PARTIAL(); |
| 5714 | } |
| 5715 | else eptr += c; |
| 5716 | break; |
| 5717 | |
| 5718 | case OP_ANYNL: |
| 5719 | for (i = min; i < max; i++) |
| 5720 | { |
| 5721 | int len = 1; |
| 5722 | if (eptr >= md->end_subject) |
| 5723 | { |
| 5724 | SCHECK_PARTIAL(); |
| 5725 | break; |
| 5726 | } |
| 5727 | GETCHARLEN(c, eptr, len); |
| 5728 | if (c == 0x000d) |
| 5729 | { |
| 5730 | if (++eptr >= md->end_subject) break; |
| 5731 | if (*eptr == 0x000a) eptr++; |
| 5732 | } |
| 5733 | else |
| 5734 | { |
| 5735 | if (c != 0x000a && |
| 5736 | (md->bsr_anycrlf || |
| 5737 | (c != 0x000b && c != 0x000c && |
| 5738 | c != 0x0085 && c != 0x2028 && c != 0x2029))) |
| 5739 | break; |
| 5740 | eptr += len; |
| 5741 | } |
| 5742 | } |
| 5743 | break; |
| 5744 | |
| 5745 | case OP_NOT_HSPACE: |
| 5746 | case OP_HSPACE: |
| 5747 | for (i = min; i < max; i++) |
| 5748 | { |
| 5749 | BOOL gotspace; |
| 5750 | int len = 1; |
| 5751 | if (eptr >= md->end_subject) |
| 5752 | { |
| 5753 | SCHECK_PARTIAL(); |
| 5754 | break; |
| 5755 | } |
| 5756 | GETCHARLEN(c, eptr, len); |
| 5757 | switch(c) |
| 5758 | { |
| 5759 | default: gotspace = FALSE; break; |
| 5760 | case 0x09: /* HT */ |
| 5761 | case 0x20: /* SPACE */ |
| 5762 | case 0xa0: /* NBSP */ |
| 5763 | case 0x1680: /* OGHAM SPACE MARK */ |
| 5764 | case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ |
| 5765 | case 0x2000: /* EN QUAD */ |
| 5766 | case 0x2001: /* EM QUAD */ |
| 5767 | case 0x2002: /* EN SPACE */ |
| 5768 | case 0x2003: /* EM SPACE */ |
| 5769 | case 0x2004: /* THREE-PER-EM SPACE */ |
| 5770 | case 0x2005: /* FOUR-PER-EM SPACE */ |
| 5771 | case 0x2006: /* SIX-PER-EM SPACE */ |
| 5772 | case 0x2007: /* FIGURE SPACE */ |
| 5773 | case 0x2008: /* PUNCTUATION SPACE */ |
| 5774 | case 0x2009: /* THIN SPACE */ |
| 5775 | case 0x200A: /* HAIR SPACE */ |
| 5776 | case 0x202f: /* NARROW NO-BREAK SPACE */ |
| 5777 | case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 5778 | case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 5779 | gotspace = TRUE; |
| 5780 | break; |
| 5781 | } |
| 5782 | if (gotspace == (ctype == OP_NOT_HSPACE)) break; |
| 5783 | eptr += len; |
| 5784 | } |
| 5785 | break; |
| 5786 | |
| 5787 | case OP_NOT_VSPACE: |
| 5788 | case OP_VSPACE: |
| 5789 | for (i = min; i < max; i++) |
| 5790 | { |
| 5791 | BOOL gotspace; |
| 5792 | int len = 1; |
| 5793 | if (eptr >= md->end_subject) |
| 5794 | { |
| 5795 | SCHECK_PARTIAL(); |
| 5796 | break; |
| 5797 | } |
| 5798 | GETCHARLEN(c, eptr, len); |
| 5799 | switch(c) |
| 5800 | { |
| 5801 | default: gotspace = FALSE; break; |
| 5802 | case 0x0a: /* LF */ |
| 5803 | case 0x0b: /* VT */ |
| 5804 | case 0x0c: /* FF */ |
| 5805 | case 0x0d: /* CR */ |
| 5806 | case 0x85: /* NEL */ |
| 5807 | case 0x2028: /* LINE SEPARATOR */ |
| 5808 | case 0x2029: /* PARAGRAPH SEPARATOR */ |
| 5809 | gotspace = TRUE; |
| 5810 | break; |
| 5811 | } |
| 5812 | if (gotspace == (ctype == OP_NOT_VSPACE)) break; |
| 5813 | eptr += len; |
| 5814 | } |
| 5815 | break; |
| 5816 | |
| 5817 | case OP_NOT_DIGIT: |
| 5818 | for (i = min; i < max; i++) |
| 5819 | { |
| 5820 | int len = 1; |
| 5821 | if (eptr >= md->end_subject) |
| 5822 | { |
| 5823 | SCHECK_PARTIAL(); |
| 5824 | break; |
| 5825 | } |
| 5826 | GETCHARLEN(c, eptr, len); |
| 5827 | if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) break; |
| 5828 | eptr+= len; |
| 5829 | } |
| 5830 | break; |
| 5831 | |
| 5832 | case OP_DIGIT: |
| 5833 | for (i = min; i < max; i++) |
| 5834 | { |
| 5835 | int len = 1; |
| 5836 | if (eptr >= md->end_subject) |
| 5837 | { |
| 5838 | SCHECK_PARTIAL(); |
| 5839 | break; |
| 5840 | } |
| 5841 | GETCHARLEN(c, eptr, len); |
| 5842 | if (c >= 256 ||(md->ctypes[c] & ctype_digit) == 0) break; |
| 5843 | eptr+= len; |
| 5844 | } |
| 5845 | break; |
| 5846 | |
| 5847 | case OP_NOT_WHITESPACE: |
| 5848 | for (i = min; i < max; i++) |
| 5849 | { |
| 5850 | int len = 1; |
| 5851 | if (eptr >= md->end_subject) |
| 5852 | { |
| 5853 | SCHECK_PARTIAL(); |
| 5854 | break; |
| 5855 | } |
| 5856 | GETCHARLEN(c, eptr, len); |
| 5857 | if (c < 256 && (md->ctypes[c] & ctype_space) != 0) break; |
| 5858 | eptr+= len; |
| 5859 | } |
| 5860 | break; |
| 5861 | |
| 5862 | case OP_WHITESPACE: |
| 5863 | for (i = min; i < max; i++) |
| 5864 | { |
| 5865 | int len = 1; |
| 5866 | if (eptr >= md->end_subject) |
| 5867 | { |
| 5868 | SCHECK_PARTIAL(); |
| 5869 | break; |
| 5870 | } |
| 5871 | GETCHARLEN(c, eptr, len); |
| 5872 | if (c >= 256 ||(md->ctypes[c] & ctype_space) == 0) break; |
| 5873 | eptr+= len; |
| 5874 | } |
| 5875 | break; |
| 5876 | |
| 5877 | case OP_NOT_WORDCHAR: |
| 5878 | for (i = min; i < max; i++) |
| 5879 | { |
| 5880 | int len = 1; |
| 5881 | if (eptr >= md->end_subject) |
| 5882 | { |
| 5883 | SCHECK_PARTIAL(); |
| 5884 | break; |
| 5885 | } |
| 5886 | GETCHARLEN(c, eptr, len); |
| 5887 | if (c < 256 && (md->ctypes[c] & ctype_word) != 0) break; |
| 5888 | eptr+= len; |
| 5889 | } |
| 5890 | break; |
| 5891 | |
| 5892 | case OP_WORDCHAR: |
| 5893 | for (i = min; i < max; i++) |
| 5894 | { |
| 5895 | int len = 1; |
| 5896 | if (eptr >= md->end_subject) |
| 5897 | { |
| 5898 | SCHECK_PARTIAL(); |
| 5899 | break; |
| 5900 | } |
| 5901 | GETCHARLEN(c, eptr, len); |
| 5902 | if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) break; |
| 5903 | eptr+= len; |
| 5904 | } |
| 5905 | break; |
| 5906 | |
| 5907 | default: |
| 5908 | RRETURN(PCRE_ERROR_INTERNAL); |
| 5909 | } |
| 5910 | |
| 5911 | /* eptr is now past the end of the maximum run. If possessive, we are |
| 5912 | done (no backing up). Otherwise, match at this position; anything other |
| 5913 | than no match is immediately returned. For nomatch, back up one |
| 5914 | character, unless we are matching \R and the last thing matched was |
| 5915 | \r\n, in which case, back up two bytes. */ |
| 5916 | |
| 5917 | if (possessive) continue; |
| 5918 | for(;;) |
| 5919 | { |
| 5920 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM46); |
| 5921 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 5922 | if (eptr-- == pp) break; /* Stop if tried at original pos */ |
| 5923 | BACKCHAR(eptr); |
| 5924 | if (ctype == OP_ANYNL && eptr > pp && *eptr == '\n' && |
| 5925 | eptr[-1] == '\r') eptr--; |
| 5926 | } |
| 5927 | } |
| 5928 | else |
| 5929 | #endif /* SUPPORT_UTF */ |
| 5930 | /* Not UTF mode */ |
| 5931 | { |
| 5932 | switch(ctype) |
| 5933 | { |
| 5934 | case OP_ANY: |
| 5935 | for (i = min; i < max; i++) |
| 5936 | { |
| 5937 | if (eptr >= md->end_subject) |
| 5938 | { |
| 5939 | SCHECK_PARTIAL(); |
| 5940 | break; |
| 5941 | } |
| 5942 | if (IS_NEWLINE(eptr)) break; |
| 5943 | if (md->partial != 0 && /* Take care with CRLF partial */ |
| 5944 | eptr + 1 >= md->end_subject && |
| 5945 | NLBLOCK->nltype == NLTYPE_FIXED && |
| 5946 | NLBLOCK->nllen == 2 && |
| 5947 | *eptr == NLBLOCK->nl[0]) |
| 5948 | { |
| 5949 | md->hitend = TRUE; |
| 5950 | if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); |
| 5951 | } |
| 5952 | eptr++; |
| 5953 | } |
| 5954 | break; |
| 5955 | |
| 5956 | case OP_ALLANY: |
| 5957 | case OP_ANYBYTE: |
| 5958 | c = max - min; |
| 5959 | if (c > (unsigned int)(md->end_subject - eptr)) |
| 5960 | { |
| 5961 | eptr = md->end_subject; |
| 5962 | SCHECK_PARTIAL(); |
| 5963 | } |
| 5964 | else eptr += c; |
| 5965 | break; |
| 5966 | |
| 5967 | case OP_ANYNL: |
| 5968 | for (i = min; i < max; i++) |
| 5969 | { |
| 5970 | if (eptr >= md->end_subject) |
| 5971 | { |
| 5972 | SCHECK_PARTIAL(); |
| 5973 | break; |
| 5974 | } |
| 5975 | c = *eptr; |
| 5976 | if (c == 0x000d) |
| 5977 | { |
| 5978 | if (++eptr >= md->end_subject) break; |
| 5979 | if (*eptr == 0x000a) eptr++; |
| 5980 | } |
| 5981 | else |
| 5982 | { |
| 5983 | if (c != 0x000a && (md->bsr_anycrlf || |
| 5984 | (c != 0x000b && c != 0x000c && c != 0x0085 |
| 5985 | #ifdef COMPILE_PCRE16 |
| 5986 | && c != 0x2028 && c != 0x2029 |
| 5987 | #endif |
| 5988 | ))) break; |
| 5989 | eptr++; |
| 5990 | } |
| 5991 | } |
| 5992 | break; |
| 5993 | |
| 5994 | case OP_NOT_HSPACE: |
| 5995 | for (i = min; i < max; i++) |
| 5996 | { |
| 5997 | if (eptr >= md->end_subject) |
| 5998 | { |
| 5999 | SCHECK_PARTIAL(); |
| 6000 | break; |
| 6001 | } |
| 6002 | c = *eptr; |
| 6003 | if (c == 0x09 || c == 0x20 || c == 0xa0 |
| 6004 | #ifdef COMPILE_PCRE16 |
| 6005 | || c == 0x1680 || c == 0x180e || (c >= 0x2000 && c <= 0x200A) |
| 6006 | || c == 0x202f || c == 0x205f || c == 0x3000 |
| 6007 | #endif |
| 6008 | ) break; |
| 6009 | eptr++; |
| 6010 | } |
| 6011 | break; |
| 6012 | |
| 6013 | case OP_HSPACE: |
| 6014 | for (i = min; i < max; i++) |
| 6015 | { |
| 6016 | if (eptr >= md->end_subject) |
| 6017 | { |
| 6018 | SCHECK_PARTIAL(); |
| 6019 | break; |
| 6020 | } |
| 6021 | c = *eptr; |
| 6022 | if (c != 0x09 && c != 0x20 && c != 0xa0 |
| 6023 | #ifdef COMPILE_PCRE16 |
| 6024 | && c != 0x1680 && c != 0x180e && (c < 0x2000 || c > 0x200A) |
| 6025 | && c != 0x202f && c != 0x205f && c != 0x3000 |
| 6026 | #endif |
| 6027 | ) break; |
| 6028 | eptr++; |
| 6029 | } |
| 6030 | break; |
| 6031 | |
| 6032 | case OP_NOT_VSPACE: |
| 6033 | for (i = min; i < max; i++) |
| 6034 | { |
| 6035 | if (eptr >= md->end_subject) |
| 6036 | { |
| 6037 | SCHECK_PARTIAL(); |
| 6038 | break; |
| 6039 | } |
| 6040 | c = *eptr; |
| 6041 | if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85 |
| 6042 | #ifdef COMPILE_PCRE16 |
| 6043 | || c == 0x2028 || c == 0x2029 |
| 6044 | #endif |
| 6045 | ) break; |
| 6046 | eptr++; |
| 6047 | } |
| 6048 | break; |
| 6049 | |
| 6050 | case OP_VSPACE: |
| 6051 | for (i = min; i < max; i++) |
| 6052 | { |
| 6053 | if (eptr >= md->end_subject) |
| 6054 | { |
| 6055 | SCHECK_PARTIAL(); |
| 6056 | break; |
| 6057 | } |
| 6058 | c = *eptr; |
| 6059 | if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85 |
| 6060 | #ifdef COMPILE_PCRE16 |
| 6061 | && c != 0x2028 && c != 0x2029 |
| 6062 | #endif |
| 6063 | ) break; |
| 6064 | eptr++; |
| 6065 | } |
| 6066 | break; |
| 6067 | |
| 6068 | case OP_NOT_DIGIT: |
| 6069 | for (i = min; i < max; i++) |
| 6070 | { |
| 6071 | if (eptr >= md->end_subject) |
| 6072 | { |
| 6073 | SCHECK_PARTIAL(); |
| 6074 | break; |
| 6075 | } |
| 6076 | if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_digit) != 0) break; |
| 6077 | eptr++; |
| 6078 | } |
| 6079 | break; |
| 6080 | |
| 6081 | case OP_DIGIT: |
| 6082 | for (i = min; i < max; i++) |
| 6083 | { |
| 6084 | if (eptr >= md->end_subject) |
| 6085 | { |
| 6086 | SCHECK_PARTIAL(); |
| 6087 | break; |
| 6088 | } |
| 6089 | if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_digit) == 0) break; |
| 6090 | eptr++; |
| 6091 | } |
| 6092 | break; |
| 6093 | |
| 6094 | case OP_NOT_WHITESPACE: |
| 6095 | for (i = min; i < max; i++) |
| 6096 | { |
| 6097 | if (eptr >= md->end_subject) |
| 6098 | { |
| 6099 | SCHECK_PARTIAL(); |
| 6100 | break; |
| 6101 | } |
| 6102 | if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_space) != 0) break; |
| 6103 | eptr++; |
| 6104 | } |
| 6105 | break; |
| 6106 | |
| 6107 | case OP_WHITESPACE: |
| 6108 | for (i = min; i < max; i++) |
| 6109 | { |
| 6110 | if (eptr >= md->end_subject) |
| 6111 | { |
| 6112 | SCHECK_PARTIAL(); |
| 6113 | break; |
| 6114 | } |
| 6115 | if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_space) == 0) break; |
| 6116 | eptr++; |
| 6117 | } |
| 6118 | break; |
| 6119 | |
| 6120 | case OP_NOT_WORDCHAR: |
| 6121 | for (i = min; i < max; i++) |
| 6122 | { |
| 6123 | if (eptr >= md->end_subject) |
| 6124 | { |
| 6125 | SCHECK_PARTIAL(); |
| 6126 | break; |
| 6127 | } |
| 6128 | if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_word) != 0) break; |
| 6129 | eptr++; |
| 6130 | } |
| 6131 | break; |
| 6132 | |
| 6133 | case OP_WORDCHAR: |
| 6134 | for (i = min; i < max; i++) |
| 6135 | { |
| 6136 | if (eptr >= md->end_subject) |
| 6137 | { |
| 6138 | SCHECK_PARTIAL(); |
| 6139 | break; |
| 6140 | } |
| 6141 | if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_word) == 0) break; |
| 6142 | eptr++; |
| 6143 | } |
| 6144 | break; |
| 6145 | |
| 6146 | default: |
| 6147 | RRETURN(PCRE_ERROR_INTERNAL); |
| 6148 | } |
| 6149 | |
| 6150 | /* eptr is now past the end of the maximum run. If possessive, we are |
| 6151 | done (no backing up). Otherwise, match at this position; anything other |
| 6152 | than no match is immediately returned. For nomatch, back up one |
| 6153 | character (byte), unless we are matching \R and the last thing matched |
| 6154 | was \r\n, in which case, back up two bytes. */ |
| 6155 | |
| 6156 | if (possessive) continue; |
| 6157 | while (eptr >= pp) |
| 6158 | { |
| 6159 | RMATCH(eptr, ecode, offset_top, md, eptrb, RM47); |
| 6160 | if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
| 6161 | eptr--; |
| 6162 | if (ctype == OP_ANYNL && eptr > pp && *eptr == '\n' && |
| 6163 | eptr[-1] == '\r') eptr--; |
| 6164 | } |
| 6165 | } |
| 6166 | |
| 6167 | /* Get here if we can't make it match with any permitted repetitions */ |
| 6168 | |
| 6169 | RRETURN(MATCH_NOMATCH); |
| 6170 | } |
| 6171 | /* Control never gets here */ |
| 6172 | |
| 6173 | /* There's been some horrible disaster. Arrival here can only mean there is |
| 6174 | something seriously wrong in the code above or the OP_xxx definitions. */ |
| 6175 | |
| 6176 | default: |
| 6177 | DPRINTF(("Unknown opcode %d\n", *ecode)); |
| 6178 | RRETURN(PCRE_ERROR_UNKNOWN_OPCODE); |
| 6179 | } |
| 6180 | |
| 6181 | /* Do not stick any code in here without much thought; it is assumed |
| 6182 | that "continue" in the code above comes out to here to repeat the main |
| 6183 | loop. */ |
| 6184 | |
| 6185 | } /* End of main loop */ |
| 6186 | /* Control never reaches here */ |
| 6187 | |
| 6188 | |
| 6189 | /* When compiling to use the heap rather than the stack for recursive calls to |
| 6190 | match(), the RRETURN() macro jumps here. The number that is saved in |
| 6191 | frame->Xwhere indicates which label we actually want to return to. */ |
| 6192 | |
| 6193 | #ifdef NO_RECURSE |
| 6194 | #define LBL(val) case val: goto L_RM##val; |
| 6195 | HEAP_RETURN: |
| 6196 | switch (frame->Xwhere) |
| 6197 | { |
| 6198 | LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8) |
| 6199 | LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17) |
| 6200 | LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33) |
| 6201 | LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52) |
| 6202 | LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58) LBL(63) LBL(64) |
| 6203 | LBL(65) LBL(66) |
| 6204 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 |
| 6205 | LBL(21) |
| 6206 | #endif |
| 6207 | #ifdef SUPPORT_UTF |
| 6208 | LBL(16) LBL(18) LBL(20) |
| 6209 | LBL(22) LBL(23) LBL(28) LBL(30) |
| 6210 | LBL(32) LBL(34) LBL(42) LBL(46) |
| 6211 | #ifdef SUPPORT_UCP |
| 6212 | LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45) |
| 6213 | LBL(59) LBL(60) LBL(61) LBL(62) |
| 6214 | #endif /* SUPPORT_UCP */ |
| 6215 | #endif /* SUPPORT_UTF */ |
| 6216 | default: |
| 6217 | DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere)); |
| 6218 | |
| 6219 | printf("+++jump error in pcre match: label %d non-existent\n", frame->Xwhere); |
| 6220 | |
| 6221 | return PCRE_ERROR_INTERNAL; |
| 6222 | } |
| 6223 | #undef LBL |
| 6224 | #endif /* NO_RECURSE */ |
| 6225 | } |
| 6226 | |
| 6227 | |
| 6228 | /*************************************************************************** |
| 6229 | **************************************************************************** |
| 6230 | RECURSION IN THE match() FUNCTION |
| 6231 | |
| 6232 | Undefine all the macros that were defined above to handle this. */ |
| 6233 | |
| 6234 | #ifdef NO_RECURSE |
| 6235 | #undef eptr |
| 6236 | #undef ecode |
| 6237 | #undef mstart |
| 6238 | #undef offset_top |
| 6239 | #undef eptrb |
| 6240 | #undef flags |
| 6241 | |
| 6242 | #undef callpat |
| 6243 | #undef charptr |
| 6244 | #undef data |
| 6245 | #undef next |
| 6246 | #undef pp |
| 6247 | #undef prev |
| 6248 | #undef saved_eptr |
| 6249 | |
| 6250 | #undef new_recursive |
| 6251 | |
| 6252 | #undef cur_is_word |
| 6253 | #undef condition |
| 6254 | #undef prev_is_word |
| 6255 | |
| 6256 | #undef ctype |
| 6257 | #undef length |
| 6258 | #undef max |
| 6259 | #undef min |
| 6260 | #undef number |
| 6261 | #undef offset |
| 6262 | #undef op |
| 6263 | #undef save_capture_last |
| 6264 | #undef save_offset1 |
| 6265 | #undef save_offset2 |
| 6266 | #undef save_offset3 |
| 6267 | #undef stacksave |
| 6268 | |
| 6269 | #undef newptrb |
| 6270 | |
| 6271 | #endif |
| 6272 | |
| 6273 | /* These two are defined as macros in both cases */ |
| 6274 | |
| 6275 | #undef fc |
| 6276 | #undef fi |
| 6277 | |
| 6278 | /*************************************************************************** |
| 6279 | ***************************************************************************/ |
| 6280 | |
| 6281 | |
| 6282 | |
| 6283 | /************************************************* |
| 6284 | * Execute a Regular Expression * |
| 6285 | *************************************************/ |
| 6286 | |
| 6287 | /* This function applies a compiled re to a subject string and picks out |
| 6288 | portions of the string if it matches. Two elements in the vector are set for |
| 6289 | each substring: the offsets to the start and end of the substring. |
| 6290 | |
| 6291 | Arguments: |
| 6292 | argument_re points to the compiled expression |
| 6293 | extra_data points to extra data or is NULL |
| 6294 | subject points to the subject string |
| 6295 | length length of subject string (may contain binary zeros) |
| 6296 | start_offset where to start in the subject string |
| 6297 | options option bits |
| 6298 | offsets points to a vector of ints to be filled in with offsets |
| 6299 | offsetcount the number of elements in the vector |
| 6300 | |
| 6301 | Returns: > 0 => success; value is the number of elements filled in |
| 6302 | = 0 => success, but offsets is not big enough |
| 6303 | -1 => failed to match |
| 6304 | < -1 => some kind of unexpected problem |
| 6305 | */ |
| 6306 | |
| 6307 | #ifdef COMPILE_PCRE8 |
| 6308 | PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
| 6309 | pcre_exec(const pcre *argument_re, const pcre_extra *extra_data, |
| 6310 | PCRE_SPTR subject, int length, int start_offset, int options, int *offsets, |
| 6311 | int offsetcount) |
| 6312 | #else |
| 6313 | PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
| 6314 | pcre16_exec(const pcre16 *argument_re, const pcre16_extra *extra_data, |
| 6315 | PCRE_SPTR16 subject, int length, int start_offset, int options, int *offsets, |
| 6316 | int offsetcount) |
| 6317 | #endif |
| 6318 | { |
| 6319 | int rc, ocount, arg_offset_max; |
| 6320 | int newline; |
| 6321 | BOOL using_temporary_offsets = FALSE; |
| 6322 | BOOL anchored; |
| 6323 | BOOL startline; |
| 6324 | BOOL firstline; |
| 6325 | BOOL utf; |
| 6326 | BOOL has_first_char = FALSE; |
| 6327 | BOOL has_req_char = FALSE; |
| 6328 | pcre_uchar first_char = 0; |
| 6329 | pcre_uchar first_char2 = 0; |
| 6330 | pcre_uchar req_char = 0; |
| 6331 | pcre_uchar req_char2 = 0; |
| 6332 | match_data match_block; |
| 6333 | match_data *md = &match_block; |
| 6334 | const pcre_uint8 *tables; |
| 6335 | const pcre_uint8 *start_bits = NULL; |
| 6336 | PCRE_PUCHAR start_match = (PCRE_PUCHAR)subject + start_offset; |
| 6337 | PCRE_PUCHAR end_subject; |
| 6338 | PCRE_PUCHAR start_partial = NULL; |
| 6339 | PCRE_PUCHAR req_char_ptr = start_match - 1; |
| 6340 | |
| 6341 | const pcre_study_data *study; |
| 6342 | const REAL_PCRE *re = (const REAL_PCRE *)argument_re; |
| 6343 | |
| 6344 | /* Check for the special magic call that measures the size of the stack used |
| 6345 | per recursive call of match(). Without the funny casting for sizeof, a Windows |
| 6346 | compiler gave this error: "unary minus operator applied to unsigned type, |
| 6347 | result still unsigned". Hopefully the cast fixes that. */ |
| 6348 | |
| 6349 | if (re == NULL && extra_data == NULL && subject == NULL && length == -999 && |
| 6350 | start_offset == -999) |
| 6351 | #ifdef NO_RECURSE |
| 6352 | return -((int)sizeof(heapframe)); |
| 6353 | #else |
| 6354 | return match(NULL, NULL, NULL, 0, NULL, NULL, 0); |
| 6355 | #endif |
| 6356 | |
| 6357 | /* Plausibility checks */ |
| 6358 | |
| 6359 | if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION; |
| 6360 | if (re == NULL || subject == NULL || (offsets == NULL && offsetcount > 0)) |
| 6361 | return PCRE_ERROR_NULL; |
| 6362 | if (offsetcount < 0) return PCRE_ERROR_BADCOUNT; |
| 6363 | if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET; |
| 6364 | |
| 6365 | /* Check that the first field in the block is the magic number. If it is not, |
| 6366 | return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to |
| 6367 | REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which |
| 6368 | means that the pattern is likely compiled with different endianness. */ |
| 6369 | |
| 6370 | if (re->magic_number != MAGIC_NUMBER) |
| 6371 | return re->magic_number == REVERSED_MAGIC_NUMBER? |
| 6372 | PCRE_ERROR_BADENDIANNESS:PCRE_ERROR_BADMAGIC; |
| 6373 | if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE; |
| 6374 | |
| 6375 | /* These two settings are used in the code for checking a UTF-8 string that |
| 6376 | follows immediately afterwards. Other values in the md block are used only |
| 6377 | during "normal" pcre_exec() processing, not when the JIT support is in use, |
| 6378 | so they are set up later. */ |
| 6379 | |
| 6380 | /* PCRE_UTF16 has the same value as PCRE_UTF8. */ |
| 6381 | utf = md->utf = (re->options & PCRE_UTF8) != 0; |
| 6382 | md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 : |
| 6383 | ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0; |
| 6384 | |
| 6385 | /* Check a UTF-8 string if required. Pass back the character offset and error |
| 6386 | code for an invalid string if a results vector is available. */ |
| 6387 | |
| 6388 | #ifdef SUPPORT_UTF |
| 6389 | if (utf && (options & PCRE_NO_UTF8_CHECK) == 0) |
| 6390 | { |
| 6391 | int erroroffset; |
| 6392 | int errorcode = PRIV(valid_utf)((PCRE_PUCHAR)subject, length, &erroroffset); |
| 6393 | if (errorcode != 0) |
| 6394 | { |
| 6395 | if (offsetcount >= 2) |
| 6396 | { |
| 6397 | offsets[0] = erroroffset; |
| 6398 | offsets[1] = errorcode; |
| 6399 | } |
| 6400 | #ifdef COMPILE_PCRE16 |
| 6401 | return (errorcode <= PCRE_UTF16_ERR1 && md->partial > 1)? |
| 6402 | PCRE_ERROR_SHORTUTF16 : PCRE_ERROR_BADUTF16; |
| 6403 | #else |
| 6404 | return (errorcode <= PCRE_UTF8_ERR5 && md->partial > 1)? |
| 6405 | PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8; |
| 6406 | #endif |
| 6407 | } |
| 6408 | |
| 6409 | /* Check that a start_offset points to the start of a UTF character. */ |
| 6410 | if (start_offset > 0 && start_offset < length && |
| 6411 | NOT_FIRSTCHAR(((PCRE_PUCHAR)subject)[start_offset])) |
| 6412 | return PCRE_ERROR_BADUTF8_OFFSET; |
| 6413 | } |
| 6414 | #endif |
| 6415 | |
| 6416 | /* If the pattern was successfully studied with JIT support, run the JIT |
| 6417 | executable instead of the rest of this function. Most options must be set at |
| 6418 | compile time for the JIT code to be usable. Fallback to the normal code path if |
| 6419 | an unsupported flag is set. */ |
| 6420 | |
| 6421 | #ifdef SUPPORT_JIT |
| 6422 | if (extra_data != NULL |
| 6423 | && (extra_data->flags & (PCRE_EXTRA_EXECUTABLE_JIT | |
| 6424 | PCRE_EXTRA_TABLES)) == PCRE_EXTRA_EXECUTABLE_JIT |
| 6425 | && extra_data->executable_jit != NULL |
| 6426 | && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL | |
| 6427 | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | |
| 6428 | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD)) == 0) |
| 6429 | { |
| 6430 | rc = PRIV(jit_exec)(re, extra_data->executable_jit, |
| 6431 | (const pcre_uchar *)subject, length, start_offset, options, |
| 6432 | ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) |
| 6433 | ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount, |
| 6434 | ((extra_data->flags & PCRE_EXTRA_MARK) != 0) ? extra_data->mark : NULL); |
| 6435 | |
| 6436 | /* PCRE_ERROR_NULL means that the selected normal or partial matching |
| 6437 | mode is not compiled. In this case we simply fallback to interpreter. */ |
| 6438 | |
| 6439 | if (rc != PCRE_ERROR_NULL) return rc; |
| 6440 | } |
| 6441 | #endif |
| 6442 | |
| 6443 | /* Carry on with non-JIT matching. This information is for finding all the |
| 6444 | numbers associated with a given name, for condition testing. */ |
| 6445 | |
| 6446 | md->name_table = (pcre_uchar *)re + re->name_table_offset; |
| 6447 | md->name_count = re->name_count; |
| 6448 | md->name_entry_size = re->name_entry_size; |
| 6449 | |
| 6450 | /* Fish out the optional data from the extra_data structure, first setting |
| 6451 | the default values. */ |
| 6452 | |
| 6453 | study = NULL; |
| 6454 | md->match_limit = MATCH_LIMIT; |
| 6455 | md->match_limit_recursion = MATCH_LIMIT_RECURSION; |
| 6456 | md->callout_data = NULL; |
| 6457 | |
| 6458 | /* The table pointer is always in native byte order. */ |
| 6459 | |
| 6460 | tables = re->tables; |
| 6461 | |
| 6462 | if (extra_data != NULL) |
| 6463 | { |
| 6464 | register unsigned int flags = extra_data->flags; |
| 6465 | if ((flags & PCRE_EXTRA_STUDY_DATA) != 0) |
| 6466 | study = (const pcre_study_data *)extra_data->study_data; |
| 6467 | if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0) |
| 6468 | md->match_limit = extra_data->match_limit; |
| 6469 | if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0) |
| 6470 | md->match_limit_recursion = extra_data->match_limit_recursion; |
| 6471 | if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0) |
| 6472 | md->callout_data = extra_data->callout_data; |
| 6473 | if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables; |
| 6474 | } |
| 6475 | |
| 6476 | /* If the exec call supplied NULL for tables, use the inbuilt ones. This |
| 6477 | is a feature that makes it possible to save compiled regex and re-use them |
| 6478 | in other programs later. */ |
| 6479 | |
| 6480 | if (tables == NULL) tables = PRIV(default_tables); |
| 6481 | |
| 6482 | /* Set up other data */ |
| 6483 | |
| 6484 | anchored = ((re->options | options) & PCRE_ANCHORED) != 0; |
| 6485 | startline = (re->flags & PCRE_STARTLINE) != 0; |
| 6486 | firstline = (re->options & PCRE_FIRSTLINE) != 0; |
| 6487 | |
| 6488 | /* The code starts after the real_pcre block and the capture name table. */ |
| 6489 | |
| 6490 | md->start_code = (const pcre_uchar *)re + re->name_table_offset + |
| 6491 | re->name_count * re->name_entry_size; |
| 6492 | |
| 6493 | md->start_subject = (PCRE_PUCHAR)subject; |
| 6494 | md->start_offset = start_offset; |
| 6495 | md->end_subject = md->start_subject + length; |
| 6496 | end_subject = md->end_subject; |
| 6497 | |
| 6498 | md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0; |
| 6499 | md->use_ucp = (re->options & PCRE_UCP) != 0; |
| 6500 | md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0; |
| 6501 | md->ignore_skip_arg = FALSE; |
| 6502 | |
| 6503 | /* Some options are unpacked into BOOL variables in the hope that testing |
| 6504 | them will be faster than individual option bits. */ |
| 6505 | |
| 6506 | md->notbol = (options & PCRE_NOTBOL) != 0; |
| 6507 | md->noteol = (options & PCRE_NOTEOL) != 0; |
| 6508 | md->notempty = (options & PCRE_NOTEMPTY) != 0; |
| 6509 | md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0; |
| 6510 | |
| 6511 | md->hitend = FALSE; |
| 6512 | md->mark = md->nomatch_mark = NULL; /* In case never set */ |
| 6513 | |
| 6514 | md->recursive = NULL; /* No recursion at top level */ |
| 6515 | md->hasthen = (re->flags & PCRE_HASTHEN) != 0; |
| 6516 | |
| 6517 | md->lcc = tables + lcc_offset; |
| 6518 | md->fcc = tables + fcc_offset; |
| 6519 | md->ctypes = tables + ctypes_offset; |
| 6520 | |
| 6521 | /* Handle different \R options. */ |
| 6522 | |
| 6523 | switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) |
| 6524 | { |
| 6525 | case 0: |
| 6526 | if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0) |
| 6527 | md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0; |
| 6528 | else |
| 6529 | #ifdef BSR_ANYCRLF |
| 6530 | md->bsr_anycrlf = TRUE; |
| 6531 | #else |
| 6532 | md->bsr_anycrlf = FALSE; |
| 6533 | #endif |
| 6534 | break; |
| 6535 | |
| 6536 | case PCRE_BSR_ANYCRLF: |
| 6537 | md->bsr_anycrlf = TRUE; |
| 6538 | break; |
| 6539 | |
| 6540 | case PCRE_BSR_UNICODE: |
| 6541 | md->bsr_anycrlf = FALSE; |
| 6542 | break; |
| 6543 | |
| 6544 | default: return PCRE_ERROR_BADNEWLINE; |
| 6545 | } |
| 6546 | |
| 6547 | /* Handle different types of newline. The three bits give eight cases. If |
| 6548 | nothing is set at run time, whatever was used at compile time applies. */ |
| 6549 | |
| 6550 | switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : |
| 6551 | (pcre_uint32)options) & PCRE_NEWLINE_BITS) |
| 6552 | { |
| 6553 | case 0: newline = NEWLINE; break; /* Compile-time default */ |
| 6554 | case PCRE_NEWLINE_CR: newline = CHAR_CR; break; |
| 6555 | case PCRE_NEWLINE_LF: newline = CHAR_NL; break; |
| 6556 | case PCRE_NEWLINE_CR+ |
| 6557 | PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break; |
| 6558 | case PCRE_NEWLINE_ANY: newline = -1; break; |
| 6559 | case PCRE_NEWLINE_ANYCRLF: newline = -2; break; |
| 6560 | default: return PCRE_ERROR_BADNEWLINE; |
| 6561 | } |
| 6562 | |
| 6563 | if (newline == -2) |
| 6564 | { |
| 6565 | md->nltype = NLTYPE_ANYCRLF; |
| 6566 | } |
| 6567 | else if (newline < 0) |
| 6568 | { |
| 6569 | md->nltype = NLTYPE_ANY; |
| 6570 | } |
| 6571 | else |
| 6572 | { |
| 6573 | md->nltype = NLTYPE_FIXED; |
| 6574 | if (newline > 255) |
| 6575 | { |
| 6576 | md->nllen = 2; |
| 6577 | md->nl[0] = (newline >> 8) & 255; |
| 6578 | md->nl[1] = newline & 255; |
| 6579 | } |
| 6580 | else |
| 6581 | { |
| 6582 | md->nllen = 1; |
| 6583 | md->nl[0] = newline; |
| 6584 | } |
| 6585 | } |
| 6586 | |
| 6587 | /* Partial matching was originally supported only for a restricted set of |
| 6588 | regexes; from release 8.00 there are no restrictions, but the bits are still |
| 6589 | defined (though never set). So there's no harm in leaving this code. */ |
| 6590 | |
| 6591 | if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0) |
| 6592 | return PCRE_ERROR_BADPARTIAL; |
| 6593 | |
| 6594 | /* If the expression has got more back references than the offsets supplied can |
| 6595 | hold, we get a temporary chunk of working store to use during the matching. |
| 6596 | Otherwise, we can use the vector supplied, rounding down its size to a multiple |
| 6597 | of 3. */ |
| 6598 | |
| 6599 | ocount = offsetcount - (offsetcount % 3); |
| 6600 | arg_offset_max = (2*ocount)/3; |
| 6601 | |
| 6602 | if (re->top_backref > 0 && re->top_backref >= ocount/3) |
| 6603 | { |
| 6604 | ocount = re->top_backref * 3 + 3; |
| 6605 | md->offset_vector = (int *)(PUBL(malloc))(ocount * sizeof(int)); |
| 6606 | if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY; |
| 6607 | using_temporary_offsets = TRUE; |
| 6608 | DPRINTF(("Got memory to hold back references\n")); |
| 6609 | } |
| 6610 | else md->offset_vector = offsets; |
| 6611 | |
| 6612 | md->offset_end = ocount; |
| 6613 | md->offset_max = (2*ocount)/3; |
| 6614 | md->offset_overflow = FALSE; |
| 6615 | md->capture_last = -1; |
| 6616 | |
| 6617 | /* Reset the working variable associated with each extraction. These should |
| 6618 | never be used unless previously set, but they get saved and restored, and so we |
| 6619 | initialize them to avoid reading uninitialized locations. Also, unset the |
| 6620 | offsets for the matched string. This is really just for tidiness with callouts, |
| 6621 | in case they inspect these fields. */ |
| 6622 | |
| 6623 | if (md->offset_vector != NULL) |
| 6624 | { |
| 6625 | register int *iptr = md->offset_vector + ocount; |
| 6626 | register int *iend = iptr - re->top_bracket; |
| 6627 | if (iend < md->offset_vector + 2) iend = md->offset_vector + 2; |
| 6628 | while (--iptr >= iend) *iptr = -1; |
| 6629 | md->offset_vector[0] = md->offset_vector[1] = -1; |
| 6630 | } |
| 6631 | |
| 6632 | /* Set up the first character to match, if available. The first_char value is |
| 6633 | never set for an anchored regular expression, but the anchoring may be forced |
| 6634 | at run time, so we have to test for anchoring. The first char may be unset for |
| 6635 | an unanchored pattern, of course. If there's no first char and the pattern was |
| 6636 | studied, there may be a bitmap of possible first characters. */ |
| 6637 | |
| 6638 | if (!anchored) |
| 6639 | { |
| 6640 | if ((re->flags & PCRE_FIRSTSET) != 0) |
| 6641 | { |
| 6642 | has_first_char = TRUE; |
| 6643 | first_char = first_char2 = (pcre_uchar)(re->first_char); |
| 6644 | if ((re->flags & PCRE_FCH_CASELESS) != 0) |
| 6645 | { |
| 6646 | first_char2 = TABLE_GET(first_char, md->fcc, first_char); |
| 6647 | #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8) |
| 6648 | if (utf && first_char > 127) |
| 6649 | first_char2 = UCD_OTHERCASE(first_char); |
| 6650 | #endif |
| 6651 | } |
| 6652 | } |
| 6653 | else |
| 6654 | if (!startline && study != NULL && |
| 6655 | (study->flags & PCRE_STUDY_MAPPED) != 0) |
| 6656 | start_bits = study->start_bits; |
| 6657 | } |
| 6658 | |
| 6659 | /* For anchored or unanchored matches, there may be a "last known required |
| 6660 | character" set. */ |
| 6661 | |
| 6662 | if ((re->flags & PCRE_REQCHSET) != 0) |
| 6663 | { |
| 6664 | has_req_char = TRUE; |
| 6665 | req_char = req_char2 = (pcre_uchar)(re->req_char); |
| 6666 | if ((re->flags & PCRE_RCH_CASELESS) != 0) |
| 6667 | { |
| 6668 | req_char2 = TABLE_GET(req_char, md->fcc, req_char); |
| 6669 | #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8) |
| 6670 | if (utf && req_char > 127) |
| 6671 | req_char2 = UCD_OTHERCASE(req_char); |
| 6672 | #endif |
| 6673 | } |
| 6674 | } |
| 6675 | |
| 6676 | |
| 6677 | /* ==========================================================================*/ |
| 6678 | |
| 6679 | /* Loop for handling unanchored repeated matching attempts; for anchored regexs |
| 6680 | the loop runs just once. */ |
| 6681 | |
| 6682 | for(;;) |
| 6683 | { |
| 6684 | PCRE_PUCHAR save_end_subject = end_subject; |
| 6685 | PCRE_PUCHAR new_start_match; |
| 6686 | |
| 6687 | /* If firstline is TRUE, the start of the match is constrained to the first |
| 6688 | line of a multiline string. That is, the match must be before or at the first |
| 6689 | newline. Implement this by temporarily adjusting end_subject so that we stop |
| 6690 | scanning at a newline. If the match fails at the newline, later code breaks |
| 6691 | this loop. */ |
| 6692 | |
| 6693 | if (firstline) |
| 6694 | { |
| 6695 | PCRE_PUCHAR t = start_match; |
| 6696 | #ifdef SUPPORT_UTF |
| 6697 | if (utf) |
| 6698 | { |
| 6699 | while (t < md->end_subject && !IS_NEWLINE(t)) |
| 6700 | { |
| 6701 | t++; |
| 6702 | ACROSSCHAR(t < end_subject, *t, t++); |
| 6703 | } |
| 6704 | } |
| 6705 | else |
| 6706 | #endif |
| 6707 | while (t < md->end_subject && !IS_NEWLINE(t)) t++; |
| 6708 | end_subject = t; |
| 6709 | } |
| 6710 | |
| 6711 | /* There are some optimizations that avoid running the match if a known |
| 6712 | starting point is not found, or if a known later character is not present. |
| 6713 | However, there is an option that disables these, for testing and for ensuring |
| 6714 | that all callouts do actually occur. The option can be set in the regex by |
| 6715 | (*NO_START_OPT) or passed in match-time options. */ |
| 6716 | |
| 6717 | if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0) |
| 6718 | { |
| 6719 | /* Advance to a unique first char if there is one. */ |
| 6720 | |
| 6721 | if (has_first_char) |
| 6722 | { |
| 6723 | if (first_char != first_char2) |
| 6724 | while (start_match < end_subject && |
| 6725 | *start_match != first_char && *start_match != first_char2) |
| 6726 | start_match++; |
| 6727 | else |
| 6728 | while (start_match < end_subject && *start_match != first_char) |
| 6729 | start_match++; |
| 6730 | } |
| 6731 | |
| 6732 | /* Or to just after a linebreak for a multiline match */ |
| 6733 | |
| 6734 | else if (startline) |
| 6735 | { |
| 6736 | if (start_match > md->start_subject + start_offset) |
| 6737 | { |
| 6738 | #ifdef SUPPORT_UTF |
| 6739 | if (utf) |
| 6740 | { |
| 6741 | while (start_match < end_subject && !WAS_NEWLINE(start_match)) |