/[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 200 by ph10, Wed Aug 1 09:10:40 2007 UTC revision 402 by ph10, Sat Mar 21 17:26:03 2009 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2007 University of Cambridge             Copyright (c) 1997-2009 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 43  pattern matching using an NFA algorithm, Line 43  pattern matching using an NFA algorithm,
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
46  #include <config.h>  #include "config.h"
47  #endif  #endif
48    
49  #define NLBLOCK md             /* Block containing newline information */  #define NLBLOCK md             /* Block containing newline information */
# Line 68  defined PCRE_ERROR_xxx codes, which are Line 68  defined PCRE_ERROR_xxx codes, which are
68  #define MATCH_MATCH        1  #define MATCH_MATCH        1
69  #define MATCH_NOMATCH      0  #define MATCH_NOMATCH      0
70    
71    /* Special internal returns from the match() function. Make them sufficiently
72    negative to avoid the external error codes. */
73    
74    #define MATCH_COMMIT       (-999)
75    #define MATCH_PRUNE        (-998)
76    #define MATCH_SKIP         (-997)
77    #define MATCH_THEN         (-996)
78    
79  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
80  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
81  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 150  printf("\n"); Line 158  printf("\n");
158    
159  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
160    
161  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
162    properly if Unicode properties are supported. Otherwise, we can check only
163    ASCII characters. */
164    
165  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
166    {    {
167    #ifdef SUPPORT_UTF8
168    #ifdef SUPPORT_UCP
169      if (md->utf8)
170        {
171        USPTR endptr = eptr + length;
172        while (eptr < endptr)
173          {
174          int c, d;
175          GETCHARINC(c, eptr);
176          GETCHARINC(d, p);
177          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
178          }
179        }
180      else
181    #endif
182    #endif
183    
184      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
185      is no UCP support. */
186    
187    while (length-- > 0)    while (length-- > 0)
188      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
189    }    }
190    
191    /* In the caseful case, we can just compare the bytes, whether or not we
192    are in UTF-8 mode. */
193    
194  else  else
195    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
196    
# Line 203  variable instead of being passed in the Line 237  variable instead of being passed in the
237  ****************************************************************************  ****************************************************************************
238  ***************************************************************************/  ***************************************************************************/
239    
240    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
241  /* Numbers for RMATCH calls */  below must be updated in sync.  */
242    
243  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
244         RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,         RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
245         RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,         RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
246         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
247         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50 };         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
248           RM51,  RM52, RM53, RM54 };
249    
250  /* These versions of the macros use the stack, as normal. There are debugging  /* These versions of the macros use the stack, as normal. There are debugging
251  versions and production versions. Note that the "rw" argument of RMATCH isn't  versions and production versions. Note that the "rw" argument of RMATCH isn't
# Line 300  typedef struct heapframe { Line 334  typedef struct heapframe {
334    /* Function local variables */    /* Function local variables */
335    
336    const uschar *Xcallpat;    const uschar *Xcallpat;
337    #ifdef SUPPORT_UTF8
338    const uschar *Xcharptr;    const uschar *Xcharptr;
339    #endif
340    const uschar *Xdata;    const uschar *Xdata;
341    const uschar *Xnext;    const uschar *Xnext;
342    const uschar *Xpp;    const uschar *Xpp;
# Line 527  int oclength; Line 563  int oclength;
563  uschar occhars[8];  uschar occhars[8];
564  #endif  #endif
565    
566    int codelink;
567    int condcode;
568  int ctype;  int ctype;
569  int length;  int length;
570  int max;  int max;
# Line 601  for (;;) Line 639  for (;;)
639    {    {
640    minimize = possessive = FALSE;    minimize = possessive = FALSE;
641    op = *ecode;    op = *ecode;
642    
643    /* For partial matching, remember if we ever hit the end of the subject after    /* For partial matching, remember if we ever hit the end of the subject after
644    matching at least one subject character. */    matching at least one subject character. */
645    
# Line 612  for (;;) Line 650  for (;;)
650    
651    switch(op)    switch(op)
652      {      {
653        case OP_FAIL:
654        RRETURN(MATCH_NOMATCH);
655    
656        case OP_PRUNE:
657        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
658          ims, eptrb, flags, RM51);
659        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
660        RRETURN(MATCH_PRUNE);
661    
662        case OP_COMMIT:
663        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
664          ims, eptrb, flags, RM52);
665        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
666        RRETURN(MATCH_COMMIT);
667    
668        case OP_SKIP:
669        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
670          ims, eptrb, flags, RM53);
671        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
672        md->start_match_ptr = eptr;   /* Pass back current position */
673        RRETURN(MATCH_SKIP);
674    
675        case OP_THEN:
676        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
677          ims, eptrb, flags, RM54);
678        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
679        RRETURN(MATCH_THEN);
680    
681      /* Handle a capturing bracket. If there is space in the offset vector, save      /* Handle a capturing bracket. If there is space in the offset vector, save
682      the current subject position in the working slot at the top of the vector.      the current subject position in the working slot at the top of the vector.
683      We mustn't change the current values of the data slot, because they may be      We mustn't change the current values of the data slot, because they may be
# Line 653  for (;;) Line 719  for (;;)
719          {          {
720          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
721            ims, eptrb, flags, RM1);            ims, eptrb, flags, RM1);
722          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
723          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
724          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
725          }          }
# Line 712  for (;;) Line 778  for (;;)
778    
779        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
780          eptrb, flags, RM2);          eptrb, flags, RM2);
781        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
782        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
783        }        }
784      /* Control never reaches here. */      /* Control never reaches here. */
# Line 725  for (;;) Line 791  for (;;)
791    
792      case OP_COND:      case OP_COND:
793      case OP_SCOND:      case OP_SCOND:
794      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */      codelink= GET(ecode, 1);
795    
796        /* Because of the way auto-callout works during compile, a callout item is
797        inserted between OP_COND and an assertion condition. */
798    
799        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
800          {
801          if (pcre_callout != NULL)
802            {
803            pcre_callout_block cb;
804            cb.version          = 1;   /* Version 1 of the callout block */
805            cb.callout_number   = ecode[LINK_SIZE+2];
806            cb.offset_vector    = md->offset_vector;
807            cb.subject          = (PCRE_SPTR)md->start_subject;
808            cb.subject_length   = md->end_subject - md->start_subject;
809            cb.start_match      = mstart - md->start_subject;
810            cb.current_position = eptr - md->start_subject;
811            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
812            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
813            cb.capture_top      = offset_top/2;
814            cb.capture_last     = md->capture_last;
815            cb.callout_data     = md->callout_data;
816            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
817            if (rrc < 0) RRETURN(rrc);
818            }
819          ecode += _pcre_OP_lengths[OP_CALLOUT];
820          }
821    
822        condcode = ecode[LINK_SIZE+1];
823    
824        /* Now see what the actual condition is */
825    
826        if (condcode == OP_RREF)         /* Recursion test */
827        {        {
828        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
829        condition = md->recursive != NULL &&        condition = md->recursive != NULL &&
# Line 733  for (;;) Line 831  for (;;)
831        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
832        }        }
833    
834      else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */      else if (condcode == OP_CREF)    /* Group used test */
835        {        {
836        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
837        condition = offset < offset_top && md->offset_vector[offset] >= 0;        condition = offset < offset_top && md->offset_vector[offset] >= 0;
838        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
839        }        }
840    
841      else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */      else if (condcode == OP_DEF)     /* DEFINE - always false */
842        {        {
843        condition = FALSE;        condition = FALSE;
844        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
# Line 760  for (;;) Line 858  for (;;)
858          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
859          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
860          }          }
861        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
862          {          {
863          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
864          }          }
865        else        else
866          {          {
867          condition = FALSE;          condition = FALSE;
868          ecode += GET(ecode, 1);          ecode += codelink;
869          }          }
870        }        }
871    
# Line 790  for (;;) Line 888  for (;;)
888          goto TAIL_RECURSE;          goto TAIL_RECURSE;
889          }          }
890        }        }
891      else                         /* Condition false & no 2nd alternative */      else                         /* Condition false & no alternative */
892        {        {
893        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
894        }        }
895      break;      break;
896    
897    
898      /* End of the pattern. If we are in a top-level recursion, we should      /* End of the pattern, either real or forced. If we are in a top-level
899      restore the offsets appropriately and continue from after the call. */      recursion, we should restore the offsets appropriately and continue from
900        after the call. */
901    
902        case OP_ACCEPT:
903      case OP_END:      case OP_END:
904      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
905        {        {
# Line 820  for (;;) Line 920  for (;;)
920      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
921      md->end_match_ptr = eptr;           /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
922      md->end_offset_top = offset_top;    /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
923      md->start_match_ptr = mstart;  /* and the start (\K can modify) */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
924      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
925    
926      /* Change option settings */      /* Change option settings */
# Line 844  for (;;) Line 944  for (;;)
944        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
945          RM4);          RM4);
946        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
947        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
948        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
949        }        }
950      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 871  for (;;) Line 971  for (;;)
971        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
972          RM5);          RM5);
973        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
974        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
975        ecode += GET(ecode,1);        ecode += GET(ecode,1);
976        }        }
977      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 895  for (;;) Line 995  for (;;)
995          {          {
996          eptr--;          eptr--;
997          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
998          BACKCHAR(eptr)          BACKCHAR(eptr);
999          }          }
1000        }        }
1001      else      else
# Line 1008  for (;;) Line 1108  for (;;)
1108              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1109            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1110            }            }
1111          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1112            {            {
1113            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1114              if (new_recursive.offset_save != stacksave)
1115                (pcre_free)(new_recursive.offset_save);
1116            RRETURN(rrc);            RRETURN(rrc);
1117            }            }
1118    
# Line 1044  for (;;) Line 1146  for (;;)
1146        {        {
1147        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1148        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
1149        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1150        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1151        }        }
1152      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1110  for (;;) Line 1212  for (;;)
1212      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1213      break;      break;
1214    
1215      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1216      that it may occur zero times. It may repeat infinitely, or not at all -      indicating that it may occur zero times. It may repeat infinitely, or not
1217      i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1218      repeat limits are compiled as a number of copies, with the optional ones      with fixed upper repeat limits are compiled as a number of copies, with the
1219      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1220    
1221      case OP_BRAZERO:      case OP_BRAZERO:
1222        {        {
# Line 1136  for (;;) Line 1238  for (;;)
1238        }        }
1239      break;      break;
1240    
1241        case OP_SKIPZERO:
1242          {
1243          next = ecode+1;
1244          do next += GET(next,1); while (*next == OP_ALT);
1245          ecode = next + 1 + LINK_SIZE;
1246          }
1247        break;
1248    
1249      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1250    
1251      case OP_KET:      case OP_KET:
# Line 1383  for (;;) Line 1493  for (;;)
1493      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1494    
1495      case OP_ANY:      case OP_ANY:
1496      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1497        {      /* Fall through */
1498        if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
1499        }      case OP_ALLANY:
1500      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
1501      if (utf8)      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1502      ecode++;      ecode++;
1503      break;      break;
1504    
# Line 1488  for (;;) Line 1597  for (;;)
1597        case 0x000d:        case 0x000d:
1598        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1599        break;        break;
1600    
1601        case 0x000a:        case 0x000a:
1602          break;
1603    
1604        case 0x000b:        case 0x000b:
1605        case 0x000c:        case 0x000c:
1606        case 0x0085:        case 0x0085:
1607        case 0x2028:        case 0x2028:
1608        case 0x2029:        case 0x2029:
1609          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1610        break;        break;
1611        }        }
1612      ecode++;      ecode++;
# Line 1604  for (;;) Line 1717  for (;;)
1717      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1718      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1719        {        {
1720        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1721    
1722        switch(ecode[1])        switch(ecode[1])
1723          {          {
# Line 1614  for (;;) Line 1726  for (;;)
1726          break;          break;
1727    
1728          case PT_LAMP:          case PT_LAMP:
1729          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1730               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1731               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1732            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1733           break;           break;
1734    
1735          case PT_GC:          case PT_GC:
1736          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1737            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1738          break;          break;
1739    
1740          case PT_PC:          case PT_PC:
1741          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1742            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1743          break;          break;
1744    
1745          case PT_SC:          case PT_SC:
1746          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1747            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1748          break;          break;
1749    
# Line 1650  for (;;) Line 1762  for (;;)
1762      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1763      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1764        {        {
1765        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1766        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1767        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1768          {          {
# Line 1660  for (;;) Line 1771  for (;;)
1771            {            {
1772            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1773            }            }
1774          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1775          if (category != ucp_M) break;          if (category != ucp_M) break;
1776          eptr += len;          eptr += len;
1777          }          }
# Line 1681  for (;;) Line 1792  for (;;)
1792      case OP_REF:      case OP_REF:
1793        {        {
1794        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1795        ecode += 3;                                 /* Advance past item */        ecode += 3;
1796    
1797          /* If the reference is unset, there are two possibilities:
1798    
1799          (a) In the default, Perl-compatible state, set the length to be longer
1800          than the amount of subject left; this ensures that every attempt at a
1801          match fails. We can't just fail here, because of the possibility of
1802          quantifiers with zero minima.
1803    
1804          (b) If the JavaScript compatibility flag is set, set the length to zero
1805          so that the back reference matches an empty string.
1806    
1807        /* If the reference is unset, set the length to be longer than the amount        Otherwise, set the length to the length of what was matched by the
1808        of subject left; this ensures that every attempt at a match fails. We        referenced subpattern. */
1809        can't just fail here, because of the possibility of quantifiers with zero  
1810        minima. */        if (offset >= offset_top || md->offset_vector[offset] < 0)
1811            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1812        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        else
1813          md->end_subject - eptr + 1 :          length = md->offset_vector[offset+1] - md->offset_vector[offset];
         md->offset_vector[offset+1] - md->offset_vector[offset];  
1814    
1815        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1816    
# Line 1965  for (;;) Line 2085  for (;;)
2085    
2086    
2087      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2088      in UTF-8 mode, because that's the only time it is compiled. */      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2089        mode, because Unicode properties are supported in non-UTF-8 mode. */
2090    
2091  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2092      case OP_XCLASS:      case OP_XCLASS:
# Line 2007  for (;;) Line 2128  for (;;)
2128        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2129          {          {
2130          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2131          GETCHARINC(c, eptr);          GETCHARINCTEST(c, eptr);
2132          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2133          }          }
2134    
# Line 2026  for (;;) Line 2147  for (;;)
2147            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2148            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2149            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2150            GETCHARINC(c, eptr);            GETCHARINCTEST(c, eptr);
2151            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2152            }            }
2153          /* Control never gets here */          /* Control never gets here */
# Line 2041  for (;;) Line 2162  for (;;)
2162            {            {
2163            int len = 1;            int len = 1;
2164            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2165            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2166            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2167            eptr += len;            eptr += len;
2168            }            }
# Line 2050  for (;;) Line 2171  for (;;)
2171            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2172            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2173            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2174            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2175            }            }
2176          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2177          }          }
# Line 2116  for (;;) Line 2237  for (;;)
2237          if (fc != dc)          if (fc != dc)
2238            {            {
2239  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2240            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2241  #endif  #endif
2242              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2243            }            }
# Line 2207  for (;;) Line 2328  for (;;)
2328  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2329          unsigned int othercase;          unsigned int othercase;
2330          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2331              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = UCD_OTHERCASE(fc)) != fc)
2332            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2333          else oclength = 0;          else oclength = 0;
2334  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 2527  for (;;) Line 2648  for (;;)
2648              {              {
2649              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2650              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2651                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2652              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2653              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2654              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
2655                RRETURN(MATCH_NOMATCH);  
2656              }              }
2657            }            }
2658          else          else
# Line 2636  for (;;) Line 2758  for (;;)
2758              {              {
2759              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2760              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2761                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2762              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2763              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2764              }              }
2765            }            }
2766          else          else
# Line 2812  for (;;) Line 2934  for (;;)
2934              {              {
2935              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2936              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2937              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2938              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
2939                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
2940                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2825  for (;;) Line 2947  for (;;)
2947              {              {
2948              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2949              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2950              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2951              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
2952                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2953              }              }
# Line 2836  for (;;) Line 2958  for (;;)
2958              {              {
2959              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2960              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2961              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2962              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
2963                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2964              }              }
# Line 2847  for (;;) Line 2969  for (;;)
2969              {              {
2970              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2971              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2972              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
2973              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
2974                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2975              }              }
# Line 2866  for (;;) Line 2988  for (;;)
2988          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2989            {            {
2990            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
2991            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
2992            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
2993            while (eptr < md->end_subject)            while (eptr < md->end_subject)
2994              {              {
# Line 2875  for (;;) Line 2997  for (;;)
2997                {                {
2998                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
2999                }                }
3000              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3001              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3002              eptr += len;              eptr += len;
3003              }              }
# Line 2893  for (;;) Line 3015  for (;;)
3015          case OP_ANY:          case OP_ANY:
3016          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3017            {            {
3018            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject || IS_NEWLINE(eptr))
                ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))  
3019              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3020            eptr++;            eptr++;
3021            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3022            }            }
3023          break;          break;
3024    
3025            case OP_ALLANY:
3026            for (i = 1; i <= min; i++)
3027              {
3028              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3029              eptr++;
3030              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3031              }
3032            break;
3033    
3034          case OP_ANYBYTE:          case OP_ANYBYTE:
3035          eptr += min;          eptr += min;
3036          break;          break;
# Line 2916  for (;;) Line 3046  for (;;)
3046              case 0x000d:              case 0x000d:
3047              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3048              break;              break;
3049    
3050              case 0x000a:              case 0x000a:
3051                break;
3052    
3053              case 0x000b:              case 0x000b:
3054              case 0x000c:              case 0x000c:
3055              case 0x0085:              case 0x0085:
3056              case 0x2028:              case 0x2028:
3057              case 0x2029:              case 0x2029:
3058                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3059              break;              break;
3060              }              }
3061            }            }
# Line 3055  for (;;) Line 3189  for (;;)
3189          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3190            {            {
3191            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3192               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
3193              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3194            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3195            }            }
3196          break;          break;
3197    
# Line 3075  for (;;) Line 3209  for (;;)
3209          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3210            {            {
3211            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3212               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3213              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3214            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3215            }            }
3216          break;          break;
3217    
# Line 3105  for (;;) Line 3239  for (;;)
3239        switch(ctype)        switch(ctype)
3240          {          {
3241          case OP_ANY:          case OP_ANY:
3242          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3243            {            {
3244            for (i = 1; i <= min; i++)            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3245              {            eptr++;
             if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
             eptr++;  
             }  
3246            }            }
3247          else eptr += min;          break;
3248    
3249            case OP_ALLANY:
3250            eptr += min;
3251          break;          break;
3252    
3253          case OP_ANYBYTE:          case OP_ANYBYTE:
# Line 3134  for (;;) Line 3268  for (;;)
3268              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3269              break;              break;
3270              case 0x000a:              case 0x000a:
3271                break;
3272    
3273              case 0x000b:              case 0x000b:
3274              case 0x000c:              case 0x000c:
3275              case 0x0085:              case 0x0085:
3276                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3277              break;              break;
3278              }              }
3279            }            }
# Line 3276  for (;;) Line 3413  for (;;)
3413              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3414              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3415              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3416              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3417              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3418                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3419                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3291  for (;;) Line 3428  for (;;)
3428              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3429              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3430              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3431              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3432              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3433                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3434              }              }
# Line 3304  for (;;) Line 3441  for (;;)
3441              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3442              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3443              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3444              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3445              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3446                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3447              }              }
# Line 3317  for (;;) Line 3454  for (;;)
3454              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3455              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3456              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3457              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3458              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3459                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3460              }              }
# Line 3339  for (;;) Line 3476  for (;;)
3476            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3477            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3478            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3479            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3480            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3481            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3482              {              {
# Line 3348  for (;;) Line 3485  for (;;)
3485                {                {
3486                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3487                }                }
3488              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3489              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3490              eptr += len;              eptr += len;
3491              }              }
# Line 3367  for (;;) Line 3504  for (;;)
3504            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3505            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3506            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
3507                 (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&                 (ctype == OP_ANY && IS_NEWLINE(eptr)))
                 IS_NEWLINE(eptr)))  
3508              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3509    
3510            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3511            switch(ctype)            switch(ctype)
3512              {              {
3513              case OP_ANY:        /* This is the DOTALL case */              case OP_ANY:        /* This is the non-NL case */
3514              break;              case OP_ALLANY:
   
3515              case OP_ANYBYTE:              case OP_ANYBYTE:
3516              break;              break;
3517    
# Line 3388  for (;;) Line 3523  for (;;)
3523                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3524                break;                break;
3525                case 0x000a:                case 0x000a:
3526                  break;
3527    
3528                case 0x000b:                case 0x000b:
3529                case 0x000c:                case 0x000c:
3530                case 0x0085:                case 0x0085:
3531                case 0x2028:                case 0x2028:
3532                case 0x2029:                case 0x2029:
3533                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3534                break;                break;
3535                }                }
3536              break;              break;
# Line 3525  for (;;) Line 3663  for (;;)
3663            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
3664            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3665            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
3666                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))                 (ctype == OP_ANY && IS_NEWLINE(eptr)))
3667              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3668    
3669            c = *eptr++;            c = *eptr++;
3670            switch(ctype)            switch(ctype)
3671              {              {
3672              case OP_ANY:   /* This is the DOTALL case */              case OP_ANY:     /* This is the non-NL case */
3673              break;              case OP_ALLANY:
   
3674              case OP_ANYBYTE:              case OP_ANYBYTE:
3675              break;              break;
3676    
# Line 3544  for (;;) Line 3681  for (;;)
3681                case 0x000d:                case 0x000d:
3682                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3683                break;                break;
3684    
3685                case 0x000a:                case 0x000a:
3686                  break;
3687    
3688                case 0x000b:                case 0x000b:
3689                case 0x000c:                case 0x000c:
3690                case 0x0085:                case 0x0085:
3691                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3692                break;                break;
3693                }                }
3694              break;              break;
# Line 3662  for (;;) Line 3803  for (;;)
3803              int len = 1;              int len = 1;
3804              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3805              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3806              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3807              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3808                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3809                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3677  for (;;) Line 3818  for (;;)
3818              int len = 1;              int len = 1;
3819              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3820              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3821              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3822              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3823                break;                break;
3824              eptr+= len;              eptr+= len;
# Line 3690  for (;;) Line 3831  for (;;)
3831              int len = 1;              int len = 1;
3832              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3833              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3834              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3835              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3836                break;                break;
3837              eptr+= len;              eptr+= len;
# Line 3703  for (;;) Line 3844  for (;;)
3844              int len = 1;              int len = 1;
3845              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3846              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3847              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3848              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3849                break;                break;
3850              eptr+= len;              eptr+= len;
# Line 3719  for (;;) Line 3860  for (;;)
3860            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
3861            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3862            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3863            BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
3864            }            }
3865          }          }
3866    
# Line 3732  for (;;) Line 3873  for (;;)
3873            {            {
3874            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
3875            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3876            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3877            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
3878            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3879              {              {
# Line 3741  for (;;) Line 3882  for (;;)
3882                {                {
3883                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3884                }                }
3885              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3886              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3887              eptr += len;              eptr += len;
3888              }              }
# Line 3758  for (;;) Line 3899  for (;;)
3899            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
3900              {              {
3901              int len = 1;              int len = 1;
             BACKCHAR(eptr);  
3902              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr; else
3903                {                {
3904                  BACKCHAR(eptr);
3905                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3906                }                }
3907              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3908              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3909              eptr--;              eptr--;
3910              }              }
# Line 3783  for (;;) Line 3924  for (;;)
3924            case OP_ANY:            case OP_ANY:
3925            if (max < INT_MAX)            if (max < INT_MAX)
3926              {              {
3927              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
               {  
               for (i = min; i < max; i++)  
                 {  
                 if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
               }  
             else  
3928                {                {
3929                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3930                  {                eptr++;
3931                  if (eptr >= md->end_subject) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
3932                }                }
3933              }              }
3934    
# Line 3807  for (;;) Line 3936  for (;;)
3936    
3937            else            else
3938              {              {
3939              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
3940                {                {
3941                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3942                  {                eptr++;
3943                  if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
3944                }                }
3945              else              }
3946              break;
3947    
3948              case OP_ALLANY:
3949              if (max < INT_MAX)
3950                {
3951                for (i = min; i < max; i++)
3952                {                {
3953                eptr = md->end_subject;                if (eptr >= md->end_subject) break;
3954                  eptr++;
3955                  while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3956                }                }
3957              }              }
3958              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
3959            break;            break;
3960    
3961            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
# Line 3845  for (;;) Line 3980  for (;;)
3980                }                }
3981              else              else
3982                {                {
3983                if (c != 0x000a && c != 0x000b && c != 0x000c &&                if (c != 0x000a &&
3984                    c != 0x0085 && c != 0x2028 && c != 0x2029)                    (md->bsr_anycrlf ||
3985                       (c != 0x000b && c != 0x000c &&
3986                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
3987                  break;                  break;
3988                eptr += len;                eptr += len;
3989                }                }
# Line 3999  for (;;) Line 4136  for (;;)
4136            }            }
4137          }          }
4138        else        else
4139  #endif  #endif  /* SUPPORT_UTF8 */
4140    
4141        /* Not UTF-8 mode */        /* Not UTF-8 mode */
4142          {          {
4143          switch(ctype)          switch(ctype)
4144            {            {
4145            case OP_ANY:            case OP_ANY:
4146            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4147              {              {
4148              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4149                {              eptr++;
               if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
               eptr++;  
               }  
             break;  
4150              }              }
4151            /* For DOTALL case, fall through and treat as \C */            break;
4152    
4153              case OP_ALLANY:
4154            case OP_ANYBYTE:            case OP_ANYBYTE:
4155            c = max - min;            c = max - min;
4156            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
# Line 4036  for (;;) Line 4170  for (;;)
4170                }                }
4171              else              else
4172                {                {
4173                if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)                if (c != 0x000a &&
4174                      (md->bsr_anycrlf ||
4175                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4176                  break;                  break;
4177                eptr++;                eptr++;
4178                }                }
# Line 4186  HEAP_RETURN: Line 4322  HEAP_RETURN:
4322  switch (frame->Xwhere)  switch (frame->Xwhere)
4323    {    {
4324    LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)    LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4325    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(16)    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4326    LBL(17) LBL(18) LBL(19) LBL(20) LBL(21) LBL(22) LBL(23) LBL(24)    LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4327    LBL(25) LBL(26) LBL(27) LBL(28) LBL(29) LBL(30) LBL(31) LBL(32)    LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4328    LBL(33) LBL(34) LBL(35) LBL(36) LBL(37) LBL(38) LBL(39) LBL(40)    LBL(53) LBL(54)
4329    LBL(41) LBL(42) LBL(43) LBL(44) LBL(45) LBL(46) LBL(47)  #ifdef SUPPORT_UTF8
4330      LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4331      LBL(32) LBL(34) LBL(42) LBL(46)
4332    #ifdef SUPPORT_UCP
4333      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4334    #endif  /* SUPPORT_UCP */
4335    #endif  /* SUPPORT_UTF8 */
4336    default:    default:
4337    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));
4338    return PCRE_ERROR_INTERNAL;    return PCRE_ERROR_INTERNAL;
# Line 4282  Returns:          > 0 => success; value Line 4424  Returns:          > 0 => success; value
4424                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4425  */  */
4426    
4427  PCRE_EXP_DEFN int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4428  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4429    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4430    int offsetcount)    int offsetcount)
# Line 4369  if (re->magic_number != MAGIC_NUMBER) Line 4511  if (re->magic_number != MAGIC_NUMBER)
4511  /* Set up other data */  /* Set up other data */
4512    
4513  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4514  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4515  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4516    
4517  /* 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. */
# Line 4384  end_subject = md->end_subject; Line 4526  end_subject = md->end_subject;
4526    
4527  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4528  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4529    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4530    
4531  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4532  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
# Line 4396  md->recursive = NULL; Line 4539  md->recursive = NULL;
4539  md->lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
4540  md->ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
4541    
4542    /* Handle different \R options. */
4543    
4544    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4545      {
4546      case 0:
4547      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4548        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4549      else
4550    #ifdef BSR_ANYCRLF
4551      md->bsr_anycrlf = TRUE;
4552    #else
4553      md->bsr_anycrlf = FALSE;
4554    #endif
4555      break;
4556    
4557      case PCRE_BSR_ANYCRLF:
4558      md->bsr_anycrlf = TRUE;
4559      break;
4560    
4561      case PCRE_BSR_UNICODE:
4562      md->bsr_anycrlf = FALSE;
4563      break;
4564    
4565      default: return PCRE_ERROR_BADNEWLINE;
4566      }
4567    
4568  /* Handle different types of newline. The three bits give eight cases. If  /* Handle different types of newline. The three bits give eight cases. If
4569  nothing is set at run time, whatever was used at compile time applies. */  nothing is set at run time, whatever was used at compile time applies. */
4570    
4571  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4572         PCRE_NEWLINE_BITS)          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4573    {    {
4574    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
4575    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
4576    case PCRE_NEWLINE_LF: newline = '\n'; break;    case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
4577    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
4578         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
4579    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
4580    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
4581    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
# Line 4439  else Line 4608  else
4608  /* Partial matching is supported only for a restricted set of regexes at the  /* Partial matching is supported only for a restricted set of regexes at the
4609  moment. */  moment. */
4610    
4611  if (md->partial && (re->options & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
4612    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
4613    
4614  /* Check a UTF-8 string if required. Unfortunately there's no way of passing  /* Check a UTF-8 string if required. Unfortunately there's no way of passing
# Line 4516  studied, there may be a bitmap of possib Line 4685  studied, there may be a bitmap of possib
4685    
4686  if (!anchored)  if (!anchored)
4687    {    {
4688    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
4689      {      {
4690      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
4691      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
# Line 4531  if (!anchored) Line 4700  if (!anchored)
4700  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
4701  character" set. */  character" set. */
4702    
4703  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
4704    {    {
4705    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
4706    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
# Line 4547  the loop runs just once. */ Line 4716  the loop runs just once. */
4716  for(;;)  for(;;)
4717    {    {
4718    USPTR save_end_subject = end_subject;    USPTR save_end_subject = end_subject;
4719      USPTR new_start_match;
4720    
4721    /* Reset the maximum number of extractions we might see. */    /* Reset the maximum number of extractions we might see. */
4722    
# Line 4557  for(;;) Line 4727  for(;;)
4727      while (iptr < iend) *iptr++ = -1;      while (iptr < iend) *iptr++ = -1;
4728      }      }
4729    
4730    /* Advance to a unique first char if possible. If firstline is TRUE, the    /* If firstline is TRUE, the start of the match is constrained to the first
4731    start of the match is constrained to the first line of a multiline string.    line of a multiline string. That is, the match must be before or at the first
4732    That is, the match must be before or at the first newline. Implement this by    newline. Implement this by temporarily adjusting end_subject so that we stop
4733    temporarily adjusting end_subject so that we stop scanning at a newline. If    scanning at a newline. If the match fails at the newline, later code breaks
4734    the match fails at the newline, later code breaks this loop. */    this loop. */
4735    
4736    if (firstline)    if (firstline)
4737      {      {
4738      USPTR t = start_match;      USPTR t = start_match;
4739    #ifdef SUPPORT_UTF8
4740        if (utf8)
4741          {
4742          while (t < md->end_subject && !IS_NEWLINE(t))
4743            {
4744            t++;
4745            while (t < end_subject && (*t & 0xc0) == 0x80) t++;
4746            }
4747          }
4748        else
4749    #endif
4750      while (t < md->end_subject && !IS_NEWLINE(t)) t++;      while (t < md->end_subject && !IS_NEWLINE(t)) t++;
4751      end_subject = t;      end_subject = t;
4752      }      }
4753    
4754    /* Now test for a unique first byte */    /* There are some optimizations that avoid running the match if a known
4755      starting point is not found, or if a known later character is not present.
4756      However, there is an option that disables these, for testing and for ensuring
4757      that all callouts do actually occur. */
4758    
4759    if (first_byte >= 0)    if ((options & PCRE_NO_START_OPTIMIZE) == 0)
4760      {      {
4761      if (first_byte_caseless)      /* Advance to a unique first byte if there is one. */
       while (start_match < end_subject &&  
              md->lcc[*start_match] != first_byte)  
         start_match++;  
     else  
       while (start_match < end_subject && *start_match != first_byte)  
         start_match++;  
     }  
4762    
4763    /* Or to just after a linebreak for a multiline match if possible */      if (first_byte >= 0)
4764          {
4765          if (first_byte_caseless)
4766            while (start_match < end_subject && md->lcc[*start_match] != first_byte)
4767              start_match++;
4768          else
4769            while (start_match < end_subject && *start_match != first_byte)
4770              start_match++;
4771          }
4772    
4773    else if (startline)      /* Or to just after a linebreak for a multiline match */
4774      {  
4775      if (start_match > md->start_subject + start_offset)      else if (startline)
4776        {        {
4777        while (start_match <= end_subject && !WAS_NEWLINE(start_match))        if (start_match > md->start_subject + start_offset)
4778          start_match++;          {
4779    #ifdef SUPPORT_UTF8
4780            if (utf8)
4781              {
4782              while (start_match < end_subject && !WAS_NEWLINE(start_match))
4783                {
4784                start_match++;
4785                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
4786                  start_match++;
4787                }
4788              }
4789            else
4790    #endif
4791            while (start_match < end_subject && !WAS_NEWLINE(start_match))
4792              start_match++;
4793    
4794            /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
4795            and we are now at a LF, advance the match position by one more character.
4796            */
4797    
4798        /* If we have just passed a CR and the newline option is ANY or ANYCRLF,          if (start_match[-1] == CHAR_CR &&
4799        and we are now at a LF, advance the match position by one more character.               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
4800        */               start_match < end_subject &&
4801                 *start_match == CHAR_NL)
4802        if (start_match[-1] == '\r' &&            start_match++;
4803             (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&          }
            start_match < end_subject &&  
            *start_match == '\n')  
         start_match++;  
4804        }        }
     }  
4805    
4806    /* Or to a non-unique first char after study */      /* Or to a non-unique first byte after study */
4807    
4808    else if (start_bits != NULL)      else if (start_bits != NULL)
     {  
     while (start_match < end_subject)  
4809        {        {
4810        register unsigned int c = *start_match;        while (start_match < end_subject)
4811        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break;          {
4812            register unsigned int c = *start_match;
4813            if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;
4814              else break;
4815            }
4816        }        }
4817      }      }   /* Starting optimizations */
4818    
4819    /* Restore fudged end_subject */    /* Restore fudged end_subject */
4820    
# Line 4625  for(;;) Line 4826  for(;;)
4826    printf("\n");    printf("\n");
4827  #endif  #endif
4828    
4829    /* If req_byte is set, we know that that character must appear in the subject    /* If req_byte is set, we know that that character must appear in the
4830    for the match to succeed. If the first character is set, req_byte must be    subject for the match to succeed. If the first character is set, req_byte
4831    later in the subject; otherwise the test starts at the match point. This    must be later in the subject; otherwise the test starts at the match point.
4832    optimization can save a huge amount of backtracking in patterns with nested    This optimization can save a huge amount of backtracking in patterns with
4833    unlimited repeats that aren't going to match. Writing separate code for    nested unlimited repeats that aren't going to match. Writing separate code
4834    cased/caseless versions makes it go faster, as does using an autoincrement    for cased/caseless versions makes it go faster, as does using an
4835    and backing off on a match.    autoincrement and backing off on a match.
4836    
4837    HOWEVER: when the subject string is very, very long, searching to its end can    HOWEVER: when the subject string is very, very long, searching to its end
4838    take a long time, and give bad performance on quite ordinary patterns. This    can take a long time, and give bad performance on quite ordinary patterns.
4839    showed up when somebody was matching something like /^\d+C/ on a 32-megabyte    This showed up when somebody was matching something like /^\d+C/ on a
4840    string... so we don't do this when the string is sufficiently long.    32-megabyte string... so we don't do this when the string is sufficiently
4841      long.
4842    
4843    ALSO: this processing is disabled when partial matching is requested.    ALSO: this processing is disabled when partial matching is requested, or if
4844    */    disabling is explicitly requested. */
4845    
4846    if (req_byte >= 0 &&    if ((options & PCRE_NO_START_OPTIMIZE) == 0 &&
4847          req_byte >= 0 &&
4848        end_subject - start_match < REQ_BYTE_MAX &&        end_subject - start_match < REQ_BYTE_MAX &&
4849        !md->partial)        !md->partial)
4850      {      {
# Line 4687  for(;;) Line 4890  for(;;)
4890    
4891    /* OK, we can now run the match. */    /* OK, we can now run the match. */
4892    
4893    md->start_match_ptr = start_match;      /* Insurance */    md->start_match_ptr = start_match;
4894    md->match_call_count = 0;    md->match_call_count = 0;
4895    rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);    rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);
4896    
4897    /* Any return other than MATCH_NOMATCH breaks the loop. */    switch(rc)
4898        {
4899        /* NOMATCH and PRUNE advance by one character. THEN at this level acts
4900        exactly like PRUNE. */
4901    
4902        case MATCH_NOMATCH:
4903        case MATCH_PRUNE:
4904        case MATCH_THEN:
4905        new_start_match = start_match + 1;
4906    #ifdef SUPPORT_UTF8
4907        if (utf8)
4908          while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80)
4909            new_start_match++;
4910    #endif
4911        break;
4912    
4913        /* SKIP passes back the next starting point explicitly. */
4914    
4915    if (rc != MATCH_NOMATCH) break;      case MATCH_SKIP:
4916        new_start_match = md->start_match_ptr;
4917        break;
4918    
4919        /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
4920    
4921        case MATCH_COMMIT:
4922        rc = MATCH_NOMATCH;
4923        goto ENDLOOP;
4924    
4925        /* Any other return is some kind of error. */
4926    
4927        default:
4928        goto ENDLOOP;
4929        }
4930    
4931      /* Control reaches here for the various types of "no match at this point"
4932      result. Reset the code to MATCH_NOMATCH for subsequent checking. */
4933    
4934      rc = MATCH_NOMATCH;
4935    
4936    /* If PCRE_FIRSTLINE is set, the match must happen before or at the first    /* If PCRE_FIRSTLINE is set, the match must happen before or at the first
4937    newline in the subject (though it may continue over the newline). Therefore,    newline in the subject (though it may continue over the newline). Therefore,
# Line 4701  for(;;) Line 4939  for(;;)
4939    
4940    if (firstline && IS_NEWLINE(start_match)) break;    if (firstline && IS_NEWLINE(start_match)) break;
4941    
4942    /* Advance the match position by one character. */    /* Advance to new matching position */
4943    
4944    start_match++;    start_match = new_start_match;
 #ifdef SUPPORT_UTF8  
   if (utf8)  
     while(start_match < end_subject && (*start_match & 0xc0) == 0x80)  
       start_match++;  
 #endif  
4945    
4946    /* Break the loop if the pattern is anchored or if we have passed the end of    /* Break the loop if the pattern is anchored or if we have passed the end of
4947    the subject. */    the subject. */
4948    
4949    if (anchored || start_match > end_subject) break;    if (anchored || start_match > end_subject) break;
4950    
4951    /* If we have just passed a CR and the newline option is CRLF or ANY or    /* If we have just passed a CR and we are now at a LF, and the pattern does
4952    ANYCRLF, and we are now at a LF, advance the match position by one more    not contain any explicit matches for \r or \n, and the newline option is CRLF
4953    character. */    or ANY or ANYCRLF, advance the match position by one more character. */
4954    
4955    if (start_match[-1] == '\r' &&    if (start_match[-1] == CHAR_CR &&
4956         (md->nltype == NLTYPE_ANY ||        start_match < end_subject &&
4957          md->nltype == NLTYPE_ANYCRLF ||        *start_match == CHAR_NL &&
4958          md->nllen == 2) &&        (re->flags & PCRE_HASCRORLF) == 0 &&
4959         start_match < end_subject &&          (md->nltype == NLTYPE_ANY ||
4960         *start_match == '\n')           md->nltype == NLTYPE_ANYCRLF ||
4961             md->nllen == 2))
4962      start_match++;      start_match++;
4963    
4964    }   /* End of for(;;) "bumpalong" loop */    }   /* End of for(;;) "bumpalong" loop */
# Line 4734  for(;;) Line 4968  for(;;)
4968  /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping  /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping
4969  conditions is true:  conditions is true:
4970    
4971  (1) The pattern is anchored;  (1) The pattern is anchored or the match was failed by (*COMMIT);
4972    
4973  (2) We are past the end of the subject;  (2) We are past the end of the subject;
4974    
# Line 4749  processing, copy those that we can. In t Line 4983  processing, copy those that we can. In t
4983  certain parts of the pattern were not used, even though there are more  certain parts of the pattern were not used, even though there are more
4984  capturing parentheses than vector slots. */  capturing parentheses than vector slots. */
4985    
4986    ENDLOOP:
4987    
4988  if (rc == MATCH_MATCH)  if (rc == MATCH_MATCH)
4989    {    {
4990    if (using_temporary_offsets)    if (using_temporary_offsets)

Legend:
Removed from v.200  
changed lines
  Added in v.402

  ViewVC Help
Powered by ViewVC 1.1.5