/[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 298 by ph10, Thu Jan 10 17:09:12 2008 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 158  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 308  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 535  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 609  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 761  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 769  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 803  for (;;) Line 865  for (;;)
865        else        else
866          {          {
867          condition = FALSE;          condition = FALSE;
868          ecode += GET(ecode, 1);          ecode += codelink;
869          }          }
870        }        }
871    
# Line 826  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        }        }
# Line 1049  for (;;) Line 1111  for (;;)
1111          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          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 1148  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 1174  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 1421  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 1646  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 1656  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 1692  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 1702  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 1723  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, set the length to be longer than the amount        /* If the reference is unset, there are two possibilities:
1798        of subject left; this ensures that every attempt at a match fails. We  
1799        can't just fail here, because of the possibility of quantifiers with zero        (a) In the default, Perl-compatible state, set the length to be longer
1800        minima. */        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        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        quantifiers with zero minima.
1803          md->end_subject - eptr + 1 :  
1804          md->offset_vector[offset+1] - md->offset_vector[offset];        (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          Otherwise, set the length to the length of what was matched by the
1808          referenced subpattern. */
1809    
1810          if (offset >= offset_top || md->offset_vector[offset] < 0)
1811            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1812          else
1813            length = 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 2007  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 2049  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 2068  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 2083  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 2158  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 2249  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 2569  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 2678  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 2854  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 2867  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 2878  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 2889  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 2908  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 2917  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 2935  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 3151  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 3325  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 3340  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 3353  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 3366  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 3388  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 3397  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 3416  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 3577  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 3718  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 3733  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 3746  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 3759  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 3788  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 3797  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 3819  for (;;) Line 3904  for (;;)
3904                BACKCHAR(eptr);                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 3839  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 3863  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 4064  for (;;) Line 4143  for (;;)
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 4348  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 4450  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 4495  switch ((((options & PCRE_NEWLINE_BITS) Line 4572  switch ((((options & PCRE_NEWLINE_BITS)
4572          (pcre_uint32)options) & 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 4650  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)  
         { NEXTCHAR(start_match); }  
     else  
       while (start_match < end_subject && *start_match != first_byte)  
         { NEXTCHAR(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          { NEXTCHAR(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,          /* 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.          and we are now at a LF, advance the match position by one more character.
4796        */          */
4797    
4798        if (start_match[-1] == '\r' &&          if (start_match[-1] == CHAR_CR &&
4799             (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
4800             start_match < end_subject &&               start_match < end_subject &&
4801             *start_match == '\n')               *start_match == CHAR_NL)
4802          start_match++;            start_match++;
4803            }
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)          {
4812          { NEXTCHAR(start_match); }          register unsigned int c = *start_match;
4813        else break;          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 4720  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 4844  for(;;) Line 4952  for(;;)
4952    not contain any explicit matches for \r or \n, and the newline option is CRLF    not contain any explicit matches for \r or \n, and the newline option is CRLF
4953    or ANY or ANYCRLF, advance the match position by one more 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        start_match < end_subject &&        start_match < end_subject &&
4957        *start_match == '\n' &&        *start_match == CHAR_NL &&
4958        (re->flags & PCRE_HASCRORLF) == 0 &&        (re->flags & PCRE_HASCRORLF) == 0 &&
4959          (md->nltype == NLTYPE_ANY ||          (md->nltype == NLTYPE_ANY ||
4960           md->nltype == NLTYPE_ANYCRLF ||           md->nltype == NLTYPE_ANYCRLF ||

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

  ViewVC Help
Powered by ViewVC 1.1.5