/[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 778 by ph10, Thu Dec 1 17:38:47 2011 UTC revision 895 by ph10, Fri Jan 20 12:12:03 2012 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-2011 University of Cambridge             Copyright (c) 1997-2012 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 113  Returns:     nothing Line 113  Returns:     nothing
113  */  */
114    
115  static void  static void
116  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)  pchars(const pcre_uchar *p, int length, BOOL is_subject, match_data *md)
117  {  {
118  unsigned int c;  unsigned int c;
119  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;
# Line 144  Returns:      < 0 if not matched, otherw Line 144  Returns:      < 0 if not matched, otherw
144  */  */
145    
146  static int  static int
147  match_ref(int offset, register USPTR eptr, int length, match_data *md,  match_ref(int offset, register PCRE_PUCHAR eptr, int length, match_data *md,
148    BOOL caseless)    BOOL caseless)
149  {  {
150  USPTR eptr_start = eptr;  PCRE_PUCHAR eptr_start = eptr;
151  register USPTR p = md->start_subject + md->offset_vector[offset];  register PCRE_PUCHAR p = md->start_subject + md->offset_vector[offset];
152    
153  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
154  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
# Line 173  ASCII characters. */ Line 173  ASCII characters. */
173    
174  if (caseless)  if (caseless)
175    {    {
176  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
177  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
178    if (md->utf8)    if (md->utf)
179      {      {
180      /* Match characters up to the end of the reference. NOTE: the number of      /* Match characters up to the end of the reference. NOTE: the number of
181      bytes matched may differ, because there are some characters whose upper and      bytes matched may differ, because there are some characters whose upper and
# Line 185  if (caseless) Line 185  if (caseless)
185      the latter. It is important, therefore, to check the length along the      the latter. It is important, therefore, to check the length along the
186      reference, not along the subject (earlier code did this wrong). */      reference, not along the subject (earlier code did this wrong). */
187    
188      USPTR endptr = p + length;      PCRE_PUCHAR endptr = p + length;
189      while (p < endptr)      while (p < endptr)
190        {        {
191        int c, d;        int c, d;
# Line 204  if (caseless) Line 204  if (caseless)
204      {      {
205      if (eptr + length > md->end_subject) return -1;      if (eptr + length > md->end_subject) return -1;
206      while (length-- > 0)      while (length-- > 0)
207        { if (md->lcc[*p++] != md->lcc[*eptr++]) return -1; }        {
208          if (TABLE_GET(*p, md->lcc, *p) != TABLE_GET(*eptr, md->lcc, *eptr)) return -1;
209          p++;
210          eptr++;
211          }
212      }      }
213    }    }
214    
# Line 217  else Line 221  else
221    while (length-- > 0) if (*p++ != *eptr++) return -1;    while (length-- > 0) if (*p++ != *eptr++) return -1;
222    }    }
223    
224  return eptr - eptr_start;  return (int)(eptr - eptr_start);
225  }  }
226    
227    
# Line 307  argument of match(), which never changes Line 311  argument of match(), which never changes
311    
312  #define RMATCH(ra,rb,rc,rd,re,rw)\  #define RMATCH(ra,rb,rc,rd,re,rw)\
313    {\    {\
314    heapframe *newframe = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (heapframe *)(PUBL(stack_malloc))(sizeof(heapframe));\
315    if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\    if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
316    frame->Xwhere = rw; \    frame->Xwhere = rw; \
317    newframe->Xeptr = ra;\    newframe->Xeptr = ra;\
# Line 328  argument of match(), which never changes Line 332  argument of match(), which never changes
332    {\    {\
333    heapframe *oldframe = frame;\    heapframe *oldframe = frame;\
334    frame = oldframe->Xprevframe;\    frame = oldframe->Xprevframe;\
335    (pcre_stack_free)(oldframe);\    if (oldframe != &frame_zero) (PUBL(stack_free))(oldframe);\
336    if (frame != NULL)\    if (frame != NULL)\
337      {\      {\
338      rrc = ra;\      rrc = ra;\
# Line 345  typedef struct heapframe { Line 349  typedef struct heapframe {
349    
350    /* Function arguments that may change */    /* Function arguments that may change */
351    
352    USPTR Xeptr;    PCRE_PUCHAR Xeptr;
353    const uschar *Xecode;    const pcre_uchar *Xecode;
354    USPTR Xmstart;    PCRE_PUCHAR Xmstart;
355    int Xoffset_top;    int Xoffset_top;
356    eptrblock *Xeptrb;    eptrblock *Xeptrb;
357    unsigned int Xrdepth;    unsigned int Xrdepth;
358    
359    /* Function local variables */    /* Function local variables */
360    
361    USPTR Xcallpat;    PCRE_PUCHAR Xcallpat;
362  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
363    USPTR Xcharptr;    PCRE_PUCHAR Xcharptr;
364  #endif  #endif
365    USPTR Xdata;    PCRE_PUCHAR Xdata;
366    USPTR Xnext;    PCRE_PUCHAR Xnext;
367    USPTR Xpp;    PCRE_PUCHAR Xpp;
368    USPTR Xprev;    PCRE_PUCHAR Xprev;
369    USPTR Xsaved_eptr;    PCRE_PUCHAR Xsaved_eptr;
370    
371    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
372    
# Line 375  typedef struct heapframe { Line 379  typedef struct heapframe {
379    int Xprop_value;    int Xprop_value;
380    int Xprop_fail_result;    int Xprop_fail_result;
381    int Xoclength;    int Xoclength;
382    uschar Xocchars[8];    pcre_uchar Xocchars[6];
383  #endif  #endif
384    
385    int Xcodelink;    int Xcodelink;
# Line 440  the subject. */ Line 444  the subject. */
444    
445    
446  /* Performance note: It might be tempting to extract commonly used fields from  /* Performance note: It might be tempting to extract commonly used fields from
447  the md structure (e.g. utf8, end_subject) into individual variables to improve  the md structure (e.g. utf, end_subject) into individual variables to improve
448  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
449  made performance worse.  made performance worse.
450    
# Line 463  Returns:       MATCH_MATCH if matched Line 467  Returns:       MATCH_MATCH if matched
467  */  */
468    
469  static int  static int
470  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,  match(REGISTER PCRE_PUCHAR eptr, REGISTER const pcre_uchar *ecode,
471    int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)    PCRE_PUCHAR mstart, int offset_top, match_data *md, eptrblock *eptrb,
472      unsigned int rdepth)
473  {  {
474  /* 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,
475  so they can be ordinary variables in all cases. Mark some of them with  so they can be ordinary variables in all cases. Mark some of them with
# Line 473  so they can be ordinary variables in all Line 478  so they can be ordinary variables in all
478  register int  rrc;         /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
479  register int  i;           /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
480  register unsigned int c;   /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
481  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf;         /* Local copy of UTF flag for speed */
482    
483  BOOL minimize, possessive; /* Quantifier options */  BOOL minimize, possessive; /* Quantifier options */
484  BOOL caseless;  BOOL caseless;
485  int condcode;  int condcode;
486    
487  /* 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
488  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame". We set up the top-level
489  heap storage. Set up the top-level frame here; others are obtained from the  frame on the stack here; subsequent instantiations are obtained from the heap
490  heap whenever RMATCH() does a "recursion". See the macro definitions above. */  whenever RMATCH() does a "recursion". See the macro definitions above. Putting
491    the top-level on the stack rather than malloc-ing them all gives a performance
492    boost in many cases where there is not much "recursion". */
493    
494  #ifdef NO_RECURSE  #ifdef NO_RECURSE
495  heapframe *frame = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));  heapframe frame_zero;
496  if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);  heapframe *frame = &frame_zero;
497  frame->Xprevframe = NULL;            /* Marks the top level */  frame->Xprevframe = NULL;            /* Marks the top level */
498    
499  /* Copy in the original argument variables */  /* Copy in the original argument variables */
# Line 513  HEAP_RECURSE: Line 520  HEAP_RECURSE:
520    
521  /* Ditto for the local variables */  /* Ditto for the local variables */
522    
523  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
524  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
525  #endif  #endif
526  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
# Line 571  declarations can be cut out in a block. Line 578  declarations can be cut out in a block.
578  below are for variables that do not have to be preserved over a recursive call  below are for variables that do not have to be preserved over a recursive call
579  to RMATCH(). */  to RMATCH(). */
580    
581  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
582  const uschar *charptr;  const pcre_uchar *charptr;
583  #endif  #endif
584  const uschar *callpat;  const pcre_uchar *callpat;
585  const uschar *data;  const pcre_uchar *data;
586  const uschar *next;  const pcre_uchar *next;
587  USPTR         pp;  PCRE_PUCHAR       pp;
588  const uschar *prev;  const pcre_uchar *prev;
589  USPTR         saved_eptr;  PCRE_PUCHAR       saved_eptr;
590    
591  recursion_info new_recursive;  recursion_info new_recursive;
592    
# Line 592  int prop_type; Line 599  int prop_type;
599  int prop_value;  int prop_value;
600  int prop_fail_result;  int prop_fail_result;
601  int oclength;  int oclength;
602  uschar occhars[8];  pcre_uchar occhars[6];
603  #endif  #endif
604    
605  int codelink;  int codelink;
# Line 608  int save_offset1, save_offset2, save_off Line 615  int save_offset1, save_offset2, save_off
615  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
616    
617  eptrblock newptrb;  eptrblock newptrb;
618    
619    /* There is a special fudge for calling match() in a way that causes it to
620    measure the size of its basic stack frame when the stack is being used for
621    recursion. The second argument (ecode) being NULL triggers this behaviour. It
622    cannot normally every be NULL. The return is the negated value of the frame
623    size. */
624    
625    if (ecode == NULL)
626      {
627      if (rdepth == 0)
628        return match((PCRE_PUCHAR)&rdepth, NULL, NULL, 0, NULL, NULL, 1);
629      else
630        {
631        int len = (char *)&rdepth - (char *)eptr;
632        return (len > 0)? -len : len;
633        }
634      }
635  #endif     /* NO_RECURSE */  #endif     /* NO_RECURSE */
636    
637  /* To save space on the stack and in the heap frame, I have doubled up on some  /* To save space on the stack and in the heap frame, I have doubled up on some
# Line 620  the alternative names that are used. */ Line 644  the alternative names that are used. */
644  #define code_offset   codelink  #define code_offset   codelink
645  #define condassert    condition  #define condassert    condition
646  #define matched_once  prev_is_word  #define matched_once  prev_is_word
647    #define foc           number
648    #define save_mark     data
649    
650  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
651  variables. */  variables. */
# Line 645  defined). However, RMATCH isn't like a f Line 671  defined). However, RMATCH isn't like a f
671  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,
672  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
673    
674  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
675  utf8 = md->utf8;       /* Local copy of the flag */  utf = md->utf;       /* Local copy of the flag */
676  #else  #else
677  utf8 = FALSE;  utf = FALSE;
678  #endif  #endif
679    
680  /* 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
# Line 689  for (;;) Line 715  for (;;)
715      case OP_MARK:      case OP_MARK:
716      md->nomatch_mark = ecode + 2;      md->nomatch_mark = ecode + 2;
717      md->mark = NULL;    /* In case previously set by assertion */      md->mark = NULL;    /* In case previously set by assertion */
718      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md,
719        eptrb, RM55);        eptrb, RM55);
720      if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&      if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&
721           md->mark == NULL) md->mark = ecode + 2;           md->mark == NULL) md->mark = ecode + 2;
# Line 702  for (;;) Line 728  for (;;)
728      unaltered. */      unaltered. */
729    
730      else if (rrc == MATCH_SKIP_ARG &&      else if (rrc == MATCH_SKIP_ARG &&
731          strcmp((char *)(ecode + 2), (char *)(md->start_match_ptr)) == 0)          STRCMP_UC_UC(ecode + 2, md->start_match_ptr) == 0)
732        {        {
733        md->start_match_ptr = eptr;        md->start_match_ptr = eptr;
734        RRETURN(MATCH_SKIP);        RRETURN(MATCH_SKIP);
# Line 715  for (;;) Line 741  for (;;)
741      /* COMMIT overrides PRUNE, SKIP, and THEN */      /* COMMIT overrides PRUNE, SKIP, and THEN */
742    
743      case OP_COMMIT:      case OP_COMMIT:
744      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
745        eptrb, RM52);        eptrb, RM52);
746      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE &&      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE &&
747          rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG &&          rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG &&
# Line 726  for (;;) Line 752  for (;;)
752      /* PRUNE overrides THEN */      /* PRUNE overrides THEN */
753    
754      case OP_PRUNE:      case OP_PRUNE:
755      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
756        eptrb, RM51);        eptrb, RM51);
757      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
758      RRETURN(MATCH_PRUNE);      RRETURN(MATCH_PRUNE);
# Line 734  for (;;) Line 760  for (;;)
760      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
761      md->nomatch_mark = ecode + 2;      md->nomatch_mark = ecode + 2;
762      md->mark = NULL;    /* In case previously set by assertion */      md->mark = NULL;    /* In case previously set by assertion */
763      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md,
764        eptrb, RM56);        eptrb, RM56);
765      if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&      if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&
766           md->mark == NULL) md->mark = ecode + 2;           md->mark == NULL) md->mark = ecode + 2;
# Line 744  for (;;) Line 770  for (;;)
770      /* SKIP overrides PRUNE and THEN */      /* SKIP overrides PRUNE and THEN */
771    
772      case OP_SKIP:      case OP_SKIP:
773      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
774        eptrb, RM53);        eptrb, RM53);
775      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
776        RRETURN(rrc);        RRETURN(rrc);
# Line 752  for (;;) Line 778  for (;;)
778      RRETURN(MATCH_SKIP);      RRETURN(MATCH_SKIP);
779    
780      /* Note that, for Perl compatibility, SKIP with an argument does NOT set      /* Note that, for Perl compatibility, SKIP with an argument does NOT set
781      nomatch_mark. There is a flag that disables this opcode when re-matching a      nomatch_mark. There is a flag that disables this opcode when re-matching a
782      pattern that ended with a SKIP for which there was not a matching MARK. */      pattern that ended with a SKIP for which there was not a matching MARK. */
783    
784      case OP_SKIP_ARG:      case OP_SKIP_ARG:
785      if (md->ignore_skip_arg)      if (md->ignore_skip_arg)
786        {        {
787        ecode += _pcre_OP_lengths[*ecode] + ecode[1];        ecode += PRIV(OP_lengths)[*ecode] + ecode[1];
788        break;        break;
789        }        }
790      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md,
791        eptrb, RM57);        eptrb, RM57);
792      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
793        RRETURN(rrc);        RRETURN(rrc);
794    
795      /* Pass back the current skip name by overloading md->start_match_ptr and      /* Pass back the current skip name by overloading md->start_match_ptr and
796      returning the special MATCH_SKIP_ARG return code. This will either be      returning the special MATCH_SKIP_ARG return code. This will either be
797      caught by a matching MARK, or get to the top, where it causes a rematch      caught by a matching MARK, or get to the top, where it causes a rematch
798      with the md->ignore_skip_arg flag set. */      with the md->ignore_skip_arg flag set. */
799    
800      md->start_match_ptr = ecode + 2;      md->start_match_ptr = ecode + 2;
# Line 779  for (;;) Line 805  for (;;)
805      match pointer to do this. */      match pointer to do this. */
806    
807      case OP_THEN:      case OP_THEN:
808      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
809        eptrb, RM54);        eptrb, RM54);
810      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
811      md->start_match_ptr = ecode;      md->start_match_ptr = ecode;
# Line 788  for (;;) Line 814  for (;;)
814      case OP_THEN_ARG:      case OP_THEN_ARG:
815      md->nomatch_mark = ecode + 2;      md->nomatch_mark = ecode + 2;
816      md->mark = NULL;    /* In case previously set by assertion */      md->mark = NULL;    /* In case previously set by assertion */
817      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top,
818        md, eptrb, RM58);        md, eptrb, RM58);
819      if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&      if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&
820           md->mark == NULL) md->mark = ecode + 2;           md->mark == NULL) md->mark = ecode + 2;
# Line 812  for (;;) Line 838  for (;;)
838      case OP_ONCE_NC:      case OP_ONCE_NC:
839      prev = ecode;      prev = ecode;
840      saved_eptr = eptr;      saved_eptr = eptr;
841        save_mark = md->mark;
842      do      do
843        {        {
844        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64);
# Line 830  for (;;) Line 857  for (;;)
857    
858        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
859        ecode += GET(ecode,1);        ecode += GET(ecode,1);
860          md->mark = save_mark;
861        }        }
862      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
863    
# Line 909  for (;;) Line 937  for (;;)
937        save_offset2 = md->offset_vector[offset+1];        save_offset2 = md->offset_vector[offset+1];
938        save_offset3 = md->offset_vector[md->offset_end - number];        save_offset3 = md->offset_vector[md->offset_end - number];
939        save_capture_last = md->capture_last;        save_capture_last = md->capture_last;
940          save_mark = md->mark;
941    
942        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
943        md->offset_vector[md->offset_end - number] =        md->offset_vector[md->offset_end - number] =
# Line 917  for (;;) Line 946  for (;;)
946        for (;;)        for (;;)
947          {          {
948          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
949          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
950            eptrb, RM1);            eptrb, RM1);
951          if (rrc == MATCH_ONCE) break;  /* Backing up through an atomic group */          if (rrc == MATCH_ONCE) break;  /* Backing up through an atomic group */
952    
# Line 945  for (;;) Line 974  for (;;)
974          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
975          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
976          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
977            md->mark = save_mark;
978          if (*ecode != OP_ALT) break;          if (*ecode != OP_ALT) break;
979          }          }
980    
# Line 1004  for (;;) Line 1034  for (;;)
1034    
1035        else if (!md->hasthen && ecode[GET(ecode, 1)] != OP_ALT)        else if (!md->hasthen && ecode[GET(ecode, 1)] != OP_ALT)
1036          {          {
1037          ecode += _pcre_OP_lengths[*ecode];          ecode += PRIV(OP_lengths)[*ecode];
1038          goto TAIL_RECURSE;          goto TAIL_RECURSE;
1039          }          }
1040    
1041        /* In all other cases, we have to make another call to match(). */        /* In all other cases, we have to make another call to match(). */
1042    
1043        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, eptrb,        save_mark = md->mark;
1044          RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, eptrb,
1045          RM2);          RM2);
1046    
1047        /* See comment in the code for capturing groups above about handling        /* See comment in the code for capturing groups above about handling
1048        THEN. */        THEN. */
1049    
# Line 1028  for (;;) Line 1059  for (;;)
1059          {          {
1060          if (rrc == MATCH_ONCE)          if (rrc == MATCH_ONCE)
1061            {            {
1062            const uschar *scode = ecode;            const pcre_uchar *scode = ecode;
1063            if (*scode != OP_ONCE)           /* If not at start, find it */            if (*scode != OP_ONCE)           /* If not at start, find it */
1064              {              {
1065              while (*scode == OP_ALT) scode += GET(scode, 1);              while (*scode == OP_ALT) scode += GET(scode, 1);
# Line 1039  for (;;) Line 1070  for (;;)
1070          RRETURN(rrc);          RRETURN(rrc);
1071          }          }
1072        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1073          md->mark = save_mark;
1074        if (*ecode != OP_ALT) break;        if (*ecode != OP_ALT) break;
1075        }        }
1076    
# Line 1070  for (;;) Line 1102  for (;;)
1102      if (offset < md->offset_max)      if (offset < md->offset_max)
1103        {        {
1104        matched_once = FALSE;        matched_once = FALSE;
1105        code_offset = ecode - md->start_code;        code_offset = (int)(ecode - md->start_code);
1106    
1107        save_offset1 = md->offset_vector[offset];        save_offset1 = md->offset_vector[offset];
1108        save_offset2 = md->offset_vector[offset+1];        save_offset2 = md->offset_vector[offset+1];
# Line 1093  for (;;) Line 1125  for (;;)
1125          md->offset_vector[md->offset_end - number] =          md->offset_vector[md->offset_end - number] =
1126            (int)(eptr - md->start_subject);            (int)(eptr - md->start_subject);
1127          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1128          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
1129            eptrb, RM63);            eptrb, RM63);
1130          if (rrc == MATCH_KETRPOS)          if (rrc == MATCH_KETRPOS)
1131            {            {
# Line 1160  for (;;) Line 1192  for (;;)
1192    
1193      POSSESSIVE_NON_CAPTURE:      POSSESSIVE_NON_CAPTURE:
1194      matched_once = FALSE;      matched_once = FALSE;
1195      code_offset = ecode - md->start_code;      code_offset = (int)(ecode - md->start_code);
1196    
1197      for (;;)      for (;;)
1198        {        {
1199        if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;        if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1200        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
1201          eptrb, RM48);          eptrb, RM48);
1202        if (rrc == MATCH_KETRPOS)        if (rrc == MATCH_KETRPOS)
1203          {          {
# Line 1215  for (;;) Line 1247  for (;;)
1247    
1248      if (ecode[LINK_SIZE+1] == OP_CALLOUT)      if (ecode[LINK_SIZE+1] == OP_CALLOUT)
1249        {        {
1250        if (pcre_callout != NULL)        if (PUBL(callout) != NULL)
1251          {          {
1252          pcre_callout_block cb;          PUBL(callout_block) cb;
1253          cb.version          = 2;   /* Version 1 of the callout block */          cb.version          = 2;   /* Version 1 of the callout block */
1254          cb.callout_number   = ecode[LINK_SIZE+2];          cb.callout_number   = ecode[LINK_SIZE+2];
1255          cb.offset_vector    = md->offset_vector;          cb.offset_vector    = md->offset_vector;
1256    #ifdef COMPILE_PCRE8
1257          cb.subject          = (PCRE_SPTR)md->start_subject;          cb.subject          = (PCRE_SPTR)md->start_subject;
1258    #else
1259            cb.subject          = (PCRE_SPTR16)md->start_subject;
1260    #endif
1261          cb.subject_length   = (int)(md->end_subject - md->start_subject);          cb.subject_length   = (int)(md->end_subject - md->start_subject);
1262          cb.start_match      = (int)(mstart - md->start_subject);          cb.start_match      = (int)(mstart - md->start_subject);
1263          cb.current_position = (int)(eptr - md->start_subject);          cb.current_position = (int)(eptr - md->start_subject);
# Line 1231  for (;;) Line 1267  for (;;)
1267          cb.capture_last     = md->capture_last;          cb.capture_last     = md->capture_last;
1268          cb.callout_data     = md->callout_data;          cb.callout_data     = md->callout_data;
1269          cb.mark             = md->nomatch_mark;          cb.mark             = md->nomatch_mark;
1270          if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);          if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);
1271          if (rrc < 0) RRETURN(rrc);          if (rrc < 0) RRETURN(rrc);
1272          }          }
1273        ecode += _pcre_OP_lengths[OP_CALLOUT];        ecode += PRIV(OP_lengths)[OP_CALLOUT];
1274        }        }
1275    
1276      condcode = ecode[LINK_SIZE+1];      condcode = ecode[LINK_SIZE+1];
# Line 1260  for (;;) Line 1296  for (;;)
1296    
1297          if (!condition && condcode == OP_NRREF)          if (!condition && condcode == OP_NRREF)
1298            {            {
1299            uschar *slotA = md->name_table;            pcre_uchar *slotA = md->name_table;
1300            for (i = 0; i < md->name_count; i++)            for (i = 0; i < md->name_count; i++)
1301              {              {
1302              if (GET2(slotA, 0) == recno) break;              if (GET2(slotA, 0) == recno) break;
# Line 1273  for (;;) Line 1309  for (;;)
1309    
1310            if (i < md->name_count)            if (i < md->name_count)
1311              {              {
1312              uschar *slotB = slotA;              pcre_uchar *slotB = slotA;
1313              while (slotB > md->name_table)              while (slotB > md->name_table)
1314                {                {
1315                slotB -= md->name_entry_size;                slotB -= md->name_entry_size;
1316                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)                if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
1317                  {                  {
1318                  condition = GET2(slotB, 0) == md->recursive->group_num;                  condition = GET2(slotB, 0) == md->recursive->group_num;
1319                  if (condition) break;                  if (condition) break;
# Line 1293  for (;;) Line 1329  for (;;)
1329                for (i++; i < md->name_count; i++)                for (i++; i < md->name_count; i++)
1330                  {                  {
1331                  slotB += md->name_entry_size;                  slotB += md->name_entry_size;
1332                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)                  if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
1333                    {                    {
1334                    condition = GET2(slotB, 0) == md->recursive->group_num;                    condition = GET2(slotB, 0) == md->recursive->group_num;
1335                    if (condition) break;                    if (condition) break;
# Line 1306  for (;;) Line 1342  for (;;)
1342    
1343          /* Chose branch according to the condition */          /* Chose branch according to the condition */
1344    
1345          ecode += condition? 3 : GET(ecode, 1);          ecode += condition? 1 + IMM2_SIZE : GET(ecode, 1);
1346          }          }
1347        }        }
1348    
# Line 1323  for (;;) Line 1359  for (;;)
1359        if (!condition && condcode == OP_NCREF)        if (!condition && condcode == OP_NCREF)
1360          {          {
1361          int refno = offset >> 1;          int refno = offset >> 1;
1362          uschar *slotA = md->name_table;          pcre_uchar *slotA = md->name_table;
1363    
1364          for (i = 0; i < md->name_count; i++)          for (i = 0; i < md->name_count; i++)
1365            {            {
# Line 1337  for (;;) Line 1373  for (;;)
1373    
1374          if (i < md->name_count)          if (i < md->name_count)
1375            {            {
1376            uschar *slotB = slotA;            pcre_uchar *slotB = slotA;
1377            while (slotB > md->name_table)            while (slotB > md->name_table)
1378              {              {
1379              slotB -= md->name_entry_size;              slotB -= md->name_entry_size;
1380              if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)              if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
1381                {                {
1382                offset = GET2(slotB, 0) << 1;                offset = GET2(slotB, 0) << 1;
1383                condition = offset < offset_top &&                condition = offset < offset_top &&
# Line 1359  for (;;) Line 1395  for (;;)
1395              for (i++; i < md->name_count; i++)              for (i++; i < md->name_count; i++)
1396                {                {
1397                slotB += md->name_entry_size;                slotB += md->name_entry_size;
1398                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)                if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
1399                  {                  {
1400                  offset = GET2(slotB, 0) << 1;                  offset = GET2(slotB, 0) << 1;
1401                  condition = offset < offset_top &&                  condition = offset < offset_top &&
# Line 1374  for (;;) Line 1410  for (;;)
1410    
1411        /* Chose branch according to the condition */        /* Chose branch according to the condition */
1412    
1413        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 1 + IMM2_SIZE : GET(ecode, 1);
1414        }        }
1415    
1416      else if (condcode == OP_DEF)     /* DEFINE - always false */      else if (condcode == OP_DEF)     /* DEFINE - always false */
# Line 1466  for (;;) Line 1502  for (;;)
1502        md->offset_vector[offset+1] = (int)(eptr - md->start_subject);        md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1503        if (offset_top <= offset) offset_top = offset + 2;        if (offset_top <= offset) offset_top = offset + 2;
1504        }        }
1505      ecode += 3;      ecode += 1 + IMM2_SIZE;
1506      break;      break;
1507    
1508    
# Line 1513  for (;;) Line 1549  for (;;)
1549    
1550      case OP_ASSERT:      case OP_ASSERT:
1551      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1552        save_mark = md->mark;
1553      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1554        {        {
1555        condassert = TRUE;        condassert = TRUE;
# Line 1534  for (;;) Line 1571  for (;;)
1571    
1572        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1573        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1574          md->mark = save_mark;
1575        }        }
1576      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1577    
# Line 1557  for (;;) Line 1595  for (;;)
1595    
1596      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1597      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1598        save_mark = md->mark;
1599      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1600        {        {
1601        condassert = TRUE;        condassert = TRUE;
# Line 1567  for (;;) Line 1606  for (;;)
1606      do      do
1607        {        {
1608        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);
1609          md->mark = save_mark;
1610        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);
1611        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1612          {          {
# Line 1593  for (;;) Line 1633  for (;;)
1633      back a number of characters, not bytes. */      back a number of characters, not bytes. */
1634    
1635      case OP_REVERSE:      case OP_REVERSE:
1636  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1637      if (utf8)      if (utf)
1638        {        {
1639        i = GET(ecode, 1);        i = GET(ecode, 1);
1640        while (i-- > 0)        while (i-- > 0)
# Line 1625  for (;;) Line 1665  for (;;)
1665      function is able to force a failure. */      function is able to force a failure. */
1666    
1667      case OP_CALLOUT:      case OP_CALLOUT:
1668      if (pcre_callout != NULL)      if (PUBL(callout) != NULL)
1669        {        {
1670        pcre_callout_block cb;        PUBL(callout_block) cb;
1671        cb.version          = 2;   /* Version 1 of the callout block */        cb.version          = 2;   /* Version 1 of the callout block */
1672        cb.callout_number   = ecode[1];        cb.callout_number   = ecode[1];
1673        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1674    #ifdef COMPILE_PCRE8
1675        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1676    #else
1677          cb.subject          = (PCRE_SPTR16)md->start_subject;
1678    #endif
1679        cb.subject_length   = (int)(md->end_subject - md->start_subject);        cb.subject_length   = (int)(md->end_subject - md->start_subject);
1680        cb.start_match      = (int)(mstart - md->start_subject);        cb.start_match      = (int)(mstart - md->start_subject);
1681        cb.current_position = (int)(eptr - md->start_subject);        cb.current_position = (int)(eptr - md->start_subject);
# Line 1641  for (;;) Line 1685  for (;;)
1685        cb.capture_last     = md->capture_last;        cb.capture_last     = md->capture_last;
1686        cb.callout_data     = md->callout_data;        cb.callout_data     = md->callout_data;
1687        cb.mark             = md->nomatch_mark;        cb.mark             = md->nomatch_mark;
1688        if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);        if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);
1689        if (rrc < 0) RRETURN(rrc);        if (rrc < 0) RRETURN(rrc);
1690        }        }
1691      ecode += 2 + 2*LINK_SIZE;      ecode += 2 + 2*LINK_SIZE;
# Line 1700  for (;;) Line 1744  for (;;)
1744        else        else
1745          {          {
1746          new_recursive.offset_save =          new_recursive.offset_save =
1747            (int *)(pcre_malloc)(new_recursive.saved_max * sizeof(int));            (int *)(PUBL(malloc))(new_recursive.saved_max * sizeof(int));
1748          if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY);          if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
1749          }          }
1750        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
# Line 1715  for (;;) Line 1759  for (;;)
1759        do        do
1760          {          {
1761          if (cbegroup) md->match_function_type = MATCH_CBEGROUP;          if (cbegroup) md->match_function_type = MATCH_CBEGROUP;
1762          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,          RMATCH(eptr, callpat + PRIV(OP_lengths)[*callpat], offset_top,
1763            md, eptrb, RM6);            md, eptrb, RM6);
1764          memcpy(md->offset_vector, new_recursive.offset_save,          memcpy(md->offset_vector, new_recursive.offset_save,
1765              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
# Line 1724  for (;;) Line 1768  for (;;)
1768            {            {
1769            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
1770            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1771              (pcre_free)(new_recursive.offset_save);              (PUBL(free))(new_recursive.offset_save);
1772    
1773            /* Set where we got to in the subject, and reset the start in case            /* Set where we got to in the subject, and reset the start in case
1774            it was changed by \K. This *is* propagated back out of a recursion,            it was changed by \K. This *is* propagated back out of a recursion,
# Line 1742  for (;;) Line 1786  for (;;)
1786            {            {
1787            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1788            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1789              (pcre_free)(new_recursive.offset_save);              (PUBL(free))(new_recursive.offset_save);
1790            RRETURN(rrc);            RRETURN(rrc);
1791            }            }
1792    
# Line 1754  for (;;) Line 1798  for (;;)
1798        DPRINTF(("Recursion didn't match\n"));        DPRINTF(("Recursion didn't match\n"));
1799        md->recursive = new_recursive.prevrec;        md->recursive = new_recursive.prevrec;
1800        if (new_recursive.offset_save != stacksave)        if (new_recursive.offset_save != stacksave)
1801          (pcre_free)(new_recursive.offset_save);          (PUBL(free))(new_recursive.offset_save);
1802        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
1803        }        }
1804    
# Line 2066  for (;;) Line 2110  for (;;)
2110        be "non-word" characters. Remember the earliest consulted character for        be "non-word" characters. Remember the earliest consulted character for
2111        partial matching. */        partial matching. */
2112    
2113  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2114        if (utf8)        if (utf)
2115          {          {
2116          /* Get status of previous character */          /* Get status of previous character */
2117    
2118          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
2119            {            {
2120            USPTR lastptr = eptr - 1;            PCRE_PUCHAR lastptr = eptr - 1;
2121            while((*lastptr & 0xc0) == 0x80) lastptr--;            BACKCHAR(lastptr);
2122            if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;            if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
2123            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
2124  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2139  for (;;) Line 2183  for (;;)
2183              }              }
2184            else            else
2185  #endif  #endif
2186            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);            prev_is_word = MAX_255(eptr[-1])
2187                && ((md->ctypes[eptr[-1]] & ctype_word) != 0);
2188            }            }
2189    
2190          /* Get status of next character */          /* Get status of next character */
# Line 2162  for (;;) Line 2207  for (;;)
2207            }            }
2208          else          else
2209  #endif  #endif
2210          cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);          cur_is_word = MAX_255(*eptr)
2211              && ((md->ctypes[*eptr] & ctype_word) != 0);
2212          }          }
2213    
2214        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 2186  for (;;) Line 2232  for (;;)
2232        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2233        }        }
2234      eptr++;      eptr++;
2235      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  #ifdef SUPPORT_UTF
2236        if (utf) ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
2237    #endif
2238      ecode++;      ecode++;
2239      break;      break;
2240    
# Line 2211  for (;;) Line 2259  for (;;)
2259        }        }
2260      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2261      if (      if (
2262  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2263         c < 256 &&         c < 256 &&
2264  #endif  #endif
2265         (md->ctypes[c] & ctype_digit) != 0         (md->ctypes[c] & ctype_digit) != 0
# Line 2228  for (;;) Line 2276  for (;;)
2276        }        }
2277      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2278      if (      if (
2279  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2280         c >= 256 ||         c > 255 ||
2281  #endif  #endif
2282         (md->ctypes[c] & ctype_digit) == 0         (md->ctypes[c] & ctype_digit) == 0
2283         )         )
# Line 2245  for (;;) Line 2293  for (;;)
2293        }        }
2294      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2295      if (      if (
2296  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2297         c < 256 &&         c < 256 &&
2298  #endif  #endif
2299         (md->ctypes[c] & ctype_space) != 0         (md->ctypes[c] & ctype_space) != 0
# Line 2262  for (;;) Line 2310  for (;;)
2310        }        }
2311      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2312      if (      if (
2313  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2314         c >= 256 ||         c > 255 ||
2315  #endif  #endif
2316         (md->ctypes[c] & ctype_space) == 0         (md->ctypes[c] & ctype_space) == 0
2317         )         )
# Line 2279  for (;;) Line 2327  for (;;)
2327        }        }
2328      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2329      if (      if (
2330  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2331         c < 256 &&         c < 256 &&
2332  #endif  #endif
2333         (md->ctypes[c] & ctype_word) != 0         (md->ctypes[c] & ctype_word) != 0
# Line 2296  for (;;) Line 2344  for (;;)
2344        }        }
2345      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2346      if (      if (
2347  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2348         c >= 256 ||         c > 255 ||
2349  #endif  #endif
2350         (md->ctypes[c] & ctype_word) == 0         (md->ctypes[c] & ctype_word) == 0
2351         )         )
# Line 2475  for (;;) Line 2523  for (;;)
2523          break;          break;
2524    
2525          case PT_GC:          case PT_GC:
2526          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))          if ((ecode[2] != PRIV(ucp_gentype)[prop->chartype]) == (op == OP_PROP))
2527            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2528          break;          break;
2529    
# Line 2492  for (;;) Line 2540  for (;;)
2540          /* These are specials */          /* These are specials */
2541    
2542          case PT_ALNUM:          case PT_ALNUM:
2543          if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||          if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
2544               _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP))               PRIV(ucp_gentype)[prop->chartype] == ucp_N) == (op == OP_NOTPROP))
2545            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2546          break;          break;
2547    
2548          case PT_SPACE:    /* Perl space */          case PT_SPACE:    /* Perl space */
2549          if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||          if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
2550               c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)               c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2551                 == (op == OP_NOTPROP))                 == (op == OP_NOTPROP))
2552            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2553          break;          break;
2554    
2555          case PT_PXSPACE:  /* POSIX space */          case PT_PXSPACE:  /* POSIX space */
2556          if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||          if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
2557               c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||               c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2558               c == CHAR_FF || c == CHAR_CR)               c == CHAR_FF || c == CHAR_CR)
2559                 == (op == OP_NOTPROP))                 == (op == OP_NOTPROP))
# Line 2513  for (;;) Line 2561  for (;;)
2561          break;          break;
2562    
2563          case PT_WORD:          case PT_WORD:
2564          if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||          if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
2565               _pcre_ucp_gentype[prop->chartype] == ucp_N ||               PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
2566               c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))               c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))
2567            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2568          break;          break;
# Line 2543  for (;;) Line 2591  for (;;)
2591      while (eptr < md->end_subject)      while (eptr < md->end_subject)
2592        {        {
2593        int len = 1;        int len = 1;
2594        if (!utf8) c = *eptr; else { GETCHARLEN(c, eptr, len); }        if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
2595        if (UCD_CATEGORY(c) != ucp_M) break;        if (UCD_CATEGORY(c) != ucp_M) break;
2596        eptr += len;        eptr += len;
2597        }        }
# Line 2564  for (;;) Line 2612  for (;;)
2612      case OP_REFI:      case OP_REFI:
2613      caseless = op == OP_REFI;      caseless = op == OP_REFI;
2614      offset = GET2(ecode, 1) << 1;               /* Doubled ref number */      offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2615      ecode += 3;      ecode += 1 + IMM2_SIZE;
2616    
2617      /* If the reference is unset, there are two possibilities:      /* If the reference is unset, there are two possibilities:
2618    
# Line 2604  for (;;) Line 2652  for (;;)
2652        case OP_CRMINRANGE:        case OP_CRMINRANGE:
2653        minimize = (*ecode == OP_CRMINRANGE);        minimize = (*ecode == OP_CRMINRANGE);
2654        min = GET2(ecode, 1);        min = GET2(ecode, 1);
2655        max = GET2(ecode, 3);        max = GET2(ecode, 1 + IMM2_SIZE);
2656        if (max == 0) max = INT_MAX;        if (max == 0) max = INT_MAX;
2657        ecode += 5;        ecode += 1 + 2 * IMM2_SIZE;
2658        break;        break;
2659    
2660        default:               /* No repeat follows */        default:               /* No repeat follows */
# Line 2620  for (;;) Line 2668  for (;;)
2668        }        }
2669    
2670      /* Handle repeated back references. If the length of the reference is      /* Handle repeated back references. If the length of the reference is
2671      zero, just continue with the main loop. */      zero, just continue with the main loop. If the length is negative, it
2672        means the reference is unset in non-Java-compatible mode. If the minimum is
2673        zero, we can continue at the same level without recursion. For any other
2674        minimum, carrying on will result in NOMATCH. */
2675    
2676      if (length == 0) continue;      if (length == 0) continue;
2677        if (length < 0 && min == 0) continue;
2678    
2679      /* First, ensure the minimum number of matches are present. We get back      /* First, ensure the minimum number of matches are present. We get back
2680      the length of the reference string explicitly rather than passing the      the length of the reference string explicitly rather than passing the
# Line 2703  for (;;) Line 2755  for (;;)
2755      case OP_NCLASS:      case OP_NCLASS:
2756      case OP_CLASS:      case OP_CLASS:
2757        {        {
2758          /* The data variable is saved across frames, so the byte map needs to
2759          be stored there. */
2760    #define BYTE_MAP ((pcre_uint8 *)data)
2761        data = ecode + 1;                /* Save for matching */        data = ecode + 1;                /* Save for matching */
2762        ecode += 33;                     /* Advance past the item */        ecode += 1 + (32 / sizeof(pcre_uchar)); /* Advance past the item */
2763    
2764        switch (*ecode)        switch (*ecode)
2765          {          {
# Line 2725  for (;;) Line 2780  for (;;)
2780          case OP_CRMINRANGE:          case OP_CRMINRANGE:
2781          minimize = (*ecode == OP_CRMINRANGE);          minimize = (*ecode == OP_CRMINRANGE);
2782          min = GET2(ecode, 1);          min = GET2(ecode, 1);
2783          max = GET2(ecode, 3);          max = GET2(ecode, 1 + IMM2_SIZE);
2784          if (max == 0) max = INT_MAX;          if (max == 0) max = INT_MAX;
2785          ecode += 5;          ecode += 1 + 2 * IMM2_SIZE;
2786          break;          break;
2787    
2788          default:               /* No repeat follows */          default:               /* No repeat follows */
# Line 2737  for (;;) Line 2792  for (;;)
2792    
2793        /* First, ensure the minimum number of matches are present. */        /* First, ensure the minimum number of matches are present. */
2794    
2795  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2796        /* UTF-8 mode */        if (utf)
       if (utf8)  
2797          {          {
2798          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2799            {            {
# Line 2754  for (;;) Line 2808  for (;;)
2808              if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);              if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
2809              }              }
2810            else            else
2811              {              if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
             if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);  
             }  
2812            }            }
2813          }          }
2814        else        else
2815  #endif  #endif
2816        /* Not UTF-8 mode */        /* Not UTF mode */
2817          {          {
2818          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2819            {            {
# Line 2771  for (;;) Line 2823  for (;;)
2823              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2824              }              }
2825            c = *eptr++;            c = *eptr++;
2826            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);  #ifndef COMPILE_PCRE8
2827              if (c > 255)
2828                {
2829                if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
2830                }
2831              else
2832    #endif
2833                if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2834            }            }
2835          }          }
2836    
# Line 2785  for (;;) Line 2844  for (;;)
2844    
2845        if (minimize)        if (minimize)
2846          {          {
2847  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2848          /* UTF-8 mode */          if (utf)
         if (utf8)  
2849            {            {
2850            for (fi = min;; fi++)            for (fi = min;; fi++)
2851              {              {
# Line 2805  for (;;) Line 2863  for (;;)
2863                if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);                if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
2864                }                }
2865              else              else
2866                {                if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
               if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);  
               }  
2867              }              }
2868            }            }
2869          else          else
2870  #endif  #endif
2871          /* Not UTF-8 mode */          /* Not UTF mode */
2872            {            {
2873            for (fi = min;; fi++)            for (fi = min;; fi++)
2874              {              {
# Line 2825  for (;;) Line 2881  for (;;)
2881                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2882                }                }
2883              c = *eptr++;              c = *eptr++;
2884              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);  #ifndef COMPILE_PCRE8
2885                if (c > 255)
2886                  {
2887                  if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
2888                  }
2889                else
2890    #endif
2891                  if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2892              }              }
2893            }            }
2894          /* Control never gets here */          /* Control never gets here */
# Line 2837  for (;;) Line 2900  for (;;)
2900          {          {
2901          pp = eptr;          pp = eptr;
2902    
2903  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2904          /* UTF-8 mode */          if (utf)
         if (utf8)  
2905            {            {
2906            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2907              {              {
# Line 2855  for (;;) Line 2917  for (;;)
2917                if (op == OP_CLASS) break;                if (op == OP_CLASS) break;
2918                }                }
2919              else              else
2920                {                if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) break;
               if ((data[c/8] & (1 << (c&7))) == 0) break;  
               }  
2921              eptr += len;              eptr += len;
2922              }              }
2923            for (;;)            for (;;)
# Line 2870  for (;;) Line 2930  for (;;)
2930            }            }
2931          else          else
2932  #endif  #endif
2933            /* Not UTF-8 mode */            /* Not UTF mode */
2934            {            {
2935            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2936              {              {
# Line 2880  for (;;) Line 2940  for (;;)
2940                break;                break;
2941                }                }
2942              c = *eptr;              c = *eptr;
2943              if ((data[c/8] & (1 << (c&7))) == 0) break;  #ifndef COMPILE_PCRE8
2944                if (c > 255)
2945                  {
2946                  if (op == OP_CLASS) break;
2947                  }
2948                else
2949    #endif
2950                  if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) break;
2951              eptr++;              eptr++;
2952              }              }
2953            while (eptr >= pp)            while (eptr >= pp)
# Line 2893  for (;;) Line 2960  for (;;)
2960    
2961          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2962          }          }
2963    #undef BYTE_MAP
2964        }        }
2965      /* Control never gets here */      /* Control never gets here */
2966    
# Line 2901  for (;;) Line 2969  for (;;)
2969      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2970      mode, because Unicode properties are supported in non-UTF-8 mode. */      mode, because Unicode properties are supported in non-UTF-8 mode. */
2971    
2972  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2973      case OP_XCLASS:      case OP_XCLASS:
2974        {        {
2975        data = ecode + 1 + LINK_SIZE;                /* Save for matching */        data = ecode + 1 + LINK_SIZE;                /* Save for matching */
# Line 2926  for (;;) Line 2994  for (;;)
2994          case OP_CRMINRANGE:          case OP_CRMINRANGE:
2995          minimize = (*ecode == OP_CRMINRANGE);          minimize = (*ecode == OP_CRMINRANGE);
2996          min = GET2(ecode, 1);          min = GET2(ecode, 1);
2997          max = GET2(ecode, 3);          max = GET2(ecode, 1 + IMM2_SIZE);
2998          if (max == 0) max = INT_MAX;          if (max == 0) max = INT_MAX;
2999          ecode += 5;          ecode += 1 + 2 * IMM2_SIZE;
3000          break;          break;
3001    
3002          default:               /* No repeat follows */          default:               /* No repeat follows */
# Line 2946  for (;;) Line 3014  for (;;)
3014            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
3015            }            }
3016          GETCHARINCTEST(c, eptr);          GETCHARINCTEST(c, eptr);
3017          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!PRIV(xclass)(c, data, utf)) RRETURN(MATCH_NOMATCH);
3018          }          }
3019    
3020        /* If max == min we can continue with the main loop without the        /* If max == min we can continue with the main loop without the
# Line 2970  for (;;) Line 3038  for (;;)
3038              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3039              }              }
3040            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3041            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!PRIV(xclass)(c, data, utf)) RRETURN(MATCH_NOMATCH);
3042            }            }
3043          /* Control never gets here */          /* Control never gets here */
3044          }          }
# Line 2988  for (;;) Line 3056  for (;;)
3056              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3057              break;              break;
3058              }              }
3059    #ifdef SUPPORT_UTF
3060            GETCHARLENTEST(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
3061            if (!_pcre_xclass(c, data)) break;  #else
3062              c = *eptr;
3063    #endif
3064              if (!PRIV(xclass)(c, data, utf)) break;
3065            eptr += len;            eptr += len;
3066            }            }
3067          for(;;)          for(;;)
# Line 2997  for (;;) Line 3069  for (;;)
3069            RMATCH(eptr, ecode, offset_top, md, eptrb, RM21);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM21);
3070            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3071            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3072            if (utf8) BACKCHAR(eptr);  #ifdef SUPPORT_UTF
3073              if (utf) BACKCHAR(eptr);
3074    #endif
3075            }            }
3076          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
3077          }          }
# Line 3009  for (;;) Line 3083  for (;;)
3083      /* Match a single character, casefully */      /* Match a single character, casefully */
3084    
3085      case OP_CHAR:      case OP_CHAR:
3086  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3087      if (utf8)      if (utf)
3088        {        {
3089        length = 1;        length = 1;
3090        ecode++;        ecode++;
# Line 3024  for (;;) Line 3098  for (;;)
3098        }        }
3099      else      else
3100  #endif  #endif
3101        /* Not UTF mode */
     /* Non-UTF-8 mode */  
3102        {        {
3103        if (md->end_subject - eptr < 1)        if (md->end_subject - eptr < 1)
3104          {          {
# Line 3037  for (;;) Line 3110  for (;;)
3110        }        }
3111      break;      break;
3112    
3113      /* Match a single character, caselessly. If we are at the end of the      /* Match a single character, caselessly. If we are at the end of the
3114      subject, give up immediately. */      subject, give up immediately. */
3115    
3116      case OP_CHARI:      case OP_CHARI:
3117      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
3118        {        {
3119        SCHECK_PARTIAL();        SCHECK_PARTIAL();
3120        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
3121        }        }
3122    
3123  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3124      if (utf8)      if (utf)
3125        {        {
3126        length = 1;        length = 1;
3127        ecode++;        ecode++;
3128        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
3129    
3130        /* 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
3131        we know that its other case must also be one byte long, so we can use the        we know that its other case must also be one byte long, so we can use the
3132        fast lookup table. We know that there is at least one byte left in the        fast lookup table. We know that there is at least one byte left in the
3133        subject. */        subject. */
3134    
3135        if (fc < 128)        if (fc < 128)
3136          {          {
3137          if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (md->lcc[fc]
3138                != TABLE_GET(*eptr, md->lcc, *eptr)) RRETURN(MATCH_NOMATCH);
3139            ecode++;
3140            eptr++;
3141          }          }
3142    
3143        /* Otherwise we must pick up the subject character. Note that we cannot        /* Otherwise we must pick up the subject character. Note that we cannot
# Line 3087  for (;;) Line 3163  for (;;)
3163          }          }
3164        }        }
3165      else      else
3166  #endif   /* SUPPORT_UTF8 */  #endif   /* SUPPORT_UTF */
3167    
3168      /* Non-UTF-8 mode */      /* Not UTF mode */
3169        {        {
3170        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (TABLE_GET(ecode[1], md->lcc, ecode[1])
3171              != TABLE_GET(*eptr, md->lcc, *eptr)) RRETURN(MATCH_NOMATCH);
3172          eptr++;
3173        ecode += 2;        ecode += 2;
3174        }        }
3175      break;      break;
# Line 3101  for (;;) Line 3179  for (;;)
3179      case OP_EXACT:      case OP_EXACT:
3180      case OP_EXACTI:      case OP_EXACTI:
3181      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
3182      ecode += 3;      ecode += 1 + IMM2_SIZE;
3183      goto REPEATCHAR;      goto REPEATCHAR;
3184    
3185      case OP_POSUPTO:      case OP_POSUPTO:
# Line 3116  for (;;) Line 3194  for (;;)
3194      min = 0;      min = 0;
3195      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3196      minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI;      minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI;
3197      ecode += 3;      ecode += 1 + IMM2_SIZE;
3198      goto REPEATCHAR;      goto REPEATCHAR;
3199    
3200      case OP_POSSTAR:      case OP_POSSTAR:
# Line 3164  for (;;) Line 3242  for (;;)
3242      /* Common code for all repeated single-character matches. */      /* Common code for all repeated single-character matches. */
3243    
3244      REPEATCHAR:      REPEATCHAR:
3245  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3246      if (utf8)      if (utf)
3247        {        {
3248        length = 1;        length = 1;
3249        charptr = ecode;        charptr = ecode;
# Line 3181  for (;;) Line 3259  for (;;)
3259          unsigned int othercase;          unsigned int othercase;
3260          if (op >= OP_STARI &&     /* Caseless */          if (op >= OP_STARI &&     /* Caseless */
3261              (othercase = UCD_OTHERCASE(fc)) != fc)              (othercase = UCD_OTHERCASE(fc)) != fc)
3262            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = PRIV(ord2utf)(othercase, occhars);
3263          else oclength = 0;          else oclength = 0;
3264  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3265    
3266          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3267            {            {
3268            if (eptr <= md->end_subject - length &&            if (eptr <= md->end_subject - length &&
3269              memcmp(eptr, charptr, length) == 0) eptr += length;              memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length;
3270  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3271            else if (oclength > 0 &&            else if (oclength > 0 &&
3272                     eptr <= md->end_subject - oclength &&                     eptr <= md->end_subject - oclength &&
3273                     memcmp(eptr, occhars, oclength) == 0) eptr += oclength;                     memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength;
3274  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3275            else            else
3276              {              {
# Line 3211  for (;;) Line 3289  for (;;)
3289              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3290              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3291              if (eptr <= md->end_subject - length &&              if (eptr <= md->end_subject - length &&
3292                memcmp(eptr, charptr, length) == 0) eptr += length;                memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length;
3293  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3294              else if (oclength > 0 &&              else if (oclength > 0 &&
3295                       eptr <= md->end_subject - oclength &&                       eptr <= md->end_subject - oclength &&
3296                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;                       memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength;
3297  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3298              else              else
3299                {                {
# Line 3232  for (;;) Line 3310  for (;;)
3310            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3311              {              {
3312              if (eptr <= md->end_subject - length &&              if (eptr <= md->end_subject - length &&
3313                  memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length;
3314  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3315              else if (oclength > 0 &&              else if (oclength > 0 &&
3316                       eptr <= md->end_subject - oclength &&                       eptr <= md->end_subject - oclength &&
3317                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;                       memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength;
3318  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3319              else              else
3320                {                {
# Line 3268  for (;;) Line 3346  for (;;)
3346        value of fc will always be < 128. */        value of fc will always be < 128. */
3347        }        }
3348      else      else
3349  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF */
3350          /* When not in UTF-8 mode, load a single-byte character. */
3351      /* When not in UTF-8 mode, load a single-byte character. */        fc = *ecode++;
   
     fc = *ecode++;  
3352    
3353      /* 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 one character, though we may
3354      may not be in UTF-8 mode. The code is duplicated for the caseless and      or may not be in UTF mode. The code is duplicated for the caseless and
3355      caseful cases, for speed, since matching characters is likely to be quite      caseful cases, for speed, since matching characters is likely to be quite
3356      common. First, ensure the minimum number of matches are present. If min =      common. First, ensure the minimum number of matches are present. If min =
3357      max, continue at the same level without recursing. Otherwise, if      max, continue at the same level without recursing. Otherwise, if
# Line 3288  for (;;) Line 3364  for (;;)
3364    
3365      if (op >= OP_STARI)  /* Caseless */      if (op >= OP_STARI)  /* Caseless */
3366        {        {
3367        fc = md->lcc[fc];  #ifdef COMPILE_PCRE8
3368          /* fc must be < 128 if UTF is enabled. */
3369          foc = md->fcc[fc];
3370    #else
3371    #ifdef SUPPORT_UTF
3372    #ifdef SUPPORT_UCP
3373          if (utf && fc > 127)
3374            foc = UCD_OTHERCASE(fc);
3375    #else
3376          if (utf && fc > 127)
3377            foc = fc;
3378    #endif /* SUPPORT_UCP */
3379          else
3380    #endif /* SUPPORT_UTF */
3381            foc = TABLE_GET(fc, md->fcc, fc);
3382    #endif /* COMPILE_PCRE8 */
3383    
3384        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
3385          {          {
3386          if (eptr >= md->end_subject)          if (eptr >= md->end_subject)
# Line 3296  for (;;) Line 3388  for (;;)
3388            SCHECK_PARTIAL();            SCHECK_PARTIAL();
3389            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
3390            }            }
3391          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != *eptr && foc != *eptr) RRETURN(MATCH_NOMATCH);
3392            eptr++;
3393          }          }
3394        if (min == max) continue;        if (min == max) continue;
3395        if (minimize)        if (minimize)
# Line 3311  for (;;) Line 3404  for (;;)
3404              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3405              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3406              }              }
3407            if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc != *eptr && foc != *eptr) RRETURN(MATCH_NOMATCH);
3408              eptr++;
3409            }            }
3410          /* Control never gets here */          /* Control never gets here */
3411          }          }
# Line 3325  for (;;) Line 3419  for (;;)
3419              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3420              break;              break;
3421              }              }
3422            if (fc != md->lcc[*eptr]) break;            if (fc != *eptr && foc != *eptr) break;
3423            eptr++;            eptr++;
3424            }            }
3425    
# Line 3414  for (;;) Line 3508  for (;;)
3508      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
3509      if (op == OP_NOTI)         /* The caseless case */      if (op == OP_NOTI)         /* The caseless case */
3510        {        {
3511  #ifdef SUPPORT_UTF8        register int ch, och;
3512        if (c < 256)        ch = *ecode++;
3513  #endif  #ifdef COMPILE_PCRE8
3514        c = md->lcc[c];        /* ch must be < 128 if UTF is enabled. */
3515        if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH);        och = md->fcc[ch];
3516    #else
3517    #ifdef SUPPORT_UTF
3518    #ifdef SUPPORT_UCP
3519          if (utf && ch > 127)
3520            och = UCD_OTHERCASE(ch);
3521    #else
3522          if (utf && ch > 127)
3523            och = ch;
3524    #endif /* SUPPORT_UCP */
3525          else
3526    #endif /* SUPPORT_UTF */
3527            och = TABLE_GET(ch, md->fcc, ch);
3528    #endif /* COMPILE_PCRE8 */
3529          if (ch == c || och == c) RRETURN(MATCH_NOMATCH);
3530        }        }
3531      else    /* Caseful */      else    /* Caseful */
3532        {        {
# Line 3436  for (;;) Line 3544  for (;;)
3544      case OP_NOTEXACT:      case OP_NOTEXACT:
3545      case OP_NOTEXACTI:      case OP_NOTEXACTI:
3546      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
3547      ecode += 3;      ecode += 1 + IMM2_SIZE;
3548      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3549    
3550      case OP_NOTUPTO:      case OP_NOTUPTO:
# Line 3446  for (;;) Line 3554  for (;;)
3554      min = 0;      min = 0;
3555      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3556      minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI;      minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI;
3557      ecode += 3;      ecode += 1 + IMM2_SIZE;
3558      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3559    
3560      case OP_NOTPOSSTAR:      case OP_NOTPOSSTAR:
# Line 3478  for (;;) Line 3586  for (;;)
3586      possessive = TRUE;      possessive = TRUE;
3587      min = 0;      min = 0;
3588      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3589      ecode += 3;      ecode += 1 + IMM2_SIZE;
3590      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3591    
3592      case OP_NOTSTAR:      case OP_NOTSTAR:
# Line 3517  for (;;) Line 3625  for (;;)
3625    
3626      if (op >= OP_NOTSTARI)     /* Caseless */      if (op >= OP_NOTSTARI)     /* Caseless */
3627        {        {
3628        fc = md->lcc[fc];  #ifdef COMPILE_PCRE8
3629          /* fc must be < 128 if UTF is enabled. */
3630          foc = md->fcc[fc];
3631    #else
3632    #ifdef SUPPORT_UTF
3633    #ifdef SUPPORT_UCP
3634          if (utf && fc > 127)
3635            foc = UCD_OTHERCASE(fc);
3636    #else
3637          if (utf && fc > 127)
3638            foc = fc;
3639    #endif /* SUPPORT_UCP */
3640          else
3641    #endif /* SUPPORT_UTF */
3642            foc = TABLE_GET(fc, md->fcc, fc);
3643    #endif /* COMPILE_PCRE8 */
3644    
3645  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3646        /* UTF-8 mode */        if (utf)
       if (utf8)  
3647          {          {
3648          register unsigned int d;          register unsigned int d;
3649          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
# Line 3532  for (;;) Line 3654  for (;;)
3654              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3655              }              }
3656            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3657            if (d < 256) d = md->lcc[d];            if (fc == d || foc == d) RRETURN(MATCH_NOMATCH);
           if (fc == d) RRETURN(MATCH_NOMATCH);  
3658            }            }
3659          }          }
3660        else        else
3661  #endif  #endif
3662          /* Not UTF mode */
       /* Not UTF-8 mode */  
3663          {          {
3664          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3665            {            {
# Line 3548  for (;;) Line 3668  for (;;)
3668              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3669              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3670              }              }
3671            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == *eptr || foc == *eptr) RRETURN(MATCH_NOMATCH);
3672              eptr++;
3673            }            }
3674          }          }
3675    
# Line 3556  for (;;) Line 3677  for (;;)
3677    
3678        if (minimize)        if (minimize)
3679          {          {
3680  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3681          /* UTF-8 mode */          if (utf)
         if (utf8)  
3682            {            {
3683            register unsigned int d;            register unsigned int d;
3684            for (fi = min;; fi++)            for (fi = min;; fi++)
# Line 3572  for (;;) Line 3692  for (;;)
3692                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3693                }                }
3694              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3695              if (d < 256) d = md->lcc[d];              if (fc == d || foc == d) RRETURN(MATCH_NOMATCH);
             if (fc == d) RRETURN(MATCH_NOMATCH);  
3696              }              }
3697            }            }
3698          else          else
3699  #endif  #endif
3700          /* Not UTF-8 mode */          /* Not UTF mode */
3701            {            {
3702            for (fi = min;; fi++)            for (fi = min;; fi++)
3703              {              {
# Line 3590  for (;;) Line 3709  for (;;)
3709                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3710                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3711                }                }
3712              if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);              if (fc == *eptr || foc == *eptr) RRETURN(MATCH_NOMATCH);
3713                eptr++;
3714              }              }
3715            }            }
3716          /* Control never gets here */          /* Control never gets here */
# Line 3602  for (;;) Line 3722  for (;;)
3722          {          {
3723          pp = eptr;          pp = eptr;
3724    
3725  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3726          /* UTF-8 mode */          if (utf)
         if (utf8)  
3727            {            {
3728            register unsigned int d;            register unsigned int d;
3729            for (i = min; i < max; i++)            for (i = min; i < max; i++)
# Line 3616  for (;;) Line 3735  for (;;)
3735                break;                break;
3736                }                }
3737              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3738              if (d < 256) d = md->lcc[d];              if (fc == d || foc == d) break;
             if (fc == d) break;  
3739              eptr += len;              eptr += len;
3740              }              }
3741          if (possessive) continue;            if (possessive) continue;
3742          for(;;)            for(;;)
3743              {              {
3744              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);
3745              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
# Line 3631  for (;;) Line 3749  for (;;)
3749            }            }
3750          else          else
3751  #endif  #endif
3752          /* Not UTF-8 mode */          /* Not UTF mode */
3753            {            {
3754            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3755              {              {
# Line 3640  for (;;) Line 3758  for (;;)
3758                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3759                break;                break;
3760                }                }
3761              if (fc == md->lcc[*eptr]) break;              if (fc == *eptr || foc == *eptr) break;
3762              eptr++;              eptr++;
3763              }              }
3764            if (possessive) continue;            if (possessive) continue;
# Line 3661  for (;;) Line 3779  for (;;)
3779    
3780      else      else
3781        {        {
3782  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3783        /* UTF-8 mode */        if (utf)
       if (utf8)  
3784          {          {
3785          register unsigned int d;          register unsigned int d;
3786          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
# Line 3679  for (;;) Line 3796  for (;;)
3796          }          }
3797        else        else
3798  #endif  #endif
3799        /* Not UTF-8 mode */        /* Not UTF mode */
3800          {          {
3801          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3802            {            {
# Line 3696  for (;;) Line 3813  for (;;)
3813    
3814        if (minimize)        if (minimize)
3815          {          {
3816  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3817          /* UTF-8 mode */          if (utf)
         if (utf8)  
3818            {            {
3819            register unsigned int d;            register unsigned int d;
3820            for (fi = min;; fi++)            for (fi = min;; fi++)
# Line 3717  for (;;) Line 3833  for (;;)
3833            }            }
3834          else          else
3835  #endif  #endif
3836          /* Not UTF-8 mode */          /* Not UTF mode */
3837            {            {
3838            for (fi = min;; fi++)            for (fi = min;; fi++)
3839              {              {
# Line 3741  for (;;) Line 3857  for (;;)
3857          {          {
3858          pp = eptr;          pp = eptr;
3859    
3860  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3861          /* UTF-8 mode */          if (utf)
         if (utf8)  
3862            {            {
3863            register unsigned int d;            register unsigned int d;
3864            for (i = min; i < max; i++)            for (i = min; i < max; i++)
# Line 3769  for (;;) Line 3884  for (;;)
3884            }            }
3885          else          else
3886  #endif  #endif
3887          /* Not UTF-8 mode */          /* Not UTF mode */
3888            {            {
3889            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3890              {              {
# Line 3802  for (;;) Line 3917  for (;;)
3917      case OP_TYPEEXACT:      case OP_TYPEEXACT:
3918      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
3919      minimize = TRUE;      minimize = TRUE;
3920      ecode += 3;      ecode += 1 + IMM2_SIZE;
3921      goto REPEATTYPE;      goto REPEATTYPE;
3922    
3923      case OP_TYPEUPTO:      case OP_TYPEUPTO:
# Line 3810  for (;;) Line 3925  for (;;)
3925      min = 0;      min = 0;
3926      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3927      minimize = *ecode == OP_TYPEMINUPTO;      minimize = *ecode == OP_TYPEMINUPTO;
3928      ecode += 3;      ecode += 1 + IMM2_SIZE;
3929      goto REPEATTYPE;      goto REPEATTYPE;
3930    
3931      case OP_TYPEPOSSTAR:      case OP_TYPEPOSSTAR:
# Line 3838  for (;;) Line 3953  for (;;)
3953      possessive = TRUE;      possessive = TRUE;
3954      min = 0;      min = 0;
3955      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3956      ecode += 3;      ecode += 1 + IMM2_SIZE;
3957      goto REPEATTYPE;      goto REPEATTYPE;
3958    
3959      case OP_TYPESTAR:      case OP_TYPESTAR:
# Line 4045  for (;;) Line 4160  for (;;)
4160            while (eptr < md->end_subject)            while (eptr < md->end_subject)
4161              {              {
4162              int len = 1;              int len = 1;
4163              if (!utf8) c = *eptr; else { GETCHARLEN(c, eptr, len); }              if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
4164              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
4165              eptr += len;              eptr += len;
4166              }              }
# Line 4057  for (;;) Line 4172  for (;;)
4172    
4173  /* Handle all other cases when the coding is UTF-8 */  /* Handle all other cases when the coding is UTF-8 */
4174    
4175  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4176        if (utf8) switch(ctype)        if (utf) switch(ctype)
4177          {          {
4178          case OP_ANY:          case OP_ANY:
4179          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
# Line 4070  for (;;) Line 4185  for (;;)
4185              }              }
4186            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
4187            eptr++;            eptr++;
4188            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4189            }            }
4190          break;          break;
4191    
# Line 4083  for (;;) Line 4198  for (;;)
4198              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4199              }              }
4200            eptr++;            eptr++;
4201            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4202            }            }
4203          break;          break;
4204    
# Line 4265  for (;;) Line 4380  for (;;)
4380              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4381              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4382              }              }
4383            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)            if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_digit) == 0)
4384              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4385              eptr++;
4386            /* 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 */
4387            }            }
4388          break;          break;
# Line 4281  for (;;) Line 4397  for (;;)
4397              }              }
4398            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
4399              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4400            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            eptr++;
4401              ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4402            }            }
4403          break;          break;
4404    
# Line 4293  for (;;) Line 4410  for (;;)
4410              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4411              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4412              }              }
4413            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)            if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_space) == 0)
4414              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4415              eptr++;
4416            /* 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 */
4417            }            }
4418          break;          break;
# Line 4309  for (;;) Line 4427  for (;;)
4427              }              }
4428            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)
4429              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4430            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            eptr++;
4431              ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4432            }            }
4433          break;          break;
4434    
# Line 4321  for (;;) Line 4440  for (;;)
4440              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4441              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4442              }              }
4443            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)            if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_word) == 0)
4444              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4445              eptr++;
4446            /* 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 */
4447            }            }
4448          break;          break;
# Line 4332  for (;;) Line 4452  for (;;)
4452          }  /* End switch(ctype) */          }  /* End switch(ctype) */
4453    
4454        else        else
4455  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF */
4456    
4457        /* Code for the non-UTF-8 case for minimum matching of operators other        /* Code for the non-UTF-8 case for minimum matching of operators other
4458        than OP_PROP and OP_NOTPROP. */        than OP_PROP and OP_NOTPROP. */
# Line 4392  for (;;) Line 4512  for (;;)
4512              case 0x000b:              case 0x000b:
4513              case 0x000c:              case 0x000c:
4514              case 0x0085:              case 0x0085:
4515    #ifdef COMPILE_PCRE16
4516                case 0x2028:
4517                case 0x2029:
4518    #endif
4519              if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);              if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4520              break;              break;
4521              }              }
# Line 4412  for (;;) Line 4536  for (;;)
4536              case 0x09:      /* HT */              case 0x09:      /* HT */
4537              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
4538              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
4539    #ifdef COMPILE_PCRE16
4540                case 0x1680:    /* OGHAM SPACE MARK */
4541                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
4542                case 0x2000:    /* EN QUAD */
4543                case 0x2001:    /* EM QUAD */
4544                case 0x2002:    /* EN SPACE */
4545                case 0x2003:    /* EM SPACE */
4546                case 0x2004:    /* THREE-PER-EM SPACE */
4547                case 0x2005:    /* FOUR-PER-EM SPACE */
4548                case 0x2006:    /* SIX-PER-EM SPACE */
4549                case 0x2007:    /* FIGURE SPACE */
4550                case 0x2008:    /* PUNCTUATION SPACE */
4551                case 0x2009:    /* THIN SPACE */
4552                case 0x200A:    /* HAIR SPACE */
4553                case 0x202f:    /* NARROW NO-BREAK SPACE */
4554                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4555                case 0x3000:    /* IDEOGRAPHIC SPACE */
4556    #endif
4557              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4558              }              }
4559            }            }
# Line 4431  for (;;) Line 4573  for (;;)
4573              case 0x09:      /* HT */              case 0x09:      /* HT */
4574              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
4575              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
4576    #ifdef COMPILE_PCRE16
4577                case 0x1680:    /* OGHAM SPACE MARK */
4578                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
4579                case 0x2000:    /* EN QUAD */
4580                case 0x2001:    /* EM QUAD */
4581                case 0x2002:    /* EN SPACE */
4582                case 0x2003:    /* EM SPACE */
4583                case 0x2004:    /* THREE-PER-EM SPACE */
4584                case 0x2005:    /* FOUR-PER-EM SPACE */
4585                case 0x2006:    /* SIX-PER-EM SPACE */
4586                case 0x2007:    /* FIGURE SPACE */
4587                case 0x2008:    /* PUNCTUATION SPACE */
4588                case 0x2009:    /* THIN SPACE */
4589                case 0x200A:    /* HAIR SPACE */
4590                case 0x202f:    /* NARROW NO-BREAK SPACE */
4591                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4592                case 0x3000:    /* IDEOGRAPHIC SPACE */
4593    #endif
4594              break;              break;
4595              }              }
4596            }            }
# Line 4452  for (;;) Line 4612  for (;;)
4612              case 0x0c:      /* FF */              case 0x0c:      /* FF */
4613              case 0x0d:      /* CR */              case 0x0d:      /* CR */
4614              case 0x85:      /* NEL */              case 0x85:      /* NEL */
4615    #ifdef COMPILE_PCRE16
4616                case 0x2028:    /* LINE SEPARATOR */
4617                case 0x2029:    /* PARAGRAPH SEPARATOR */
4618    #endif
4619              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4620              }              }
4621            }            }
# Line 4473  for (;;) Line 4637  for (;;)
4637              case 0x0c:      /* FF */              case 0x0c:      /* FF */
4638              case 0x0d:      /* CR */              case 0x0d:      /* CR */
4639              case 0x85:      /* NEL */              case 0x85:      /* NEL */
4640    #ifdef COMPILE_PCRE16
4641                case 0x2028:    /* LINE SEPARATOR */
4642                case 0x2029:    /* PARAGRAPH SEPARATOR */
4643    #endif
4644              break;              break;
4645              }              }
4646            }            }
# Line 4486  for (;;) Line 4654  for (;;)
4654              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4655              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4656              }              }
4657            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_digit) != 0)
4658                RRETURN(MATCH_NOMATCH);
4659              eptr++;
4660            }            }
4661          break;          break;
4662    
# Line 4498  for (;;) Line 4668  for (;;)
4668              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4669              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4670              }              }
4671            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_digit) == 0)
4672                RRETURN(MATCH_NOMATCH);
4673              eptr++;
4674            }            }
4675          break;          break;
4676    
# Line 4510  for (;;) Line 4682  for (;;)
4682              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4683              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4684              }              }
4685            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_space) != 0)
4686                RRETURN(MATCH_NOMATCH);
4687              eptr++;
4688            }            }
4689          break;          break;
4690    
# Line 4522  for (;;) Line 4696  for (;;)
4696              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4697              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4698              }              }
4699            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_space) == 0)
4700                RRETURN(MATCH_NOMATCH);
4701              eptr++;
4702            }            }
4703          break;          break;
4704    
# Line 4534  for (;;) Line 4710  for (;;)
4710              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4711              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4712              }              }
4713            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_word) != 0)
4714              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4715              eptr++;
4716            }            }
4717          break;          break;
4718    
# Line 4547  for (;;) Line 4724  for (;;)
4724              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4725              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4726              }              }
4727            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_word) == 0)
4728              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4729              eptr++;
4730            }            }
4731          break;          break;
4732    
# Line 4766  for (;;) Line 4944  for (;;)
4944            while (eptr < md->end_subject)            while (eptr < md->end_subject)
4945              {              {
4946              int len = 1;              int len = 1;
4947              if (!utf8) c = *eptr; else { GETCHARLEN(c, eptr, len); }              if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
4948              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
4949              eptr += len;              eptr += len;
4950              }              }
# Line 4775  for (;;) Line 4953  for (;;)
4953        else        else
4954  #endif     /* SUPPORT_UCP */  #endif     /* SUPPORT_UCP */
4955    
4956  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4957        /* UTF-8 mode */        if (utf)
       if (utf8)  
4958          {          {
4959          for (fi = min;; fi++)          for (fi = min;; fi++)
4960            {            {
# Line 4919  for (;;) Line 5096  for (;;)
5096              break;              break;
5097    
5098              case OP_WHITESPACE:              case OP_WHITESPACE:
5099              if  (c >= 256 || (md->ctypes[c] & ctype_space) == 0)              if (c >= 256 || (md->ctypes[c] & ctype_space) == 0)
5100                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
5101              break;              break;
5102    
# Line 4940  for (;;) Line 5117  for (;;)
5117          }          }
5118        else        else
5119  #endif  #endif
5120        /* Not UTF-8 mode */        /* Not UTF mode */
5121          {          {
5122          for (fi = min;; fi++)          for (fi = min;; fi++)
5123            {            {
# Line 4976  for (;;) Line 5153  for (;;)
5153                case 0x000b:                case 0x000b:
5154                case 0x000c:                case 0x000c:
5155                case 0x0085:                case 0x0085:
5156    #ifdef COMPILE_PCRE16
5157                  case 0x2028:
5158                  case 0x2029:
5159    #endif
5160                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
5161                break;                break;
5162                }                }
# Line 4988  for (;;) Line 5169  for (;;)
5169                case 0x09:      /* HT */                case 0x09:      /* HT */
5170                case 0x20:      /* SPACE */                case 0x20:      /* SPACE */
5171                case 0xa0:      /* NBSP */                case 0xa0:      /* NBSP */
5172    #ifdef COMPILE_PCRE16
5173                  case 0x1680:    /* OGHAM SPACE MARK */
5174                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
5175                  case 0x2000:    /* EN QUAD */
5176                  case 0x2001:    /* EM QUAD */
5177                  case 0x2002:    /* EN SPACE */
5178                  case 0x2003:    /* EM SPACE */
5179                  case 0x2004:    /* THREE-PER-EM SPACE */
5180                  case 0x2005:    /* FOUR-PER-EM SPACE */
5181                  case 0x2006:    /* SIX-PER-EM SPACE */
5182                  case 0x2007:    /* FIGURE SPACE */
5183                  case 0x2008:    /* PUNCTUATION SPACE */
5184                  case 0x2009:    /* THIN SPACE */
5185                  case 0x200A:    /* HAIR SPACE */
5186                  case 0x202f:    /* NARROW NO-BREAK SPACE */
5187                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
5188                  case 0x3000:    /* IDEOGRAPHIC SPACE */
5189    #endif
5190                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
5191                }                }
5192              break;              break;
# Line 4999  for (;;) Line 5198  for (;;)
5198                case 0x09:      /* HT */                case 0x09:      /* HT */
5199                case 0x20:      /* SPACE */                case 0x20:      /* SPACE */
5200                case 0xa0:      /* NBSP */                case 0xa0:      /* NBSP */
5201    #ifdef COMPILE_PCRE16
5202                  case 0x1680:    /* OGHAM SPACE MARK */
5203                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
5204                  case 0x2000:    /* EN QUAD */
5205                  case 0x2001:    /* EM QUAD */
5206                  case 0x2002:    /* EN SPACE */
5207                  case 0x2003:    /* EM SPACE */
5208                  case 0x2004:    /* THREE-PER-EM SPACE */
5209                  case 0x2005:    /* FOUR-PER-EM SPACE */
5210                  case 0x2006:    /* SIX-PER-EM SPACE */
5211                  case 0x2007:    /* FIGURE SPACE */
5212                  case 0x2008:    /* PUNCTUATION SPACE */
5213                  case 0x2009:    /* THIN SPACE */
5214                  case 0x200A:    /* HAIR SPACE */
5215                  case 0x202f:    /* NARROW NO-BREAK SPACE */
5216                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
5217                  case 0x3000:    /* IDEOGRAPHIC SPACE */
5218    #endif
5219                break;                break;
5220                }                }
5221              break;              break;
# Line 5012  for (;;) Line 5229  for (;;)
5229                case 0x0c:      /* FF */                case 0x0c:      /* FF */
5230                case 0x0d:      /* CR */                case 0x0d:      /* CR */
5231                case 0x85:      /* NEL */                case 0x85:      /* NEL */
5232    #ifdef COMPILE_PCRE16
5233                  case 0x2028:    /* LINE SEPARATOR */
5234                  case 0x2029:    /* PARAGRAPH SEPARATOR */
5235    #endif
5236                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
5237                }                }
5238              break;              break;
# Line 5025  for (;;) Line 5246  for (;;)
5246                case 0x0c:      /* FF */                case 0x0c:      /* FF */
5247                case 0x0d:      /* CR */                case 0x0d:      /* CR */
5248                case 0x85:      /* NEL */                case 0x85:      /* NEL */
5249    #ifdef COMPILE_PCRE16
5250                  case 0x2028:    /* LINE SEPARATOR */
5251                  case 0x2029:    /* PARAGRAPH SEPARATOR */
5252    #endif
5253                break;                break;
5254                }                }
5255              break;              break;
5256    
5257              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
5258              if ((md->ctypes[c] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);              if (MAX_255(c) && (md->ctypes[c] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
5259              break;              break;
5260    
5261              case OP_DIGIT:              case OP_DIGIT:
5262              if ((md->ctypes[c] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);              if (!MAX_255(c) || (md->ctypes[c] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
5263              break;              break;
5264    
5265              case OP_NOT_WHITESPACE:              case OP_NOT_WHITESPACE:
5266              if ((md->ctypes[c] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);              if (MAX_255(c) && (md->ctypes[c] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
5267              break;              break;
5268    
5269              case OP_WHITESPACE:              case OP_WHITESPACE:
5270              if  ((md->ctypes[c] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);              if (!MAX_255(c) || (md->ctypes[c] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
5271              break;              break;
5272    
5273              case OP_NOT_WORDCHAR:              case OP_NOT_WORDCHAR:
5274              if ((md->ctypes[c] & ctype_word) != 0) RRETURN(MATCH_NOMATCH);              if (MAX_255(c) && (md->ctypes[c] & ctype_word) != 0) RRETURN(MATCH_NOMATCH);
5275              break;              break;
5276    
5277              case OP_WORDCHAR:              case OP_WORDCHAR:
5278              if ((md->ctypes[c] & ctype_word) == 0) RRETURN(MATCH_NOMATCH);              if (!MAX_255(c) || (md->ctypes[c] & ctype_word) == 0) RRETURN(MATCH_NOMATCH);
5279              break;              break;
5280    
5281              default:              default:
# Line 5239  for (;;) Line 5464  for (;;)
5464            RMATCH(eptr, ecode, offset_top, md, eptrb, RM44);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM44);
5465            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5466            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5467            if (utf8) BACKCHAR(eptr);            if (utf) BACKCHAR(eptr);
5468            }            }
5469          }          }
5470    
# Line 5256  for (;;) Line 5481  for (;;)
5481              SCHECK_PARTIAL();              SCHECK_PARTIAL();
5482              break;              break;
5483              }              }
5484            if (!utf8) c = *eptr; else { GETCHARLEN(c, eptr, len); }            if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
5485            if (UCD_CATEGORY(c) == ucp_M) break;            if (UCD_CATEGORY(c) == ucp_M) break;
5486            eptr += len;            eptr += len;
5487            while (eptr < md->end_subject)            while (eptr < md->end_subject)
5488              {              {
5489              len = 1;              len = 1;
5490              if (!utf8) c = *eptr; else { GETCHARLEN(c, eptr, len); }              if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
5491              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
5492              eptr += len;              eptr += len;
5493              }              }
# Line 5279  for (;;) Line 5504  for (;;)
5504            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5505            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
5506              {              {
5507              if (!utf8) c = *eptr; else              if (!utf) c = *eptr; else
5508                {                {
5509                BACKCHAR(eptr);                BACKCHAR(eptr);
5510                GETCHAR(c, eptr);                GETCHAR(c, eptr);
# Line 5293  for (;;) Line 5518  for (;;)
5518        else        else
5519  #endif   /* SUPPORT_UCP */  #endif   /* SUPPORT_UCP */
5520    
5521  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
5522        /* UTF-8 mode */        if (utf)
   
       if (utf8)  
5523          {          {
5524          switch(ctype)          switch(ctype)
5525            {            {
# Line 5312  for (;;) Line 5535  for (;;)
5535                  }                  }
5536                if (IS_NEWLINE(eptr)) break;                if (IS_NEWLINE(eptr)) break;
5537                eptr++;                eptr++;
5538                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5539                }                }
5540              }              }
5541    
# Line 5329  for (;;) Line 5552  for (;;)
5552                  }                  }
5553                if (IS_NEWLINE(eptr)) break;                if (IS_NEWLINE(eptr)) break;
5554                eptr++;                eptr++;
5555                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5556                }                }
5557              }              }
5558            break;            break;
# Line 5345  for (;;) Line 5568  for (;;)
5568                  break;                  break;
5569                  }                  }
5570                eptr++;                eptr++;
5571                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5572                }                }
5573              }              }
5574            else            else
# Line 5578  for (;;) Line 5801  for (;;)
5801            }            }
5802          }          }
5803        else        else
5804  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF */
5805          /* Not UTF mode */
       /* Not UTF-8 mode */  
5806          {          {
5807          switch(ctype)          switch(ctype)
5808            {            {
# Line 5624  for (;;) Line 5846  for (;;)
5846                }                }
5847              else              else
5848                {                {
5849                if (c != 0x000a &&                if (c != 0x000a && (md->bsr_anycrlf ||
5850                    (md->bsr_anycrlf ||                  (c != 0x000b && c != 0x000c && c != 0x0085
5851                      (c != 0x000b && c != 0x000c && c != 0x0085)))  #ifdef COMPILE_PCRE16
5852                  break;                  && c != 0x2028 && c != 0x2029
5853    #endif
5854                    ))) break;
5855                eptr++;                eptr++;
5856                }                }
5857              }              }
# Line 5642  for (;;) Line 5866  for (;;)
5866                break;                break;
5867                }                }
5868              c = *eptr;              c = *eptr;
5869              if (c == 0x09 || c == 0x20 || c == 0xa0) break;              if (c == 0x09 || c == 0x20 || c == 0xa0
5870    #ifdef COMPILE_PCRE16
5871                  || c == 0x1680 || c == 0x180e || (c >= 0x2000 && c <= 0x200A)
5872                  || c == 0x202f || c == 0x205f || c == 0x3000
5873    #endif
5874                  ) break;
5875              eptr++;              eptr++;
5876              }              }
5877            break;            break;
# Line 5656  for (;;) Line 5885  for (;;)
5885                break;                break;
5886                }                }
5887              c = *eptr;              c = *eptr;
5888              if (c != 0x09 && c != 0x20 && c != 0xa0) break;              if (c != 0x09 && c != 0x20 && c != 0xa0
5889    #ifdef COMPILE_PCRE16
5890                  && c != 0x1680 && c != 0x180e && (c < 0x2000 || c > 0x200A)
5891                  && c != 0x202f && c != 0x205f && c != 0x3000
5892    #endif
5893                  ) break;
5894              eptr++;              eptr++;
5895              }              }
5896            break;            break;
# Line 5670  for (;;) Line 5904  for (;;)
5904                break;                break;
5905                }                }
5906              c = *eptr;              c = *eptr;
5907              if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)              if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85
5908                break;  #ifdef COMPILE_PCRE16
5909                  || c == 0x2028 || c == 0x2029
5910    #endif
5911                  ) break;
5912              eptr++;              eptr++;
5913              }              }
5914            break;            break;
# Line 5685  for (;;) Line 5922  for (;;)
5922                break;                break;
5923                }                }
5924              c = *eptr;              c = *eptr;
5925              if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)              if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85
5926                break;  #ifdef COMPILE_PCRE16
5927                  && c != 0x2028 && c != 0x2029
5928    #endif
5929                  ) break;
5930              eptr++;              eptr++;
5931              }              }
5932            break;            break;
# Line 5699  for (;;) Line 5939  for (;;)
5939                SCHECK_PARTIAL();                SCHECK_PARTIAL();
5940                break;                break;
5941                }                }
5942              if ((md->ctypes[*eptr] & ctype_digit) != 0) break;              if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_digit) != 0) break;
5943              eptr++;              eptr++;
5944              }              }
5945            break;            break;
# Line 5712  for (;;) Line 5952  for (;;)
5952                SCHECK_PARTIAL();                SCHECK_PARTIAL();
5953                break;                break;
5954                }                }
5955              if ((md->ctypes[*eptr] & ctype_digit) == 0) break;              if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_digit) == 0) break;
5956              eptr++;              eptr++;
5957              }              }
5958            break;            break;
# Line 5725  for (;;) Line 5965  for (;;)
5965                SCHECK_PARTIAL();                SCHECK_PARTIAL();
5966                break;                break;
5967                }                }
5968              if ((md->ctypes[*eptr] & ctype_space) != 0) break;              if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_space) != 0) break;
5969              eptr++;              eptr++;
5970              }              }
5971            break;            break;
# Line 5738  for (;;) Line 5978  for (;;)
5978                SCHECK_PARTIAL();                SCHECK_PARTIAL();
5979                break;                break;
5980                }                }
5981              if ((md->ctypes[*eptr] & ctype_space) == 0) break;              if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_space) == 0) break;
5982              eptr++;              eptr++;
5983              }              }
5984            break;            break;
# Line 5751  for (;;) Line 5991  for (;;)
5991                SCHECK_PARTIAL();                SCHECK_PARTIAL();
5992                break;                break;
5993                }                }
5994              if ((md->ctypes[*eptr] & ctype_word) != 0) break;              if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_word) != 0) break;
5995              eptr++;              eptr++;
5996              }              }
5997            break;            break;
# Line 5764  for (;;) Line 6004  for (;;)
6004                SCHECK_PARTIAL();                SCHECK_PARTIAL();
6005                break;                break;
6006                }                }
6007              if ((md->ctypes[*eptr] & ctype_word) == 0) break;              if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_word) == 0) break;
6008              eptr++;              eptr++;
6009              }              }
6010            break;            break;
# Line 5827  switch (frame->Xwhere) Line 6067  switch (frame->Xwhere)
6067    LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)    LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
6068    LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58) LBL(63) LBL(64)    LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58) LBL(63) LBL(64)
6069    LBL(65) LBL(66)    LBL(65) LBL(66)
6070  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
6071    LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)    LBL(21)
6072    #endif
6073    #ifdef SUPPORT_UTF
6074      LBL(16) LBL(18) LBL(20)
6075      LBL(22) LBL(23) LBL(28) LBL(30)
6076    LBL(32) LBL(34) LBL(42) LBL(46)    LBL(32) LBL(34) LBL(42) LBL(46)
6077  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6078    LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)    LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
6079    LBL(59) LBL(60) LBL(61) LBL(62)    LBL(59) LBL(60) LBL(61) LBL(62)
6080  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
6081  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF */
6082    default:    default:
6083    DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));    DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
6084    
6085    printf("+++jump error in pcre match: label %d non-existent\n", frame->Xwhere);
6086    
6087    return PCRE_ERROR_INTERNAL;    return PCRE_ERROR_INTERNAL;
6088    }    }
6089  #undef LBL  #undef LBL
# Line 5923  Returns:          > 0 => success; value Line 6170  Returns:          > 0 => success; value
6170                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
6171  */  */
6172    
6173    #ifdef COMPILE_PCRE8
6174  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
6175  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
6176    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
6177    int offsetcount)    int offsetcount)
6178    #else
6179    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
6180    pcre16_exec(const pcre16 *argument_re, const pcre16_extra *extra_data,
6181      PCRE_SPTR16 subject, int length, int start_offset, int options, int *offsets,
6182      int offsetcount)
6183    #endif
6184  {  {
6185  int rc, ocount, arg_offset_max;  int rc, ocount, arg_offset_max;
 int first_byte = -1;  
 int req_byte = -1;  
 int req_byte2 = -1;  
6186  int newline;  int newline;
6187  BOOL using_temporary_offsets = FALSE;  BOOL using_temporary_offsets = FALSE;
6188  BOOL anchored;  BOOL anchored;
6189  BOOL startline;  BOOL startline;
6190  BOOL firstline;  BOOL firstline;
6191  BOOL first_byte_caseless = FALSE;  BOOL utf;
6192  BOOL req_byte_caseless = FALSE;  BOOL has_first_char = FALSE;
6193  BOOL utf8;  BOOL has_req_char = FALSE;
6194    pcre_uchar first_char = 0;
6195    pcre_uchar first_char2 = 0;
6196    pcre_uchar req_char = 0;
6197    pcre_uchar req_char2 = 0;
6198  match_data match_block;  match_data match_block;
6199  match_data *md = &match_block;  match_data *md = &match_block;
6200  const uschar *tables;  const pcre_uint8 *tables;
6201  const uschar *start_bits = NULL;  const pcre_uint8 *start_bits = NULL;
6202  USPTR start_match = (USPTR)subject + start_offset;  PCRE_PUCHAR start_match = (PCRE_PUCHAR)subject + start_offset;
6203  USPTR end_subject;  PCRE_PUCHAR end_subject;
6204  USPTR start_partial = NULL;  PCRE_PUCHAR start_partial = NULL;
6205  USPTR req_byte_ptr = start_match - 1;  PCRE_PUCHAR req_char_ptr = start_match - 1;
6206    
 pcre_study_data internal_study;  
6207  const pcre_study_data *study;  const pcre_study_data *study;
6208    const REAL_PCRE *re = (const REAL_PCRE *)argument_re;
6209    
6210  real_pcre internal_re;  /* Check for the special magic call that measures the size of the stack used
6211  const real_pcre *external_re = (const real_pcre *)argument_re;  per recursive call of match(). */
6212  const real_pcre *re = external_re;  
6213    if (re == NULL && extra_data == NULL && subject == NULL && length == -1)
6214    #ifdef NO_RECURSE
6215      return -sizeof(heapframe);
6216    #else
6217      return match(NULL, NULL, NULL, 0, NULL, NULL, 0);
6218    #endif
6219    
6220  /* Plausibility checks */  /* Plausibility checks */
6221    
6222  if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;  if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;
6223  if (re == NULL || subject == NULL ||  if (re == NULL || subject == NULL || (offsets == NULL && offsetcount > 0))
6224     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;    return PCRE_ERROR_NULL;
6225  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
6226  if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;  if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
6227    
6228    /* Check that the first field in the block is the magic number. If it is not,
6229    return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to
6230    REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which
6231    means that the pattern is likely compiled with different endianness. */
6232    
6233    if (re->magic_number != MAGIC_NUMBER)
6234      return re->magic_number == REVERSED_MAGIC_NUMBER?
6235        PCRE_ERROR_BADENDIANNESS:PCRE_ERROR_BADMAGIC;
6236    if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
6237    
6238  /* These two settings are used in the code for checking a UTF-8 string that  /* These two settings are used in the code for checking a UTF-8 string that
6239  follows immediately afterwards. Other values in the md block are used only  follows immediately afterwards. Other values in the md block are used only
6240  during "normal" pcre_exec() processing, not when the JIT support is in use,  during "normal" pcre_exec() processing, not when the JIT support is in use,
6241  so they are set up later. */  so they are set up later. */
6242    
6243  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
6244    utf = md->utf = (re->options & PCRE_UTF8) != 0;
6245  md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :  md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
6246                ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;                ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
6247    
6248  /* Check a UTF-8 string if required. Pass back the character offset and error  /* Check a UTF-8 string if required. Pass back the character offset and error
6249  code for an invalid string if a results vector is available. */  code for an invalid string if a results vector is available. */
6250    
6251  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
6252  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf && (options & PCRE_NO_UTF8_CHECK) == 0)
6253    {    {
6254    int erroroffset;    int erroroffset;
6255    int errorcode = _pcre_valid_utf8((USPTR)subject, length, &erroroffset);    int errorcode = PRIV(valid_utf)((PCRE_PUCHAR)subject, length, &erroroffset);
6256    if (errorcode != 0)    if (errorcode != 0)
6257      {      {
6258      if (offsetcount >= 2)      if (offsetcount >= 2)
# Line 5988  if (utf8 && (options & PCRE_NO_UTF8_CHEC Line 6260  if (utf8 && (options & PCRE_NO_UTF8_CHEC
6260        offsets[0] = erroroffset;        offsets[0] = erroroffset;
6261        offsets[1] = errorcode;        offsets[1] = errorcode;
6262        }        }
6263    #ifdef COMPILE_PCRE16
6264        return (errorcode <= PCRE_UTF16_ERR1 && md->partial > 1)?
6265          PCRE_ERROR_SHORTUTF16 : PCRE_ERROR_BADUTF16;
6266    #else
6267      return (errorcode <= PCRE_UTF8_ERR5 && md->partial > 1)?      return (errorcode <= PCRE_UTF8_ERR5 && md->partial > 1)?
6268        PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;        PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;
6269    #endif
6270      }      }
6271    
6272    /* Check that a start_offset points to the start of a UTF-8 character. */    /* Check that a start_offset points to the start of a UTF character. */
6273    if (start_offset > 0 && start_offset < length &&    if (start_offset > 0 && start_offset < length &&
6274        (((USPTR)subject)[start_offset] & 0xc0) == 0x80)        NOT_FIRSTCHAR(((PCRE_PUCHAR)subject)[start_offset]))
6275      return PCRE_ERROR_BADUTF8_OFFSET;      return PCRE_ERROR_BADUTF8_OFFSET;
6276    }    }
6277  #endif  #endif
# Line 6012  if (extra_data != NULL Line 6289  if (extra_data != NULL
6289      && (extra_data->flags & PCRE_EXTRA_TABLES) == 0      && (extra_data->flags & PCRE_EXTRA_TABLES) == 0
6290      && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL |      && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL |
6291                      PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART)) == 0)                      PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART)) == 0)
6292    return _pcre_jit_exec(re, extra_data->executable_jit, subject, length,    return PRIV(jit_exec)(re, extra_data->executable_jit,
6293      start_offset, options, ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)      (const pcre_uchar *)subject, length, start_offset, options,
6294        ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)
6295      ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount);      ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount);
6296  #endif  #endif
6297    
6298  /* Carry on with non-JIT matching. This information is for finding all the  /* Carry on with non-JIT matching. This information is for finding all the
6299  numbers associated with a given name, for condition testing. */  numbers associated with a given name, for condition testing. */
6300    
6301  md->name_table = (uschar *)re + re->name_table_offset;  md->name_table = (pcre_uchar *)re + re->name_table_offset;
6302  md->name_count = re->name_count;  md->name_count = re->name_count;
6303  md->name_entry_size = re->name_entry_size;  md->name_entry_size = re->name_entry_size;
6304    
# Line 6034  md->callout_data = NULL; Line 6312  md->callout_data = NULL;
6312    
6313  /* The table pointer is always in native byte order. */  /* The table pointer is always in native byte order. */
6314    
6315  tables = external_re->tables;  tables = re->tables;
6316    
6317  if (extra_data != NULL)  if (extra_data != NULL)
6318    {    {
# Line 6054  if (extra_data != NULL) Line 6332  if (extra_data != NULL)
6332  is a feature that makes it possible to save compiled regex and re-use them  is a feature that makes it possible to save compiled regex and re-use them
6333  in other programs later. */  in other programs later. */
6334    
6335  if (tables == NULL) tables = _pcre_default_tables;  if (tables == NULL) tables = PRIV(default_tables);
   
 /* Check that the first field in the block is the magic number. If it is not,  
 test for a regex that was compiled on a host of opposite endianness. If this is  
 the case, flipped values are put in internal_re and internal_study if there was  
 study data too. */  
   
 if (re->magic_number != MAGIC_NUMBER)  
   {  
   re = _pcre_try_flipped(re, &internal_re, study, &internal_study);  
   if (re == NULL) return PCRE_ERROR_BADMAGIC;  
   if (study != NULL) study = &internal_study;  
   }  
6336    
6337  /* Set up other data */  /* Set up other data */
6338    
# Line 6076  firstline = (re->options & PCRE_FIRSTLIN Line 6342  firstline = (re->options & PCRE_FIRSTLIN
6342    
6343  /* The code starts after the real_pcre block and the capture name table. */  /* The code starts after the real_pcre block and the capture name table. */
6344    
6345  md->start_code = (const uschar *)external_re + re->name_table_offset +  md->start_code = (const pcre_uchar *)re + re->name_table_offset +
6346    re->name_count * re->name_entry_size;    re->name_count * re->name_entry_size;
6347    
6348  md->start_subject = (USPTR)subject;  md->start_subject = (PCRE_PUCHAR)subject;
6349  md->start_offset = start_offset;  md->start_offset = start_offset;
6350  md->end_subject = md->start_subject + length;  md->end_subject = md->start_subject + length;
6351  end_subject = md->end_subject;  end_subject = md->end_subject;
# Line 6104  md->recursive = NULL; Line 6370  md->recursive = NULL;
6370  md->hasthen = (re->flags & PCRE_HASTHEN) != 0;  md->hasthen = (re->flags & PCRE_HASTHEN) != 0;
6371    
6372  md->lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
6373    md->fcc = tables + fcc_offset;
6374  md->ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
6375    
6376  /* Handle different \R options. */  /* Handle different \R options. */
# Line 6190  arg_offset_max = (2*ocount)/3; Line 6457  arg_offset_max = (2*ocount)/3;
6457  if (re->top_backref > 0 && re->top_backref >= ocount/3)  if (re->top_backref > 0 && re->top_backref >= ocount/3)
6458    {    {
6459    ocount = re->top_backref * 3 + 3;    ocount = re->top_backref * 3 + 3;
6460    md->offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));    md->offset_vector = (int *)(PUBL(malloc))(ocount * sizeof(int));
6461    if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY;    if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY;
6462    using_temporary_offsets = TRUE;    using_temporary_offsets = TRUE;
6463    DPRINTF(("Got memory to hold back references\n"));    DPRINTF(("Got memory to hold back references\n"));
# Line 6217  if (md->offset_vector != NULL) Line 6484  if (md->offset_vector != NULL)
6484    md->offset_vector[0] = md->offset_vector[1] = -1;    md->offset_vector[0] = md->offset_vector[1] = -1;
6485    }    }
6486    
6487  /* Set up the first character to match, if available. The first_byte value is  /* Set up the first character to match, if available. The first_char value is
6488  never set for an anchored regular expression, but the anchoring may be forced  never set for an anchored regular expression, but the anchoring may be forced
6489  at run time, so we have to test for anchoring. The first char may be unset for  at run time, so we have to test for anchoring. The first char may be unset for
6490  an unanchored pattern, of course. If there's no first char and the pattern was  an unanchored pattern, of course. If there's no first char and the pattern was
# Line 6227  if (!anchored) Line 6494  if (!anchored)
6494    {    {
6495    if ((re->flags & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
6496      {      {
6497      first_byte = re->first_byte & 255;      has_first_char = TRUE;
6498      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      first_char = first_char2 = re->first_char;
6499        first_byte = md->lcc[first_byte];      if ((re->flags & PCRE_FCH_CASELESS) != 0)
6500          {
6501          first_char2 = TABLE_GET(first_char, md->fcc, first_char);
6502    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
6503          if (utf && first_char > 127)
6504            first_char2 = UCD_OTHERCASE(first_char);
6505    #endif
6506          }
6507      }      }
6508    else    else
6509      if (!startline && study != NULL &&      if (!startline && study != NULL &&
# Line 6242  character" set. */ Line 6516  character" set. */
6516    
6517  if ((re->flags & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
6518    {    {
6519    req_byte = re->req_byte & 255;    has_req_char = TRUE;
6520    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_char = req_char2 = re->req_char;
6521    req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */    if ((re->flags & PCRE_RCH_CASELESS) != 0)
6522        {
6523        req_char2 = TABLE_GET(req_char, md->fcc, req_char);
6524    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
6525        if (utf && req_char > 127)
6526          req_char2 = UCD_OTHERCASE(req_char);
6527    #endif
6528        }
6529    }    }
6530    
6531    
   
   
6532  /* ==========================================================================*/  /* ==========================================================================*/
6533    
6534  /* Loop for handling unanchored repeated matching attempts; for anchored regexs  /* Loop for handling unanchored repeated matching attempts; for anchored regexs
# Line 6257  the loop runs just once. */ Line 6536  the loop runs just once. */
6536    
6537  for(;;)  for(;;)
6538    {    {
6539    USPTR save_end_subject = end_subject;    PCRE_PUCHAR save_end_subject = end_subject;
6540    USPTR new_start_match;    PCRE_PUCHAR new_start_match;
6541    
6542    /* If firstline is TRUE, the start of the match is constrained to the first    /* If firstline is TRUE, the start of the match is constrained to the first
6543    line of a multiline string. That is, the match must be before or at the first    line of a multiline string. That is, the match must be before or at the first
# Line 6268  for(;;) Line 6547  for(;;)
6547    
6548    if (firstline)    if (firstline)
6549      {      {
6550      USPTR t = start_match;      PCRE_PUCHAR t = start_match;
6551  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
6552      if (utf8)      if (utf)
6553        {        {
6554        while (t < md->end_subject && !IS_NEWLINE(t))        while (t < md->end_subject && !IS_NEWLINE(t))
6555          {          {
6556          t++;          t++;
6557          while (t < end_subject && (*t & 0xc0) == 0x80) t++;          ACROSSCHAR(t < end_subject, *t, t++);
6558          }          }
6559        }        }
6560      else      else
# Line 6292  for(;;) Line 6571  for(;;)
6571    
6572    if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0)    if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0)
6573      {      {
6574      /* Advance to a unique first byte if there is one. */      /* Advance to a unique first char if there is one. */
6575    
6576      if (first_byte >= 0)      if (has_first_char)
6577        {        {
6578        if (first_byte_caseless)        if (first_char != first_char2)
6579          while (start_match < end_subject && md->lcc[*start_match] != first_byte)          while (start_match < end_subject &&
6580                *start_match != first_char && *start_match != first_char2)
6581            start_match++;            start_match++;
6582        else        else
6583          while (start_match < end_subject && *start_match != first_byte)          while (start_match < end_subject && *start_match != first_char)
6584            start_match++;            start_match++;
6585        }        }
6586    
# Line 6310  for(;;) Line 6590  for(;;)
6590        {        {
6591        if (start_match > md->start_subject + start_offset)        if (start_match > md->start_subject + start_offset)
6592          {          {
6593  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
6594          if (utf8)          if (utf)
6595            {            {
6596            while (start_match < end_subject && !WAS_NEWLINE(start_match))            while (start_match < end_subject && !WAS_NEWLINE(start_match))
6597              {              {
6598              start_match++;              start_match++;
6599              while(start_match < end_subject && (*start_match & 0xc0) == 0x80)              ACROSSCHAR(start_match < end_subject, *start_match,
6600                start_match++;                start_match++);
6601              }              }
6602            }            }
6603          else          else
# Line 6344  for(;;) Line 6624  for(;;)
6624        while (start_match < end_subject)        while (start_match < end_subject)
6625          {          {
6626          register unsigned int c = *start_match;          register unsigned int c = *start_match;
6627    #ifndef COMPILE_PCRE8
6628            if (c > 255) c = 255;
6629    #endif
6630          if ((start_bits[c/8] & (1 << (c&7))) == 0)          if ((start_bits[c/8] & (1 << (c&7))) == 0)
6631            {            {
6632            start_match++;            start_match++;
6633  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
6634            if (utf8)            /* In non 8-bit mode, the iteration will stop for
6635              while(start_match < end_subject && (*start_match & 0xc0) == 0x80)            characters > 255 at the beginning or not stop at all. */
6636                start_match++;            if (utf)
6637                ACROSSCHAR(start_match < end_subject, *start_match,
6638                  start_match++);
6639  #endif  #endif
6640            }            }
6641          else break;          else break;
# Line 6379  for(;;) Line 6664  for(;;)
6664        break;        break;
6665        }        }
6666    
6667      /* If req_byte is set, we know that that character must appear in the      /* If req_char is set, we know that that character must appear in the
6668      subject for the match to succeed. If the first character is set, req_byte      subject for the match to succeed. If the first character is set, req_char
6669      must be later in the subject; otherwise the test starts at the match point.      must be later in the subject; otherwise the test starts at the match point.
6670      This optimization can save a huge amount of backtracking in patterns with      This optimization can save a huge amount of backtracking in patterns with
6671      nested unlimited repeats that aren't going to match. Writing separate code      nested unlimited repeats that aren't going to match. Writing separate code
# Line 6393  for(;;) Line 6678  for(;;)
6678      32-megabyte string... so we don't do this when the string is sufficiently      32-megabyte string... so we don't do this when the string is sufficiently
6679      long. */      long. */
6680    
6681      if (req_byte >= 0 && end_subject - start_match < REQ_BYTE_MAX)      if (has_req_char && end_subject - start_match < REQ_BYTE_MAX)
6682        {        {
6683        register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);        register PCRE_PUCHAR p = start_match + (has_first_char? 1:0);
6684    
6685        /* We don't need to repeat the search if we haven't yet reached the        /* We don't need to repeat the search if we haven't yet reached the
6686        place we found it at last time. */        place we found it at last time. */
6687    
6688        if (p > req_byte_ptr)        if (p > req_char_ptr)
6689          {          {
6690          if (req_byte_caseless)          if (req_char != req_char2)
6691            {            {
6692            while (p < end_subject)            while (p < end_subject)
6693              {              {
6694              register int pp = *p++;              register int pp = *p++;
6695              if (pp == req_byte || pp == req_byte2) { p--; break; }              if (pp == req_char || pp == req_char2) { p--; break; }
6696              }              }
6697            }            }
6698          else          else
6699            {            {
6700            while (p < end_subject)            while (p < end_subject)
6701              {              {
6702              if (*p++ == req_byte) { p--; break; }              if (*p++ == req_char) { p--; break; }
6703              }              }
6704            }            }
6705    
# Line 6431  for(;;) Line 6716  for(;;)
6716          found it, so that we don't search again next time round the loop if          found it, so that we don't search again next time round the loop if
6717          the start hasn't passed this character yet. */          the start hasn't passed this character yet. */
6718    
6719          req_byte_ptr = p;          req_char_ptr = p;
6720          }          }
6721        }        }
6722      }      }
# Line 6456  for(;;) Line 6741  for(;;)
6741    switch(rc)    switch(rc)
6742      {      {
6743      /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched      /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched
6744      the SKIP's arg was not found. In this circumstance, Perl ignores the SKIP      the SKIP's arg was not found. In this circumstance, Perl ignores the SKIP
6745      entirely. The only way we can do that is to re-do the match at the same      entirely. The only way we can do that is to re-do the match at the same
6746      point, with a flag to force SKIP with an argument to be ignored. Just      point, with a flag to force SKIP with an argument to be ignored. Just
6747      treating this case as NOMATCH does not work because it does not check other      treating this case as NOMATCH does not work because it does not check other
6748      alternatives in patterns such as A(*SKIP:A)B|AC when the subject is AC. */      alternatives in patterns such as A(*SKIP:A)B|AC when the subject is AC. */
6749    
6750      case MATCH_SKIP_ARG:      case MATCH_SKIP_ARG:
6751      new_start_match = start_match;      new_start_match = start_match;
6752      md->ignore_skip_arg = TRUE;      md->ignore_skip_arg = TRUE;
6753      break;      break;
6754    
6755      /* SKIP passes back the next starting point explicitly, but if it is the      /* SKIP passes back the next starting point explicitly, but if it is the
6756      same as the match we have just done, treat it as NOMATCH. */      same as the match we have just done, treat it as NOMATCH. */
# Line 6486  for(;;) Line 6771  for(;;)
6771      case MATCH_THEN:      case MATCH_THEN:
6772      md->ignore_skip_arg = FALSE;      md->ignore_skip_arg = FALSE;
6773      new_start_match = start_match + 1;      new_start_match = start_match + 1;
6774  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
6775      if (utf8)      if (utf)
6776        while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80)        ACROSSCHAR(new_start_match < end_subject, *new_start_match,
6777          new_start_match++;          new_start_match++);
6778  #endif  #endif
6779      break;      break;
6780    
# Line 6527  for(;;) Line 6812  for(;;)
6812    
6813    /* If we have just passed a CR and we are now at a LF, and the pattern does    /* If we have just passed a CR and we are now at a LF, and the pattern does
6814    not contain any explicit matches for \r or \n, and the newline option is CRLF    not contain any explicit matches for \r or \n, and the newline option is CRLF
6815    or ANY or ANYCRLF, advance the match position by one more character. */    or ANY or ANYCRLF, advance the match position by one more character. In
6816      normal matching start_match will aways be greater than the first position at
6817      this stage, but a failed *SKIP can cause a return at the same point, which is
6818      why the first test exists. */
6819    
6820    if (start_match[-1] == CHAR_CR &&    if (start_match > (PCRE_PUCHAR)subject + start_offset &&
6821          start_match[-1] == CHAR_CR &&
6822        start_match < end_subject &&        start_match < end_subject &&
6823        *start_match == CHAR_NL &&        *start_match == CHAR_NL &&
6824        (re->flags & PCRE_HASCRORLF) == 0 &&        (re->flags & PCRE_HASCRORLF) == 0 &&
# Line 6575  if (rc == MATCH_MATCH || rc == MATCH_ACC Line 6864  if (rc == MATCH_MATCH || rc == MATCH_ACC
6864        }        }
6865      if (md->end_offset_top > arg_offset_max) md->offset_overflow = TRUE;      if (md->end_offset_top > arg_offset_max) md->offset_overflow = TRUE;
6866      DPRINTF(("Freeing temporary memory\n"));      DPRINTF(("Freeing temporary memory\n"));
6867      (pcre_free)(md->offset_vector);      (PUBL(free))(md->offset_vector);
6868      }      }
6869    
6870    /* Set the return code to the number of captured strings, or 0 if there were    /* Set the return code to the number of captured strings, or 0 if there were
# Line 6614  if (rc == MATCH_MATCH || rc == MATCH_ACC Line 6903  if (rc == MATCH_MATCH || rc == MATCH_ACC
6903      }      }
6904    
6905    /* Return MARK data if requested */    /* Return MARK data if requested */
6906    
6907    if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)    if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)
6908      *(extra_data->mark) = (unsigned char *)(md->mark);      *(extra_data->mark) = (pcre_uchar *)md->mark;
6909    DPRINTF((">>>> returning %d\n", rc));    DPRINTF((">>>> returning %d\n", rc));
6910    return rc;    return rc;
6911    }    }
# Line 6627  attempt has failed at all permitted star Line 6916  attempt has failed at all permitted star
6916  if (using_temporary_offsets)  if (using_temporary_offsets)
6917    {    {
6918    DPRINTF(("Freeing temporary memory\n"));    DPRINTF(("Freeing temporary memory\n"));
6919    (pcre_free)(md->offset_vector);    (PUBL(free))(md->offset_vector);
6920    }    }
6921    
6922  /* For anything other than nomatch or partial match, just return the code. */  /* For anything other than nomatch or partial match, just return the code. */
# Line 6646  if (start_partial != NULL) Line 6935  if (start_partial != NULL)
6935    md->mark = NULL;    md->mark = NULL;
6936    if (offsetcount > 1)    if (offsetcount > 1)
6937      {      {
6938      offsets[0] = (int)(start_partial - (USPTR)subject);      offsets[0] = (int)(start_partial - (PCRE_PUCHAR)subject);
6939      offsets[1] = (int)(end_subject - (USPTR)subject);      offsets[1] = (int)(end_subject - (PCRE_PUCHAR)subject);
6940      }      }
6941    rc = PCRE_ERROR_PARTIAL;    rc = PCRE_ERROR_PARTIAL;
6942    }    }
# Line 6663  else Line 6952  else
6952  /* Return the MARK data if it has been requested. */  /* Return the MARK data if it has been requested. */
6953    
6954  if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)  if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)
6955    *(extra_data->mark) = (unsigned char *)(md->nomatch_mark);    *(extra_data->mark) = (pcre_uchar *)md->nomatch_mark;
6956  return rc;  return rc;
6957  }  }
6958    

Legend:
Removed from v.778  
changed lines
  Added in v.895

  ViewVC Help
Powered by ViewVC 1.1.5