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