2007-11-24 Eric Seidel <eric@webkit.org>
[WebKit-https.git] / JavaScriptCore / pcre / pcre_exec.cpp
1 /* This is JavaScriptCore's variant of the PCRE library. While this library
2 started out as a copy of PCRE, many of the features of PCRE have been
3 removed. This library now supports only the regular expression features
4 required by the JavaScript language specification, and has only the functions
5 needed by JavaScriptCore and the rest of WebKit.
6
7                  Originally written by Philip Hazel
8            Copyright (c) 1997-2006 University of Cambridge
9     Copyright (C) 2002, 2004, 2006, 2007 Apple Inc. All rights reserved.
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 /* This module contains jsRegExpExecute(), the externally visible function
41 that does pattern matching using an NFA algorithm, following the rules from
42 the JavaScript specification. There are also some supporting functions. */
43
44 #include "config.h"
45
46 #include "pcre_internal.h"
47
48 #include <wtf/ASCIICType.h>
49 #include <wtf/Vector.h>
50
51 using namespace WTF;
52
53 #ifdef __GNUC__
54 #define USE_COMPUTED_GOTO_FOR_MATCH_RECURSION
55 //#define USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP
56 #endif
57
58 /* Avoid warnings on Windows. */
59 #undef min
60 #undef max
61
62 /* Structure for building a chain of data that actually lives on the
63 stack, for holding the values of the subject pointer at the start of each
64 subpattern, so as to detect when an empty string has been matched by a
65 subpattern - to break infinite loops. When NO_RECURSE is set, these blocks
66 are on the heap, not on the stack. */
67
68 struct eptrblock {
69   struct eptrblock* epb_prev;
70   UChar* epb_saved_eptr;
71 };
72
73 /* Structure for remembering the local variables in a private frame */
74
75
76
77 #ifndef USE_COMPUTED_GOTO_FOR_MATCH_RECURSION
78 typedef int ReturnLocation;
79 #else
80 typedef void* ReturnLocation;
81 #endif
82
83 struct MatchFrame {
84   ReturnLocation returnLocation;
85
86   struct MatchFrame* previousFrame;
87
88   /* Function arguments that may change */
89
90   UChar* eptr;
91   const uschar* ecode;
92   int offset_top;
93   eptrblock* eptrb;
94
95   /* Function local variables */
96
97   const uschar* data;
98   const uschar* next;
99   const UChar* pp;
100   const uschar* prev;
101   const UChar* saved_eptr;
102
103   int repeat_othercase;
104
105   int ctype;
106   int fc;
107   int fi;
108   int length;
109   int max;
110   int number;
111   int offset;
112   int save_offset1, save_offset2, save_offset3;
113
114   eptrblock newptrb;
115 };
116
117 /* Structure for passing "static" information around between the functions
118 doing traditional NFA matching, so that they are thread-safe. */
119
120 typedef struct match_data {
121   unsigned long int match_call_count;      /* As it says */
122   int   *offset_vector;         /* Offset vector */
123   int    offset_end;            /* One past the end */
124   int    offset_max;            /* The maximum usable for return data */
125   const uschar *lcc;            /* Points to lower casing table */
126   const uschar *ctypes;         /* Points to table of type maps */
127   bool   offset_overflow;       /* Set if too many extractions */
128   UChar*  start_subject;         /* Start of the subject string */
129   UChar*  end_subject;           /* End of the subject string */
130   UChar*  end_match_ptr;         /* Subject position at end match */
131   int    end_offset_top;        /* Highwater mark at end of match */
132   bool   multiline;
133   bool   caseless;
134 } match_data;
135
136 #define match_isgroup      true    /* Set if start of bracketed group */
137
138 /* Non-error returns from the match() function. Error returns are externally
139 defined PCRE_ERROR_xxx codes, which are all negative. */
140
141 #define MATCH_MATCH        1
142 #define MATCH_NOMATCH      0
143
144 /* Min and max values for the common repeats; for the maxima, 0 => infinity */
145
146 static const char rep_min[] = { 0, 0, 1, 1, 0, 0 };
147 static const char rep_max[] = { 0, 0, 0, 0, 1, 1 };
148
149
150
151 #ifdef DEBUG
152 /*************************************************
153 *        Debugging function to print chars       *
154 *************************************************/
155
156 /* Print a sequence of chars in printable format, stopping at the end of the
157 subject if the requested.
158
159 Arguments:
160   p           points to characters
161   length      number to print
162   is_subject  true if printing from within md->start_subject
163   md          pointer to matching data block, if is_subject is true
164
165 Returns:     nothing
166 */
167
168 static void
169 pchars(const UChar* p, int length, bool is_subject, match_data *md)
170 {
171 int c;
172 if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
173 while (length-- > 0)
174   if (isprint(c = *(p++))) printf("%c", c);
175   else if (c < 256) printf("\\x%02x", c);
176   else printf("\\x{%x}", c);
177 }
178 #endif
179
180
181
182 /*************************************************
183 *          Match a back-reference                *
184 *************************************************/
185
186 /* If a back reference hasn't been set, the length that is passed is greater
187 than the number of characters left in the string, so the match fails.
188
189 Arguments:
190   offset      index into the offset vector
191   eptr        points into the subject
192   length      length to be matched
193   md          points to match data block
194
195 Returns:      true if matched
196 */
197
198 static bool
199 match_ref(int offset, UChar* eptr, int length, match_data *md)
200 {
201 UChar* p = md->start_subject + md->offset_vector[offset];
202
203 #ifdef DEBUG
204 if (eptr >= md->end_subject)
205   printf("matching subject <null>");
206 else
207   {
208   printf("matching subject ");
209   pchars(eptr, length, true, md);
210   }
211 printf(" against backref ");
212 pchars(p, length, false, md);
213 printf("\n");
214 #endif
215
216 /* Always fail if not enough characters left */
217
218 if (length > md->end_subject - eptr) return false;
219
220 /* Separate the caselesss case for speed */
221
222 if (md->caseless)
223   {
224   while (length-- > 0)
225     {
226     UChar c = *p++;
227     int othercase = _pcre_ucp_othercase(c);
228     UChar d = *eptr++;
229     if (c != d && othercase != d) return false;
230     }
231   }
232 else
233   { while (length-- > 0) if (*p++ != *eptr++) return false; }
234
235 return true;
236 }
237
238
239
240 /***************************************************************************
241 ****************************************************************************
242                    RECURSION IN THE match() FUNCTION
243
244 The original match() function was highly recursive. The current version
245 still has the remnants of the original in that recursive processing of the
246 regular expression is triggered by invoking a macro named RMATCH. This is
247 no longer really much like a recursive call to match() itself.
248 ****************************************************************************
249 ***************************************************************************/
250
251 /* These versions of the macros use the stack, as normal. There are debugging
252 versions and production versions. */
253
254 #ifndef USE_COMPUTED_GOTO_FOR_MATCH_RECURSION
255
256 /* Use numbered labels and switch statement at the bottom of the match function. */
257
258 #define RMATCH_WHERE(num) num
259 #define RRETURN_LABEL RRETURN_SWITCH
260
261 #else
262
263 /* Use GCC's computed goto extension. */
264
265 /* For one test case this is more than 40% faster than the switch statement.
266 We could avoid the use of the num argument entirely by using local labels,
267 but using it for the GCC case as well as the non-GCC case allows us to share
268 a bit more code and notice if we use conflicting numbers.*/
269
270 #define RMATCH_WHERE(num) &&RRETURN_##num
271 #define RRETURN_LABEL *stack.currentFrame->returnLocation
272
273 #endif
274
275 #define RMATCH(num, ra, rb, rc)\
276   {\
277     stack.pushNewFrame((ra), (rb), RMATCH_WHERE(num)); \
278     is_group_start = (rc);\
279     ++rdepth;\
280     DPRINTF(("restarting from line %d\n", __LINE__));\
281     goto RECURSE;\
282 RRETURN_##num:\
283     stack.popCurrentFrame(); \
284     --rdepth;\
285     DPRINTF(("did a goto back to line %d\n", __LINE__));\
286   }
287  
288 #define RRETURN goto RRETURN_LABEL
289
290 #define RRETURN_NO_MATCH \
291   {\
292     is_match = false;\
293     RRETURN;\
294   }
295
296 /*************************************************
297 *         Match from current position            *
298 *************************************************/
299
300 /* On entry ecode points to the first opcode, and eptr to the first character
301 in the subject string, while eptrb holds the value of eptr at the start of the
302 last bracketed group - used for breaking infinite loops matching zero-length
303 strings. This function is called recursively in many circumstances. Whenever it
304 returns a negative (error) response, the outer incarnation must also return the
305 same response.
306
307 Arguments:
308    eptr        pointer in subject
309    ecode       position in code
310    offset_top  current top pointer
311    md          pointer to "static" info for the match
312
313 Returns:       MATCH_MATCH if matched            )  these values are >= 0
314                MATCH_NOMATCH if failed to match  )
315                a negative PCRE_ERROR_xxx value if aborted by an error condition
316                  (e.g. stopped by repeated call or recursion limit)
317 */
318
319 struct MatchStack {
320     MatchStack()
321     {
322         framesEnd = frames + sizeof(frames) / sizeof(frames[0]);
323         currentFrame = frames;
324     }
325     
326     /* The value 16 here is large enough that most regular expressions don't require
327      any calls to pcre_stack_malloc, yet the amount of stack used for the array is
328      modest enough that we don't run out of stack. */
329     MatchFrame frames[16];
330     MatchFrame* framesEnd;
331     MatchFrame* currentFrame;
332     
333     inline bool canUseStackBufferForNextFrame()
334     {
335         return (currentFrame >= frames && currentFrame + 1 < framesEnd);
336     }
337     
338     inline MatchFrame* allocateNextFrame()
339     {
340         if (canUseStackBufferForNextFrame())
341             return currentFrame + 1;
342         return new MatchFrame;
343     }
344     
345     inline void pushNewFrame(const uschar* ecode, eptrblock* eptrb, ReturnLocation returnLocation)
346     {
347         MatchFrame* newframe = allocateNextFrame();
348         newframe->previousFrame = currentFrame;
349
350         newframe->eptr = currentFrame->eptr;
351         newframe->offset_top = currentFrame->offset_top;
352         newframe->ecode = ecode;
353         newframe->eptrb = eptrb;
354         newframe->returnLocation = returnLocation;
355
356         currentFrame = newframe;
357     }
358     
359     inline bool frameIsStackAllocated(MatchFrame* frame)
360     {
361         return (frame >= frames && frame < framesEnd);
362     }
363     
364     inline void popCurrentFrame()
365     {
366         MatchFrame* oldFrame = currentFrame;
367         currentFrame = currentFrame->previousFrame;
368         if (!frameIsStackAllocated(oldFrame))
369             delete oldFrame;
370     }
371
372     void unrollAnyHeapAllocatedFrames()
373     {
374         while (!frameIsStackAllocated(currentFrame)) {
375             MatchFrame* oldFrame = currentFrame;
376             currentFrame = currentFrame->previousFrame;
377             delete oldFrame;
378         }
379     }
380 };
381
382 static int matchError(int errorCode, MatchStack& stack)
383 {
384     stack.unrollAnyHeapAllocatedFrames();
385     return errorCode;
386 }
387
388 /* Get the next UTF-8 character, not advancing the pointer, incrementing length
389  if there are extra bytes. This is called when we know we are in UTF-8 mode. */
390
391 static inline void getUTF8CharAndIncrementLength(int& c, const uschar* eptr, int& len)
392 {
393     c = *eptr;
394     if ((c & 0xc0) == 0xc0) {
395         int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */
396         int gcss = 6 * gcaa;
397         c = (c & _pcre_utf8_table3[gcaa]) << gcss;
398         for (int gcii = 1; gcii <= gcaa; gcii++) {
399             gcss -= 6;
400             c |= (eptr[gcii] & 0x3f) << gcss;
401         }
402         len += gcaa;
403     }
404 }
405
406 static int match(UChar* eptr, const uschar* ecode, int offset_top, match_data* md)
407 {
408     int is_match = false;
409     int i;
410     int c;
411     
412     unsigned rdepth = 0;
413     
414     bool cur_is_word;
415     bool prev_is_word;
416     bool is_group_start = true;
417     int min;
418     bool minimize = false; /* Initialization not really needed, but some compilers think so. */
419     
420     MatchStack stack;
421
422     /* The opcode jump table. */
423 #ifdef USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP
424 #define EMIT_JUMP_TABLE_ENTRY(opcode) &&LABEL_OP_##opcode,
425     static void* opcode_jump_table[256] = { FOR_EACH_OPCODE(EMIT_JUMP_TABLE_ENTRY) };
426 #undef EMIT_JUMP_TABLE_ENTRY
427 #endif
428     
429     /* One-time setup of the opcode jump table. */
430 #ifdef USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP
431     i = 255;
432     while (!opcode_jump_table[i])
433         opcode_jump_table[i--] = &&CAPTURING_BRACKET;
434 #endif
435     
436 #ifdef USE_COMPUTED_GOTO_FOR_MATCH_RECURSION
437     stack.currentFrame->returnLocation = &&RETURN;
438 #else
439     stack.currentFrame->returnLocation = 0;
440 #endif
441     
442     stack.currentFrame->eptr = eptr;
443     stack.currentFrame->ecode = ecode;
444     stack.currentFrame->offset_top = offset_top;
445     stack.currentFrame->eptrb = NULL;
446     
447     /* This is where control jumps back to to effect "recursion" */
448     
449 RECURSE:
450     
451     /* OK, now we can get on with the real code of the function. Recursive calls
452      are specified by the macro RMATCH and RRETURN is used to return. When
453      NO_RECURSE is *not* defined, these just turn into a recursive call to match()
454      and a "return", respectively (possibly with some debugging if DEBUG is
455      defined). However, RMATCH isn't like a function call because it's quite a
456      complicated macro. It has to be used in one particular way. This shouldn't,
457      however, impact performance when true recursion is being used. */
458     
459     /* First check that we haven't called match() too many times, or that we
460      haven't exceeded the recursive call limit. */
461     
462     if (md->match_call_count++ >= MATCH_LIMIT)
463         return matchError(JSRegExpErrorMatchLimit, stack);
464     if (rdepth >= MATCH_LIMIT_RECURSION)
465         return matchError(JSRegExpErrorRecursionLimit, stack);
466     
467     /* At the start of a bracketed group, add the current subject pointer to the
468      stack of such pointers, to be re-instated at the end of the group when we hit
469      the closing ket. When match() is called in other circumstances, we don't add to
470      this stack. */
471     
472     if (is_group_start) {
473         stack.currentFrame->newptrb.epb_prev = stack.currentFrame->eptrb;
474         stack.currentFrame->newptrb.epb_saved_eptr = stack.currentFrame->eptr;
475         stack.currentFrame->eptrb = &stack.currentFrame->newptrb;
476     }
477     
478     /* Now start processing the operations. */
479     
480 #ifndef USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP
481     while (true)
482 #endif
483     {
484         
485 #ifdef USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP
486 #define BEGIN_OPCODE(opcode) LABEL_OP_##opcode
487 #define NEXT_OPCODE goto *opcode_jump_table[*stack.currentFrame->ecode]
488 #else
489 #define BEGIN_OPCODE(opcode) case OP_##opcode
490 #define NEXT_OPCODE continue
491 #endif
492         
493 #ifdef USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP
494         NEXT_OPCODE;
495 #else
496         switch (*stack.currentFrame->ecode)
497 #endif
498         {
499                 /* Non-capturing bracket: optimized */
500                 
501                 BEGIN_OPCODE(BRA):
502             NON_CAPTURING_BRACKET:
503                 DPRINTF(("start bracket 0\n"));
504                 do {
505                     RMATCH(2, stack.currentFrame->ecode + 1 + LINK_SIZE, stack.currentFrame->eptrb, match_isgroup);
506                     if (is_match)
507                         RRETURN;
508                     stack.currentFrame->ecode += GET(stack.currentFrame->ecode, 1);
509                 } while (*stack.currentFrame->ecode == OP_ALT);
510                 DPRINTF(("bracket 0 failed\n"));
511                 RRETURN;
512                 
513                 /* Skip over large extraction number data if encountered. */
514                 
515                 BEGIN_OPCODE(BRANUMBER):
516                 stack.currentFrame->ecode += 3;
517                 NEXT_OPCODE;
518                 
519                 /* End of the pattern. */
520                 
521                 BEGIN_OPCODE(END):
522                 md->end_match_ptr = stack.currentFrame->eptr;          /* Record where we ended */
523                 md->end_offset_top = stack.currentFrame->offset_top;   /* and how many extracts were taken */
524                 is_match = true;
525                 RRETURN;
526                 
527                 /* Assertion brackets. Check the alternative branches in turn - the
528                  matching won't pass the KET for an assertion. If any one branch matches,
529                  the assertion is true. Lookbehind assertions have an OP_REVERSE item at the
530                  start of each branch to move the current point backwards, so the code at
531                  this level is identical to the lookahead case. */
532                 
533                 BEGIN_OPCODE(ASSERT):
534                 do {
535                     RMATCH(6, stack.currentFrame->ecode + 1 + LINK_SIZE, NULL, match_isgroup);
536                     if (is_match)
537                         break;
538                     stack.currentFrame->ecode += GET(stack.currentFrame->ecode, 1);
539                 } while (*stack.currentFrame->ecode == OP_ALT);
540                 if (*stack.currentFrame->ecode == OP_KET)
541                     RRETURN_NO_MATCH;
542                 
543                 /* Continue from after the assertion, updating the offsets high water
544                  mark, since extracts may have been taken during the assertion. */
545                 
546                 do stack.currentFrame->ecode += GET(stack.currentFrame->ecode,1); while (*stack.currentFrame->ecode == OP_ALT);
547                 stack.currentFrame->ecode += 1 + LINK_SIZE;
548                 stack.currentFrame->offset_top = md->end_offset_top;
549                 NEXT_OPCODE;
550                 
551                 /* Negative assertion: all branches must fail to match */
552                 
553                 BEGIN_OPCODE(ASSERT_NOT):
554                 do {
555                     RMATCH(7, stack.currentFrame->ecode + 1 + LINK_SIZE, NULL, match_isgroup);
556                     if (is_match)
557                         RRETURN_NO_MATCH;
558                     stack.currentFrame->ecode += GET(stack.currentFrame->ecode,1);
559                 } while (*stack.currentFrame->ecode == OP_ALT);
560                 
561                 stack.currentFrame->ecode += 1 + LINK_SIZE;
562                 NEXT_OPCODE;
563                 
564                 /* "Once" brackets are like assertion brackets except that after a match,
565                  the point in the subject string is not moved back. Thus there can never be
566                  a move back into the brackets. Friedl calls these "atomic" subpatterns.
567                  Check the alternative branches in turn - the matching won't pass the KET
568                  for this kind of subpattern. If any one branch matches, we carry on as at
569                  the end of a normal bracket, leaving the subject pointer. */
570                 
571                 BEGIN_OPCODE(ONCE):
572                 stack.currentFrame->prev = stack.currentFrame->ecode;
573                 stack.currentFrame->saved_eptr = stack.currentFrame->eptr;
574                 
575                 do {
576                     RMATCH(9, stack.currentFrame->ecode + 1 + LINK_SIZE, stack.currentFrame->eptrb, match_isgroup);
577                     if (is_match)
578                         break;
579                     stack.currentFrame->ecode += GET(stack.currentFrame->ecode,1);
580                 } while (*stack.currentFrame->ecode == OP_ALT);
581                 
582                 /* If hit the end of the group (which could be repeated), fail */
583                 
584                 if (*stack.currentFrame->ecode != OP_ONCE && *stack.currentFrame->ecode != OP_ALT)
585                     RRETURN;
586                 
587                 /* Continue as from after the assertion, updating the offsets high water
588                  mark, since extracts may have been taken. */
589                 
590                 do stack.currentFrame->ecode += GET(stack.currentFrame->ecode,1); while (*stack.currentFrame->ecode == OP_ALT);
591                 
592                 stack.currentFrame->offset_top = md->end_offset_top;
593                 stack.currentFrame->eptr = md->end_match_ptr;
594                 
595                 /* For a non-repeating ket, just continue at this level. This also
596                  happens for a repeating ket if no characters were matched in the group.
597                  This is the forcible breaking of infinite loops as implemented in Perl
598                  5.005. If there is an options reset, it will get obeyed in the normal
599                  course of events. */
600                 
601                 if (*stack.currentFrame->ecode == OP_KET || stack.currentFrame->eptr == stack.currentFrame->saved_eptr) {
602                     stack.currentFrame->ecode += 1+LINK_SIZE;
603                     NEXT_OPCODE;
604                 }
605                 
606                 /* The repeating kets try the rest of the pattern or restart from the
607                  preceding bracket, in the appropriate order. We need to reset any options
608                  that changed within the bracket before re-running it, so check the next
609                  opcode. */
610                 
611                 if (*stack.currentFrame->ecode == OP_KETRMIN) {
612                     RMATCH(10, stack.currentFrame->ecode + 1 + LINK_SIZE, stack.currentFrame->eptrb, 0);
613                     if (is_match)
614                         RRETURN;
615                     RMATCH(11, stack.currentFrame->prev, stack.currentFrame->eptrb, match_isgroup);
616                     if (is_match)
617                         RRETURN;
618                 } else { /* OP_KETRMAX */
619                     RMATCH(12, stack.currentFrame->prev, stack.currentFrame->eptrb, match_isgroup);
620                     if (is_match)
621                         RRETURN;
622                     RMATCH(13, stack.currentFrame->ecode + 1+LINK_SIZE, stack.currentFrame->eptrb, 0);
623                     if (is_match)
624                         RRETURN;
625                 }
626                 RRETURN;
627                 
628                 /* An alternation is the end of a branch; scan along to find the end of the
629                  bracketed group and go to there. */
630                 
631                 BEGIN_OPCODE(ALT):
632                 do stack.currentFrame->ecode += GET(stack.currentFrame->ecode,1); while (*stack.currentFrame->ecode == OP_ALT);
633                 NEXT_OPCODE;
634                 
635                 /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating
636                  that it may occur zero times. It may repeat infinitely, or not at all -
637                  i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper
638                  repeat limits are compiled as a number of copies, with the optional ones
639                  preceded by BRAZERO or BRAMINZERO. */
640                 
641                 BEGIN_OPCODE(BRAZERO):
642                 {
643                     stack.currentFrame->next = stack.currentFrame->ecode+1;
644                     RMATCH(14, stack.currentFrame->next, stack.currentFrame->eptrb, match_isgroup);
645                     if (is_match)
646                         RRETURN;
647                     do stack.currentFrame->next += GET(stack.currentFrame->next,1); while (*stack.currentFrame->next == OP_ALT);
648                     stack.currentFrame->ecode = stack.currentFrame->next + 1+LINK_SIZE;
649                 }
650                 NEXT_OPCODE;
651                 
652                 BEGIN_OPCODE(BRAMINZERO):
653                 {
654                     stack.currentFrame->next = stack.currentFrame->ecode+1;
655                     do stack.currentFrame->next += GET(stack.currentFrame->next,1); while (*stack.currentFrame->next == OP_ALT);
656                     RMATCH(15, stack.currentFrame->next + 1+LINK_SIZE, stack.currentFrame->eptrb, match_isgroup);
657                     if (is_match)
658                         RRETURN;
659                     stack.currentFrame->ecode++;
660                 }
661                 NEXT_OPCODE;
662                 
663                 /* End of a group, repeated or non-repeating. If we are at the end of
664                  an assertion "group", stop matching and return MATCH_MATCH, but record the
665                  current high water mark for use by positive assertions. Do this also
666                  for the "once" (not-backup up) groups. */
667                 
668                 BEGIN_OPCODE(KET):
669                 BEGIN_OPCODE(KETRMIN):
670                 BEGIN_OPCODE(KETRMAX):
671                 stack.currentFrame->prev = stack.currentFrame->ecode - GET(stack.currentFrame->ecode, 1);
672                 stack.currentFrame->saved_eptr = stack.currentFrame->eptrb->epb_saved_eptr;
673                 
674                 /* Back up the stack of bracket start pointers. */
675                 
676                 stack.currentFrame->eptrb = stack.currentFrame->eptrb->epb_prev;
677                 
678                 if (*stack.currentFrame->prev == OP_ASSERT || *stack.currentFrame->prev == OP_ASSERT_NOT || *stack.currentFrame->prev == OP_ONCE) {
679                     md->end_match_ptr = stack.currentFrame->eptr;      /* For ONCE */
680                     md->end_offset_top = stack.currentFrame->offset_top;
681                     is_match = true;
682                     RRETURN;
683                 }
684                 
685                 /* In all other cases except a conditional group we have to check the
686                  group number back at the start and if necessary complete handling an
687                  extraction by setting the offsets and bumping the high water mark. */
688                 
689                 stack.currentFrame->number = *stack.currentFrame->prev - OP_BRA;
690                 
691                 /* For extended extraction brackets (large number), we have to fish out
692                  the number from a dummy opcode at the start. */
693                 
694                 if (stack.currentFrame->number > EXTRACT_BASIC_MAX)
695                     stack.currentFrame->number = GET2(stack.currentFrame->prev, 2+LINK_SIZE);
696                 stack.currentFrame->offset = stack.currentFrame->number << 1;
697                 
698 #ifdef DEBUG
699                 printf("end bracket %d", stack.currentFrame->number);
700                 printf("\n");
701 #endif
702                 
703                 /* Test for a numbered group. This includes groups called as a result
704                  of recursion. Note that whole-pattern recursion is coded as a recurse
705                  into group 0, so it won't be picked up here. Instead, we catch it when
706                  the OP_END is reached. */
707                 
708                 if (stack.currentFrame->number > 0) {
709                     if (stack.currentFrame->offset >= md->offset_max)
710                         md->offset_overflow = true;
711                     else {
712                         md->offset_vector[stack.currentFrame->offset] =
713                         md->offset_vector[md->offset_end - stack.currentFrame->number];
714                         md->offset_vector[stack.currentFrame->offset+1] = stack.currentFrame->eptr - md->start_subject;
715                         if (stack.currentFrame->offset_top <= stack.currentFrame->offset)
716                             stack.currentFrame->offset_top = stack.currentFrame->offset + 2;
717                     }
718                 }
719                 
720                 /* For a non-repeating ket, just continue at this level. This also
721                  happens for a repeating ket if no characters were matched in the group.
722                  This is the forcible breaking of infinite loops as implemented in Perl
723                  5.005. If there is an options reset, it will get obeyed in the normal
724                  course of events. */
725                 
726                 if (*stack.currentFrame->ecode == OP_KET || stack.currentFrame->eptr == stack.currentFrame->saved_eptr) {
727                     stack.currentFrame->ecode += 1 + LINK_SIZE;
728                     NEXT_OPCODE;
729                 }
730                 
731                 /* The repeating kets try the rest of the pattern or restart from the
732                  preceding bracket, in the appropriate order. */
733                 
734                 if (*stack.currentFrame->ecode == OP_KETRMIN) {
735                     RMATCH(16, stack.currentFrame->ecode + 1+LINK_SIZE, stack.currentFrame->eptrb, 0);
736                     if (is_match)
737                         RRETURN;
738                     RMATCH(17, stack.currentFrame->prev, stack.currentFrame->eptrb, match_isgroup);
739                     if (is_match)
740                         RRETURN;
741                 } else { /* OP_KETRMAX */
742                     RMATCH(18, stack.currentFrame->prev, stack.currentFrame->eptrb, match_isgroup);
743                     if (is_match)
744                         RRETURN;
745                     RMATCH(19, stack.currentFrame->ecode + 1+LINK_SIZE, stack.currentFrame->eptrb, 0);
746                     if (is_match)
747                         RRETURN;
748                 }
749                 RRETURN;
750                 
751                 /* Start of subject, or after internal newline if multiline. */
752                 
753                 BEGIN_OPCODE(CIRC):
754                 if (stack.currentFrame->eptr != md->start_subject && (!md->multiline || !isNewline(stack.currentFrame->eptr[-1])))
755                     RRETURN_NO_MATCH;
756                 stack.currentFrame->ecode++;
757                 NEXT_OPCODE;
758                 
759                 /* End of subject, or before internal newline if multiline. */
760                 
761                 BEGIN_OPCODE(DOLL):
762                 if (stack.currentFrame->eptr < md->end_subject && (!md->multiline || !isNewline(*stack.currentFrame->eptr)))
763                     RRETURN_NO_MATCH;
764                 stack.currentFrame->ecode++;
765                 NEXT_OPCODE;
766                 
767                 /* Word boundary assertions */
768                 
769                 BEGIN_OPCODE(NOT_WORD_BOUNDARY):
770                 BEGIN_OPCODE(WORD_BOUNDARY):
771                 /* Find out if the previous and current characters are "word" characters.
772                  It takes a bit more work in UTF-8 mode. Characters > 128 are assumed to
773                  be "non-word" characters. */
774                 
775                 if (stack.currentFrame->eptr == md->start_subject)
776                     prev_is_word = false;
777                 else {
778                     const UChar* lastptr = stack.currentFrame->eptr - 1;
779                     while(isTrailingSurrogate(*lastptr))
780                         lastptr--;
781                     getChar(c, lastptr);
782                     prev_is_word = c < 128 && (md->ctypes[c] & ctype_word) != 0;
783                 }
784                 if (stack.currentFrame->eptr >= md->end_subject)
785                     cur_is_word = false;
786                 else {
787                     getChar(c, stack.currentFrame->eptr);
788                     cur_is_word = c < 128 && (md->ctypes[c] & ctype_word) != 0;
789                 }
790                 
791                 /* Now see if the situation is what we want */
792                 
793                 if ((*stack.currentFrame->ecode++ == OP_WORD_BOUNDARY) ? cur_is_word == prev_is_word : cur_is_word != prev_is_word)
794                     RRETURN_NO_MATCH;
795                 NEXT_OPCODE;
796                 
797                 /* Match a single character type; inline for speed */
798                 
799                 BEGIN_OPCODE(ANY):
800                 if (stack.currentFrame->eptr < md->end_subject && isNewline(*stack.currentFrame->eptr))
801                     RRETURN_NO_MATCH;
802                 if (stack.currentFrame->eptr++ >= md->end_subject)
803                     RRETURN_NO_MATCH;
804                 while (stack.currentFrame->eptr < md->end_subject && isTrailingSurrogate(*stack.currentFrame->eptr))
805                     stack.currentFrame->eptr++;
806                 stack.currentFrame->ecode++;
807                 NEXT_OPCODE;
808                 
809                 BEGIN_OPCODE(NOT_DIGIT):
810                 if (stack.currentFrame->eptr >= md->end_subject)
811                     RRETURN_NO_MATCH;
812                 GETCHARINCTEST(c, stack.currentFrame->eptr);
813                 if (isASCIIDigit(c))
814                     RRETURN_NO_MATCH;
815                 stack.currentFrame->ecode++;
816                 NEXT_OPCODE;
817                 
818                 BEGIN_OPCODE(DIGIT):
819                 if (stack.currentFrame->eptr >= md->end_subject)
820                     RRETURN_NO_MATCH;
821                 GETCHARINCTEST(c, stack.currentFrame->eptr);
822                 if (!isASCIIDigit(c))
823                     RRETURN_NO_MATCH;
824                 stack.currentFrame->ecode++;
825                 NEXT_OPCODE;
826                 
827                 BEGIN_OPCODE(NOT_WHITESPACE):
828                 if (stack.currentFrame->eptr >= md->end_subject)
829                     RRETURN_NO_MATCH;
830                 GETCHARINCTEST(c, stack.currentFrame->eptr);
831                 if (c < 128 && (md->ctypes[c] & ctype_space))
832                     RRETURN_NO_MATCH;
833                 stack.currentFrame->ecode++;
834                 NEXT_OPCODE;
835                 
836                 BEGIN_OPCODE(WHITESPACE):
837                 if (stack.currentFrame->eptr >= md->end_subject)
838                     RRETURN_NO_MATCH;
839                 GETCHARINCTEST(c, stack.currentFrame->eptr);
840                 if (c >= 128 || !(md->ctypes[c] & ctype_space))
841                     RRETURN_NO_MATCH;
842                 stack.currentFrame->ecode++;
843                 NEXT_OPCODE;
844                 
845                 BEGIN_OPCODE(NOT_WORDCHAR):
846                 if (stack.currentFrame->eptr >= md->end_subject)
847                     RRETURN_NO_MATCH;
848                 GETCHARINCTEST(c, stack.currentFrame->eptr);
849                 if (c < 128 && (md->ctypes[c] & ctype_word))
850                     RRETURN_NO_MATCH;
851                 stack.currentFrame->ecode++;
852                 NEXT_OPCODE;
853                 
854                 BEGIN_OPCODE(WORDCHAR):
855                 if (stack.currentFrame->eptr >= md->end_subject)
856                     RRETURN_NO_MATCH;
857                 GETCHARINCTEST(c, stack.currentFrame->eptr);
858                 if (c >= 128 || !(md->ctypes[c] & ctype_word))
859                     RRETURN_NO_MATCH;
860                 stack.currentFrame->ecode++;
861                 NEXT_OPCODE;
862                 
863                 /* Match a back reference, possibly repeatedly. Look past the end of the
864                  item to see if there is repeat information following. The code is similar
865                  to that for character classes, but repeated for efficiency. Then obey
866                  similar code to character type repeats - written out again for speed.
867                  However, if the referenced string is the empty string, always treat
868                  it as matched, any number of times (otherwise there could be infinite
869                  loops). */
870                 
871                 BEGIN_OPCODE(REF):
872                 stack.currentFrame->offset = GET2(stack.currentFrame->ecode, 1) << 1;               /* Doubled ref number */
873                 stack.currentFrame->ecode += 3;                                 /* Advance past item */
874                 
875                 /* If the reference is unset, set the length to be longer than the amount
876                  of subject left; this ensures that every attempt at a match fails. We
877                  can't just fail here, because of the possibility of quantifiers with zero
878                  minima. */
879                 
880                 if (stack.currentFrame->offset >= stack.currentFrame->offset_top || md->offset_vector[stack.currentFrame->offset] < 0)
881                     stack.currentFrame->length = 0;
882                 else
883                     stack.currentFrame->length = md->offset_vector[stack.currentFrame->offset+1] - md->offset_vector[stack.currentFrame->offset];
884                 
885                 /* Set up for repetition, or handle the non-repeated case */
886                 
887                 switch (*stack.currentFrame->ecode) {
888                 case OP_CRSTAR:
889                 case OP_CRMINSTAR:
890                 case OP_CRPLUS:
891                 case OP_CRMINPLUS:
892                 case OP_CRQUERY:
893                 case OP_CRMINQUERY:
894                     c = *stack.currentFrame->ecode++ - OP_CRSTAR;
895                     minimize = (c & 1) != 0;
896                     min = rep_min[c];                 /* Pick up values from tables; */
897                     stack.currentFrame->max = rep_max[c];                 /* zero for max => infinity */
898                     if (stack.currentFrame->max == 0)
899                         stack.currentFrame->max = INT_MAX;
900                     break;
901                     
902                 case OP_CRRANGE:
903                 case OP_CRMINRANGE:
904                     minimize = (*stack.currentFrame->ecode == OP_CRMINRANGE);
905                     min = GET2(stack.currentFrame->ecode, 1);
906                     stack.currentFrame->max = GET2(stack.currentFrame->ecode, 3);
907                     if (stack.currentFrame->max == 0)
908                         stack.currentFrame->max = INT_MAX;
909                     stack.currentFrame->ecode += 5;
910                     break;
911                 
912                 default:               /* No repeat follows */
913                     if (!match_ref(stack.currentFrame->offset, stack.currentFrame->eptr, stack.currentFrame->length, md))
914                         RRETURN_NO_MATCH;
915                     stack.currentFrame->eptr += stack.currentFrame->length;
916                     NEXT_OPCODE;
917                 }
918                 
919                 /* If the length of the reference is zero, just continue with the
920                  main loop. */
921                 
922                 if (stack.currentFrame->length == 0)
923                     NEXT_OPCODE;
924                 
925                 /* First, ensure the minimum number of matches are present. */
926                 
927                 for (i = 1; i <= min; i++) {
928                     if (!match_ref(stack.currentFrame->offset, stack.currentFrame->eptr, stack.currentFrame->length, md))
929                         RRETURN_NO_MATCH;
930                     stack.currentFrame->eptr += stack.currentFrame->length;
931                 }
932                 
933                 /* If min = max, continue at the same level without recursion.
934                  They are not both allowed to be zero. */
935                 
936                 if (min == stack.currentFrame->max)
937                     NEXT_OPCODE;
938                 
939                 /* If minimizing, keep trying and advancing the pointer */
940                 
941                 if (minimize) {
942                     for (stack.currentFrame->fi = min;; stack.currentFrame->fi++) {
943                         RMATCH(20, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
944                         if (is_match)
945                             RRETURN;
946                         if (stack.currentFrame->fi >= stack.currentFrame->max || !match_ref(stack.currentFrame->offset, stack.currentFrame->eptr, stack.currentFrame->length, md))
947                             RRETURN;
948                         stack.currentFrame->eptr += stack.currentFrame->length;
949                     }
950                     /* Control never reaches here */
951                 }
952                 
953                 /* If maximizing, find the longest string and work backwards */
954                 
955                 else {
956                     stack.currentFrame->pp = stack.currentFrame->eptr;
957                     for (i = min; i < stack.currentFrame->max; i++) {
958                         if (!match_ref(stack.currentFrame->offset, stack.currentFrame->eptr, stack.currentFrame->length, md))
959                             break;
960                         stack.currentFrame->eptr += stack.currentFrame->length;
961                     }
962                     while (stack.currentFrame->eptr >= stack.currentFrame->pp) {
963                         RMATCH(21, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
964                         if (is_match)
965                             RRETURN;
966                         stack.currentFrame->eptr -= stack.currentFrame->length;
967                     }
968                     RRETURN_NO_MATCH;
969                 }
970                 /* Control never reaches here */
971                 
972                 /* Match a bit-mapped character class, possibly repeatedly. This op code is
973                  used when all the characters in the class have values in the range 0-255,
974                  and either the matching is caseful, or the characters are in the range
975                  0-127 when UTF-8 processing is enabled. The only difference between
976                  OP_CLASS and OP_NCLASS occurs when a data character outside the range is
977                  encountered.
978                  
979                  First, look past the end of the item to see if there is repeat information
980                  following. Then obey similar code to character type repeats - written out
981                  again for speed. */
982                 
983                 BEGIN_OPCODE(NCLASS):
984                 BEGIN_OPCODE(CLASS):
985                 stack.currentFrame->data = stack.currentFrame->ecode + 1;                /* Save for matching */
986                 stack.currentFrame->ecode += 33;                     /* Advance past the item */
987                 
988                 switch (*stack.currentFrame->ecode) {
989                 case OP_CRSTAR:
990                 case OP_CRMINSTAR:
991                 case OP_CRPLUS:
992                 case OP_CRMINPLUS:
993                 case OP_CRQUERY:
994                 case OP_CRMINQUERY:
995                     c = *stack.currentFrame->ecode++ - OP_CRSTAR;
996                     minimize = (c & 1) != 0;
997                     min = rep_min[c];                 /* Pick up values from tables; */
998                     stack.currentFrame->max = rep_max[c];                 /* zero for max => infinity */
999                     if (stack.currentFrame->max == 0)
1000                         stack.currentFrame->max = INT_MAX;
1001                     break;
1002                     
1003                 case OP_CRRANGE:
1004                 case OP_CRMINRANGE:
1005                     minimize = (*stack.currentFrame->ecode == OP_CRMINRANGE);
1006                     min = GET2(stack.currentFrame->ecode, 1);
1007                     stack.currentFrame->max = GET2(stack.currentFrame->ecode, 3);
1008                     if (stack.currentFrame->max == 0)
1009                         stack.currentFrame->max = INT_MAX;
1010                     stack.currentFrame->ecode += 5;
1011                     break;
1012                     
1013                 default:               /* No repeat follows */
1014                     min = stack.currentFrame->max = 1;
1015                     break;
1016                 }
1017                 
1018                 /* First, ensure the minimum number of matches are present. */
1019                 
1020                 for (i = 1; i <= min; i++) {
1021                     if (stack.currentFrame->eptr >= md->end_subject)
1022                         RRETURN_NO_MATCH;
1023                     GETCHARINC(c, stack.currentFrame->eptr);
1024                     if (c > 255) {
1025                         if (stack.currentFrame->data[-1] == OP_CLASS)
1026                             RRETURN_NO_MATCH;
1027                     } else {
1028                         if ((stack.currentFrame->data[c/8] & (1 << (c&7))) == 0)
1029                             RRETURN_NO_MATCH;
1030                     }
1031                 }
1032                 
1033                 /* If max == min we can continue with the main loop without the
1034                  need to recurse. */
1035                 
1036                 if (min == stack.currentFrame->max)
1037                     NEXT_OPCODE;      
1038                 
1039                 /* If minimizing, keep testing the rest of the expression and advancing
1040                  the pointer while it matches the class. */
1041                 if (minimize) {
1042                     {
1043                         for (stack.currentFrame->fi = min;; stack.currentFrame->fi++) {
1044                             RMATCH(22, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1045                             if (is_match)
1046                                 RRETURN;
1047                             if (stack.currentFrame->fi >= stack.currentFrame->max || stack.currentFrame->eptr >= md->end_subject)
1048                                 RRETURN;
1049                             GETCHARINC(c, stack.currentFrame->eptr);
1050                             if (c > 255) {
1051                                 if (stack.currentFrame->data[-1] == OP_CLASS)
1052                                     RRETURN;
1053                             } else {
1054                                 if ((stack.currentFrame->data[c/8] & (1 << (c&7))) == 0)
1055                                     RRETURN;
1056                             }
1057                         }
1058                     }
1059                     /* Control never reaches here */
1060                 }
1061                 /* If maximizing, find the longest possible run, then work backwards. */
1062                 else {
1063                     stack.currentFrame->pp = stack.currentFrame->eptr;
1064                     
1065                     for (i = min; i < stack.currentFrame->max; i++) {
1066                         int len = 1;
1067                         if (stack.currentFrame->eptr >= md->end_subject)
1068                             break;
1069                         GETCHARLEN(c, stack.currentFrame->eptr, len);
1070                         if (c > 255) {
1071                             if (stack.currentFrame->data[-1] == OP_CLASS)
1072                                 break;
1073                         } else {
1074                             if ((stack.currentFrame->data[c/8] & (1 << (c&7))) == 0)
1075                                 break;
1076                         }
1077                         stack.currentFrame->eptr += len;
1078                     }
1079                     for (;;) {
1080                         RMATCH(24, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1081                         if (is_match)
1082                             RRETURN;
1083                         if (stack.currentFrame->eptr-- == stack.currentFrame->pp)
1084                             break;        /* Stop if tried at original pos */
1085                         BACKCHAR(stack.currentFrame->eptr);
1086                     }
1087                     
1088                     RRETURN;
1089                 }
1090                 /* Control never reaches here */
1091                 
1092                 /* Match an extended character class. This opcode is encountered only
1093                  in UTF-8 mode, because that's the only time it is compiled. */
1094                 
1095                 BEGIN_OPCODE(XCLASS):
1096                 stack.currentFrame->data = stack.currentFrame->ecode + 1 + LINK_SIZE;                /* Save for matching */
1097                 stack.currentFrame->ecode += GET(stack.currentFrame->ecode, 1);                      /* Advance past the item */
1098                 
1099                 switch (*stack.currentFrame->ecode) {
1100                 case OP_CRSTAR:
1101                 case OP_CRMINSTAR:
1102                 case OP_CRPLUS:
1103                 case OP_CRMINPLUS:
1104                 case OP_CRQUERY:
1105                 case OP_CRMINQUERY:
1106                     c = *stack.currentFrame->ecode++ - OP_CRSTAR;
1107                     minimize = (c & 1) != 0;
1108                     min = rep_min[c];                 /* Pick up values from tables; */
1109                     stack.currentFrame->max = rep_max[c];                 /* zero for max => infinity */
1110                     if (stack.currentFrame->max == 0)
1111                         stack.currentFrame->max = INT_MAX;
1112                     break;
1113                     
1114                 case OP_CRRANGE:
1115                 case OP_CRMINRANGE:
1116                     minimize = (*stack.currentFrame->ecode == OP_CRMINRANGE);
1117                     min = GET2(stack.currentFrame->ecode, 1);
1118                     stack.currentFrame->max = GET2(stack.currentFrame->ecode, 3);
1119                     if (stack.currentFrame->max == 0)
1120                         stack.currentFrame->max = INT_MAX;
1121                     stack.currentFrame->ecode += 5;
1122                     break;
1123                     
1124                 default:               /* No repeat follows */
1125                     min = stack.currentFrame->max = 1;
1126             }
1127                 
1128                 /* First, ensure the minimum number of matches are present. */
1129                 
1130                 for (i = 1; i <= min; i++) {
1131                     if (stack.currentFrame->eptr >= md->end_subject)
1132                         RRETURN_NO_MATCH;
1133                     GETCHARINC(c, stack.currentFrame->eptr);
1134                     if (!_pcre_xclass(c, stack.currentFrame->data))
1135                         RRETURN_NO_MATCH;
1136                 }
1137                 
1138                 /* If max == min we can continue with the main loop without the
1139                  need to recurse. */
1140                 
1141                 if (min == stack.currentFrame->max)
1142                     NEXT_OPCODE;
1143                 
1144                 /* If minimizing, keep testing the rest of the expression and advancing
1145                  the pointer while it matches the class. */
1146                 
1147                 if (minimize) {
1148                     for (stack.currentFrame->fi = min;; stack.currentFrame->fi++) {
1149                         RMATCH(26, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1150                         if (is_match)
1151                             RRETURN;
1152                         if (stack.currentFrame->fi >= stack.currentFrame->max || stack.currentFrame->eptr >= md->end_subject)
1153                             RRETURN;
1154                         GETCHARINC(c, stack.currentFrame->eptr);
1155                         if (!_pcre_xclass(c, stack.currentFrame->data))
1156                             RRETURN;
1157                     }
1158                     /* Control never reaches here */
1159                 }
1160                 
1161                 /* If maximizing, find the longest possible run, then work backwards. */
1162                 
1163                 else {
1164                     stack.currentFrame->pp = stack.currentFrame->eptr;
1165                     for (i = min; i < stack.currentFrame->max; i++) {
1166                         int len = 1;
1167                         if (stack.currentFrame->eptr >= md->end_subject)
1168                             break;
1169                         GETCHARLEN(c, stack.currentFrame->eptr, len);
1170                         if (!_pcre_xclass(c, stack.currentFrame->data))
1171                             break;
1172                         stack.currentFrame->eptr += len;
1173                     }
1174                     for(;;) {
1175                         RMATCH(27, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1176                         if (is_match)
1177                             RRETURN;
1178                         if (stack.currentFrame->eptr-- == stack.currentFrame->pp)
1179                             break;        /* Stop if tried at original pos */
1180                         BACKCHAR(stack.currentFrame->eptr)
1181                     }
1182                     RRETURN;
1183                 }
1184                 
1185                 /* Control never reaches here */
1186                 
1187                 /* Match a single character, casefully */
1188                 
1189                 BEGIN_OPCODE(CHAR):
1190                 stack.currentFrame->length = 1;
1191                 stack.currentFrame->ecode++;
1192                 getUTF8CharAndIncrementLength(stack.currentFrame->fc, stack.currentFrame->ecode, stack.currentFrame->length);
1193             {
1194                 int dc;
1195                 stack.currentFrame->ecode += stack.currentFrame->length;
1196                 switch (md->end_subject - stack.currentFrame->eptr) {
1197                 case 0:
1198                     RRETURN_NO_MATCH;
1199                 case 1:
1200                     dc = *stack.currentFrame->eptr++;
1201                     if (isLeadingSurrogate(dc))
1202                         RRETURN_NO_MATCH;
1203                     break;
1204                     default:
1205                     GETCHARINC(dc, stack.currentFrame->eptr);
1206                 }
1207                 if (stack.currentFrame->fc != dc)
1208                     RRETURN_NO_MATCH;
1209             }
1210                 NEXT_OPCODE;
1211                 
1212                 /* Match a single character, caselessly */
1213                 
1214                 BEGIN_OPCODE(CHARNC):
1215                 stack.currentFrame->length = 1;
1216                 stack.currentFrame->ecode++;
1217                 getUTF8CharAndIncrementLength(stack.currentFrame->fc, stack.currentFrame->ecode, stack.currentFrame->length);
1218                 
1219                 if (md->end_subject - stack.currentFrame->eptr == 0)
1220                     RRETURN_NO_MATCH;
1221                 
1222             {
1223                 int dc;
1224                 if (md->end_subject - stack.currentFrame->eptr == 1) {
1225                     dc = *stack.currentFrame->eptr++;
1226                     if (isLeadingSurrogate(dc))
1227                         RRETURN_NO_MATCH;
1228                 } else
1229                     GETCHARINC(dc, stack.currentFrame->eptr);
1230                 stack.currentFrame->ecode += stack.currentFrame->length;
1231                 
1232                 /* If we have Unicode property support, we can use it to test the other
1233                  case of the character, if there is one. */
1234                 
1235                 if (stack.currentFrame->fc != dc) {
1236                     if (dc != _pcre_ucp_othercase(stack.currentFrame->fc))
1237                         RRETURN_NO_MATCH;
1238                 }
1239             }
1240                 NEXT_OPCODE;
1241                 
1242                 /* Match a single ASCII character. */
1243                 
1244                 BEGIN_OPCODE(ASCII_CHAR):
1245                 if (md->end_subject == stack.currentFrame->eptr)
1246                     RRETURN_NO_MATCH;
1247                 if (*stack.currentFrame->eptr != stack.currentFrame->ecode[1])
1248                     RRETURN_NO_MATCH;
1249                 ++stack.currentFrame->eptr;
1250                 stack.currentFrame->ecode += 2;
1251                 NEXT_OPCODE;
1252                 
1253                 /* Match one of two cases of an ASCII character. */
1254                 
1255                 BEGIN_OPCODE(ASCII_LETTER_NC):
1256                 if (md->end_subject == stack.currentFrame->eptr)
1257                     RRETURN_NO_MATCH;
1258                 if ((*stack.currentFrame->eptr | 0x20) != stack.currentFrame->ecode[1])
1259                     RRETURN_NO_MATCH;
1260                 ++stack.currentFrame->eptr;
1261                 stack.currentFrame->ecode += 2;
1262                 NEXT_OPCODE;
1263                 
1264                 /* Match a single character repeatedly; different opcodes share code. */
1265                 
1266                 BEGIN_OPCODE(EXACT):
1267                 min = stack.currentFrame->max = GET2(stack.currentFrame->ecode, 1);
1268                 minimize = false;
1269                 stack.currentFrame->ecode += 3;
1270                 goto REPEATCHAR;
1271                 
1272                 BEGIN_OPCODE(UPTO):
1273                 BEGIN_OPCODE(MINUPTO):
1274                 min = 0;
1275                 stack.currentFrame->max = GET2(stack.currentFrame->ecode, 1);
1276                 minimize = *stack.currentFrame->ecode == OP_MINUPTO;
1277                 stack.currentFrame->ecode += 3;
1278                 goto REPEATCHAR;
1279                 
1280                 BEGIN_OPCODE(STAR):
1281                 BEGIN_OPCODE(MINSTAR):
1282                 BEGIN_OPCODE(PLUS):
1283                 BEGIN_OPCODE(MINPLUS):
1284                 BEGIN_OPCODE(QUERY):
1285                 BEGIN_OPCODE(MINQUERY):
1286                 c = *stack.currentFrame->ecode++ - OP_STAR;
1287                 minimize = (c & 1) != 0;
1288                 min = rep_min[c];                 /* Pick up values from tables; */
1289                 stack.currentFrame->max = rep_max[c];                 /* zero for max => infinity */
1290                 if (stack.currentFrame->max == 0)
1291                     stack.currentFrame->max = INT_MAX;
1292                 
1293                 /* Common code for all repeated single-character matches. We can give
1294                  up quickly if there are fewer than the minimum number of characters left in
1295                  the subject. */
1296                 
1297             REPEATCHAR:
1298                 
1299                 stack.currentFrame->length = 1;
1300                 getUTF8CharAndIncrementLength(stack.currentFrame->fc, stack.currentFrame->ecode, stack.currentFrame->length);
1301                 if (min * (stack.currentFrame->fc > 0xFFFF ? 2 : 1) > md->end_subject - stack.currentFrame->eptr)
1302                     RRETURN_NO_MATCH;
1303                 stack.currentFrame->ecode += stack.currentFrame->length;
1304                 
1305                 if (stack.currentFrame->fc <= 0xFFFF) {
1306                     int othercase = md->caseless ? _pcre_ucp_othercase(stack.currentFrame->fc) : -1;
1307                     
1308                     for (i = 1; i <= min; i++) {
1309                         if (*stack.currentFrame->eptr != stack.currentFrame->fc && *stack.currentFrame->eptr != othercase)
1310                             RRETURN_NO_MATCH;
1311                         ++stack.currentFrame->eptr;
1312                     }
1313                     
1314                     if (min == stack.currentFrame->max)
1315                         NEXT_OPCODE;
1316                     
1317                     if (minimize) {
1318                         stack.currentFrame->repeat_othercase = othercase;
1319                         for (stack.currentFrame->fi = min;; stack.currentFrame->fi++) {
1320                             RMATCH(28, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1321                             if (is_match)
1322                                 RRETURN;
1323                             if (stack.currentFrame->fi >= stack.currentFrame->max || stack.currentFrame->eptr >= md->end_subject)
1324                                 RRETURN;
1325                             if (*stack.currentFrame->eptr != stack.currentFrame->fc && *stack.currentFrame->eptr != stack.currentFrame->repeat_othercase)
1326                                 RRETURN;
1327                             ++stack.currentFrame->eptr;
1328                         }
1329                         /* Control never reaches here */
1330                     } else {
1331                         stack.currentFrame->pp = stack.currentFrame->eptr;
1332                         for (i = min; i < stack.currentFrame->max; i++) {
1333                             if (stack.currentFrame->eptr >= md->end_subject)
1334                                 break;
1335                             if (*stack.currentFrame->eptr != stack.currentFrame->fc && *stack.currentFrame->eptr != othercase)
1336                                 break;
1337                             ++stack.currentFrame->eptr;
1338                         }
1339                         while (stack.currentFrame->eptr >= stack.currentFrame->pp) {
1340                             RMATCH(29, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1341                             if (is_match)
1342                                 RRETURN;
1343                             --stack.currentFrame->eptr;
1344                         }
1345                         RRETURN_NO_MATCH;
1346                     }
1347                     /* Control never reaches here */
1348                 } else {
1349                     /* No case on surrogate pairs, so no need to bother with "othercase". */
1350                     
1351                     for (i = 1; i <= min; i++) {
1352                         int nc;
1353                         getChar(nc, stack.currentFrame->eptr);
1354                         if (nc != stack.currentFrame->fc)
1355                             RRETURN_NO_MATCH;
1356                         stack.currentFrame->eptr += 2;
1357                     }
1358                     
1359                     if (min == stack.currentFrame->max)
1360                         NEXT_OPCODE;
1361                     
1362                     if (minimize) {
1363                         for (stack.currentFrame->fi = min;; stack.currentFrame->fi++) {
1364                             int nc;
1365                             RMATCH(30, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1366                             if (is_match)
1367                                 RRETURN;
1368                             if (stack.currentFrame->fi >= stack.currentFrame->max || stack.currentFrame->eptr >= md->end_subject)
1369                                 RRETURN;
1370                             getChar(nc, stack.currentFrame->eptr);
1371                             if (*stack.currentFrame->eptr != stack.currentFrame->fc)
1372                                 RRETURN;
1373                             stack.currentFrame->eptr += 2;
1374                         }
1375                         /* Control never reaches here */
1376                     } else {
1377                         stack.currentFrame->pp = stack.currentFrame->eptr;
1378                         for (i = min; i < stack.currentFrame->max; i++) {
1379                             int nc;
1380                             if (stack.currentFrame->eptr > md->end_subject - 2)
1381                                 break;
1382                             getChar(nc, stack.currentFrame->eptr);
1383                             if (*stack.currentFrame->eptr != stack.currentFrame->fc)
1384                                 break;
1385                             stack.currentFrame->eptr += 2;
1386                         }
1387                         while (stack.currentFrame->eptr >= stack.currentFrame->pp) {
1388                             RMATCH(31, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1389                             if (is_match)
1390                                 RRETURN;
1391                             stack.currentFrame->eptr -= 2;
1392                         }
1393                         RRETURN_NO_MATCH;
1394                     }
1395                     /* Control never reaches here */
1396                 }
1397                 /* Control never reaches here */
1398                 
1399                 /* Match a negated single one-byte character. The character we are
1400                  checking can be multibyte. */
1401                 
1402                 BEGIN_OPCODE(NOT):
1403                 if (stack.currentFrame->eptr >= md->end_subject)
1404                     RRETURN_NO_MATCH;
1405                 stack.currentFrame->ecode++;
1406                 GETCHARINCTEST(c, stack.currentFrame->eptr);
1407                 if (md->caseless) {
1408                     if (c < 128)
1409                         c = md->lcc[c];
1410                     if (md->lcc[*stack.currentFrame->ecode++] == c)
1411                         RRETURN_NO_MATCH;
1412                 } else {
1413                     if (*stack.currentFrame->ecode++ == c)
1414                         RRETURN_NO_MATCH;
1415                 }
1416                 NEXT_OPCODE;
1417                 
1418                 /* Match a negated single one-byte character repeatedly. This is almost a
1419                  repeat of the code for a repeated single character, but I haven't found a
1420                  nice way of commoning these up that doesn't require a test of the
1421                  positive/negative option for each character match. Maybe that wouldn't add
1422                  very much to the time taken, but character matching *is* what this is all
1423                  about... */
1424                 
1425                 BEGIN_OPCODE(NOTEXACT):
1426                 min = stack.currentFrame->max = GET2(stack.currentFrame->ecode, 1);
1427                 minimize = false;
1428                 stack.currentFrame->ecode += 3;
1429                 goto REPEATNOTCHAR;
1430                 
1431                 BEGIN_OPCODE(NOTUPTO):
1432                 BEGIN_OPCODE(NOTMINUPTO):
1433                 min = 0;
1434                 stack.currentFrame->max = GET2(stack.currentFrame->ecode, 1);
1435                 minimize = *stack.currentFrame->ecode == OP_NOTMINUPTO;
1436                 stack.currentFrame->ecode += 3;
1437                 goto REPEATNOTCHAR;
1438                 
1439                 BEGIN_OPCODE(NOTSTAR):
1440                 BEGIN_OPCODE(NOTMINSTAR):
1441                 BEGIN_OPCODE(NOTPLUS):
1442                 BEGIN_OPCODE(NOTMINPLUS):
1443                 BEGIN_OPCODE(NOTQUERY):
1444                 BEGIN_OPCODE(NOTMINQUERY):
1445                 c = *stack.currentFrame->ecode++ - OP_NOTSTAR;
1446                 minimize = (c & 1) != 0;
1447                 min = rep_min[c];                 /* Pick up values from tables; */
1448                 stack.currentFrame->max = rep_max[c];                 /* zero for max => infinity */
1449                 if (stack.currentFrame->max == 0) stack.currentFrame->max = INT_MAX;
1450                 
1451                 /* Common code for all repeated single-byte matches. We can give up quickly
1452                  if there are fewer than the minimum number of bytes left in the
1453                  subject. */
1454                 
1455             REPEATNOTCHAR:
1456                 if (min > md->end_subject - stack.currentFrame->eptr)
1457                     RRETURN_NO_MATCH;
1458                 stack.currentFrame->fc = *stack.currentFrame->ecode++;
1459                 
1460                 /* The code is duplicated for the caseless and caseful cases, for speed,
1461                  since matching characters is likely to be quite common. First, ensure the
1462                  minimum number of matches are present. If min = max, continue at the same
1463                  level without recursing. Otherwise, if minimizing, keep trying the rest of
1464                  the expression and advancing one matching character if failing, up to the
1465                  maximum. Alternatively, if maximizing, find the maximum number of
1466                  characters and work backwards. */
1467                 
1468                 DPRINTF(("negative matching %c{%d,%d}\n", stack.currentFrame->fc, min, stack.currentFrame->max));
1469                 
1470                 if (md->caseless) {
1471                     if (stack.currentFrame->fc < 128)
1472                         stack.currentFrame->fc = md->lcc[stack.currentFrame->fc];
1473                     
1474                     {
1475                         int d;
1476                         for (i = 1; i <= min; i++) {
1477                             GETCHARINC(d, stack.currentFrame->eptr);
1478                             if (d < 128)
1479                                 d = md->lcc[d];
1480                             if (stack.currentFrame->fc == d)
1481                                 RRETURN_NO_MATCH;
1482                         }
1483                     }
1484                     
1485                     if (min == stack.currentFrame->max)
1486                         NEXT_OPCODE;      
1487                     
1488                     if (minimize) {
1489                         int d;
1490                         for (stack.currentFrame->fi = min;; stack.currentFrame->fi++) {
1491                             RMATCH(38, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1492                             if (is_match)
1493                                 RRETURN;
1494                             GETCHARINC(d, stack.currentFrame->eptr);
1495                             if (d < 128)
1496                                 d = md->lcc[d];
1497                             if (stack.currentFrame->fi >= stack.currentFrame->max || stack.currentFrame->eptr >= md->end_subject || stack.currentFrame->fc == d)
1498                                 RRETURN;
1499                         }
1500                         /* Control never reaches here */
1501                     }
1502                     
1503                     /* Maximize case */
1504                     
1505                     else {
1506                         stack.currentFrame->pp = stack.currentFrame->eptr;
1507                         
1508                         {
1509                             int d;
1510                             for (i = min; i < stack.currentFrame->max; i++) {
1511                                 int len = 1;
1512                                 if (stack.currentFrame->eptr >= md->end_subject)
1513                                     break;
1514                                 GETCHARLEN(d, stack.currentFrame->eptr, len);
1515                                 if (d < 128)
1516                                     d = md->lcc[d];
1517                                 if (stack.currentFrame->fc == d)
1518                                     break;
1519                                 stack.currentFrame->eptr += len;
1520                             }
1521                             for (;;) {
1522                                 RMATCH(40, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1523                                 if (is_match)
1524                                     RRETURN;
1525                                 if (stack.currentFrame->eptr-- == stack.currentFrame->pp)
1526                                     break;        /* Stop if tried at original pos */
1527                                 BACKCHAR(stack.currentFrame->eptr);
1528                             }
1529                         }
1530                         
1531                         RRETURN;
1532                     }
1533                     /* Control never reaches here */
1534                 }
1535                 
1536                 /* Caseful comparisons */
1537                 
1538                 else {
1539                     {
1540                         int d;
1541                         for (i = 1; i <= min; i++) {
1542                             GETCHARINC(d, stack.currentFrame->eptr);
1543                             if (stack.currentFrame->fc == d)
1544                                 RRETURN_NO_MATCH;
1545                         }
1546                     }
1547                     
1548                     if (min == stack.currentFrame->max)
1549                         NEXT_OPCODE;
1550                     
1551                     if (minimize) {
1552                         int d;
1553                         for (stack.currentFrame->fi = min;; stack.currentFrame->fi++) {
1554                             RMATCH(42, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1555                             if (is_match)
1556                                 RRETURN;
1557                             GETCHARINC(d, stack.currentFrame->eptr);
1558                             if (stack.currentFrame->fi >= stack.currentFrame->max || stack.currentFrame->eptr >= md->end_subject || stack.currentFrame->fc == d)
1559                                 RRETURN;
1560                         }
1561                         /* Control never reaches here */
1562                     }
1563                     
1564                     /* Maximize case */
1565                     
1566                     else {
1567                         stack.currentFrame->pp = stack.currentFrame->eptr;
1568                         
1569                         {
1570                             int d;
1571                             for (i = min; i < stack.currentFrame->max; i++) {
1572                                 int len = 1;
1573                                 if (stack.currentFrame->eptr >= md->end_subject)
1574                                     break;
1575                                 GETCHARLEN(d, stack.currentFrame->eptr, len);
1576                                 if (stack.currentFrame->fc == d)
1577                                     break;
1578                                 stack.currentFrame->eptr += len;
1579                             }
1580                             for (;;) {
1581                                 RMATCH(44, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1582                                 if (is_match)
1583                                     RRETURN;
1584                                 if (stack.currentFrame->eptr-- == stack.currentFrame->pp)
1585                                     break;        /* Stop if tried at original pos */
1586                                 BACKCHAR(stack.currentFrame->eptr);
1587                             }
1588                         }
1589                         
1590                         RRETURN;
1591                     }
1592                 }
1593                 /* Control never reaches here */
1594                 
1595                 /* Match a single character type repeatedly; several different opcodes
1596                  share code. This is very similar to the code for single characters, but we
1597                  repeat it in the interests of efficiency. */
1598                 
1599                 BEGIN_OPCODE(TYPEEXACT):
1600                 min = stack.currentFrame->max = GET2(stack.currentFrame->ecode, 1);
1601                 minimize = true;
1602                 stack.currentFrame->ecode += 3;
1603                 goto REPEATTYPE;
1604                 
1605                 BEGIN_OPCODE(TYPEUPTO):
1606                 BEGIN_OPCODE(TYPEMINUPTO):
1607                 min = 0;
1608                 stack.currentFrame->max = GET2(stack.currentFrame->ecode, 1);
1609                 minimize = *stack.currentFrame->ecode == OP_TYPEMINUPTO;
1610                 stack.currentFrame->ecode += 3;
1611                 goto REPEATTYPE;
1612                 
1613                 BEGIN_OPCODE(TYPESTAR):
1614                 BEGIN_OPCODE(TYPEMINSTAR):
1615                 BEGIN_OPCODE(TYPEPLUS):
1616                 BEGIN_OPCODE(TYPEMINPLUS):
1617                 BEGIN_OPCODE(TYPEQUERY):
1618                 BEGIN_OPCODE(TYPEMINQUERY):
1619                 c = *stack.currentFrame->ecode++ - OP_TYPESTAR;
1620                 minimize = (c & 1) != 0;
1621                 min = rep_min[c];                 /* Pick up values from tables; */
1622                 stack.currentFrame->max = rep_max[c];                 /* zero for max => infinity */
1623                 if (stack.currentFrame->max == 0)
1624                     stack.currentFrame->max = INT_MAX;
1625                 
1626                 /* Common code for all repeated single character type matches. Note that
1627                  in UTF-8 mode, '.' matches a character of any length, but for the other
1628                  character types, the valid characters are all one-byte long. */
1629                 
1630             REPEATTYPE:
1631                 stack.currentFrame->ctype = *stack.currentFrame->ecode++;      /* Code for the character type */
1632                 
1633                 /* First, ensure the minimum number of matches are present. Use inline
1634                  code for maximizing the speed, and do the type test once at the start
1635                  (i.e. keep it out of the loop). Also we can test that there are at least
1636                  the minimum number of bytes before we start. This isn't as effective in
1637                  UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that
1638                  is tidier. Also separate the UCP code, which can be the same for both UTF-8
1639                  and single-bytes. */
1640                 
1641                 if (min > md->end_subject - stack.currentFrame->eptr)
1642                     RRETURN_NO_MATCH;
1643                 if (min > 0) {
1644                     switch(stack.currentFrame->ctype) {
1645                         case OP_ANY:
1646                             for (i = 1; i <= min; i++) {
1647                                 if (stack.currentFrame->eptr >= md->end_subject || isNewline(*stack.currentFrame->eptr))
1648                                     RRETURN_NO_MATCH;
1649                                 ++stack.currentFrame->eptr;
1650                                 while (stack.currentFrame->eptr < md->end_subject && isTrailingSurrogate(*stack.currentFrame->eptr))
1651                                     stack.currentFrame->eptr++;
1652                             }
1653                             break;
1654                             
1655                             case OP_NOT_DIGIT:
1656                             for (i = 1; i <= min; i++) {
1657                                 if (stack.currentFrame->eptr >= md->end_subject)
1658                                     RRETURN_NO_MATCH;
1659                                 GETCHARINC(c, stack.currentFrame->eptr);
1660                                 if (isASCIIDigit(c))
1661                                     RRETURN_NO_MATCH;
1662                             }
1663                             break;
1664                             
1665                             case OP_DIGIT:
1666                             for (i = 1; i <= min; i++) {
1667                                 if (stack.currentFrame->eptr >= md->end_subject || !isASCIIDigit(*stack.currentFrame->eptr++))
1668                                     RRETURN_NO_MATCH;
1669                                 /* No need to skip more bytes - we know it's a 1-byte character */
1670                             }
1671                             break;
1672                             
1673                             case OP_NOT_WHITESPACE:
1674                             for (i = 1; i <= min; i++) {
1675                                 if (stack.currentFrame->eptr >= md->end_subject ||
1676                                     (*stack.currentFrame->eptr < 128 && (md->ctypes[*stack.currentFrame->eptr] & ctype_space) != 0))
1677                                     RRETURN_NO_MATCH;
1678                                 while (++stack.currentFrame->eptr < md->end_subject && isTrailingSurrogate(*stack.currentFrame->eptr)) { }
1679                             }
1680                             break;
1681                             
1682                             case OP_WHITESPACE:
1683                             for (i = 1; i <= min; i++) {
1684                                 if (stack.currentFrame->eptr >= md->end_subject ||
1685                                     *stack.currentFrame->eptr >= 128 || (md->ctypes[*stack.currentFrame->eptr++] & ctype_space) == 0)
1686                                     RRETURN_NO_MATCH;
1687                                 /* No need to skip more bytes - we know it's a 1-byte character */
1688                             }
1689                             break;
1690                             
1691                             case OP_NOT_WORDCHAR:
1692                             for (i = 1; i <= min; i++) {
1693                                 if (stack.currentFrame->eptr >= md->end_subject ||
1694                                     (*stack.currentFrame->eptr < 128 && (md->ctypes[*stack.currentFrame->eptr] & ctype_word) != 0))
1695                                     RRETURN_NO_MATCH;
1696                                 while (++stack.currentFrame->eptr < md->end_subject && isTrailingSurrogate(*stack.currentFrame->eptr)) { }
1697                             }
1698                             break;
1699                             
1700                             case OP_WORDCHAR:
1701                             for (i = 1; i <= min; i++) {
1702                                 if (stack.currentFrame->eptr >= md->end_subject ||
1703                                     *stack.currentFrame->eptr >= 128 || (md->ctypes[*stack.currentFrame->eptr++] & ctype_word) == 0)
1704                                     RRETURN_NO_MATCH;
1705                                 /* No need to skip more bytes - we know it's a 1-byte character */
1706                             }
1707                             break;
1708                             
1709                             default:
1710                             ASSERT_NOT_REACHED();
1711                             return matchError(JSRegExpErrorInternal, stack);
1712                     }  /* End switch(stack.currentFrame->ctype) */
1713                 }
1714                 
1715                 /* If min = max, continue at the same level without recursing */
1716                 
1717                 if (min == stack.currentFrame->max)
1718                     NEXT_OPCODE;    
1719                 
1720                 /* If minimizing, we have to test the rest of the pattern before each
1721                  subsequent match. */
1722                 
1723                 if (minimize) {
1724                     for (stack.currentFrame->fi = min;; stack.currentFrame->fi++) {
1725                         RMATCH(48, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1726                         if (is_match)
1727                             RRETURN;
1728                         if (stack.currentFrame->fi >= stack.currentFrame->max || stack.currentFrame->eptr >= md->end_subject)
1729                             RRETURN;
1730                         
1731                         GETCHARINC(c, stack.currentFrame->eptr);
1732                         switch(stack.currentFrame->ctype) {
1733                         case OP_ANY:
1734                             if (isNewline(c))
1735                                 RRETURN;
1736                             break;
1737                             
1738                         case OP_NOT_DIGIT:
1739                             if (isASCIIDigit(c))
1740                                 RRETURN;
1741                             break;
1742                             
1743                         case OP_DIGIT:
1744                             if (!isASCIIDigit(c))
1745                                 RRETURN;
1746                             break;
1747                             
1748                         case OP_NOT_WHITESPACE:
1749                             if (c < 128 && (md->ctypes[c] & ctype_space))
1750                                 RRETURN;
1751                             break;
1752                             
1753                         case OP_WHITESPACE:
1754                             if  (c >= 128 || !(md->ctypes[c] & ctype_space))
1755                                 RRETURN;
1756                             break;
1757                             
1758                         case OP_NOT_WORDCHAR:
1759                             if (c < 128 && (md->ctypes[c] & ctype_word))
1760                                 RRETURN;
1761                             break;
1762                             
1763                         case OP_WORDCHAR:
1764                             if (c >= 128 || !(md->ctypes[c] & ctype_word))
1765                                 RRETURN;
1766                             break;
1767                             
1768                         default:
1769                             ASSERT_NOT_REACHED();
1770                             return matchError(JSRegExpErrorInternal, stack);
1771                         }
1772                     }
1773                     /* Control never reaches here */
1774                 }
1775                 
1776                 /* If maximizing it is worth using inline code for speed, doing the type
1777                  test once at the start (i.e. keep it out of the loop). */
1778                 
1779                 else {
1780                     stack.currentFrame->pp = stack.currentFrame->eptr;  /* Remember where we started */
1781                     
1782                     switch(stack.currentFrame->ctype) {
1783                         case OP_ANY:
1784                             
1785                             /* Special code is required for UTF8, but when the maximum is unlimited
1786                              we don't need it, so we repeat the non-UTF8 code. This is probably
1787                              worth it, because .* is quite a common idiom. */
1788                             
1789                             if (stack.currentFrame->max < INT_MAX) {
1790                                 for (i = min; i < stack.currentFrame->max; i++) {
1791                                     if (stack.currentFrame->eptr >= md->end_subject || isNewline(*stack.currentFrame->eptr))
1792                                         break;
1793                                     stack.currentFrame->eptr++;
1794                                     while (stack.currentFrame->eptr < md->end_subject && (*stack.currentFrame->eptr & 0xc0) == 0x80)
1795                                         stack.currentFrame->eptr++;
1796                                 }
1797                             }
1798                             
1799                             /* Handle unlimited UTF-8 repeat */
1800                             
1801                             else {
1802                                 for (i = min; i < stack.currentFrame->max; i++) {
1803                                     if (stack.currentFrame->eptr >= md->end_subject || isNewline(*stack.currentFrame->eptr))
1804                                         break;
1805                                     stack.currentFrame->eptr++;
1806                                 }
1807                                 break;
1808                             }
1809                             break;
1810                             
1811                             case OP_NOT_DIGIT:
1812                             for (i = min; i < stack.currentFrame->max; i++) {
1813                                 int len = 1;
1814                                 if (stack.currentFrame->eptr >= md->end_subject)
1815                                     break;
1816                                 GETCHARLEN(c, stack.currentFrame->eptr, len);
1817                                 if (isASCIIDigit(c))
1818                                     break;
1819                                 stack.currentFrame->eptr+= len;
1820                             }
1821                             break;
1822                             
1823                             case OP_DIGIT:
1824                             for (i = min; i < stack.currentFrame->max; i++) {
1825                                 int len = 1;
1826                                 if (stack.currentFrame->eptr >= md->end_subject)
1827                                     break;
1828                                 GETCHARLEN(c, stack.currentFrame->eptr, len);
1829                                 if (!isASCIIDigit(c))
1830                                     break;
1831                                 stack.currentFrame->eptr+= len;
1832                             }
1833                             break;
1834                             
1835                             case OP_NOT_WHITESPACE:
1836                             for (i = min; i < stack.currentFrame->max; i++) {
1837                                 int len = 1;
1838                                 if (stack.currentFrame->eptr >= md->end_subject)
1839                                     break;
1840                                 GETCHARLEN(c, stack.currentFrame->eptr, len);
1841                                 if (c < 128 && (md->ctypes[c] & ctype_space))
1842                                     break;
1843                                 stack.currentFrame->eptr+= len;
1844                             }
1845                             break;
1846                             
1847                             case OP_WHITESPACE:
1848                             for (i = min; i < stack.currentFrame->max; i++) {
1849                                 int len = 1;
1850                                 if (stack.currentFrame->eptr >= md->end_subject)
1851                                     break;
1852                                 GETCHARLEN(c, stack.currentFrame->eptr, len);
1853                                 if (c >= 128 || !(md->ctypes[c] & ctype_space))
1854                                     break;
1855                                 stack.currentFrame->eptr+= len;
1856                             }
1857                             break;
1858                             
1859                             case OP_NOT_WORDCHAR:
1860                             for (i = min; i < stack.currentFrame->max; i++) {
1861                                 int len = 1;
1862                                 if (stack.currentFrame->eptr >= md->end_subject)
1863                                     break;
1864                                 GETCHARLEN(c, stack.currentFrame->eptr, len);
1865                                 if (c < 128 && (md->ctypes[c] & ctype_word))
1866                                     break;
1867                                 stack.currentFrame->eptr+= len;
1868                             }
1869                             break;
1870                             
1871                             case OP_WORDCHAR:
1872                             for (i = min; i < stack.currentFrame->max; i++) {
1873                                 int len = 1;
1874                                 if (stack.currentFrame->eptr >= md->end_subject)
1875                                     break;
1876                                 GETCHARLEN(c, stack.currentFrame->eptr, len);
1877                                 if (c >= 128 || !(md->ctypes[c] & ctype_word))
1878                                     break;
1879                                 stack.currentFrame->eptr+= len;
1880                             }
1881                             break;
1882                             
1883                             default:
1884                             ASSERT_NOT_REACHED();
1885                             return matchError(JSRegExpErrorInternal, stack);
1886                     }
1887                     
1888                     /* stack.currentFrame->eptr is now past the end of the maximum run */
1889                     
1890                     for (;;) {
1891                         RMATCH(52, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
1892                         if (is_match)
1893                             RRETURN;
1894                         if (stack.currentFrame->eptr-- == stack.currentFrame->pp)
1895                             break;        /* Stop if tried at original pos */
1896                         BACKCHAR(stack.currentFrame->eptr);
1897                     }
1898                     
1899                     /* Get here if we can't make it match with any permitted repetitions */
1900                     
1901                     RRETURN;
1902                 }
1903                 /* Control never reaches here */
1904                 
1905                 BEGIN_OPCODE(CRMINPLUS):
1906                 BEGIN_OPCODE(CRMINQUERY):
1907                 BEGIN_OPCODE(CRMINRANGE):
1908                 BEGIN_OPCODE(CRMINSTAR):
1909                 BEGIN_OPCODE(CRPLUS):
1910                 BEGIN_OPCODE(CRQUERY):
1911                 BEGIN_OPCODE(CRRANGE):
1912                 BEGIN_OPCODE(CRSTAR):
1913                 ASSERT_NOT_REACHED();
1914                 return matchError(JSRegExpErrorInternal, stack);
1915                 
1916 #ifdef USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP
1917             CAPTURING_BRACKET:
1918 #else
1919                 default:
1920 #endif
1921                 /* Opening capturing bracket. If there is space in the offset vector, save
1922                  the current subject position in the working slot at the top of the vector. We
1923                  mustn't change the current values of the data slot, because they may be set
1924                  from a previous iteration of this group, and be referred to by a reference
1925                  inside the group.
1926                  
1927                  If the bracket fails to match, we need to restore this value and also the
1928                  values of the final offsets, in case they were set by a previous iteration of
1929                  the same bracket.
1930                  
1931                  If there isn't enough space in the offset vector, treat this as if it were a
1932                  non-capturing bracket. Don't worry about setting the flag for the error case
1933                  here; that is handled in the code for KET. */
1934                 
1935                 ASSERT(*stack.currentFrame->ecode > OP_BRA);
1936                 
1937                 stack.currentFrame->number = *stack.currentFrame->ecode - OP_BRA;
1938                 
1939                 /* For extended extraction brackets (large number), we have to fish out the
1940                  number from a dummy opcode at the start. */
1941                 
1942                 if (stack.currentFrame->number > EXTRACT_BASIC_MAX)
1943                     stack.currentFrame->number = GET2(stack.currentFrame->ecode, 2+LINK_SIZE);
1944                 stack.currentFrame->offset = stack.currentFrame->number << 1;
1945                 
1946 #ifdef DEBUG
1947                 printf("start bracket %d subject=", stack.currentFrame->number);
1948                 pchars(stack.currentFrame->eptr, 16, true, md);
1949                 printf("\n");
1950 #endif
1951                 
1952                 if (stack.currentFrame->offset < md->offset_max) {
1953                     stack.currentFrame->save_offset1 = md->offset_vector[stack.currentFrame->offset];
1954                     stack.currentFrame->save_offset2 = md->offset_vector[stack.currentFrame->offset + 1];
1955                     stack.currentFrame->save_offset3 = md->offset_vector[md->offset_end - stack.currentFrame->number];
1956                     
1957                     DPRINTF(("saving %d %d %d\n", stack.currentFrame->save_offset1, stack.currentFrame->save_offset2, stack.currentFrame->save_offset3));
1958                     md->offset_vector[md->offset_end - stack.currentFrame->number] = stack.currentFrame->eptr - md->start_subject;
1959                     
1960                     do {
1961                         RMATCH(1, stack.currentFrame->ecode + 1 + LINK_SIZE, stack.currentFrame->eptrb, match_isgroup);
1962                         if (is_match) RRETURN;
1963                         stack.currentFrame->ecode += GET(stack.currentFrame->ecode, 1);
1964                     } while (*stack.currentFrame->ecode == OP_ALT);
1965                     
1966                     DPRINTF(("bracket %d failed\n", stack.currentFrame->number));
1967                     
1968                     md->offset_vector[stack.currentFrame->offset] = stack.currentFrame->save_offset1;
1969                     md->offset_vector[stack.currentFrame->offset + 1] = stack.currentFrame->save_offset2;
1970                     md->offset_vector[md->offset_end - stack.currentFrame->number] = stack.currentFrame->save_offset3;
1971                     
1972                     RRETURN;
1973                 }
1974                 
1975                 /* Insufficient room for saving captured contents */
1976                 
1977                 goto NON_CAPTURING_BRACKET;
1978         }
1979         
1980         /* Do not stick any code in here without much thought; it is assumed
1981          that "continue" in the code above comes out to here to repeat the main
1982          loop. */
1983         
1984     } /* End of main loop */
1985     
1986     ASSERT_NOT_REACHED();
1987     
1988 #ifndef USE_COMPUTED_GOTO_FOR_MATCH_RECURSION
1989     
1990 RRETURN_SWITCH:
1991     switch (stack.currentFrame->returnLocation)
1992     {
1993         case 0: goto RETURN;
1994         case 1: goto RRETURN_1;
1995         case 2: goto RRETURN_2;
1996         case 6: goto RRETURN_6;
1997         case 7: goto RRETURN_7;
1998         case 9: goto RRETURN_9;
1999         case 10: goto RRETURN_10;
2000         case 11: goto RRETURN_11;
2001         case 12: goto RRETURN_12;
2002         case 13: goto RRETURN_13;
2003         case 14: goto RRETURN_14;
2004         case 15: goto RRETURN_15;
2005         case 16: goto RRETURN_16;
2006         case 17: goto RRETURN_17;
2007         case 18: goto RRETURN_18;
2008         case 19: goto RRETURN_19;
2009         case 20: goto RRETURN_20;
2010         case 21: goto RRETURN_21;
2011         case 22: goto RRETURN_22;
2012         case 24: goto RRETURN_24;
2013         case 26: goto RRETURN_26;
2014         case 27: goto RRETURN_27;
2015         case 28: goto RRETURN_28;
2016         case 29: goto RRETURN_29;
2017         case 30: goto RRETURN_30;
2018         case 31: goto RRETURN_31;
2019         case 38: goto RRETURN_38;
2020         case 40: goto RRETURN_40;
2021         case 42: goto RRETURN_42;
2022         case 44: goto RRETURN_44;
2023         case 48: goto RRETURN_48;
2024         case 52: goto RRETURN_52;
2025     }
2026     
2027     ASSERT_NOT_REACHED();
2028     return matchError(JSRegExpErrorInternal, stack);
2029     
2030 #endif
2031     
2032 RETURN:
2033     return is_match ? MATCH_MATCH : MATCH_NOMATCH;
2034 }
2035
2036
2037 /*************************************************
2038 *         Execute a Regular Expression           *
2039 *************************************************/
2040
2041 /* This function applies a compiled re to a subject string and picks out
2042 portions of the string if it matches. Two elements in the vector are set for
2043 each substring: the offsets to the start and end of the substring.
2044
2045 Arguments:
2046   re              points to the compiled expression
2047   extra_data      points to extra data or is NULL
2048   subject         points to the subject string
2049   length          length of subject string (may contain binary zeros)
2050   start_offset    where to start in the subject string
2051   options         option bits
2052   offsets         points to a vector of ints to be filled in with offsets
2053   offsetcount     the number of elements in the vector
2054
2055 Returns:          > 0 => success; value is the number of elements filled in
2056                   = 0 => success, but offsets is not big enough
2057                    -1 => failed to match
2058                  < -1 => some kind of unexpected problem
2059 */
2060
2061 int jsRegExpExecute(const JSRegExp* re,
2062                     const UChar* subject, int length, int start_offset, int* offsets,
2063                     int offsetcount)
2064 {
2065     ASSERT(re);
2066     ASSERT(subject);
2067     ASSERT(offsetcount >= 0);
2068     ASSERT(offsets || offsetcount == 0);
2069     
2070     match_data match_block;
2071     match_block.start_subject = (UChar*)subject;
2072     match_block.end_subject = match_block.start_subject + length;
2073     UChar* end_subject = match_block.end_subject;
2074     
2075     match_block.lcc = _pcre_default_tables + lcc_offset;
2076     match_block.ctypes = _pcre_default_tables + ctypes_offset;
2077     
2078     match_block.multiline = (re->options & PCRE_MULTILINE) != 0;
2079     match_block.caseless = (re->options & PCRE_CASELESS) != 0;
2080     
2081     /* If the expression has got more back references than the offsets supplied can
2082      hold, we get a temporary chunk of working store to use during the matching.
2083      Otherwise, we can use the vector supplied, rounding down its size to a multiple
2084      of 3. */
2085     
2086     int ocount = offsetcount - (offsetcount % 3);
2087     
2088     bool using_temporary_offsets = false;
2089     if (re->top_backref > 0 && re->top_backref >= ocount/3) {
2090         ocount = re->top_backref * 3 + 3;
2091         match_block.offset_vector = new int[ocount];
2092         if (!match_block.offset_vector)
2093             return JSRegExpErrorNoMemory;
2094         using_temporary_offsets = true;
2095     } else
2096         match_block.offset_vector = offsets;
2097     
2098     match_block.offset_end = ocount;
2099     match_block.offset_max = (2*ocount)/3;
2100     match_block.offset_overflow = false;
2101     
2102     /* Compute the minimum number of offsets that we need to reset each time. Doing
2103      this makes a huge difference to execution time when there aren't many brackets
2104      in the pattern. */
2105     
2106     int resetcount = 2 + re->top_bracket * 2;
2107     if (resetcount > offsetcount)
2108         resetcount = ocount;
2109     
2110     /* Reset the working variable associated with each extraction. These should
2111      never be used unless previously set, but they get saved and restored, and so we
2112      initialize them to avoid reading uninitialized locations. */
2113     
2114     if (match_block.offset_vector) {
2115         int* iptr = match_block.offset_vector + ocount;
2116         int* iend = iptr - resetcount/2 + 1;
2117         while (--iptr >= iend)
2118             *iptr = -1;
2119     }
2120     
2121     /* Set up the first character to match, if available. The first_byte value is
2122      never set for an anchored regular expression, but the anchoring may be forced
2123      at run time, so we have to test for anchoring. The first char may be unset for
2124      an unanchored pattern, of course. If there's no first char and the pattern was
2125      studied, there may be a bitmap of possible first characters. */
2126     
2127     bool first_byte_caseless = false;
2128     int first_byte = -1;
2129     if (re->options & PCRE_FIRSTSET) {
2130         first_byte = re->first_byte & 255;
2131         if ((first_byte_caseless = (re->first_byte & REQ_CASELESS)))
2132             first_byte = match_block.lcc[first_byte];
2133     }
2134     
2135     /* For anchored or unanchored matches, there may be a "last known required
2136      character" set. */
2137     
2138     bool req_byte_caseless = false;
2139     int req_byte = -1;
2140     int req_byte2 = -1;
2141     if (re->options & PCRE_REQCHSET) {
2142         req_byte = re->req_byte & 255;
2143         req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
2144         req_byte2 = (_pcre_default_tables + fcc_offset)[req_byte];  /* case flipped */
2145     }
2146     
2147     /* Loop for handling unanchored repeated matching attempts; for anchored regexs
2148      the loop runs just once. */
2149     
2150     UChar* start_match = (UChar*)subject + start_offset;
2151     UChar* req_byte_ptr = start_match - 1;
2152     bool startline = re->options & PCRE_STARTLINE;
2153     
2154     do {
2155         UChar* save_end_subject = end_subject;
2156         
2157         /* Reset the maximum number of extractions we might see. */
2158         
2159         if (match_block.offset_vector) {
2160             int* iptr = match_block.offset_vector;
2161             int* iend = iptr + resetcount;
2162             while (iptr < iend)
2163                 *iptr++ = -1;
2164         }
2165         
2166         /* Advance to a unique first char if possible. If firstline is true, the
2167          start of the match is constrained to the first line of a multiline string.
2168          Implement this by temporarily adjusting end_subject so that we stop scanning
2169          at a newline. If the match fails at the newline, later code breaks this loop.
2170          */
2171         
2172         /* Now test for a unique first byte */
2173         
2174         if (first_byte >= 0) {
2175             UChar first_char = first_byte;
2176             if (first_byte_caseless)
2177                 while (start_match < end_subject) {
2178                     int sm = *start_match;
2179                     if (sm > 127)
2180                         break;
2181                     if (match_block.lcc[sm] == first_char)
2182                         break;
2183                     start_match++;
2184                 }
2185             else
2186                 while (start_match < end_subject && *start_match != first_char)
2187                     start_match++;
2188         }
2189         
2190         /* Or to just after \n for a multiline match if possible */
2191         
2192         else if (startline) {
2193             if (start_match > match_block.start_subject + start_offset) {
2194                 while (start_match < end_subject && !isNewline(start_match[-1]))
2195                     start_match++;
2196             }
2197         }
2198         
2199         /* Restore fudged end_subject */
2200         
2201         end_subject = save_end_subject;
2202         
2203 #ifdef DEBUG  /* Sigh. Some compilers never learn. */
2204         printf(">>>> Match against: ");
2205         pchars(start_match, end_subject - start_match, true, &match_block);
2206         printf("\n");
2207 #endif
2208         
2209         /* If req_byte is set, we know that that character must appear in the subject
2210          for the match to succeed. If the first character is set, req_byte must be
2211          later in the subject; otherwise the test starts at the match point. This
2212          optimization can save a huge amount of backtracking in patterns with nested
2213          unlimited repeats that aren't going to match. Writing separate code for
2214          cased/caseless versions makes it go faster, as does using an autoincrement
2215          and backing off on a match.
2216          
2217          HOWEVER: when the subject string is very, very long, searching to its end can
2218          take a long time, and give bad performance on quite ordinary patterns. This
2219          showed up when somebody was matching /^C/ on a 32-megabyte string... so we
2220          don't do this when the string is sufficiently long.
2221          
2222          ALSO: this processing is disabled when partial matching is requested.
2223          */
2224         
2225         if (req_byte >= 0 && end_subject - start_match < REQ_BYTE_MAX) {
2226             UChar* p = start_match + ((first_byte >= 0)? 1 : 0);
2227             
2228             /* We don't need to repeat the search if we haven't yet reached the
2229              place we found it at last time. */
2230             
2231             if (p > req_byte_ptr) {
2232                 if (req_byte_caseless) {
2233                     while (p < end_subject) {
2234                         int pp = *p++;
2235                         if (pp == req_byte || pp == req_byte2) {
2236                             p--;
2237                             break;
2238                         }
2239                     }
2240                 } else {
2241                     while (p < end_subject) {
2242                         if (*p++ == req_byte) {
2243                             p--;
2244                             break;
2245                         }
2246                     }
2247                 }
2248                 
2249                 /* If we can't find the required character, break the matching loop */
2250                 
2251                 if (p >= end_subject)
2252                     break;
2253                 
2254                 /* If we have found the required character, save the point where we
2255                  found it, so that we don't search again next time round the loop if
2256                  the start hasn't passed this character yet. */
2257                 
2258                 req_byte_ptr = p;
2259             }
2260         }
2261         
2262         /* When a match occurs, substrings will be set for all internal extractions;
2263          we just need to set up the whole thing as substring 0 before returning. If
2264          there were too many extractions, set the return code to zero. In the case
2265          where we had to get some local store to hold offsets for backreferences, copy
2266          those back references that we can. In this case there need not be overflow
2267          if certain parts of the pattern were not used. */
2268         
2269         match_block.match_call_count = 0;
2270         
2271         
2272         /* The code starts after the JSRegExp block and the capture name table. */
2273         const uschar* start_code = (const uschar*)(re + 1);
2274         
2275         int returnCode = match(start_match, start_code, 2, &match_block);
2276         
2277         /* When the result is no match, if the subject's first character was a
2278          newline and the PCRE_FIRSTLINE option is set, break (which will return
2279          PCRE_ERROR_NOMATCH). The option requests that a match occur before the first
2280          newline in the subject. Otherwise, advance the pointer to the next character
2281          and continue - but the continuation will actually happen only when the
2282          pattern is not anchored. */
2283         
2284         if (returnCode == MATCH_NOMATCH) {
2285             start_match++;
2286             while(start_match < end_subject && isTrailingSurrogate(*start_match))
2287                 start_match++;
2288             continue;
2289         }
2290         
2291         if (returnCode != MATCH_MATCH) {
2292             DPRINTF((">>>> error: returning %d\n", rc));
2293             return returnCode;
2294         }
2295         
2296         /* We have a match! Copy the offset information from temporary store if
2297          necessary */
2298         
2299         if (using_temporary_offsets) {
2300             if (offsetcount >= 4) {
2301                 memcpy(offsets + 2, match_block.offset_vector + 2, (offsetcount - 2) * sizeof(int));
2302                 DPRINTF(("Copied offsets from temporary memory\n"));
2303             }
2304             if (match_block.end_offset_top > offsetcount)
2305                 match_block.offset_overflow = true;
2306             
2307             DPRINTF(("Freeing temporary memory\n"));
2308             delete [] match_block.offset_vector;
2309         }
2310         
2311         returnCode = match_block.offset_overflow? 0 : match_block.end_offset_top/2;
2312         
2313         if (offsetcount < 2)
2314             returnCode = 0;
2315         else {
2316             offsets[0] = start_match - match_block.start_subject;
2317             offsets[1] = match_block.end_match_ptr - match_block.start_subject;
2318         }
2319         
2320         DPRINTF((">>>> returning %d\n", rc));
2321         return returnCode;
2322     } while (start_match <= end_subject);
2323     
2324     if (using_temporary_offsets) {
2325         DPRINTF(("Freeing temporary memory\n"));
2326         delete [] match_block.offset_vector;
2327     }
2328     
2329     DPRINTF((">>>> returning PCRE_ERROR_NOMATCH\n"));
2330     return JSRegExpErrorNoMatch;
2331 }