/[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 400 by ph10, Sat Mar 21 16:59:40 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 527  int oclength; Line 561  int oclength;
561  uschar occhars[8];  uschar occhars[8];
562  #endif  #endif
563    
564    int codelink;
565    int condcode;
566  int ctype;  int ctype;
567  int length;  int length;
568  int max;  int max;
# Line 601  for (;;) Line 637  for (;;)
637    {    {
638    minimize = possessive = FALSE;    minimize = possessive = FALSE;
639    op = *ecode;    op = *ecode;
640    
641    /* 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
642    matching at least one subject character. */    matching at least one subject character. */
643    
# Line 612  for (;;) Line 648  for (;;)
648    
649    switch(op)    switch(op)
650      {      {
651        case OP_FAIL:
652        RRETURN(MATCH_NOMATCH);
653    
654        case OP_PRUNE:
655        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
656          ims, eptrb, flags, RM51);
657        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
658        RRETURN(MATCH_PRUNE);
659    
660        case OP_COMMIT:
661        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
662          ims, eptrb, flags, RM52);
663        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
664        RRETURN(MATCH_COMMIT);
665    
666        case OP_SKIP:
667        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
668          ims, eptrb, flags, RM53);
669        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
670        md->start_match_ptr = eptr;   /* Pass back current position */
671        RRETURN(MATCH_SKIP);
672    
673        case OP_THEN:
674        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
675          ims, eptrb, flags, RM54);
676        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
677        RRETURN(MATCH_THEN);
678    
679      /* 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
680      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.
681      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 717  for (;;)
717          {          {
718          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
719            ims, eptrb, flags, RM1);            ims, eptrb, flags, RM1);
720          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
721          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
722          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
723          }          }
# Line 712  for (;;) Line 776  for (;;)
776    
777        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
778          eptrb, flags, RM2);          eptrb, flags, RM2);
779        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
780        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
781        }        }
782      /* Control never reaches here. */      /* Control never reaches here. */
# Line 725  for (;;) Line 789  for (;;)
789    
790      case OP_COND:      case OP_COND:
791      case OP_SCOND:      case OP_SCOND:
792      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */      codelink= GET(ecode, 1);
793    
794        /* Because of the way auto-callout works during compile, a callout item is
795        inserted between OP_COND and an assertion condition. */
796    
797        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
798          {
799          if (pcre_callout != NULL)
800            {
801            pcre_callout_block cb;
802            cb.version          = 1;   /* Version 1 of the callout block */
803            cb.callout_number   = ecode[LINK_SIZE+2];
804            cb.offset_vector    = md->offset_vector;
805            cb.subject          = (PCRE_SPTR)md->start_subject;
806            cb.subject_length   = md->end_subject - md->start_subject;
807            cb.start_match      = mstart - md->start_subject;
808            cb.current_position = eptr - md->start_subject;
809            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
810            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
811            cb.capture_top      = offset_top/2;
812            cb.capture_last     = md->capture_last;
813            cb.callout_data     = md->callout_data;
814            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
815            if (rrc < 0) RRETURN(rrc);
816            }
817          ecode += _pcre_OP_lengths[OP_CALLOUT];
818          }
819    
820        condcode = ecode[LINK_SIZE+1];
821    
822        /* Now see what the actual condition is */
823    
824        if (condcode == OP_RREF)         /* Recursion test */
825        {        {
826        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
827        condition = md->recursive != NULL &&        condition = md->recursive != NULL &&
# Line 733  for (;;) Line 829  for (;;)
829        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
830        }        }
831    
832      else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */      else if (condcode == OP_CREF)    /* Group used test */
833        {        {
834        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
835        condition = offset < offset_top && md->offset_vector[offset] >= 0;        condition = offset < offset_top && md->offset_vector[offset] >= 0;
836        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
837        }        }
838    
839      else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */      else if (condcode == OP_DEF)     /* DEFINE - always false */
840        {        {
841        condition = FALSE;        condition = FALSE;
842        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
# Line 760  for (;;) Line 856  for (;;)
856          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
857          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
858          }          }
859        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
860          {          {
861          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
862          }          }
863        else        else
864          {          {
865          condition = FALSE;          condition = FALSE;
866          ecode += GET(ecode, 1);          ecode += codelink;
867          }          }
868        }        }
869    
# Line 790  for (;;) Line 886  for (;;)
886          goto TAIL_RECURSE;          goto TAIL_RECURSE;
887          }          }
888        }        }
889      else                         /* Condition false & no 2nd alternative */      else                         /* Condition false & no alternative */
890        {        {
891        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
892        }        }
893      break;      break;
894    
895    
896      /* 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
897      restore the offsets appropriately and continue from after the call. */      recursion, we should restore the offsets appropriately and continue from
898        after the call. */
899    
900        case OP_ACCEPT:
901      case OP_END:      case OP_END:
902      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
903        {        {
# Line 820  for (;;) Line 918  for (;;)
918      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
919      md->end_match_ptr = eptr;           /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
920      md->end_offset_top = offset_top;    /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
921      md->start_match_ptr = mstart;  /* and the start (\K can modify) */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
922      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
923    
924      /* Change option settings */      /* Change option settings */
# Line 844  for (;;) Line 942  for (;;)
942        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
943          RM4);          RM4);
944        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
945        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
946        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
947        }        }
948      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 871  for (;;) Line 969  for (;;)
969        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
970          RM5);          RM5);
971        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
972        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
973        ecode += GET(ecode,1);        ecode += GET(ecode,1);
974        }        }
975      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 895  for (;;) Line 993  for (;;)
993          {          {
994          eptr--;          eptr--;
995          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
996          BACKCHAR(eptr)          BACKCHAR(eptr);
997          }          }
998        }        }
999      else      else
# Line 1008  for (;;) Line 1106  for (;;)
1106              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1107            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1108            }            }
1109          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1110            {            {
1111            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1112              if (new_recursive.offset_save != stacksave)
1113                (pcre_free)(new_recursive.offset_save);
1114            RRETURN(rrc);            RRETURN(rrc);
1115            }            }
1116    
# Line 1044  for (;;) Line 1144  for (;;)
1144        {        {
1145        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);
1146        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
1147        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1148        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1149        }        }
1150      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1110  for (;;) Line 1210  for (;;)
1210      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1211      break;      break;
1212    
1213      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1214      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
1215      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
1216      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
1217      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1218    
1219      case OP_BRAZERO:      case OP_BRAZERO:
1220        {        {
# Line 1136  for (;;) Line 1236  for (;;)
1236        }        }
1237      break;      break;
1238    
1239        case OP_SKIPZERO:
1240          {
1241          next = ecode+1;
1242          do next += GET(next,1); while (*next == OP_ALT);
1243          ecode = next + 1 + LINK_SIZE;
1244          }
1245        break;
1246    
1247      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1248    
1249      case OP_KET:      case OP_KET:
# Line 1383  for (;;) Line 1491  for (;;)
1491      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1492    
1493      case OP_ANY:      case OP_ANY:
1494      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1495        {      /* Fall through */
1496        if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
1497        }      case OP_ALLANY:
1498      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
1499      if (utf8)      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1500      ecode++;      ecode++;
1501      break;      break;
1502    
# Line 1488  for (;;) Line 1595  for (;;)
1595        case 0x000d:        case 0x000d:
1596        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1597        break;        break;
1598    
1599        case 0x000a:        case 0x000a:
1600          break;
1601    
1602        case 0x000b:        case 0x000b:
1603        case 0x000c:        case 0x000c:
1604        case 0x0085:        case 0x0085:
1605        case 0x2028:        case 0x2028:
1606        case 0x2029:        case 0x2029:
1607          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1608        break;        break;
1609        }        }
1610      ecode++;      ecode++;
# Line 1604  for (;;) Line 1715  for (;;)
1715      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1716      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1717        {        {
1718        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1719    
1720        switch(ecode[1])        switch(ecode[1])
1721          {          {
# Line 1614  for (;;) Line 1724  for (;;)
1724          break;          break;
1725    
1726          case PT_LAMP:          case PT_LAMP:
1727          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1728               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1729               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1730            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1731           break;           break;
1732    
1733          case PT_GC:          case PT_GC:
1734          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1735            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1736          break;          break;
1737    
1738          case PT_PC:          case PT_PC:
1739          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1740            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1741          break;          break;
1742    
1743          case PT_SC:          case PT_SC:
1744          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1745            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1746          break;          break;
1747    
# Line 1650  for (;;) Line 1760  for (;;)
1760      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1761      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1762        {        {
1763        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1764        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1765        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1766          {          {
# Line 1660  for (;;) Line 1769  for (;;)
1769            {            {
1770            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1771            }            }
1772          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1773          if (category != ucp_M) break;          if (category != ucp_M) break;
1774          eptr += len;          eptr += len;
1775          }          }
# Line 1681  for (;;) Line 1790  for (;;)
1790      case OP_REF:      case OP_REF:
1791        {        {
1792        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1793        ecode += 3;                                 /* Advance past item */        ecode += 3;
1794    
1795          /* If the reference is unset, there are two possibilities:
1796    
1797          (a) In the default, Perl-compatible state, set the length to be longer
1798          than the amount of subject left; this ensures that every attempt at a
1799          match fails. We can't just fail here, because of the possibility of
1800          quantifiers with zero minima.
1801    
1802          (b) If the JavaScript compatibility flag is set, set the length to zero
1803          so that the back reference matches an empty string.
1804    
1805        /* 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
1806        of subject left; this ensures that every attempt at a match fails. We        referenced subpattern. */
1807        can't just fail here, because of the possibility of quantifiers with zero  
1808        minima. */        if (offset >= offset_top || md->offset_vector[offset] < 0)
1809            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1810        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        else
1811          md->end_subject - eptr + 1 :          length = md->offset_vector[offset+1] - md->offset_vector[offset];
         md->offset_vector[offset+1] - md->offset_vector[offset];  
1812    
1813        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1814    
# Line 1965  for (;;) Line 2083  for (;;)
2083    
2084    
2085      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2086      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
2087        mode, because Unicode properties are supported in non-UTF-8 mode. */
2088    
2089  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2090      case OP_XCLASS:      case OP_XCLASS:
# Line 2007  for (;;) Line 2126  for (;;)
2126        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2127          {          {
2128          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2129          GETCHARINC(c, eptr);          GETCHARINCTEST(c, eptr);
2130          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2131          }          }
2132    
# Line 2026  for (;;) Line 2145  for (;;)
2145            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2146            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2147            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2148            GETCHARINC(c, eptr);            GETCHARINCTEST(c, eptr);
2149            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2150            }            }
2151          /* Control never gets here */          /* Control never gets here */
# Line 2041  for (;;) Line 2160  for (;;)
2160            {            {
2161            int len = 1;            int len = 1;
2162            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2163            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2164            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2165            eptr += len;            eptr += len;
2166            }            }
# Line 2050  for (;;) Line 2169  for (;;)
2169            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2170            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2171            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2172            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2173            }            }
2174          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2175          }          }
# Line 2116  for (;;) Line 2235  for (;;)
2235          if (fc != dc)          if (fc != dc)
2236            {            {
2237  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2238            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2239  #endif  #endif
2240              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2241            }            }
# Line 2207  for (;;) Line 2326  for (;;)
2326  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2327          unsigned int othercase;          unsigned int othercase;
2328          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2329              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = UCD_OTHERCASE(fc)) != fc)
2330            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2331          else oclength = 0;          else oclength = 0;
2332  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 2527  for (;;) Line 2646  for (;;)
2646              {              {
2647              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2648              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2649                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2650              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2651              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2652              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
2653                RRETURN(MATCH_NOMATCH);  
2654              }              }
2655            }            }
2656          else          else
# Line 2636  for (;;) Line 2756  for (;;)
2756              {              {
2757              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2758              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2759                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2760              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2761              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2762              }              }
2763            }            }
2764          else          else
# Line 2812  for (;;) Line 2932  for (;;)
2932              {              {
2933              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2934              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2935              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2936              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
2937                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
2938                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2825  for (;;) Line 2945  for (;;)
2945              {              {
2946              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2947              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2948              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2949              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
2950                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2951              }              }
# Line 2836  for (;;) Line 2956  for (;;)
2956              {              {
2957              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2958              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2959              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2960              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
2961                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2962              }              }
# Line 2847  for (;;) Line 2967  for (;;)
2967              {              {
2968              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2969              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2970              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
2971              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
2972                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2973              }              }
# Line 2866  for (;;) Line 2986  for (;;)
2986          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2987            {            {
2988            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
2989            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
2990            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
2991            while (eptr < md->end_subject)            while (eptr < md->end_subject)
2992              {              {
# Line 2875  for (;;) Line 2995  for (;;)
2995                {                {
2996                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
2997                }                }
2998              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2999              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3000              eptr += len;              eptr += len;
3001              }              }
# Line 2893  for (;;) Line 3013  for (;;)
3013          case OP_ANY:          case OP_ANY:
3014          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3015            {            {
3016            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject || IS_NEWLINE(eptr))
                ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))  
3017              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3018            eptr++;            eptr++;
3019            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3020            }            }
3021          break;          break;
3022    
3023            case OP_ALLANY:
3024            for (i = 1; i <= min; i++)
3025              {
3026              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3027              eptr++;
3028              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3029              }
3030            break;
3031    
3032          case OP_ANYBYTE:          case OP_ANYBYTE:
3033          eptr += min;          eptr += min;
3034          break;          break;
# Line 2916  for (;;) Line 3044  for (;;)
3044              case 0x000d:              case 0x000d:
3045              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3046              break;              break;
3047    
3048              case 0x000a:              case 0x000a:
3049                break;
3050    
3051              case 0x000b:              case 0x000b:
3052              case 0x000c:              case 0x000c:
3053              case 0x0085:              case 0x0085:
3054              case 0x2028:              case 0x2028:
3055              case 0x2029:              case 0x2029:
3056                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3057              break;              break;
3058              }              }
3059            }            }
# Line 3055  for (;;) Line 3187  for (;;)
3187          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3188            {            {
3189            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3190               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
3191              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3192            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3193            }            }
3194          break;          break;
3195    
# Line 3075  for (;;) Line 3207  for (;;)
3207          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3208            {            {
3209            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3210               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3211              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3212            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3213            }            }
3214          break;          break;
3215    
# Line 3105  for (;;) Line 3237  for (;;)
3237        switch(ctype)        switch(ctype)
3238          {          {
3239          case OP_ANY:          case OP_ANY:
3240          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3241            {            {
3242            for (i = 1; i <= min; i++)            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3243              {            eptr++;
             if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
             eptr++;  
             }  
3244            }            }
3245          else eptr += min;          break;
3246    
3247            case OP_ALLANY:
3248            eptr += min;
3249          break;          break;
3250    
3251          case OP_ANYBYTE:          case OP_ANYBYTE:
# Line 3134  for (;;) Line 3266  for (;;)
3266              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3267              break;              break;
3268              case 0x000a:              case 0x000a:
3269                break;
3270    
3271              case 0x000b:              case 0x000b:
3272              case 0x000c:              case 0x000c:
3273              case 0x0085:              case 0x0085:
3274                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3275              break;              break;
3276              }              }
3277            }            }
# Line 3276  for (;;) Line 3411  for (;;)
3411              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3412              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3413              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3414              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3415              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3416                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3417                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3291  for (;;) Line 3426  for (;;)
3426              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3427              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3428              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3429              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3430              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3431                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3432              }              }
# Line 3304  for (;;) Line 3439  for (;;)
3439              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3440              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3441              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3442              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3443              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3444                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3445              }              }
# Line 3317  for (;;) Line 3452  for (;;)
3452              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3453              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3454              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3455              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3456              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3457                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3458              }              }
# Line 3339  for (;;) Line 3474  for (;;)
3474            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3475            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3476            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3477            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3478            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3479            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3480              {              {
# Line 3348  for (;;) Line 3483  for (;;)
3483                {                {
3484                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3485                }                }
3486              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3487              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3488              eptr += len;              eptr += len;
3489              }              }
# Line 3367  for (;;) Line 3502  for (;;)
3502            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3503            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3504            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
3505                 (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&                 (ctype == OP_ANY && IS_NEWLINE(eptr)))
                 IS_NEWLINE(eptr)))  
3506              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3507    
3508            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3509            switch(ctype)            switch(ctype)
3510              {              {
3511              case OP_ANY:        /* This is the DOTALL case */              case OP_ANY:        /* This is the non-NL case */
3512              break;              case OP_ALLANY:
   
3513              case OP_ANYBYTE:              case OP_ANYBYTE:
3514              break;              break;
3515    
# Line 3388  for (;;) Line 3521  for (;;)
3521                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3522                break;                break;
3523                case 0x000a:                case 0x000a:
3524                  break;
3525    
3526                case 0x000b:                case 0x000b:
3527                case 0x000c:                case 0x000c:
3528                case 0x0085:                case 0x0085:
3529                case 0x2028:                case 0x2028:
3530                case 0x2029:                case 0x2029:
3531                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3532                break;                break;
3533                }                }
3534              break;              break;
# Line 3525  for (;;) Line 3661  for (;;)
3661            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
3662            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3663            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
3664                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))                 (ctype == OP_ANY && IS_NEWLINE(eptr)))
3665              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3666    
3667            c = *eptr++;            c = *eptr++;
3668            switch(ctype)            switch(ctype)
3669              {              {
3670              case OP_ANY:   /* This is the DOTALL case */              case OP_ANY:     /* This is the non-NL case */
3671              break;              case OP_ALLANY:
   
3672              case OP_ANYBYTE:              case OP_ANYBYTE:
3673              break;              break;
3674    
# Line 3544  for (;;) Line 3679  for (;;)
3679                case 0x000d:                case 0x000d:
3680                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3681                break;                break;
3682    
3683                case 0x000a:                case 0x000a:
3684                  break;
3685    
3686                case 0x000b:                case 0x000b:
3687                case 0x000c:                case 0x000c:
3688                case 0x0085:                case 0x0085:
3689                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3690                break;                break;
3691                }                }
3692              break;              break;
# Line 3662  for (;;) Line 3801  for (;;)
3801              int len = 1;              int len = 1;
3802              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3803              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3804              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3805              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3806                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3807                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3677  for (;;) Line 3816  for (;;)
3816              int len = 1;              int len = 1;
3817              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3818              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3819              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3820              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3821                break;                break;
3822              eptr+= len;              eptr+= len;
# Line 3690  for (;;) Line 3829  for (;;)
3829              int len = 1;              int len = 1;
3830              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3831              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3832              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3833              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3834                break;                break;
3835              eptr+= len;              eptr+= len;
# Line 3703  for (;;) Line 3842  for (;;)
3842              int len = 1;              int len = 1;
3843              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3844              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3845              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3846              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3847                break;                break;
3848              eptr+= len;              eptr+= len;
# Line 3719  for (;;) Line 3858  for (;;)
3858            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
3859            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3860            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3861            BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
3862            }            }
3863          }          }
3864    
# Line 3732  for (;;) Line 3871  for (;;)
3871            {            {
3872            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
3873            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3874            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3875            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
3876            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3877              {              {
# Line 3741  for (;;) Line 3880  for (;;)
3880                {                {
3881                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3882                }                }
3883              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3884              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3885              eptr += len;              eptr += len;
3886              }              }
# Line 3758  for (;;) Line 3897  for (;;)
3897            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
3898              {              {
3899              int len = 1;              int len = 1;
             BACKCHAR(eptr);  
3900              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr; else
3901                {                {
3902                  BACKCHAR(eptr);
3903                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3904                }                }
3905              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3906              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3907              eptr--;              eptr--;
3908              }              }
# Line 3783  for (;;) Line 3922  for (;;)
3922            case OP_ANY:            case OP_ANY:
3923            if (max < INT_MAX)            if (max < INT_MAX)
3924              {              {
3925              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  
3926                {                {
3927                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3928                  {                eptr++;
3929                  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++;  
                 }  
3930                }                }
3931              }              }
3932    
# Line 3807  for (;;) Line 3934  for (;;)
3934    
3935            else            else
3936              {              {
3937              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
3938                {                {
3939                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3940                  {                eptr++;
3941                  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++;  
                 }  
3942                }                }
3943              else              }
3944              break;
3945    
3946              case OP_ALLANY:
3947              if (max < INT_MAX)
3948                {
3949                for (i = min; i < max; i++)
3950                {                {
3951                eptr = md->end_subject;                if (eptr >= md->end_subject) break;
3952                  eptr++;
3953                  while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3954                }                }
3955              }              }
3956              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
3957            break;            break;
3958    
3959            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
# Line 3845  for (;;) Line 3978  for (;;)
3978                }                }
3979              else              else
3980                {                {
3981                if (c != 0x000a && c != 0x000b && c != 0x000c &&                if (c != 0x000a &&
3982                    c != 0x0085 && c != 0x2028 && c != 0x2029)                    (md->bsr_anycrlf ||
3983                       (c != 0x000b && c != 0x000c &&
3984                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
3985                  break;                  break;
3986                eptr += len;                eptr += len;
3987                }                }
# Line 3999  for (;;) Line 4134  for (;;)
4134            }            }
4135          }          }
4136        else        else
4137  #endif  #endif  /* SUPPORT_UTF8 */
4138    
4139        /* Not UTF-8 mode */        /* Not UTF-8 mode */
4140          {          {
4141          switch(ctype)          switch(ctype)
4142            {            {
4143            case OP_ANY:            case OP_ANY:
4144            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4145              {              {
4146              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4147                {              eptr++;
               if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
               eptr++;  
               }  
             break;  
4148              }              }
4149            /* For DOTALL case, fall through and treat as \C */            break;
4150    
4151              case OP_ALLANY:
4152            case OP_ANYBYTE:            case OP_ANYBYTE:
4153            c = max - min;            c = max - min;
4154            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
# Line 4036  for (;;) Line 4168  for (;;)
4168                }                }
4169              else              else
4170                {                {
4171                if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)                if (c != 0x000a &&
4172                      (md->bsr_anycrlf ||
4173                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4174                  break;                  break;
4175                eptr++;                eptr++;
4176                }                }
# Line 4186  HEAP_RETURN: Line 4320  HEAP_RETURN:
4320  switch (frame->Xwhere)  switch (frame->Xwhere)
4321    {    {
4322    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)
4323    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)
4324    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)
4325    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)
4326    LBL(33) LBL(34) LBL(35) LBL(36) LBL(37) LBL(38) LBL(39) LBL(40)    LBL(53) LBL(54)
4327    LBL(41) LBL(42) LBL(43) LBL(44) LBL(45) LBL(46) LBL(47)  #ifdef SUPPORT_UTF8
4328      LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4329      LBL(32) LBL(34) LBL(42) LBL(46)
4330    #ifdef SUPPORT_UCP
4331      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4332    #endif  /* SUPPORT_UCP */
4333    #endif  /* SUPPORT_UTF8 */
4334    default:    default:
4335    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));
4336    return PCRE_ERROR_INTERNAL;    return PCRE_ERROR_INTERNAL;
# Line 4282  Returns:          > 0 => success; value Line 4422  Returns:          > 0 => success; value
4422                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4423  */  */
4424    
4425  PCRE_EXP_DEFN int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4426  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4427    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4428    int offsetcount)    int offsetcount)
# Line 4369  if (re->magic_number != MAGIC_NUMBER) Line 4509  if (re->magic_number != MAGIC_NUMBER)
4509  /* Set up other data */  /* Set up other data */
4510    
4511  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4512  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4513  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4514    
4515  /* 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 4524  end_subject = md->end_subject;
4524    
4525  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4526  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4527    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4528    
4529  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4530  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
# Line 4396  md->recursive = NULL; Line 4537  md->recursive = NULL;
4537  md->lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
4538  md->ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
4539    
4540    /* Handle different \R options. */
4541    
4542    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4543      {
4544      case 0:
4545      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4546        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4547      else
4548    #ifdef BSR_ANYCRLF
4549      md->bsr_anycrlf = TRUE;
4550    #else
4551      md->bsr_anycrlf = FALSE;
4552    #endif
4553      break;
4554    
4555      case PCRE_BSR_ANYCRLF:
4556      md->bsr_anycrlf = TRUE;
4557      break;
4558    
4559      case PCRE_BSR_UNICODE:
4560      md->bsr_anycrlf = FALSE;
4561      break;
4562    
4563      default: return PCRE_ERROR_BADNEWLINE;
4564      }
4565    
4566  /* Handle different types of newline. The three bits give eight cases. If  /* Handle different types of newline. The three bits give eight cases. If
4567  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. */
4568    
4569  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4570         PCRE_NEWLINE_BITS)          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4571    {    {
4572    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
4573    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
4574    case PCRE_NEWLINE_LF: newline = '\n'; break;    case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
4575    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
4576         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
4577    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
4578    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
4579    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
# Line 4439  else Line 4606  else
4606  /* 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
4607  moment. */  moment. */
4608    
4609  if (md->partial && (re->options & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
4610    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
4611    
4612  /* 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 4683  studied, there may be a bitmap of possib
4683    
4684  if (!anchored)  if (!anchored)
4685    {    {
4686    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
4687      {      {
4688      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
4689      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 4698  if (!anchored)
4698  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
4699  character" set. */  character" set. */
4700    
4701  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
4702    {    {
4703    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
4704    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 4714  the loop runs just once. */
4714  for(;;)  for(;;)
4715    {    {
4716    USPTR save_end_subject = end_subject;    USPTR save_end_subject = end_subject;
4717      USPTR new_start_match;
4718    
4719    /* Reset the maximum number of extractions we might see. */    /* Reset the maximum number of extractions we might see. */
4720    
# Line 4557  for(;;) Line 4725  for(;;)
4725      while (iptr < iend) *iptr++ = -1;      while (iptr < iend) *iptr++ = -1;
4726      }      }
4727    
4728    /* 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
4729    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
4730    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
4731    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
4732    the match fails at the newline, later code breaks this loop. */    this loop. */
4733    
4734    if (firstline)    if (firstline)
4735      {      {
4736      USPTR t = start_match;      USPTR t = start_match;
4737    #ifdef SUPPORT_UTF8
4738        if (utf8)
4739          {
4740          while (t < md->end_subject && !IS_NEWLINE(t))
4741            {
4742            t++;
4743            while (t < end_subject && (*t & 0xc0) == 0x80) t++;
4744            }
4745          }
4746        else
4747    #endif
4748      while (t < md->end_subject && !IS_NEWLINE(t)) t++;      while (t < md->end_subject && !IS_NEWLINE(t)) t++;
4749      end_subject = t;      end_subject = t;
4750      }      }
4751    
4752    /* Now test for a unique first byte */    /* There are some optimizations that avoid running the match if a known
4753      starting point is not found, or if a known later character is not present.
4754      However, there is an option that disables these, for testing and for ensuring
4755      that all callouts do actually occur. */
4756    
4757    if (first_byte >= 0)    if ((options & PCRE_NO_START_OPTIMIZE) == 0)
4758      {      {
4759      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++;  
     }  
4760    
4761    /* Or to just after a linebreak for a multiline match if possible */      if (first_byte >= 0)
4762          {
4763          if (first_byte_caseless)
4764            while (start_match < end_subject && md->lcc[*start_match] != first_byte)
4765              start_match++;
4766          else
4767            while (start_match < end_subject && *start_match != first_byte)
4768              start_match++;
4769          }
4770    
4771    else if (startline)      /* Or to just after a linebreak for a multiline match */
4772      {  
4773      if (start_match > md->start_subject + start_offset)      else if (startline)
4774        {        {
4775        while (start_match <= end_subject && !WAS_NEWLINE(start_match))        if (start_match > md->start_subject + start_offset)
4776          start_match++;          {
4777    #ifdef SUPPORT_UTF8
4778            if (utf8)
4779              {
4780              while (start_match < end_subject && !WAS_NEWLINE(start_match))
4781                {
4782                start_match++;
4783                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
4784                  start_match++;
4785                }
4786              }
4787            else
4788    #endif
4789            while (start_match < end_subject && !WAS_NEWLINE(start_match))
4790              start_match++;
4791    
4792            /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
4793            and we are now at a LF, advance the match position by one more character.
4794            */
4795    
4796        /* If we have just passed a CR and the newline option is ANY or ANYCRLF,          if (start_match[-1] == CHAR_CR &&
4797        and we are now at a LF, advance the match position by one more character.               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
4798        */               start_match < end_subject &&
4799                 *start_match == CHAR_NL)
4800        if (start_match[-1] == '\r' &&            start_match++;
4801             (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&          }
            start_match < end_subject &&  
            *start_match == '\n')  
         start_match++;  
4802        }        }
     }  
4803    
4804    /* Or to a non-unique first char after study */      /* Or to a non-unique first byte after study */
4805    
4806    else if (start_bits != NULL)      else if (start_bits != NULL)
     {  
     while (start_match < end_subject)  
4807        {        {
4808        register unsigned int c = *start_match;        while (start_match < end_subject)
4809        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break;          {
4810            register unsigned int c = *start_match;
4811            if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;
4812              else break;
4813            }
4814        }        }
4815      }      }   /* Starting optimizations */
4816    
4817    /* Restore fudged end_subject */    /* Restore fudged end_subject */
4818    
# Line 4625  for(;;) Line 4824  for(;;)
4824    printf("\n");    printf("\n");
4825  #endif  #endif
4826    
4827    /* 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
4828    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
4829    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.
4830    optimization can save a huge amount of backtracking in patterns with nested    This optimization can save a huge amount of backtracking in patterns with
4831    unlimited repeats that aren't going to match. Writing separate code for    nested unlimited repeats that aren't going to match. Writing separate code
4832    cased/caseless versions makes it go faster, as does using an autoincrement    for cased/caseless versions makes it go faster, as does using an
4833    and backing off on a match.    autoincrement and backing off on a match.
4834    
4835    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
4836    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.
4837    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
4838    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
4839      long.
4840    
4841    ALSO: this processing is disabled when partial matching is requested.    ALSO: this processing is disabled when partial matching is requested, or if
4842    */    disabling is explicitly requested. */
4843    
4844    if (req_byte >= 0 &&    if ((options & PCRE_NO_START_OPTIMIZE) == 0 &&
4845          req_byte >= 0 &&
4846        end_subject - start_match < REQ_BYTE_MAX &&        end_subject - start_match < REQ_BYTE_MAX &&
4847        !md->partial)        !md->partial)
4848      {      {
# Line 4687  for(;;) Line 4888  for(;;)
4888    
4889    /* OK, we can now run the match. */    /* OK, we can now run the match. */
4890    
4891    md->start_match_ptr = start_match;      /* Insurance */    md->start_match_ptr = start_match;
4892    md->match_call_count = 0;    md->match_call_count = 0;
4893    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);
4894    
4895    /* Any return other than MATCH_NOMATCH breaks the loop. */    switch(rc)
4896        {
4897        /* NOMATCH and PRUNE advance by one character. THEN at this level acts
4898        exactly like PRUNE. */
4899    
4900        case MATCH_NOMATCH:
4901        case MATCH_PRUNE:
4902        case MATCH_THEN:
4903        new_start_match = start_match + 1;
4904    #ifdef SUPPORT_UTF8
4905        if (utf8)
4906          while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80)
4907            new_start_match++;
4908    #endif
4909        break;
4910    
4911        /* SKIP passes back the next starting point explicitly. */
4912    
4913    if (rc != MATCH_NOMATCH) break;      case MATCH_SKIP:
4914        new_start_match = md->start_match_ptr;
4915        break;
4916    
4917        /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
4918    
4919        case MATCH_COMMIT:
4920        rc = MATCH_NOMATCH;
4921        goto ENDLOOP;
4922    
4923        /* Any other return is some kind of error. */
4924    
4925        default:
4926        goto ENDLOOP;
4927        }
4928    
4929      /* Control reaches here for the various types of "no match at this point"
4930      result. Reset the code to MATCH_NOMATCH for subsequent checking. */
4931    
4932      rc = MATCH_NOMATCH;
4933    
4934    /* 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
4935    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 4937  for(;;)
4937    
4938    if (firstline && IS_NEWLINE(start_match)) break;    if (firstline && IS_NEWLINE(start_match)) break;
4939    
4940    /* Advance the match position by one character. */    /* Advance to new matching position */
4941    
4942    start_match++;    start_match = new_start_match;
 #ifdef SUPPORT_UTF8  
   if (utf8)  
     while(start_match < end_subject && (*start_match & 0xc0) == 0x80)  
       start_match++;  
 #endif  
4943    
4944    /* 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
4945    the subject. */    the subject. */
4946    
4947    if (anchored || start_match > end_subject) break;    if (anchored || start_match > end_subject) break;
4948    
4949    /* 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
4950    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
4951    character. */    or ANY or ANYCRLF, advance the match position by one more character. */
4952    
4953    if (start_match[-1] == '\r' &&    if (start_match[-1] == CHAR_CR &&
4954         (md->nltype == NLTYPE_ANY ||        start_match < end_subject &&
4955          md->nltype == NLTYPE_ANYCRLF ||        *start_match == CHAR_NL &&
4956          md->nllen == 2) &&        (re->flags & PCRE_HASCRORLF) == 0 &&
4957         start_match < end_subject &&          (md->nltype == NLTYPE_ANY ||
4958         *start_match == '\n')           md->nltype == NLTYPE_ANYCRLF ||
4959             md->nllen == 2))
4960      start_match++;      start_match++;
4961    
4962    }   /* End of for(;;) "bumpalong" loop */    }   /* End of for(;;) "bumpalong" loop */
# Line 4734  for(;;) Line 4966  for(;;)
4966  /* 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
4967  conditions is true:  conditions is true:
4968    
4969  (1) The pattern is anchored;  (1) The pattern is anchored or the match was failed by (*COMMIT);
4970    
4971  (2) We are past the end of the subject;  (2) We are past the end of the subject;
4972    
# Line 4749  processing, copy those that we can. In t Line 4981  processing, copy those that we can. In t
4981  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
4982  capturing parentheses than vector slots. */  capturing parentheses than vector slots. */
4983    
4984    ENDLOOP:
4985    
4986  if (rc == MATCH_MATCH)  if (rc == MATCH_MATCH)
4987    {    {
4988    if (using_temporary_offsets)    if (using_temporary_offsets)

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

  ViewVC Help
Powered by ViewVC 1.1.5