/[pcre]/code/trunk/pcre_exec.c
ViewVC logotype

Diff of /code/trunk/pcre_exec.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 91 by nigel, Sat Feb 24 21:41:34 2007 UTC revision 459 by ph10, Sun Oct 4 09:21:39 2009 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2006 University of Cambridge             Copyright (c) 1997-2009 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 42  POSSIBILITY OF SUCH DAMAGE. Line 42  POSSIBILITY OF SUCH DAMAGE.
42  pattern matching using an NFA algorithm, trying to mimic Perl as closely as  pattern matching using an NFA algorithm, trying to mimic Perl as closely as
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45  #define NLBLOCK md           /* The block containing newline information */  #ifdef HAVE_CONFIG_H
46    #include "config.h"
47    #endif
48    
49    #define NLBLOCK md             /* Block containing newline information */
50    #define PSSTART start_subject  /* Field containing processed string start */
51    #define PSEND   end_subject    /* Field containing processed string end */
52    
53  #include "pcre_internal.h"  #include "pcre_internal.h"
54    
55    /* Undefine some potentially clashing cpp symbols */
56    
57  /* Structure for building a chain of data that actually lives on the  #undef min
58  stack, for holding the values of the subject pointer at the start of each  #undef max
 subpattern, so as to detect when an empty string has been matched by a  
 subpattern - to break infinite loops. When NO_RECURSE is set, these blocks  
 are on the heap, not on the stack. */  
   
 typedef struct eptrblock {  
   struct eptrblock *epb_prev;  
   USPTR epb_saved_eptr;  
 } eptrblock;  
59    
60  /* Flag bits for the match() function */  /* Flag bits for the match() function */
61    
62  #define match_condassert   0x01    /* Called to check a condition assertion */  #define match_condassert     0x01  /* Called to check a condition assertion */
63  #define match_isgroup      0x02    /* Set if start of bracketed group */  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
64    
65  /* Non-error returns from the match() function. Error returns are externally  /* Non-error returns from the match() function. Error returns are externally
66  defined PCRE_ERROR_xxx codes, which are all negative. */  defined PCRE_ERROR_xxx codes, which are all negative. */
# Line 68  defined PCRE_ERROR_xxx codes, which are Line 68  defined PCRE_ERROR_xxx codes, which are
68  #define MATCH_MATCH        1  #define MATCH_MATCH        1
69  #define MATCH_NOMATCH      0  #define MATCH_NOMATCH      0
70    
71    /* Special internal returns from the match() function. Make them sufficiently
72    negative to avoid the external error codes. */
73    
74    #define MATCH_COMMIT       (-999)
75    #define MATCH_PRUNE        (-998)
76    #define MATCH_SKIP         (-997)
77    #define MATCH_THEN         (-996)
78    
79  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
80  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
81  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 101  Returns:     nothing Line 109  Returns:     nothing
109  static void  static void
110  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
111  {  {
112  int c;  unsigned int c;
113  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
114  while (length-- > 0)  while (length-- > 0)
115    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);
# Line 150  printf("\n"); Line 158  printf("\n");
158    
159  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
160    
161  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
162    properly if Unicode properties are supported. Otherwise, we can check only
163    ASCII characters. */
164    
165  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
166    {    {
167    #ifdef SUPPORT_UTF8
168    #ifdef SUPPORT_UCP
169      if (md->utf8)
170        {
171        USPTR endptr = eptr + length;
172        while (eptr < endptr)
173          {
174          int c, d;
175          GETCHARINC(c, eptr);
176          GETCHARINC(d, p);
177          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
178          }
179        }
180      else
181    #endif
182    #endif
183    
184      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
185      is no UCP support. */
186    
187    while (length-- > 0)    while (length-- > 0)
188      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
189    }    }
190    
191    /* In the caseful case, we can just compare the bytes, whether or not we
192    are in UTF-8 mode. */
193    
194  else  else
195    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
196    
# Line 186  calls by keeping local variables that ne Line 220  calls by keeping local variables that ne
220  obtained from malloc() instead instead of on the stack. Macros are used to  obtained from malloc() instead instead of on the stack. Macros are used to
221  achieve this so that the actual code doesn't look very different to what it  achieve this so that the actual code doesn't look very different to what it
222  always used to.  always used to.
223    
224    The original heap-recursive code used longjmp(). However, it seems that this
225    can be very slow on some operating systems. Following a suggestion from Stan
226    Switzer, the use of longjmp() has been abolished, at the cost of having to
227    provide a unique number for each call to RMATCH. There is no way of generating
228    a sequence of numbers at compile time in C. I have given them names, to make
229    them stand out more clearly.
230    
231    Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
232    FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
233    tests. Furthermore, not using longjmp() means that local dynamic variables
234    don't have indeterminate values; this has meant that the frame size can be
235    reduced because the result can be "passed back" by straight setting of the
236    variable instead of being passed in the frame.
237  ****************************************************************************  ****************************************************************************
238  ***************************************************************************/  ***************************************************************************/
239    
240    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
241    below must be updated in sync.  */
242    
243    enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
244           RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
245           RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
246           RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
247           RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
248           RM51,  RM52, RM53, RM54 };
249    
250  /* These versions of the macros use the stack, as normal. There are debugging  /* These versions of the macros use the stack, as normal. There are debugging
251  versions and production versions. */  versions and production versions. Note that the "rw" argument of RMATCH isn't
252    actuall used in this definition. */
253    
254  #ifndef NO_RECURSE  #ifndef NO_RECURSE
255  #define REGISTER register  #define REGISTER register
256    
257  #ifdef DEBUG  #ifdef DEBUG
258  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259    { \    { \
260    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
261    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
262    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
263    }    }
264  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 208  versions and production versions. */ Line 267  versions and production versions. */
267    return ra; \    return ra; \
268    }    }
269  #else  #else
270  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
271    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)
272  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
273  #endif  #endif
274    
275  #else  #else
276    
277    
278  /* These versions of the macros manage a private stack on the heap. Note  /* These versions of the macros manage a private stack on the heap. Note that
279  that the rd argument of RMATCH isn't actually used. It's the md argument of  the "rd" argument of RMATCH isn't actually used in this definition. It's the md
280  match(), which never changes. */  argument of match(), which never changes. */
281    
282  #define REGISTER  #define REGISTER
283    
284  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
285    {\    {\
286    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
287    if (setjmp(frame->Xwhere) == 0)\    frame->Xwhere = rw; \
288      {\    newframe->Xeptr = ra;\
289      newframe->Xeptr = ra;\    newframe->Xecode = rb;\
290      newframe->Xecode = rb;\    newframe->Xmstart = mstart;\
291      newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
292      newframe->Xims = re;\    newframe->Xims = re;\
293      newframe->Xeptrb = rf;\    newframe->Xeptrb = rf;\
294      newframe->Xflags = rg;\    newframe->Xflags = rg;\
295      newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xrdepth = frame->Xrdepth + 1;\
296      newframe->Xprevframe = frame;\    newframe->Xprevframe = frame;\
297      frame = newframe;\    frame = newframe;\
298      DPRINTF(("restarting from line %d\n", __LINE__));\    DPRINTF(("restarting from line %d\n", __LINE__));\
299      goto HEAP_RECURSE;\    goto HEAP_RECURSE;\
300      }\    L_##rw:\
301    else\    DPRINTF(("jumped back to line %d\n", __LINE__));\
     {\  
     DPRINTF(("longjumped back to line %d\n", __LINE__));\  
     frame = md->thisframe;\  
     rx = frame->Xresult;\  
     }\  
302    }    }
303    
304  #define RRETURN(ra)\  #define RRETURN(ra)\
# Line 254  match(), which never changes. */ Line 308  match(), which never changes. */
308    (pcre_stack_free)(newframe);\    (pcre_stack_free)(newframe);\
309    if (frame != NULL)\    if (frame != NULL)\
310      {\      {\
311      frame->Xresult = ra;\      rrc = ra;\
312      md->thisframe = frame;\      goto HEAP_RETURN;\
     longjmp(frame->Xwhere, 1);\  
313      }\      }\
314    return ra;\    return ra;\
315    }    }
# Line 269  typedef struct heapframe { Line 322  typedef struct heapframe {
322    
323    /* Function arguments that may change */    /* Function arguments that may change */
324    
325    const uschar *Xeptr;    USPTR Xeptr;
326    const uschar *Xecode;    const uschar *Xecode;
327      USPTR Xmstart;
328    int Xoffset_top;    int Xoffset_top;
329    long int Xims;    long int Xims;
330    eptrblock *Xeptrb;    eptrblock *Xeptrb;
# Line 279  typedef struct heapframe { Line 333  typedef struct heapframe {
333    
334    /* Function local variables */    /* Function local variables */
335    
336    const uschar *Xcallpat;    USPTR Xcallpat;
337    const uschar *Xcharptr;  #ifdef SUPPORT_UTF8
338    const uschar *Xdata;    USPTR Xcharptr;
339    const uschar *Xnext;  #endif
340    const uschar *Xpp;    USPTR Xdata;
341    const uschar *Xprev;    USPTR Xnext;
342    const uschar *Xsaved_eptr;    USPTR Xpp;
343      USPTR Xprev;
344      USPTR Xsaved_eptr;
345    
346    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
347    
348    BOOL Xcur_is_word;    BOOL Xcur_is_word;
349    BOOL Xcondition;    BOOL Xcondition;
   BOOL Xminimize;  
350    BOOL Xprev_is_word;    BOOL Xprev_is_word;
351    
352    unsigned long int Xoriginal_ims;    unsigned long int Xoriginal_ims;
# Line 303  typedef struct heapframe { Line 358  typedef struct heapframe {
358    int Xprop_category;    int Xprop_category;
359    int Xprop_chartype;    int Xprop_chartype;
360    int Xprop_script;    int Xprop_script;
361    int *Xprop_test_variable;    int Xoclength;
362      uschar Xocchars[8];
363  #endif  #endif
364    
365      int Xcodelink;
366    int Xctype;    int Xctype;
367    int Xfc;    unsigned int Xfc;
368    int Xfi;    int Xfi;
369    int Xlength;    int Xlength;
370    int Xmax;    int Xmax;
# Line 321  typedef struct heapframe { Line 378  typedef struct heapframe {
378    
379    eptrblock Xnewptrb;    eptrblock Xnewptrb;
380    
381    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
382    
383    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
384    
385  } heapframe;  } heapframe;
386    
# Line 340  typedef struct heapframe { Line 396  typedef struct heapframe {
396  *         Match from current position            *  *         Match from current position            *
397  *************************************************/  *************************************************/
398    
399  /* On entry ecode points to the first opcode, and eptr to the first character  /* This function is called recursively in many circumstances. Whenever it
 in the subject string, while eptrb holds the value of eptr at the start of the  
 last bracketed group - used for breaking infinite loops matching zero-length  
 strings. This function is called recursively in many circumstances. Whenever it  
400  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
401  same response.  same response. */
402    
403    /* These macros pack up tests that are used for partial matching, and which
404    appears several times in the code. We set the "hit end" flag if the pointer is
405    at the end of the subject and also past the start of the subject (i.e.
406    something has been matched). For hard partial matching, we then return
407    immediately. The second one is used when we already know we are past the end of
408    the subject. */
409    
410    #define CHECK_PARTIAL()\
411      if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\
412        {\
413        md->hitend = TRUE;\
414        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
415        }
416    
417    #define SCHECK_PARTIAL()\
418      if (md->partial && eptr > mstart)\
419        {\
420        md->hitend = TRUE;\
421        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
422        }
423    
424  Performance note: It might be tempting to extract commonly used fields from the  
425  md structure (e.g. utf8, end_subject) into individual variables to improve  /* Performance note: It might be tempting to extract commonly used fields from
426    the md structure (e.g. utf8, end_subject) into individual variables to improve
427  performance. Tests using gcc on a SPARC disproved this; in the first case, it  performance. Tests using gcc on a SPARC disproved this; in the first case, it
428  made performance worse.  made performance worse.
429    
430  Arguments:  Arguments:
431     eptr        pointer in subject     eptr        pointer to current character in subject
432     ecode       position in code     ecode       pointer to current position in compiled code
433       mstart      pointer to the current match start position (can be modified
434                     by encountering \K)
435     offset_top  current top pointer     offset_top  current top pointer
436     md          pointer to "static" info for the match     md          pointer to "static" info for the match
437     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 362  Arguments: Line 439  Arguments:
439                   brackets - for testing for empty matches                   brackets - for testing for empty matches
440     flags       can contain     flags       can contain
441                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
442                   match_isgroup - this is the start of a bracketed group                   match_cbegroup - this is the start of an unlimited repeat
443                       group that can match an empty string
444     rdepth      the recursion depth     rdepth      the recursion depth
445    
446  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
# Line 372  Returns:       MATCH_MATCH if matched Line 450  Returns:       MATCH_MATCH if matched
450  */  */
451    
452  static int  static int
453  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
454    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
455    int flags, unsigned int rdepth)    int flags, unsigned int rdepth)
456  {  {
457  /* These variables do not need to be preserved over recursion in this function,  /* These variables do not need to be preserved over recursion in this function,
458  so they can be ordinary variables in all cases. Mark them with "register"  so they can be ordinary variables in all cases. Mark some of them with
459  because they are used a lot in loops. */  "register" because they are used a lot in loops. */
460    
461  register int  rrc;         /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
462  register int  i;           /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
463  register unsigned int  c;  /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
464  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
465    
466    BOOL minimize, possessive; /* Quantifier options */
467    int condcode;
468    
469  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
470  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame" which is obtained from
471  heap storage. Set up the top-level frame here; others are obtained from the  heap storage. Set up the top-level frame here; others are obtained from the
# Line 398  frame->Xprevframe = NULL;            /* Line 479  frame->Xprevframe = NULL;            /*
479    
480  frame->Xeptr = eptr;  frame->Xeptr = eptr;
481  frame->Xecode = ecode;  frame->Xecode = ecode;
482    frame->Xmstart = mstart;
483  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
484  frame->Xims = ims;  frame->Xims = ims;
485  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 412  HEAP_RECURSE: Line 494  HEAP_RECURSE:
494    
495  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
496  #define ecode              frame->Xecode  #define ecode              frame->Xecode
497    #define mstart             frame->Xmstart
498  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
499  #define ims                frame->Xims  #define ims                frame->Xims
500  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 424  HEAP_RECURSE: Line 507  HEAP_RECURSE:
507  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
508  #endif  #endif
509  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
510    #define codelink           frame->Xcodelink
511  #define data               frame->Xdata  #define data               frame->Xdata
512  #define next               frame->Xnext  #define next               frame->Xnext
513  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 434  HEAP_RECURSE: Line 518  HEAP_RECURSE:
518    
519  #define cur_is_word        frame->Xcur_is_word  #define cur_is_word        frame->Xcur_is_word
520  #define condition          frame->Xcondition  #define condition          frame->Xcondition
 #define minimize           frame->Xminimize  
521  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
522    
523  #define original_ims       frame->Xoriginal_ims  #define original_ims       frame->Xoriginal_ims
# Line 446  HEAP_RECURSE: Line 529  HEAP_RECURSE:
529  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
530  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
531  #define prop_script        frame->Xprop_script  #define prop_script        frame->Xprop_script
532  #define prop_test_variable frame->Xprop_test_variable  #define oclength           frame->Xoclength
533    #define occhars            frame->Xocchars
534  #endif  #endif
535    
536  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 470  HEAP_RECURSE: Line 554  HEAP_RECURSE:
554  get preserved during recursion in the normal way. In this environment, fi and  get preserved during recursion in the normal way. In this environment, fi and
555  i, and fc and c, can be the same variables. */  i, and fc and c, can be the same variables. */
556    
557  #else  #else         /* NO_RECURSE not defined */
558  #define fi i  #define fi i
559  #define fc c  #define fc c
560    
# Line 489  recursion_info new_recursive;      /* wi Line 573  recursion_info new_recursive;      /* wi
573                                     /* that do not have to be preserved over  */                                     /* that do not have to be preserved over  */
574  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
575  BOOL condition;  BOOL condition;
 BOOL minimize;  
576  BOOL prev_is_word;  BOOL prev_is_word;
577    
578  unsigned long int original_ims;  unsigned long int original_ims;
# Line 501  int prop_fail_result; Line 584  int prop_fail_result;
584  int prop_category;  int prop_category;
585  int prop_chartype;  int prop_chartype;
586  int prop_script;  int prop_script;
587  int *prop_test_variable;  int oclength;
588    uschar occhars[8];
589  #endif  #endif
590    
591    int codelink;
592  int ctype;  int ctype;
593  int length;  int length;
594  int max;  int max;
# Line 516  int save_offset1, save_offset2, save_off Line 601  int save_offset1, save_offset2, save_off
601  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
602    
603  eptrblock newptrb;  eptrblock newptrb;
604  #endif  #endif     /* NO_RECURSE */
605    
606  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
607  variables. */  variables. */
# Line 524  variables. */ Line 609  variables. */
609  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
610  prop_value = 0;  prop_value = 0;
611  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_variable = NULL;  
612  #endif  #endif
613    
614    
615  /* This label is used for tail recursion, which is used in a few cases even  /* This label is used for tail recursion, which is used in a few cases even
616  when NO_RECURSE is not defined, in order to reduce the amount of stack that is  when NO_RECURSE is not defined, in order to reduce the amount of stack that is
617  used. Thanks to Ian Taylor for noticing this possibility and sending the  used. Thanks to Ian Taylor for noticing this possibility and sending the
# Line 542  defined). However, RMATCH isn't like a f Line 627  defined). However, RMATCH isn't like a f
627  complicated macro. It has to be used in one particular way. This shouldn't,  complicated macro. It has to be used in one particular way. This shouldn't,
628  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
629    
630    #ifdef SUPPORT_UTF8
631    utf8 = md->utf8;       /* Local copy of the flag */
632    #else
633    utf8 = FALSE;
634    #endif
635    
636  /* First check that we haven't called match() too many times, or that we  /* First check that we haven't called match() too many times, or that we
637  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
638    
# Line 550  if (rdepth >= md->match_limit_recursion) Line 641  if (rdepth >= md->match_limit_recursion)
641    
642  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
643    
644  #ifdef SUPPORT_UTF8  /* At the start of a group with an unlimited repeat that may match an empty
645  utf8 = md->utf8;       /* Local copy of the flag */  string, the match_cbegroup flag is set. When this is the case, add the current
646  #else  subject pointer to the chain of such remembered pointers, to be checked when we
647  utf8 = FALSE;  hit the closing ket, in order to break infinite loops that match no characters.
648  #endif  When match() is called in other circumstances, don't add to the chain. The
649    match_cbegroup flag must NOT be used with tail recursion, because the memory
650  /* At the start of a bracketed group, add the current subject pointer to the  block that is used is on the stack, so a new one may be required for each
651  stack of such pointers, to be re-instated at the end of the group when we hit  match(). */
 the closing ket. When match() is called in other circumstances, we don't add to  
 this stack. */  
652    
653  if ((flags & match_isgroup) != 0)  if ((flags & match_cbegroup) != 0)
654    {    {
   newptrb.epb_prev = eptrb;  
655    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
656      newptrb.epb_prev = eptrb;
657    eptrb = &newptrb;    eptrb = &newptrb;
658    }    }
659    
660  /* Now start processing the operations. */  /* Now start processing the opcodes. */
661    
662  for (;;)  for (;;)
663    {    {
664      minimize = possessive = FALSE;
665    op = *ecode;    op = *ecode;
   minimize = FALSE;  
   
   /* For partial matching, remember if we ever hit the end of the subject after  
   matching at least one subject character. */  
666    
667    if (md->partial &&    switch(op)
       eptr >= md->end_subject &&  
       eptr > md->start_match)  
     md->hitend = TRUE;  
   
   /* Opening capturing bracket. If there is space in the offset vector, save  
   the current subject position in the working slot at the top of the vector. We  
   mustn't change the current values of the data slot, because they may be set  
   from a previous iteration of this group, and be referred to by a reference  
   inside the group.  
   
   If the bracket fails to match, we need to restore this value and also the  
   values of the final offsets, in case they were set by a previous iteration of  
   the same bracket.  
   
   If there isn't enough space in the offset vector, treat this as if it were a  
   non-capturing bracket. Don't worry about setting the flag for the error case  
   here; that is handled in the code for KET. */  
   
   if (op > OP_BRA)  
668      {      {
669      number = op - OP_BRA;      case OP_FAIL:
670        RRETURN(MATCH_NOMATCH);
671    
672      /* For extended extraction brackets (large number), we have to fish out the      case OP_PRUNE:
673      number from a dummy opcode at the start. */      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
674          ims, eptrb, flags, RM51);
675      if (number > EXTRACT_BASIC_MAX)      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
676        number = GET2(ecode, 2+LINK_SIZE);      RRETURN(MATCH_PRUNE);
677    
678        case OP_COMMIT:
679        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
680          ims, eptrb, flags, RM52);
681        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
682        RRETURN(MATCH_COMMIT);
683    
684        case OP_SKIP:
685        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
686          ims, eptrb, flags, RM53);
687        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
688        md->start_match_ptr = eptr;   /* Pass back current position */
689        RRETURN(MATCH_SKIP);
690    
691        case OP_THEN:
692        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
693          ims, eptrb, flags, RM54);
694        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
695        RRETURN(MATCH_THEN);
696    
697        /* Handle a capturing bracket. If there is space in the offset vector, save
698        the current subject position in the working slot at the top of the vector.
699        We mustn't change the current values of the data slot, because they may be
700        set from a previous iteration of this group, and be referred to by a
701        reference inside the group.
702    
703        If the bracket fails to match, we need to restore this value and also the
704        values of the final offsets, in case they were set by a previous iteration
705        of the same bracket.
706    
707        If there isn't enough space in the offset vector, treat this as if it were
708        a non-capturing bracket. Don't worry about setting the flag for the error
709        case here; that is handled in the code for KET. */
710    
711        case OP_CBRA:
712        case OP_SCBRA:
713        number = GET2(ecode, 1+LINK_SIZE);
714      offset = number << 1;      offset = number << 1;
715    
716  #ifdef DEBUG  #ifdef DEBUG
717      printf("start bracket %d subject=", number);      printf("start bracket %d\n", number);
718        printf("subject=");
719      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
720      printf("\n");      printf("\n");
721  #endif  #endif
# Line 624  for (;;) Line 730  for (;;)
730        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
731        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
732    
733          flags = (op == OP_SCBRA)? match_cbegroup : 0;
734        do        do
735          {          {
736          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
737            match_isgroup);            ims, eptrb, flags, RM1);
738          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
739          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
740          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
741          }          }
# Line 643  for (;;) Line 750  for (;;)
750        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
751        }        }
752    
753      /* Insufficient room for saving captured contents */      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
754        as a non-capturing bracket. */
     else op = OP_BRA;  
     }  
   
   /* Other types of node can be handled by a switch */  
755    
756    switch(op)      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
757      {      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
     case OP_BRA:     /* Non-capturing bracket: optimized */  
     DPRINTF(("start bracket 0\n"));  
758    
759      /* Loop for all the alternatives */      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
760    
761        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
762        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
763    
764        /* Non-capturing bracket. Loop for all the alternatives. When we get to the
765        final alternative within the brackets, we would return the result of a
766        recursive call to match() whatever happened. We can reduce stack usage by
767        turning this into a tail recursion, except in the case when match_cbegroup
768        is set.*/
769    
770        case OP_BRA:
771        case OP_SBRA:
772        DPRINTF(("start non-capturing bracket\n"));
773        flags = (op >= OP_SBRA)? match_cbegroup : 0;
774      for (;;)      for (;;)
775        {        {
776        /* When we get to the final alternative within the brackets, we would        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
777        return the result of a recursive call to match() whatever happened. We          {
778        can reduce stack usage by turning this into a tail recursion. */          if (flags == 0)    /* Not a possibly empty group */
779              {
780        if (ecode[GET(ecode, 1)] != OP_ALT)            ecode += _pcre_OP_lengths[*ecode];
781         {            DPRINTF(("bracket 0 tail recursion\n"));
782         ecode += 1 + LINK_SIZE;            goto TAIL_RECURSE;
783         flags = match_isgroup;            }
784         DPRINTF(("bracket 0 tail recursion\n"));  
785         goto TAIL_RECURSE;          /* Possibly empty group; can't use tail recursion. */
786         }  
787            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
788              eptrb, flags, RM48);
789            RRETURN(rrc);
790            }
791    
792        /* For non-final alternatives, continue the loop for a NOMATCH result;        /* For non-final alternatives, continue the loop for a NOMATCH result;
793        otherwise return. */        otherwise return. */
794    
795        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
796          match_isgroup);          eptrb, flags, RM2);
797        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
798        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
799        }        }
800      /* Control never reaches here. */      /* Control never reaches here. */
# Line 688  for (;;) Line 806  for (;;)
806      obeyed, we can use tail recursion to avoid using another stack frame. */      obeyed, we can use tail recursion to avoid using another stack frame. */
807    
808      case OP_COND:      case OP_COND:
809      if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */      case OP_SCOND:
810        codelink= GET(ecode, 1);
811    
812        /* Because of the way auto-callout works during compile, a callout item is
813        inserted between OP_COND and an assertion condition. */
814    
815        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
816          {
817          if (pcre_callout != NULL)
818            {
819            pcre_callout_block cb;
820            cb.version          = 1;   /* Version 1 of the callout block */
821            cb.callout_number   = ecode[LINK_SIZE+2];
822            cb.offset_vector    = md->offset_vector;
823            cb.subject          = (PCRE_SPTR)md->start_subject;
824            cb.subject_length   = md->end_subject - md->start_subject;
825            cb.start_match      = mstart - md->start_subject;
826            cb.current_position = eptr - md->start_subject;
827            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
828            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
829            cb.capture_top      = offset_top/2;
830            cb.capture_last     = md->capture_last;
831            cb.callout_data     = md->callout_data;
832            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
833            if (rrc < 0) RRETURN(rrc);
834            }
835          ecode += _pcre_OP_lengths[OP_CALLOUT];
836          }
837    
838        condcode = ecode[LINK_SIZE+1];
839    
840        /* Now see what the actual condition is */
841    
842        if (condcode == OP_RREF || condcode == OP_NRREF)    /* Recursion test */
843          {
844          if (md->recursive == NULL)                /* Not recursing => FALSE */
845            {
846            condition = FALSE;
847            ecode += GET(ecode, 1);
848            }
849          else
850            {
851            int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
852            condition =  (recno == RREF_ANY || recno == md->recursive->group_num);
853    
854            /* If the test is for recursion into a specific subpattern, and it is
855            false, but the test was set up by name, scan the table to see if the
856            name refers to any other numbers, and test them. The condition is true
857            if any one is set. */
858    
859            if (!condition && condcode == OP_NRREF && recno != RREF_ANY)
860              {
861              uschar *slotA = md->name_table;
862              for (i = 0; i < md->name_count; i++)
863                {
864                if (GET2(slotA, 0) == recno) break;
865                slotA += md->name_entry_size;
866                }
867    
868              /* Found a name for the number - there can be only one; duplicate
869              names for different numbers are allowed, but not vice versa. First
870              scan down for duplicates. */
871    
872              if (i < md->name_count)
873                {
874                uschar *slotB = slotA;
875                while (slotB > md->name_table)
876                  {
877                  slotB -= md->name_entry_size;
878                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
879                    {
880                    condition = GET2(slotB, 0) == md->recursive->group_num;
881                    if (condition) break;
882                    }
883                  else break;
884                  }
885    
886                /* Scan up for duplicates */
887    
888                if (!condition)
889                  {
890                  slotB = slotA;
891                  for (i++; i < md->name_count; i++)
892                    {
893                    slotB += md->name_entry_size;
894                    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
895                      {
896                      condition = GET2(slotB, 0) == md->recursive->group_num;
897                      if (condition) break;
898                      }
899                    else break;
900                    }
901                  }
902                }
903              }
904    
905            /* Chose branch according to the condition */
906    
907            ecode += condition? 3 : GET(ecode, 1);
908            }
909          }
910    
911        else if (condcode == OP_CREF || condcode == OP_NCREF)  /* Group used test */
912        {        {
913        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
914        condition = (offset == CREF_RECURSE * 2)?        condition = offset < offset_top && md->offset_vector[offset] >= 0;
915          (md->recursive != NULL) :  
916          (offset < offset_top && md->offset_vector[offset] >= 0);        /* If the numbered capture is unset, but the reference was by name,
917        ecode += condition? (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1));        scan the table to see if the name refers to any other numbers, and test
918        flags = match_isgroup;        them. The condition is true if any one is set. This is tediously similar
919        goto TAIL_RECURSE;        to the code above, but not close enough to try to amalgamate. */
920    
921          if (!condition && condcode == OP_NCREF)
922            {
923            int refno = offset >> 1;
924            uschar *slotA = md->name_table;
925    
926            for (i = 0; i < md->name_count; i++)
927              {
928              if (GET2(slotA, 0) == refno) break;
929              slotA += md->name_entry_size;
930              }
931    
932            /* Found a name for the number - there can be only one; duplicate names
933            for different numbers are allowed, but not vice versa. First scan down
934            for duplicates. */
935    
936            if (i < md->name_count)
937              {
938              uschar *slotB = slotA;
939              while (slotB > md->name_table)
940                {
941                slotB -= md->name_entry_size;
942                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
943                  {
944                  offset = GET2(slotB, 0) << 1;
945                  condition = offset < offset_top &&
946                    md->offset_vector[offset] >= 0;
947                  if (condition) break;
948                  }
949                else break;
950                }
951    
952              /* Scan up for duplicates */
953    
954              if (!condition)
955                {
956                slotB = slotA;
957                for (i++; i < md->name_count; i++)
958                  {
959                  slotB += md->name_entry_size;
960                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
961                    {
962                    offset = GET2(slotB, 0) << 1;
963                    condition = offset < offset_top &&
964                      md->offset_vector[offset] >= 0;
965                    if (condition) break;
966                    }
967                  else break;
968                  }
969                }
970              }
971            }
972    
973          /* Chose branch according to the condition */
974    
975          ecode += condition? 3 : GET(ecode, 1);
976          }
977    
978        else if (condcode == OP_DEF)     /* DEFINE - always false */
979          {
980          condition = FALSE;
981          ecode += GET(ecode, 1);
982        }        }
983    
984      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
985      the final argument TRUE causes it to stop at the end of an assertion. */      the final argument match_condassert causes it to stop at the end of an
986        assertion. */
987    
988      else      else
989        {        {
990        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
991            match_condassert | match_isgroup);            match_condassert, RM3);
992        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
993          {          {
994          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);          condition = TRUE;
995            ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
996          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
997          }          }
998        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
999          {          {
1000          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1001          }          }
1002        else ecode += GET(ecode, 1);        else
1003            {
1004            condition = FALSE;
1005            ecode += codelink;
1006            }
1007          }
1008    
1009        /* We are now at the branch that is to be obeyed. As there is only one,      /* We are now at the branch that is to be obeyed. As there is only one,
1010        we can use tail recursion to avoid using another stack frame. */      we can use tail recursion to avoid using another stack frame, except when
1011        match_cbegroup is required for an unlimited repeat of a possibly empty
1012        group. If the second alternative doesn't exist, we can just plough on. */
1013    
1014        if (condition || *ecode == OP_ALT)
1015          {
1016        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1017        flags = match_isgroup;        if (op == OP_SCOND)        /* Possibly empty group */
1018        goto TAIL_RECURSE;          {
1019            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
1020            RRETURN(rrc);
1021            }
1022          else                       /* Group must match something */
1023            {
1024            flags = 0;
1025            goto TAIL_RECURSE;
1026            }
1027        }        }
1028      /* Control never reaches here */      else                         /* Condition false & no alternative */
1029          {
1030          ecode += 1 + LINK_SIZE;
1031          }
1032        break;
1033    
1034    
1035      /* Skip over conditional reference or large extraction number data if      /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes,
1036      encountered. */      to close any currently open capturing brackets. */
1037    
1038        case OP_CLOSE:
1039        number = GET2(ecode, 1);
1040        offset = number << 1;
1041    
1042    #ifdef DEBUG
1043          printf("end bracket %d at *ACCEPT", number);
1044          printf("\n");
1045    #endif
1046    
1047      case OP_CREF:      md->capture_last = number;
1048      case OP_BRANUMBER:      if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1049          {
1050          md->offset_vector[offset] =
1051            md->offset_vector[md->offset_end - number];
1052          md->offset_vector[offset+1] = eptr - md->start_subject;
1053          if (offset_top <= offset) offset_top = offset + 2;
1054          }
1055      ecode += 3;      ecode += 3;
1056      break;      break;
1057    
1058    
1059      /* End of the pattern. If we are in a recursion, we should restore the      /* End of the pattern, either real or forced. If we are in a top-level
1060      offsets appropriately and continue from after the call. */      recursion, we should restore the offsets appropriately and continue from
1061        after the call. */
1062    
1063        case OP_ACCEPT:
1064      case OP_END:      case OP_END:
1065      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
1066        {        {
# Line 745  for (;;) Line 1069  for (;;)
1069        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1070        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1071          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1072        md->start_match = rec->save_start;        offset_top = rec->offset_top;
1073          mstart = rec->save_start;
1074        ims = original_ims;        ims = original_ims;
1075        ecode = rec->after_call;        ecode = rec->after_call;
1076        break;        break;
1077        }        }
1078    
1079      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is
1080      string - backtracking will then try other alternatives, if any. */      set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of
1081        the subject. In both cases, backtracking will then try other alternatives,
1082        if any. */
1083    
1084        if (eptr == mstart &&
1085            (md->notempty ||
1086              (md->notempty_atstart &&
1087                mstart == md->start_subject + md->start_offset)))
1088          RRETURN(MATCH_NOMATCH);
1089    
1090        /* Otherwise, we have a match. */
1091    
1092      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      md->end_match_ptr = eptr;           /* Record where we ended */
1093      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
1094      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
1095      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
1096    
1097      /* Change option settings */      /* Change option settings */
# Line 777  for (;;) Line 1112  for (;;)
1112      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1113      do      do
1114        {        {
1115        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1116          match_isgroup);          RM4);
1117        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
1118        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1119        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1120        }        }
1121      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 804  for (;;) Line 1139  for (;;)
1139      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1140      do      do
1141        {        {
1142        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1143          match_isgroup);          RM5);
1144        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
1145        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1146        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1147        }        }
1148      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 826  for (;;) Line 1161  for (;;)
1161  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1162      if (utf8)      if (utf8)
1163        {        {
1164        c = GET(ecode,1);        i = GET(ecode, 1);
1165        for (i = 0; i < c; i++)        while (i-- > 0)
1166          {          {
1167          eptr--;          eptr--;
1168          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1169          BACKCHAR(eptr)          BACKCHAR(eptr);
1170          }          }
1171        }        }
1172      else      else
# Line 840  for (;;) Line 1175  for (;;)
1175      /* No UTF-8 support, or not in UTF-8 mode: count is byte count */      /* No UTF-8 support, or not in UTF-8 mode: count is byte count */
1176    
1177        {        {
1178        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
1179        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1180        }        }
1181    
1182      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1183    
1184        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1185      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1186      break;      break;
1187    
# Line 862  for (;;) Line 1198  for (;;)
1198        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1199        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1200        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1201        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1202        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1203        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1204        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 897  for (;;) Line 1233  for (;;)
1233      case OP_RECURSE:      case OP_RECURSE:
1234        {        {
1235        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1236        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1237            GET2(callpat, 1 + LINK_SIZE);
       /* For extended extraction brackets (large number), we have to fish out  
       the number from a dummy opcode at the start. */  
   
       if (new_recursive.group_num > EXTRACT_BASIC_MAX)  
         new_recursive.group_num = GET2(callpat, 2+LINK_SIZE);  
1238    
1239        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1240    
# Line 929  for (;;) Line 1260  for (;;)
1260    
1261        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1262              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1263        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1264        md->start_match = eptr;        new_recursive.offset_top = offset_top;
1265          mstart = eptr;
1266    
1267        /* OK, now we can do the recursion. For each top-level alternative we        /* OK, now we can do the recursion. For each top-level alternative we
1268        restore the offset and recursion data. */        restore the offset and recursion data. */
1269    
1270        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1271          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1272        do        do
1273          {          {
1274          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1275              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1276          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1277            {            {
1278            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 948  for (;;) Line 1281  for (;;)
1281              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1282            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1283            }            }
1284          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1285            {            {
1286            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1287              if (new_recursive.offset_save != stacksave)
1288                (pcre_free)(new_recursive.offset_save);
1289            RRETURN(rrc);            RRETURN(rrc);
1290            }            }
1291    
# Line 982  for (;;) Line 1317  for (;;)
1317    
1318      do      do
1319        {        {
1320        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
         eptrb, match_isgroup);  
1321        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
1322        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1323        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1324        }        }
1325      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 997  for (;;) Line 1331  for (;;)
1331      /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1332      mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1333    
1334      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1335    
1336      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1337      eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
# Line 1028  for (;;) Line 1362  for (;;)
1362    
1363      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1364        {        {
1365        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
1366        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1367        ecode = prev;        ecode = prev;
1368        flags = match_isgroup;        flags = 0;
1369        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1370        }        }
1371      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1372        {        {
1373        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1374        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1375        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1376        flags = 0;        flags = 0;
# Line 1051  for (;;) Line 1385  for (;;)
1385      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1386      break;      break;
1387    
1388      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1389      that it may occur zero times. It may repeat infinitely, or not at all -      indicating that it may occur zero times. It may repeat infinitely, or not
1390      i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1391      repeat limits are compiled as a number of copies, with the optional ones      with fixed upper repeat limits are compiled as a number of copies, with the
1392      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1393    
1394      case OP_BRAZERO:      case OP_BRAZERO:
1395        {        {
1396        next = ecode+1;        next = ecode+1;
1397        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1398        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1399        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1400        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1401        }        }
1402      break;      break;
1403    
1404      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1405        {        {
1406        next = ecode+1;        next = ecode+1;
1407        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1408        RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb,        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
         match_isgroup);  
1409        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1410        ecode++;        ecode++;
1411        }        }
1412      break;      break;
1413    
1414      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1415      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1416      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1417      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1418          ecode = next + 1 + LINK_SIZE;
1419          }
1420        break;
1421    
1422        /* End of a group, repeated or non-repeating. */
1423    
1424      case OP_KET:      case OP_KET:
1425      case OP_KETRMIN:      case OP_KETRMIN:
1426      case OP_KETRMAX:      case OP_KETRMAX:
1427      prev = ecode - GET(ecode, 1);      prev = ecode - GET(ecode, 1);
     saved_eptr = eptrb->epb_saved_eptr;  
1428    
1429      /* Back up the stack of bracket start pointers. */      /* If this was a group that remembered the subject start, in order to break
1430        infinite repeats of empty string matches, retrieve the subject start from
1431        the chain. Otherwise, set it NULL. */
1432    
1433      eptrb = eptrb->epb_prev;      if (*prev >= OP_SBRA)
1434          {
1435          saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1436          eptrb = eptrb->epb_prev;              /* Backup to previous group */
1437          }
1438        else saved_eptr = NULL;
1439    
1440        /* If we are at the end of an assertion group, stop matching and return
1441        MATCH_MATCH, but record the current high water mark for use by positive
1442        assertions. Do this also for the "once" (atomic) groups. */
1443    
1444      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1445          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
# Line 1102  for (;;) Line 1450  for (;;)
1450        RRETURN(MATCH_MATCH);        RRETURN(MATCH_MATCH);
1451        }        }
1452    
1453      /* In all other cases except a conditional group we have to check the      /* For capturing groups we have to check the group number back at the start
1454      group number back at the start and if necessary complete handling an      and if necessary complete handling an extraction by setting the offsets and
1455      extraction by setting the offsets and bumping the high water mark. */      bumping the high water mark. Note that whole-pattern recursion is coded as
1456        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1457        when the OP_END is reached. Other recursion is handled here. */
1458    
1459      if (*prev != OP_COND)      if (*prev == OP_CBRA || *prev == OP_SCBRA)
1460        {        {
1461        number = *prev - OP_BRA;        number = GET2(prev, 1+LINK_SIZE);
   
       /* For extended extraction brackets (large number), we have to fish out  
       the number from a dummy opcode at the start. */  
   
       if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);  
1462        offset = number << 1;        offset = number << 1;
1463    
1464  #ifdef DEBUG  #ifdef DEBUG
1465        printf("end bracket %d", number);        printf("end bracket %d", number);
1466        printf("\n");        printf("\n");
1467  #endif  #endif
1468    
1469        /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1470        of recursion. Note that whole-pattern recursion is coded as a recurse        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
       into group 0, so it won't be picked up here. Instead, we catch it when  
       the OP_END is reached. */  
   
       if (number > 0)  
1471          {          {
1472          md->capture_last = number;          md->offset_vector[offset] =
1473          if (offset >= md->offset_max) md->offset_overflow = TRUE; else            md->offset_vector[md->offset_end - number];
1474            {          md->offset_vector[offset+1] = eptr - md->start_subject;
1475            md->offset_vector[offset] =          if (offset_top <= offset) offset_top = offset + 2;
1476              md->offset_vector[md->offset_end - number];          }
1477            md->offset_vector[offset+1] = eptr - md->start_subject;  
1478            if (offset_top <= offset) offset_top = offset + 2;        /* Handle a recursively called group. Restore the offsets
1479            }        appropriately and continue from after the call. */
1480    
1481          /* Handle a recursively called group. Restore the offsets        if (md->recursive != NULL && md->recursive->group_num == number)
1482          appropriately and continue from after the call. */          {
1483            recursion_info *rec = md->recursive;
1484          if (md->recursive != NULL && md->recursive->group_num == number)          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1485            {          md->recursive = rec->prevrec;
1486            recursion_info *rec = md->recursive;          mstart = rec->save_start;
1487            DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          memcpy(md->offset_vector, rec->offset_save,
1488            md->recursive = rec->prevrec;            rec->saved_max * sizeof(int));
1489            md->start_match = rec->save_start;          offset_top = rec->offset_top;
1490            memcpy(md->offset_vector, rec->offset_save,          ecode = rec->after_call;
1491              rec->saved_max * sizeof(int));          ims = original_ims;
1492            ecode = rec->after_call;          break;
           ims = original_ims;  
           break;  
           }  
1493          }          }
1494        }        }
1495    
1496      /* Reset the value of the ims flags, in case they got changed during      /* For both capturing and non-capturing groups, reset the value of the ims
1497      the group. */      flags, in case they got changed during the group. */
1498    
1499      ims = original_ims;      ims = original_ims;
1500      DPRINTF(("ims reset to %02lx\n", ims));      DPRINTF(("ims reset to %02lx\n", ims));
# Line 1175  for (;;) Line 1513  for (;;)
1513    
1514      /* The repeating kets try the rest of the pattern or restart from the      /* The repeating kets try the rest of the pattern or restart from the
1515      preceding bracket, in the appropriate order. In the second case, we can use      preceding bracket, in the appropriate order. In the second case, we can use
1516      tail recursion to avoid using another stack frame. */      tail recursion to avoid using another stack frame, unless we have an
1517        unlimited repeat of a group that can match an empty string. */
1518    
1519        flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1520    
1521      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1522        {        {
1523        RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1524        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1525          if (flags != 0)    /* Could match an empty string */
1526            {
1527            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1528            RRETURN(rrc);
1529            }
1530        ecode = prev;        ecode = prev;
       flags = match_isgroup;  
1531        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1532        }        }
1533      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1534        {        {
1535        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1536        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1537        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1538        flags = 0;        flags = 0;
# Line 1202  for (;;) Line 1547  for (;;)
1547      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1548        {        {
1549        if (eptr != md->start_subject &&        if (eptr != md->start_subject &&
1550            (eptr == md->end_subject ||            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
            eptr < md->start_subject + md->nllen ||  
            !IS_NEWLINE(eptr - md->nllen)))  
1551          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
1552        ecode++;        ecode++;
1553        break;        break;
# Line 1225  for (;;) Line 1568  for (;;)
1568      ecode++;      ecode++;
1569      break;      break;
1570    
1571        /* Reset the start of match point */
1572    
1573        case OP_SET_SOM:
1574        mstart = eptr;
1575        ecode++;
1576        break;
1577    
1578      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1579      newline unless endonly is set, else end of subject unless noteol is set. */      newline unless endonly is set, else end of subject unless noteol is set. */
1580    
# Line 1244  for (;;) Line 1594  for (;;)
1594        if (!md->endonly)        if (!md->endonly)
1595          {          {
1596          if (eptr != md->end_subject &&          if (eptr != md->end_subject &&
1597              (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr)))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1598            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1599          ecode++;          ecode++;
1600          break;          break;
# Line 1263  for (;;) Line 1613  for (;;)
1613    
1614      case OP_EODN:      case OP_EODN:
1615      if (eptr != md->end_subject &&      if (eptr != md->end_subject &&
1616          (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr)))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1617        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
1618      ecode++;      ecode++;
1619      break;      break;
# Line 1276  for (;;) Line 1626  for (;;)
1626    
1627        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1628        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
1629        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1630          partial matching. */
1631    
1632  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1633        if (utf8)        if (utf8)
1634          {          {
1635          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1636            {            {
1637            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1638            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1639              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1640            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1641            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1642            }            }
1643          if (eptr >= md->end_subject) cur_is_word = FALSE; else          if (eptr >= md->end_subject)
1644              {
1645              SCHECK_PARTIAL();
1646              cur_is_word = FALSE;
1647              }
1648            else
1649            {            {
1650            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1651            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
# Line 1297  for (;;) Line 1654  for (;;)
1654        else        else
1655  #endif  #endif
1656    
1657        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode */
1658    
1659          {          {
1660          prev_is_word = (eptr != md->start_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1661            ((md->ctypes[eptr[-1]] & ctype_word) != 0);            {
1662          cur_is_word = (eptr < md->end_subject) &&            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1663            ((md->ctypes[*eptr] & ctype_word) != 0);            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1664              }
1665            if (eptr >= md->end_subject)
1666              {
1667              SCHECK_PARTIAL();
1668              cur_is_word = FALSE;
1669              }
1670            else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1671          }          }
1672    
1673        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1317  for (;;) Line 1681  for (;;)
1681      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1682    
1683      case OP_ANY:      case OP_ANY:
1684      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1685        /* Fall through */
1686    
1687        case OP_ALLANY:
1688        if (eptr++ >= md->end_subject)
1689        {        {
1690        if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))        SCHECK_PARTIAL();
1691          RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
1692        }        }
1693      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
     if (utf8)  
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1694      ecode++;      ecode++;
1695      break;      break;
1696    
# Line 1332  for (;;) Line 1698  for (;;)
1698      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1699    
1700      case OP_ANYBYTE:      case OP_ANYBYTE:
1701      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1702          {
1703          SCHECK_PARTIAL();
1704          RRETURN(MATCH_NOMATCH);
1705          }
1706      ecode++;      ecode++;
1707      break;      break;
1708    
1709      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1710      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1711          {
1712          SCHECK_PARTIAL();
1713          RRETURN(MATCH_NOMATCH);
1714          }
1715      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1716      if (      if (
1717  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1350  for (;;) Line 1724  for (;;)
1724      break;      break;
1725    
1726      case OP_DIGIT:      case OP_DIGIT:
1727      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1728          {
1729          SCHECK_PARTIAL();
1730          RRETURN(MATCH_NOMATCH);
1731          }
1732      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1733      if (      if (
1734  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1363  for (;;) Line 1741  for (;;)
1741      break;      break;
1742    
1743      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1744      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1745          {
1746          SCHECK_PARTIAL();
1747          RRETURN(MATCH_NOMATCH);
1748          }
1749      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1750      if (      if (
1751  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1376  for (;;) Line 1758  for (;;)
1758      break;      break;
1759    
1760      case OP_WHITESPACE:      case OP_WHITESPACE:
1761      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1762          {
1763          SCHECK_PARTIAL();
1764          RRETURN(MATCH_NOMATCH);
1765          }
1766      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1767      if (      if (
1768  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1389  for (;;) Line 1775  for (;;)
1775      break;      break;
1776    
1777      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1778      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1779          {
1780          SCHECK_PARTIAL();
1781          RRETURN(MATCH_NOMATCH);
1782          }
1783      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1784      if (      if (
1785  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1402  for (;;) Line 1792  for (;;)
1792      break;      break;
1793    
1794      case OP_WORDCHAR:      case OP_WORDCHAR:
1795      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1796          {
1797          SCHECK_PARTIAL();
1798          RRETURN(MATCH_NOMATCH);
1799          }
1800      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1801      if (      if (
1802  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1414  for (;;) Line 1808  for (;;)
1808      ecode++;      ecode++;
1809      break;      break;
1810    
1811        case OP_ANYNL:
1812        if (eptr >= md->end_subject)
1813          {
1814          SCHECK_PARTIAL();
1815          RRETURN(MATCH_NOMATCH);
1816          }
1817        GETCHARINCTEST(c, eptr);
1818        switch(c)
1819          {
1820          default: RRETURN(MATCH_NOMATCH);
1821          case 0x000d:
1822          if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1823          break;
1824    
1825          case 0x000a:
1826          break;
1827    
1828          case 0x000b:
1829          case 0x000c:
1830          case 0x0085:
1831          case 0x2028:
1832          case 0x2029:
1833          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1834          break;
1835          }
1836        ecode++;
1837        break;
1838    
1839        case OP_NOT_HSPACE:
1840        if (eptr >= md->end_subject)
1841          {
1842          SCHECK_PARTIAL();
1843          RRETURN(MATCH_NOMATCH);
1844          }
1845        GETCHARINCTEST(c, eptr);
1846        switch(c)
1847          {
1848          default: break;
1849          case 0x09:      /* HT */
1850          case 0x20:      /* SPACE */
1851          case 0xa0:      /* NBSP */
1852          case 0x1680:    /* OGHAM SPACE MARK */
1853          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1854          case 0x2000:    /* EN QUAD */
1855          case 0x2001:    /* EM QUAD */
1856          case 0x2002:    /* EN SPACE */
1857          case 0x2003:    /* EM SPACE */
1858          case 0x2004:    /* THREE-PER-EM SPACE */
1859          case 0x2005:    /* FOUR-PER-EM SPACE */
1860          case 0x2006:    /* SIX-PER-EM SPACE */
1861          case 0x2007:    /* FIGURE SPACE */
1862          case 0x2008:    /* PUNCTUATION SPACE */
1863          case 0x2009:    /* THIN SPACE */
1864          case 0x200A:    /* HAIR SPACE */
1865          case 0x202f:    /* NARROW NO-BREAK SPACE */
1866          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1867          case 0x3000:    /* IDEOGRAPHIC SPACE */
1868          RRETURN(MATCH_NOMATCH);
1869          }
1870        ecode++;
1871        break;
1872    
1873        case OP_HSPACE:
1874        if (eptr >= md->end_subject)
1875          {
1876          SCHECK_PARTIAL();
1877          RRETURN(MATCH_NOMATCH);
1878          }
1879        GETCHARINCTEST(c, eptr);
1880        switch(c)
1881          {
1882          default: RRETURN(MATCH_NOMATCH);
1883          case 0x09:      /* HT */
1884          case 0x20:      /* SPACE */
1885          case 0xa0:      /* NBSP */
1886          case 0x1680:    /* OGHAM SPACE MARK */
1887          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1888          case 0x2000:    /* EN QUAD */
1889          case 0x2001:    /* EM QUAD */
1890          case 0x2002:    /* EN SPACE */
1891          case 0x2003:    /* EM SPACE */
1892          case 0x2004:    /* THREE-PER-EM SPACE */
1893          case 0x2005:    /* FOUR-PER-EM SPACE */
1894          case 0x2006:    /* SIX-PER-EM SPACE */
1895          case 0x2007:    /* FIGURE SPACE */
1896          case 0x2008:    /* PUNCTUATION SPACE */
1897          case 0x2009:    /* THIN SPACE */
1898          case 0x200A:    /* HAIR SPACE */
1899          case 0x202f:    /* NARROW NO-BREAK SPACE */
1900          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1901          case 0x3000:    /* IDEOGRAPHIC SPACE */
1902          break;
1903          }
1904        ecode++;
1905        break;
1906    
1907        case OP_NOT_VSPACE:
1908        if (eptr >= md->end_subject)
1909          {
1910          SCHECK_PARTIAL();
1911          RRETURN(MATCH_NOMATCH);
1912          }
1913        GETCHARINCTEST(c, eptr);
1914        switch(c)
1915          {
1916          default: break;
1917          case 0x0a:      /* LF */
1918          case 0x0b:      /* VT */
1919          case 0x0c:      /* FF */
1920          case 0x0d:      /* CR */
1921          case 0x85:      /* NEL */
1922          case 0x2028:    /* LINE SEPARATOR */
1923          case 0x2029:    /* PARAGRAPH SEPARATOR */
1924          RRETURN(MATCH_NOMATCH);
1925          }
1926        ecode++;
1927        break;
1928    
1929        case OP_VSPACE:
1930        if (eptr >= md->end_subject)
1931          {
1932          SCHECK_PARTIAL();
1933          RRETURN(MATCH_NOMATCH);
1934          }
1935        GETCHARINCTEST(c, eptr);
1936        switch(c)
1937          {
1938          default: RRETURN(MATCH_NOMATCH);
1939          case 0x0a:      /* LF */
1940          case 0x0b:      /* VT */
1941          case 0x0c:      /* FF */
1942          case 0x0d:      /* CR */
1943          case 0x85:      /* NEL */
1944          case 0x2028:    /* LINE SEPARATOR */
1945          case 0x2029:    /* PARAGRAPH SEPARATOR */
1946          break;
1947          }
1948        ecode++;
1949        break;
1950    
1951  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1952      /* Check the next character by Unicode property. We will get here only      /* Check the next character by Unicode property. We will get here only
1953      if the support is in the binary; otherwise a compile-time error occurs. */      if the support is in the binary; otherwise a compile-time error occurs. */
1954    
1955      case OP_PROP:      case OP_PROP:
1956      case OP_NOTPROP:      case OP_NOTPROP:
1957      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1958          {
1959          SCHECK_PARTIAL();
1960          RRETURN(MATCH_NOMATCH);
1961          }
1962      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1963        {        {
1964        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1965    
1966        switch(ecode[1])        switch(ecode[1])
1967          {          {
# Line 1433  for (;;) Line 1970  for (;;)
1970          break;          break;
1971    
1972          case PT_LAMP:          case PT_LAMP:
1973          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1974               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1975               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1976            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1977           break;           break;
1978    
1979          case PT_GC:          case PT_GC:
1980          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1981            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1982          break;          break;
1983    
1984          case PT_PC:          case PT_PC:
1985          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1986            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1987          break;          break;
1988    
1989          case PT_SC:          case PT_SC:
1990          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1991            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1992          break;          break;
1993    
1994          default:          default:
1995          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
         break;  
1996          }          }
1997    
1998        ecode += 3;        ecode += 3;
# Line 1467  for (;;) Line 2003  for (;;)
2003      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
2004    
2005      case OP_EXTUNI:      case OP_EXTUNI:
2006      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2007          {
2008          SCHECK_PARTIAL();
2009          RRETURN(MATCH_NOMATCH);
2010          }
2011      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2012        {        {
2013        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
2014        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
2015        while (eptr < md->end_subject)        while (eptr < md->end_subject)
2016          {          {
# Line 1480  for (;;) Line 2019  for (;;)
2019            {            {
2020            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
2021            }            }
2022          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
2023          if (category != ucp_M) break;          if (category != ucp_M) break;
2024          eptr += len;          eptr += len;
2025          }          }
# Line 1501  for (;;) Line 2040  for (;;)
2040      case OP_REF:      case OP_REF:
2041        {        {
2042        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2043        ecode += 3;                                 /* Advance past item */        ecode += 3;
2044    
2045          /* If the reference is unset, there are two possibilities:
2046    
2047          (a) In the default, Perl-compatible state, set the length to be longer
2048          than the amount of subject left; this ensures that every attempt at a
2049          match fails. We can't just fail here, because of the possibility of
2050          quantifiers with zero minima.
2051    
2052          (b) If the JavaScript compatibility flag is set, set the length to zero
2053          so that the back reference matches an empty string.
2054    
2055        /* If the reference is unset, set the length to be longer than the amount        Otherwise, set the length to the length of what was matched by the
2056        of subject left; this ensures that every attempt at a match fails. We        referenced subpattern. */
2057        can't just fail here, because of the possibility of quantifiers with zero  
2058        minima. */        if (offset >= offset_top || md->offset_vector[offset] < 0)
2059            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
2060        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        else
2061          md->end_subject - eptr + 1 :          length = md->offset_vector[offset+1] - md->offset_vector[offset];
         md->offset_vector[offset+1] - md->offset_vector[offset];  
2062    
2063        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
2064    
# Line 1539  for (;;) Line 2087  for (;;)
2087          break;          break;
2088    
2089          default:               /* No repeat follows */          default:               /* No repeat follows */
2090          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2091              {
2092              CHECK_PARTIAL();
2093              RRETURN(MATCH_NOMATCH);
2094              }
2095          eptr += length;          eptr += length;
2096          continue;              /* With the main loop */          continue;              /* With the main loop */
2097          }          }
# Line 1555  for (;;) Line 2107  for (;;)
2107    
2108        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2109          {          {
2110          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2111              {
2112              CHECK_PARTIAL();
2113              RRETURN(MATCH_NOMATCH);
2114              }
2115          eptr += length;          eptr += length;
2116          }          }
2117    
# Line 1570  for (;;) Line 2126  for (;;)
2126          {          {
2127          for (fi = min;; fi++)          for (fi = min;; fi++)
2128            {            {
2129            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2130            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2131            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) RRETURN(MATCH_NOMATCH);
2132              if (!match_ref(offset, eptr, length, md, ims))
2133                {
2134                CHECK_PARTIAL();
2135              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2136                }
2137            eptr += length;            eptr += length;
2138            }            }
2139          /* Control never gets here */          /* Control never gets here */
# Line 1591  for (;;) Line 2151  for (;;)
2151            }            }
2152          while (eptr >= pp)          while (eptr >= pp)
2153            {            {
2154            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
2155            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2156            eptr -= length;            eptr -= length;
2157            }            }
# Line 1600  for (;;) Line 2160  for (;;)
2160        }        }
2161      /* Control never gets here */      /* Control never gets here */
2162    
   
   
2163      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2164      used when all the characters in the class have values in the range 0-255,      used when all the characters in the class have values in the range 0-255,
2165      and either the matching is caseful, or the characters are in the range      and either the matching is caseful, or the characters are in the range
# Line 1656  for (;;) Line 2214  for (;;)
2214          {          {
2215          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2216            {            {
2217            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2218                {
2219                SCHECK_PARTIAL();
2220                RRETURN(MATCH_NOMATCH);
2221                }
2222            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2223            if (c > 255)            if (c > 255)
2224              {              {
# Line 1674  for (;;) Line 2236  for (;;)
2236          {          {
2237          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2238            {            {
2239            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2240                {
2241                SCHECK_PARTIAL();
2242                RRETURN(MATCH_NOMATCH);
2243                }
2244            c = *eptr++;            c = *eptr++;
2245            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2246            }            }
# Line 1696  for (;;) Line 2262  for (;;)
2262            {            {
2263            for (fi = min;; fi++)            for (fi = min;; fi++)
2264              {              {
2265              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2266              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2267              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2268                if (eptr >= md->end_subject)
2269                  {
2270                  SCHECK_PARTIAL();
2271                  RRETURN(MATCH_NOMATCH);
2272                  }
2273              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2274              if (c > 255)              if (c > 255)
2275                {                {
# Line 1716  for (;;) Line 2287  for (;;)
2287            {            {
2288            for (fi = min;; fi++)            for (fi = min;; fi++)
2289              {              {
2290              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2291              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2292              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2293                if (eptr >= md->end_subject)
2294                  {
2295                  SCHECK_PARTIAL();
2296                  RRETURN(MATCH_NOMATCH);
2297                  }
2298              c = *eptr++;              c = *eptr++;
2299              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2300              }              }
# Line 1753  for (;;) Line 2329  for (;;)
2329              }              }
2330            for (;;)            for (;;)
2331              {              {
2332              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2333              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2334              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2335              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1772  for (;;) Line 2348  for (;;)
2348              }              }
2349            while (eptr >= pp)            while (eptr >= pp)
2350              {              {
2351              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2352              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2353              eptr--;              eptr--;
2354              }              }
# Line 1785  for (;;) Line 2361  for (;;)
2361    
2362    
2363      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2364      in UTF-8 mode, because that's the only time it is compiled. */      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2365        mode, because Unicode properties are supported in non-UTF-8 mode. */
2366    
2367  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2368      case OP_XCLASS:      case OP_XCLASS:
# Line 1826  for (;;) Line 2403  for (;;)
2403    
2404        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2405          {          {
2406          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2407          GETCHARINC(c, eptr);            {
2408              SCHECK_PARTIAL();
2409              RRETURN(MATCH_NOMATCH);
2410              }
2411            GETCHARINCTEST(c, eptr);
2412          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2413          }          }
2414    
# Line 1843  for (;;) Line 2424  for (;;)
2424          {          {
2425          for (fi = min;; fi++)          for (fi = min;; fi++)
2426            {            {
2427            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2428            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2429            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
2430            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2431                {
2432                SCHECK_PARTIAL();
2433                RRETURN(MATCH_NOMATCH);
2434                }
2435              GETCHARINCTEST(c, eptr);
2436            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2437            }            }
2438          /* Control never gets here */          /* Control never gets here */
# Line 1861  for (;;) Line 2447  for (;;)
2447            {            {
2448            int len = 1;            int len = 1;
2449            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2450            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2451            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2452            eptr += len;            eptr += len;
2453            }            }
2454          for(;;)          for(;;)
2455            {            {
2456            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2457            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2458            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2459            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2460            }            }
2461          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2462          }          }
# Line 1888  for (;;) Line 2474  for (;;)
2474        length = 1;        length = 1;
2475        ecode++;        ecode++;
2476        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2477        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2478            {
2479            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2480            RRETURN(MATCH_NOMATCH);
2481            }
2482        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2483        }        }
2484      else      else
# Line 1896  for (;;) Line 2486  for (;;)
2486    
2487      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2488        {        {
2489        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2490            {
2491            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2492            RRETURN(MATCH_NOMATCH);
2493            }
2494        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2495        ecode += 2;        ecode += 2;
2496        }        }
# Line 1912  for (;;) Line 2506  for (;;)
2506        ecode++;        ecode++;
2507        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2508    
2509        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2510            {
2511            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2512            RRETURN(MATCH_NOMATCH);
2513            }
2514    
2515        /* If the pattern character's value is < 128, we have only one byte, and        /* If the pattern character's value is < 128, we have only one byte, and
2516        can use the fast lookup table. */        can use the fast lookup table. */
# Line 1926  for (;;) Line 2524  for (;;)
2524    
2525        else        else
2526          {          {
2527          int dc;          unsigned int dc;
2528          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2529          ecode += length;          ecode += length;
2530    
# Line 1936  for (;;) Line 2534  for (;;)
2534          if (fc != dc)          if (fc != dc)
2535            {            {
2536  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2537            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2538  #endif  #endif
2539              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2540            }            }
# Line 1947  for (;;) Line 2545  for (;;)
2545    
2546      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2547        {        {
2548        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2549            {
2550            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2551            RRETURN(MATCH_NOMATCH);
2552            }
2553        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2554        ecode += 2;        ecode += 2;
2555        }        }
2556      break;      break;
2557    
2558      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2559    
2560      case OP_EXACT:      case OP_EXACT:
2561      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2562      ecode += 3;      ecode += 3;
2563      goto REPEATCHAR;      goto REPEATCHAR;
2564    
2565        case OP_POSUPTO:
2566        possessive = TRUE;
2567        /* Fall through */
2568    
2569      case OP_UPTO:      case OP_UPTO:
2570      case OP_MINUPTO:      case OP_MINUPTO:
2571      min = 0;      min = 0;
# Line 1968  for (;;) Line 2574  for (;;)
2574      ecode += 3;      ecode += 3;
2575      goto REPEATCHAR;      goto REPEATCHAR;
2576    
2577        case OP_POSSTAR:
2578        possessive = TRUE;
2579        min = 0;
2580        max = INT_MAX;
2581        ecode++;
2582        goto REPEATCHAR;
2583    
2584        case OP_POSPLUS:
2585        possessive = TRUE;
2586        min = 1;
2587        max = INT_MAX;
2588        ecode++;
2589        goto REPEATCHAR;
2590    
2591        case OP_POSQUERY:
2592        possessive = TRUE;
2593        min = 0;
2594        max = 1;
2595        ecode++;
2596        goto REPEATCHAR;
2597    
2598      case OP_STAR:      case OP_STAR:
2599      case OP_MINSTAR:      case OP_MINSTAR:
2600      case OP_PLUS:      case OP_PLUS:
# Line 1976  for (;;) Line 2603  for (;;)
2603      case OP_MINQUERY:      case OP_MINQUERY:
2604      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2605      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2606    
2607      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2608      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2609      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2610    
2611      /* Common code for all repeated single-character matches. We can give      /* Common code for all repeated single-character matches. */
     up quickly if there are fewer than the minimum number of characters left in  
     the subject. */  
2612    
2613      REPEATCHAR:      REPEATCHAR:
2614  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1991  for (;;) Line 2617  for (;;)
2617        length = 1;        length = 1;
2618        charptr = ecode;        charptr = ecode;
2619        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2620        ecode += length;        ecode += length;
2621    
2622        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 1999  for (;;) Line 2624  for (;;)
2624    
2625        if (length > 1)        if (length > 1)
2626          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2627  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2628          int othercase;          unsigned int othercase;
2629          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2630              (othercase = _pcre_ucp_othercase(fc)) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase >= 0)  
2631            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2632            else oclength = 0;
2633  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2634    
2635          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2636            {            {
2637            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2638            /* Need braces because of following else */              memcmp(eptr, charptr, length) == 0) eptr += length;
2639            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2640              else if (oclength > 0 &&
2641                       eptr <= md->end_subject - oclength &&
2642                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2643    #endif  /* SUPPORT_UCP */
2644            else            else
2645              {              {
2646              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2647              eptr += oclength;              RRETURN(MATCH_NOMATCH);
2648              }              }
2649            }            }
2650    
# Line 2028  for (;;) Line 2654  for (;;)
2654            {            {
2655            for (fi = min;; fi++)            for (fi = min;; fi++)
2656              {              {
2657              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2658              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2659              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2660              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2661              /* Need braces because of following else */                memcmp(eptr, charptr, length) == 0) eptr += length;
2662              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2663                else if (oclength > 0 &&
2664                         eptr <= md->end_subject - oclength &&
2665                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2666    #endif  /* SUPPORT_UCP */
2667              else              else
2668                {                {
2669                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2670                eptr += oclength;                RRETURN(MATCH_NOMATCH);
2671                }                }
2672              }              }
2673            /* Control never gets here */            /* Control never gets here */
2674            }            }
2675          else  
2676            else  /* Maximize */
2677            {            {
2678            pp = eptr;            pp = eptr;
2679            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2680              {              {
2681              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2682              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2683              else if (oclength == 0) break;  #ifdef SUPPORT_UCP
2684              else              else if (oclength > 0 &&
2685                {                       eptr <= md->end_subject - oclength &&
2686                if (memcmp(eptr, occhars, oclength) != 0) break;                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2687                eptr += oclength;  #endif  /* SUPPORT_UCP */
2688                }              else break;
2689                }
2690    
2691              if (possessive) continue;
2692    
2693              for(;;)
2694                {
2695                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2696                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2697                if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2698    #ifdef SUPPORT_UCP
2699                eptr--;
2700                BACKCHAR(eptr);
2701    #else   /* without SUPPORT_UCP */
2702                eptr -= length;
2703    #endif  /* SUPPORT_UCP */
2704              }              }
           while (eptr >= pp)  
            {  
            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);  
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
            eptr -= length;  
            }  
           RRETURN(MATCH_NOMATCH);  
2705            }            }
2706          /* Control never gets here */          /* Control never gets here */
2707          }          }
# Line 2075  for (;;) Line 2714  for (;;)
2714  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2715    
2716      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2717        {  
2718        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2719    
2720      /* The value of fc at this point is always less than 256, though we may or      /* The value of fc at this point is always less than 256, though we may or
2721      may not be in UTF-8 mode. The code is duplicated for the caseless and      may not be in UTF-8 mode. The code is duplicated for the caseless and
# Line 2096  for (;;) Line 2733  for (;;)
2733        {        {
2734        fc = md->lcc[fc];        fc = md->lcc[fc];
2735        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2736            {
2737            if (eptr >= md->end_subject)
2738              {
2739              SCHECK_PARTIAL();
2740              RRETURN(MATCH_NOMATCH);
2741              }
2742          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2743            }
2744        if (min == max) continue;        if (min == max) continue;
2745        if (minimize)        if (minimize)
2746          {          {
2747          for (fi = min;; fi++)          for (fi = min;; fi++)
2748            {            {
2749            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2750            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2751            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
2752                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2753                {
2754                SCHECK_PARTIAL();
2755              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2756                }
2757              if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2758            }            }
2759          /* Control never gets here */          /* Control never gets here */
2760          }          }
2761        else        else  /* Maximize */
2762          {          {
2763          pp = eptr;          pp = eptr;
2764          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2118  for (;;) Line 2766  for (;;)
2766            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2767            eptr++;            eptr++;
2768            }            }
2769    
2770            if (possessive) continue;
2771    
2772          while (eptr >= pp)          while (eptr >= pp)
2773            {            {
2774            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2775            eptr--;            eptr--;
2776            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2777            }            }
# Line 2133  for (;;) Line 2784  for (;;)
2784    
2785      else      else
2786        {        {
2787        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2788            {
2789            if (eptr >= md->end_subject)
2790              {
2791              SCHECK_PARTIAL();
2792              RRETURN(MATCH_NOMATCH);
2793              }
2794            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2795            }
2796    
2797        if (min == max) continue;        if (min == max) continue;
2798    
2799        if (minimize)        if (minimize)
2800          {          {
2801          for (fi = min;; fi++)          for (fi = min;; fi++)
2802            {            {
2803            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2804            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2805            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) RRETURN(MATCH_NOMATCH);
2806              if (eptr >= md->end_subject)
2807                {
2808                SCHECK_PARTIAL();
2809              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2810                }
2811              if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2812            }            }
2813          /* Control never gets here */          /* Control never gets here */
2814          }          }
2815        else        else  /* Maximize */
2816          {          {
2817          pp = eptr;          pp = eptr;
2818          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2154  for (;;) Line 2820  for (;;)
2820            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject || fc != *eptr) break;
2821            eptr++;            eptr++;
2822            }            }
2823            if (possessive) continue;
2824    
2825          while (eptr >= pp)          while (eptr >= pp)
2826            {            {
2827            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2828            eptr--;            eptr--;
2829            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2830            }            }
# Line 2169  for (;;) Line 2837  for (;;)
2837      checking can be multibyte. */      checking can be multibyte. */
2838    
2839      case OP_NOT:      case OP_NOT:
2840      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2841          {
2842          SCHECK_PARTIAL();
2843          RRETURN(MATCH_NOMATCH);
2844          }
2845      ecode++;      ecode++;
2846      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2847      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2206  for (;;) Line 2878  for (;;)
2878      ecode += 3;      ecode += 3;
2879      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
2880    
2881        case OP_NOTPOSSTAR:
2882        possessive = TRUE;
2883        min = 0;
2884        max = INT_MAX;
2885        ecode++;
2886        goto REPEATNOTCHAR;
2887    
2888        case OP_NOTPOSPLUS:
2889        possessive = TRUE;
2890        min = 1;
2891        max = INT_MAX;
2892        ecode++;
2893        goto REPEATNOTCHAR;
2894    
2895        case OP_NOTPOSQUERY:
2896        possessive = TRUE;
2897        min = 0;
2898        max = 1;
2899        ecode++;
2900        goto REPEATNOTCHAR;
2901    
2902        case OP_NOTPOSUPTO:
2903        possessive = TRUE;
2904        min = 0;
2905        max = GET2(ecode, 1);
2906        ecode += 3;
2907        goto REPEATNOTCHAR;
2908    
2909      case OP_NOTSTAR:      case OP_NOTSTAR:
2910      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
2911      case OP_NOTPLUS:      case OP_NOTPLUS:
# Line 2218  for (;;) Line 2918  for (;;)
2918      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2919      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2920    
2921      /* Common code for all repeated single-byte matches. We can give up quickly      /* Common code for all repeated single-byte matches. */
     if there are fewer than the minimum number of bytes left in the  
     subject. */  
2922    
2923      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2924      fc = *ecode++;      fc = *ecode++;
2925    
2926      /* The code is duplicated for the caseless and caseful cases, for speed,      /* The code is duplicated for the caseless and caseful cases, for speed,
# Line 2245  for (;;) Line 2942  for (;;)
2942        /* UTF-8 mode */        /* UTF-8 mode */
2943        if (utf8)        if (utf8)
2944          {          {
2945          register int d;          register unsigned int d;
2946          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2947            {            {
2948              if (eptr >= md->end_subject)
2949                {
2950                SCHECK_PARTIAL();
2951                RRETURN(MATCH_NOMATCH);
2952                }
2953            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2954            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
2955            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
# Line 2259  for (;;) Line 2961  for (;;)
2961        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2962          {          {
2963          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2964              {
2965              if (eptr >= md->end_subject)
2966                {
2967                SCHECK_PARTIAL();
2968                RRETURN(MATCH_NOMATCH);
2969                }
2970            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2971              }
2972          }          }
2973    
2974        if (min == max) continue;        if (min == max) continue;
# Line 2270  for (;;) Line 2979  for (;;)
2979          /* UTF-8 mode */          /* UTF-8 mode */
2980          if (utf8)          if (utf8)
2981            {            {
2982            register int d;            register unsigned int d;
2983            for (fi = min;; fi++)            for (fi = min;; fi++)
2984              {              {
2985              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2986              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2987                if (fi >= max) RRETURN(MATCH_NOMATCH);
2988                if (eptr >= md->end_subject)
2989                  {
2990                  SCHECK_PARTIAL();
2991                  RRETURN(MATCH_NOMATCH);
2992                  }
2993              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2994              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2995              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2996              }              }
2997            }            }
2998          else          else
# Line 2287  for (;;) Line 3001  for (;;)
3001            {            {
3002            for (fi = min;; fi++)            for (fi = min;; fi++)
3003              {              {
3004              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
3005              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3006              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) RRETURN(MATCH_NOMATCH);
3007                if (eptr >= md->end_subject)
3008                  {
3009                  SCHECK_PARTIAL();
3010                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3011                  }
3012                if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
3013              }              }
3014            }            }
3015          /* Control never gets here */          /* Control never gets here */
# Line 2306  for (;;) Line 3025  for (;;)
3025          /* UTF-8 mode */          /* UTF-8 mode */
3026          if (utf8)          if (utf8)
3027            {            {
3028            register int d;            register unsigned int d;
3029            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3030              {              {
3031              int len = 1;              int len = 1;
# Line 2316  for (;;) Line 3035  for (;;)
3035              if (fc == d) break;              if (fc == d) break;
3036              eptr += len;              eptr += len;
3037              }              }
3038            for(;;)          if (possessive) continue;
3039            for(;;)
3040              {              {
3041              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
3042              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3043              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3044              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2333  for (;;) Line 3053  for (;;)
3053              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
3054              eptr++;              eptr++;
3055              }              }
3056              if (possessive) continue;
3057            while (eptr >= pp)            while (eptr >= pp)
3058              {              {
3059              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
3060              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3061              eptr--;              eptr--;
3062              }              }
# Line 2354  for (;;) Line 3075  for (;;)
3075        /* UTF-8 mode */        /* UTF-8 mode */
3076        if (utf8)        if (utf8)
3077          {          {
3078          register int d;          register unsigned int d;
3079          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3080            {            {
3081              if (eptr >= md->end_subject)
3082                {
3083                SCHECK_PARTIAL();
3084                RRETURN(MATCH_NOMATCH);
3085                }
3086            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3087            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
3088            }            }
# Line 2366  for (;;) Line 3092  for (;;)
3092        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3093          {          {
3094          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3095              {
3096              if (eptr >= md->end_subject)
3097                {
3098                SCHECK_PARTIAL();
3099                RRETURN(MATCH_NOMATCH);
3100                }
3101            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3102              }
3103          }          }
3104    
3105        if (min == max) continue;        if (min == max) continue;
# Line 2377  for (;;) Line 3110  for (;;)
3110          /* UTF-8 mode */          /* UTF-8 mode */
3111          if (utf8)          if (utf8)
3112            {            {
3113            register int d;            register unsigned int d;
3114            for (fi = min;; fi++)            for (fi = min;; fi++)
3115              {              {
3116              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
3117              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3118              GETCHARINC(d, eptr);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3119              if (fi >= max || eptr >= md->end_subject || fc == d)              if (eptr >= md->end_subject)
3120                  {
3121                  SCHECK_PARTIAL();
3122                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3123                  }
3124                GETCHARINC(d, eptr);
3125                if (fc == d) RRETURN(MATCH_NOMATCH);
3126              }              }
3127            }            }
3128          else          else
# Line 2393  for (;;) Line 3131  for (;;)
3131            {            {
3132            for (fi = min;; fi++)            for (fi = min;; fi++)
3133              {              {
3134              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
3135              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3136              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) RRETURN(MATCH_NOMATCH);
3137                if (eptr >= md->end_subject)
3138                  {
3139                  SCHECK_PARTIAL();
3140                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3141                  }
3142                if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3143              }              }
3144            }            }
3145          /* Control never gets here */          /* Control never gets here */
# Line 2412  for (;;) Line 3155  for (;;)
3155          /* UTF-8 mode */          /* UTF-8 mode */
3156          if (utf8)          if (utf8)
3157            {            {
3158            register int d;            register unsigned int d;
3159            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3160              {              {
3161              int len = 1;              int len = 1;
# Line 2421  for (;;) Line 3164  for (;;)
3164              if (fc == d) break;              if (fc == d) break;
3165              eptr += len;              eptr += len;
3166              }              }
3167              if (possessive) continue;
3168            for(;;)            for(;;)
3169              {              {
3170              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
3171              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3172              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3173              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2438  for (;;) Line 3182  for (;;)
3182              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject || fc == *eptr) break;
3183              eptr++;              eptr++;
3184              }              }
3185              if (possessive) continue;
3186            while (eptr >= pp)            while (eptr >= pp)
3187              {              {
3188              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
3189              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3190              eptr--;              eptr--;
3191              }              }
# Line 2469  for (;;) Line 3214  for (;;)
3214      ecode += 3;      ecode += 3;
3215      goto REPEATTYPE;      goto REPEATTYPE;
3216    
3217        case OP_TYPEPOSSTAR:
3218        possessive = TRUE;
3219        min = 0;
3220        max = INT_MAX;
3221        ecode++;
3222        goto REPEATTYPE;
3223    
3224        case OP_TYPEPOSPLUS:
3225        possessive = TRUE;
3226        min = 1;
3227        max = INT_MAX;
3228        ecode++;
3229        goto REPEATTYPE;
3230    
3231        case OP_TYPEPOSQUERY:
3232        possessive = TRUE;
3233        min = 0;
3234        max = 1;
3235        ecode++;
3236        goto REPEATTYPE;
3237    
3238        case OP_TYPEPOSUPTO:
3239        possessive = TRUE;
3240        min = 0;
3241        max = GET2(ecode, 1);
3242        ecode += 3;
3243        goto REPEATTYPE;
3244    
3245      case OP_TYPESTAR:      case OP_TYPESTAR:
3246      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
3247      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2500  for (;;) Line 3273  for (;;)
3273    
3274      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3275      code for maximizing the speed, and do the type test once at the start      code for maximizing the speed, and do the type test once at the start
3276      (i.e. keep it out of the loop). Also we can test that there are at least      (i.e. keep it out of the loop). Separate the UTF-8 code completely as that
     the minimum number of bytes before we start. This isn't as effective in  
     UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that  
3277      is tidier. Also separate the UCP code, which can be the same for both UTF-8      is tidier. Also separate the UCP code, which can be the same for both UTF-8
3278      and single-bytes. */      and single-bytes. */
3279    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3280      if (min > 0)      if (min > 0)
3281        {        {
3282  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2518  for (;;) Line 3288  for (;;)
3288            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3289            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3290              {              {
3291              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3292              GETCHARINC(c, eptr);                {
3293                  SCHECK_PARTIAL();
3294                  RRETURN(MATCH_NOMATCH);
3295                  }
3296                GETCHARINCTEST(c, eptr);
3297              }              }
3298            break;            break;
3299    
3300            case PT_LAMP:            case PT_LAMP:
3301            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3302              {              {
3303              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3304              GETCHARINC(c, eptr);                {
3305              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3306                  RRETURN(MATCH_NOMATCH);
3307                  }
3308                GETCHARINCTEST(c, eptr);
3309                prop_chartype = UCD_CHARTYPE(c);
3310              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3311                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3312                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2539  for (;;) Line 3317  for (;;)
3317            case PT_GC:            case PT_GC:
3318            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3319              {              {
3320              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3321              GETCHARINC(c, eptr);                {
3322              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3323                  RRETURN(MATCH_NOMATCH);
3324                  }
3325                GETCHARINCTEST(c, eptr);
3326                prop_category = UCD_CATEGORY(c);
3327              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3328                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3329              }              }
# Line 2550  for (;;) Line 3332  for (;;)
3332            case PT_PC:            case PT_PC:
3333            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3334              {              {
3335              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3336              GETCHARINC(c, eptr);                {
3337              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3338                  RRETURN(MATCH_NOMATCH);
3339                  }
3340                GETCHARINCTEST(c, eptr);
3341                prop_chartype = UCD_CHARTYPE(c);
3342              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3343                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3344              }              }
# Line 2561  for (;;) Line 3347  for (;;)
3347            case PT_SC:            case PT_SC:
3348            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3349              {              {
3350              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3351              GETCHARINC(c, eptr);                {
3352              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3353                  RRETURN(MATCH_NOMATCH);
3354                  }
3355                GETCHARINCTEST(c, eptr);
3356                prop_script = UCD_SCRIPT(c);
3357              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3358                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3359              }              }
# Line 2571  for (;;) Line 3361  for (;;)
3361    
3362            default:            default:
3363            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3364            }            }
3365          }          }
3366    
# Line 2582  for (;;) Line 3371  for (;;)
3371          {          {
3372          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3373            {            {
3374              if (eptr >= md->end_subject)
3375                {
3376                SCHECK_PARTIAL();
3377                RRETURN(MATCH_NOMATCH);
3378                }
3379            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3380            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3381            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3382            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3383              {              {
3384              int len = 1;              int len = 1;
3385              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3386                {                else { GETCHARLEN(c, eptr, len); }
3387                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3388              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3389              eptr += len;              eptr += len;
3390              }              }
# Line 2610  for (;;) Line 3402  for (;;)
3402          case OP_ANY:          case OP_ANY:
3403          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3404            {            {
3405            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3406                 ((ims & PCRE_DOTALL) == 0 &&              {
3407                   eptr <= md->end_subject - md->nllen &&              SCHECK_PARTIAL();
3408                   IS_NEWLINE(eptr)))              RRETURN(MATCH_NOMATCH);
3409                }
3410              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3411              eptr++;
3412              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3413              }
3414            break;
3415    
3416            case OP_ALLANY:
3417            for (i = 1; i <= min; i++)
3418              {
3419              if (eptr >= md->end_subject)
3420                {
3421                SCHECK_PARTIAL();
3422              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3423                }
3424            eptr++;            eptr++;
3425            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3426            }            }
3427          break;          break;
3428    
3429          case OP_ANYBYTE:          case OP_ANYBYTE:
3430            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3431          eptr += min;          eptr += min;
3432          break;          break;
3433    
3434          case OP_NOT_DIGIT:          case OP_ANYNL:
3435          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3436            {            {
3437            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3438            GETCHARINC(c, eptr);              {
3439            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)              SCHECK_PARTIAL();
3440              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3441                }
3442              GETCHARINC(c, eptr);
3443              switch(c)
3444                {
3445                default: RRETURN(MATCH_NOMATCH);
3446                case 0x000d:
3447                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3448                break;
3449    
3450                case 0x000a:
3451                break;
3452    
3453                case 0x000b:
3454                case 0x000c:
3455                case 0x0085:
3456                case 0x2028:
3457                case 0x2029:
3458                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3459                break;
3460                }
3461            }            }
3462          break;          break;
3463    
3464          case OP_DIGIT:          case OP_NOT_HSPACE:
3465          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3466            {            {
3467            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3468               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3469                SCHECK_PARTIAL();
3470              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3471            /* No need to skip more bytes - we know it's a 1-byte character */              }
3472              GETCHARINC(c, eptr);
3473              switch(c)
3474                {
3475                default: break;
3476                case 0x09:      /* HT */
3477                case 0x20:      /* SPACE */
3478                case 0xa0:      /* NBSP */
3479                case 0x1680:    /* OGHAM SPACE MARK */
3480                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3481                case 0x2000:    /* EN QUAD */
3482                case 0x2001:    /* EM QUAD */
3483                case 0x2002:    /* EN SPACE */
3484                case 0x2003:    /* EM SPACE */
3485                case 0x2004:    /* THREE-PER-EM SPACE */
3486                case 0x2005:    /* FOUR-PER-EM SPACE */
3487                case 0x2006:    /* SIX-PER-EM SPACE */
3488                case 0x2007:    /* FIGURE SPACE */
3489                case 0x2008:    /* PUNCTUATION SPACE */
3490                case 0x2009:    /* THIN SPACE */
3491                case 0x200A:    /* HAIR SPACE */
3492                case 0x202f:    /* NARROW NO-BREAK SPACE */
3493                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3494                case 0x3000:    /* IDEOGRAPHIC SPACE */
3495                RRETURN(MATCH_NOMATCH);
3496                }
3497            }            }
3498          break;          break;
3499    
3500          case OP_NOT_WHITESPACE:          case OP_HSPACE:
3501          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3502            {            {
3503            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3504               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))              {
3505                SCHECK_PARTIAL();
3506              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3507            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              }
3508              GETCHARINC(c, eptr);
3509              switch(c)
3510                {
3511                default: RRETURN(MATCH_NOMATCH);
3512                case 0x09:      /* HT */
3513                case 0x20:      /* SPACE */
3514                case 0xa0:      /* NBSP */
3515                case 0x1680:    /* OGHAM SPACE MARK */
3516                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3517                case 0x2000:    /* EN QUAD */
3518                case 0x2001:    /* EM QUAD */
3519                case 0x2002:    /* EN SPACE */
3520                case 0x2003:    /* EM SPACE */
3521                case 0x2004:    /* THREE-PER-EM SPACE */
3522                case 0x2005:    /* FOUR-PER-EM SPACE */
3523                case 0x2006:    /* SIX-PER-EM SPACE */
3524                case 0x2007:    /* FIGURE SPACE */
3525                case 0x2008:    /* PUNCTUATION SPACE */
3526                case 0x2009:    /* THIN SPACE */
3527                case 0x200A:    /* HAIR SPACE */
3528                case 0x202f:    /* NARROW NO-BREAK SPACE */
3529                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3530                case 0x3000:    /* IDEOGRAPHIC SPACE */
3531                break;
3532                }
3533            }            }
3534          break;          break;
3535    
3536          case OP_WHITESPACE:          case OP_NOT_VSPACE:
3537          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3538            {            {
3539            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3540               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3541                SCHECK_PARTIAL();
3542              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3543            /* No need to skip more bytes - we know it's a 1-byte character */              }
3544            }            GETCHARINC(c, eptr);
3545              switch(c)
3546                {
3547                default: break;
3548                case 0x0a:      /* LF */
3549                case 0x0b:      /* VT */
3550                case 0x0c:      /* FF */
3551                case 0x0d:      /* CR */
3552                case 0x85:      /* NEL */
3553                case 0x2028:    /* LINE SEPARATOR */
3554                case 0x2029:    /* PARAGRAPH SEPARATOR */
3555                RRETURN(MATCH_NOMATCH);
3556                }
3557              }
3558            break;
3559    
3560            case OP_VSPACE:
3561            for (i = 1; i <= min; i++)
3562              {
3563              if (eptr >= md->end_subject)
3564                {
3565                SCHECK_PARTIAL();
3566                RRETURN(MATCH_NOMATCH);
3567                }
3568              GETCHARINC(c, eptr);
3569              switch(c)
3570                {
3571                default: RRETURN(MATCH_NOMATCH);
3572                case 0x0a:      /* LF */
3573                case 0x0b:      /* VT */
3574                case 0x0c:      /* FF */
3575                case 0x0d:      /* CR */
3576                case 0x85:      /* NEL */
3577                case 0x2028:    /* LINE SEPARATOR */
3578                case 0x2029:    /* PARAGRAPH SEPARATOR */
3579                break;
3580                }
3581              }
3582            break;
3583    
3584            case OP_NOT_DIGIT:
3585            for (i = 1; i <= min; i++)
3586              {
3587              if (eptr >= md->end_subject)
3588                {
3589                SCHECK_PARTIAL();
3590                RRETURN(MATCH_NOMATCH);
3591                }
3592              GETCHARINC(c, eptr);
3593              if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3594                RRETURN(MATCH_NOMATCH);
3595              }
3596            break;
3597    
3598            case OP_DIGIT:
3599            for (i = 1; i <= min; i++)
3600              {
3601              if (eptr >= md->end_subject)
3602                {
3603                SCHECK_PARTIAL();
3604                RRETURN(MATCH_NOMATCH);
3605                }
3606              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3607                RRETURN(MATCH_NOMATCH);
3608              /* No need to skip more bytes - we know it's a 1-byte character */
3609              }
3610            break;
3611    
3612            case OP_NOT_WHITESPACE:
3613            for (i = 1; i <= min; i++)
3614              {
3615              if (eptr >= md->end_subject)
3616                {
3617                SCHECK_PARTIAL();
3618                RRETURN(MATCH_NOMATCH);
3619                }
3620              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3621                RRETURN(MATCH_NOMATCH);
3622              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3623              }
3624            break;
3625    
3626            case OP_WHITESPACE:
3627            for (i = 1; i <= min; i++)
3628              {
3629              if (eptr >= md->end_subject)
3630                {
3631                SCHECK_PARTIAL();
3632                RRETURN(MATCH_NOMATCH);
3633                }
3634              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3635                RRETURN(MATCH_NOMATCH);
3636              /* No need to skip more bytes - we know it's a 1-byte character */
3637              }
3638          break;          break;
3639    
3640          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3641          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3642            {            {
3643            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3644               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3645              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3646            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3647            }            }
3648          break;          break;
3649    
3650          case OP_WORDCHAR:          case OP_WORDCHAR:
3651          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3652            {            {
3653            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3654               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3655                SCHECK_PARTIAL();
3656                RRETURN(MATCH_NOMATCH);
3657                }
3658              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3659              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3660            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
3661            }            }
# Line 2697  for (;;) Line 3674  for (;;)
3674        switch(ctype)        switch(ctype)
3675          {          {
3676          case OP_ANY:          case OP_ANY:
3677          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3678            {            {
3679            for (i = 1; i <= min; i++)            if (eptr >= md->end_subject)
3680              {              {
3681              if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))              SCHECK_PARTIAL();
3682                RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
             eptr++;  
3683              }              }
3684              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3685              eptr++;
3686            }            }
3687          else eptr += min;          break;
3688    
3689            case OP_ALLANY:
3690            if (eptr > md->end_subject - min)
3691              {
3692              SCHECK_PARTIAL();
3693              RRETURN(MATCH_NOMATCH);
3694              }
3695            eptr += min;
3696          break;          break;
3697    
3698          case OP_ANYBYTE:          case OP_ANYBYTE:
3699            if (eptr > md->end_subject - min)
3700              {
3701              SCHECK_PARTIAL();
3702              RRETURN(MATCH_NOMATCH);
3703              }
3704          eptr += min;          eptr += min;
3705          break;          break;
3706    
3707            case OP_ANYNL:
3708            for (i = 1; i <= min; i++)
3709              {
3710              if (eptr >= md->end_subject)
3711                {
3712                SCHECK_PARTIAL();
3713                RRETURN(MATCH_NOMATCH);
3714                }
3715              switch(*eptr++)
3716                {
3717                default: RRETURN(MATCH_NOMATCH);
3718                case 0x000d:
3719                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3720                break;
3721                case 0x000a:
3722                break;
3723    
3724                case 0x000b:
3725                case 0x000c:
3726                case 0x0085:
3727                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3728                break;
3729                }
3730              }
3731            break;
3732    
3733            case OP_NOT_HSPACE:
3734            for (i = 1; i <= min; i++)
3735              {
3736              if (eptr >= md->end_subject)
3737                {
3738                SCHECK_PARTIAL();
3739                RRETURN(MATCH_NOMATCH);
3740                }
3741              switch(*eptr++)
3742                {
3743                default: break;
3744                case 0x09:      /* HT */
3745                case 0x20:      /* SPACE */
3746                case 0xa0:      /* NBSP */
3747                RRETURN(MATCH_NOMATCH);
3748                }
3749              }
3750            break;
3751    
3752            case OP_HSPACE:
3753            for (i = 1; i <= min; i++)
3754              {
3755              if (eptr >= md->end_subject)
3756                {
3757                SCHECK_PARTIAL();
3758                RRETURN(MATCH_NOMATCH);
3759                }
3760              switch(*eptr++)
3761                {
3762                default: RRETURN(MATCH_NOMATCH);
3763                case 0x09:      /* HT */
3764                case 0x20:      /* SPACE */
3765                case 0xa0:      /* NBSP */
3766                break;
3767                }
3768              }
3769            break;
3770    
3771            case OP_NOT_VSPACE:
3772            for (i = 1; i <= min; i++)
3773              {
3774              if (eptr >= md->end_subject)
3775                {
3776                SCHECK_PARTIAL();
3777                RRETURN(MATCH_NOMATCH);
3778                }
3779              switch(*eptr++)
3780                {
3781                default: break;
3782                case 0x0a:      /* LF */
3783                case 0x0b:      /* VT */
3784                case 0x0c:      /* FF */
3785                case 0x0d:      /* CR */
3786                case 0x85:      /* NEL */
3787                RRETURN(MATCH_NOMATCH);
3788                }
3789              }
3790            break;
3791    
3792            case OP_VSPACE:
3793            for (i = 1; i <= min; i++)
3794              {
3795              if (eptr >= md->end_subject)
3796                {
3797                SCHECK_PARTIAL();
3798                RRETURN(MATCH_NOMATCH);
3799                }
3800              switch(*eptr++)
3801                {
3802                default: RRETURN(MATCH_NOMATCH);
3803                case 0x0a:      /* LF */
3804                case 0x0b:      /* VT */
3805                case 0x0c:      /* FF */
3806                case 0x0d:      /* CR */
3807                case 0x85:      /* NEL */
3808                break;
3809                }
3810              }
3811            break;
3812    
3813          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3814          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3815              {
3816              if (eptr >= md->end_subject)
3817                {
3818                SCHECK_PARTIAL();
3819                RRETURN(MATCH_NOMATCH);
3820                }
3821            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
3822              }
3823          break;          break;
3824    
3825          case OP_DIGIT:          case OP_DIGIT:
3826          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3827              {
3828              if (eptr >= md->end_subject)
3829                {
3830                SCHECK_PARTIAL();
3831                RRETURN(MATCH_NOMATCH);
3832                }
3833            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
3834              }
3835          break;          break;
3836    
3837          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3838          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3839              {
3840              if (eptr >= md->end_subject)
3841                {
3842                SCHECK_PARTIAL();
3843                RRETURN(MATCH_NOMATCH);
3844                }
3845            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
3846              }
3847          break;          break;
3848    
3849          case OP_WHITESPACE:          case OP_WHITESPACE:
3850          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3851              {
3852              if (eptr >= md->end_subject)
3853                {
3854                SCHECK_PARTIAL();
3855                RRETURN(MATCH_NOMATCH);
3856                }
3857            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
3858              }
3859          break;          break;
3860    
3861          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3862          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3863              {
3864              if (eptr >= md->end_subject)
3865                {
3866                SCHECK_PARTIAL();
3867                RRETURN(MATCH_NOMATCH);
3868                }
3869            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
3870              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3871              }
3872          break;          break;
3873    
3874          case OP_WORDCHAR:          case OP_WORDCHAR:
3875          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3876              {
3877              if (eptr >= md->end_subject)
3878                {
3879                SCHECK_PARTIAL();
3880                RRETURN(MATCH_NOMATCH);
3881                }
3882            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
3883              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3884              }
3885          break;          break;
3886    
3887          default:          default:
# Line 2768  for (;;) Line 3907  for (;;)
3907            case PT_ANY:            case PT_ANY:
3908            for (fi = min;; fi++)            for (fi = min;; fi++)
3909              {              {
3910              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3911              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3912              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3913                if (eptr >= md->end_subject)
3914                  {
3915                  SCHECK_PARTIAL();
3916                  RRETURN(MATCH_NOMATCH);
3917                  }
3918              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3919              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3920              }              }
3921            break;            /* Control never gets here */
3922    
3923            case PT_LAMP:            case PT_LAMP:
3924            for (fi = min;; fi++)            for (fi = min;; fi++)
3925              {              {
3926              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3927              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3928              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3929                if (eptr >= md->end_subject)
3930                  {
3931                  SCHECK_PARTIAL();
3932                  RRETURN(MATCH_NOMATCH);
3933                  }
3934              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3935              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3936              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3937                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3938                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3939                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3940              }              }
3941            break;            /* Control never gets here */
3942    
3943            case PT_GC:            case PT_GC:
3944            for (fi = min;; fi++)            for (fi = min;; fi++)
3945              {              {
3946              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3947              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3948              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3949                if (eptr >= md->end_subject)
3950                  {
3951                  SCHECK_PARTIAL();
3952                  RRETURN(MATCH_NOMATCH);
3953                  }
3954              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3955              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3956              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3957                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3958              }              }
3959            break;            /* Control never gets here */
3960    
3961            case PT_PC:            case PT_PC:
3962            for (fi = min;; fi++)            for (fi = min;; fi++)
3963              {              {
3964              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3965              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3966              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3967                if (eptr >= md->end_subject)
3968                  {
3969                  SCHECK_PARTIAL();
3970                  RRETURN(MATCH_NOMATCH);
3971                  }
3972              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3973              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3974              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3975                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3976              }              }
3977            break;            /* Control never gets here */
3978    
3979            case PT_SC:            case PT_SC:
3980            for (fi = min;; fi++)            for (fi = min;; fi++)
3981              {              {
3982              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3983              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3984              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3985                if (eptr >= md->end_subject)
3986                  {
3987                  SCHECK_PARTIAL();
3988                  RRETURN(MATCH_NOMATCH);
3989                  }
3990              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3991              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3992              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3993                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3994              }              }
3995            break;            /* Control never gets here */
3996    
3997            default:            default:
3998            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3999            }            }
4000          }          }
4001    
# Line 2843  for (;;) Line 4006  for (;;)
4006          {          {
4007          for (fi = min;; fi++)          for (fi = min;; fi++)
4008            {            {
4009            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
4010            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4011            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
4012              if (eptr >= md->end_subject)
4013                {
4014                SCHECK_PARTIAL();
4015                RRETURN(MATCH_NOMATCH);
4016                }
4017            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4018            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
4019            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
4020            while (eptr < md->end_subject)            while (eptr < md->end_subject)
4021              {              {
4022              int len = 1;              int len = 1;
4023              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
4024                {                else { GETCHARLEN(c, eptr, len); }
4025                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
4026              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
4027              eptr += len;              eptr += len;
4028              }              }
# Line 2872  for (;;) Line 4038  for (;;)
4038          {          {
4039          for (fi = min;; fi++)          for (fi = min;; fi++)
4040            {            {
4041            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
4042            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4043            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
4044                 (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&            if (eptr >= md->end_subject)
4045                  eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)))              {
4046                SCHECK_PARTIAL();
4047                RRETURN(MATCH_NOMATCH);
4048                }
4049              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4050              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
4051            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4052            switch(ctype)            switch(ctype)
4053              {              {
4054              case OP_ANY:        /* This is the DOTALL case */              case OP_ANY:        /* This is the non-NL case */
4055                case OP_ALLANY:
4056                case OP_ANYBYTE:
4057              break;              break;
4058    
4059              case OP_ANYBYTE:              case OP_ANYNL:
4060                switch(c)
4061                  {
4062                  default: RRETURN(MATCH_NOMATCH);
4063                  case 0x000d:
4064                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4065                  break;
4066                  case 0x000a:
4067                  break;
4068    
4069                  case 0x000b:
4070                  case 0x000c:
4071                  case 0x0085:
4072                  case 0x2028:
4073                  case 0x2029:
4074                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4075                  break;
4076                  }
4077                break;
4078    
4079                case OP_NOT_HSPACE:
4080                switch(c)
4081                  {
4082                  default: break;
4083                  case 0x09:      /* HT */
4084                  case 0x20:      /* SPACE */
4085                  case 0xa0:      /* NBSP */
4086                  case 0x1680:    /* OGHAM SPACE MARK */
4087                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
4088                  case 0x2000:    /* EN QUAD */
4089                  case 0x2001:    /* EM QUAD */
4090                  case 0x2002:    /* EN SPACE */
4091                  case 0x2003:    /* EM SPACE */
4092                  case 0x2004:    /* THREE-PER-EM SPACE */
4093                  case 0x2005:    /* FOUR-PER-EM SPACE */
4094                  case 0x2006:    /* SIX-PER-EM SPACE */
4095                  case 0x2007:    /* FIGURE SPACE */
4096                  case 0x2008:    /* PUNCTUATION SPACE */
4097                  case 0x2009:    /* THIN SPACE */
4098                  case 0x200A:    /* HAIR SPACE */
4099                  case 0x202f:    /* NARROW NO-BREAK SPACE */
4100                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4101                  case 0x3000:    /* IDEOGRAPHIC SPACE */
4102                  RRETURN(MATCH_NOMATCH);
4103                  }
4104                break;
4105    
4106                case OP_HSPACE:
4107                switch(c)
4108                  {
4109                  default: RRETURN(MATCH_NOMATCH);
4110                  case 0x09:      /* HT */
4111                  case 0x20:      /* SPACE */
4112                  case 0xa0:      /* NBSP */
4113                  case 0x1680:    /* OGHAM SPACE MARK */
4114                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
4115                  case 0x2000:    /* EN QUAD */
4116                  case 0x2001:    /* EM QUAD */
4117                  case 0x2002:    /* EN SPACE */
4118                  case 0x2003:    /* EM SPACE */
4119                  case 0x2004:    /* THREE-PER-EM SPACE */
4120                  case 0x2005:    /* FOUR-PER-EM SPACE */
4121                  case 0x2006:    /* SIX-PER-EM SPACE */
4122                  case 0x2007:    /* FIGURE SPACE */
4123                  case 0x2008:    /* PUNCTUATION SPACE */
4124                  case 0x2009:    /* THIN SPACE */
4125                  case 0x200A:    /* HAIR SPACE */
4126                  case 0x202f:    /* NARROW NO-BREAK SPACE */
4127                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4128                  case 0x3000:    /* IDEOGRAPHIC SPACE */
4129                  break;
4130                  }
4131                break;