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

Diff of /code/trunk/pcre_compile.c

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

revision 964 by ph10, Fri May 4 13:03:39 2012 UTC revision 1041 by ph10, Sun Sep 16 10:16:27 2012 UTC
# Line 490  static const char error_texts[] = Line 490  static const char error_texts[] =
490    "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)\0"    "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)\0"
491    "invalid UTF-16 string\0"    "invalid UTF-16 string\0"
492    /* 75 */    /* 75 */
493    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"
494      "character value in \\u.... sequence is too large\0"
495    ;    ;
496    
497  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
# Line 788  else if ((i = escapes[c - CHAR_0]) != 0) Line 789  else if ((i = escapes[c - CHAR_0]) != 0)
789    
790  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
791  /* Not alphanumeric */  /* Not alphanumeric */
792  else if (c < 'a' || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}  else if (c < CHAR_a || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}
793  else if ((i = escapes[c - 0x48]) != 0)  c = i;  else if ((i = escapes[c - 0x48]) != 0)  c = i;
794  #endif  #endif
795    
# Line 831  else Line 832  else
832            c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
833  #endif  #endif
834            }            }
835    
836    #ifdef COMPILE_PCRE8
837            if (c > (utf ? 0x10ffff : 0xff))
838    #else
839    #ifdef COMPILE_PCRE16
840            if (c > (utf ? 0x10ffff : 0xffff))
841    #endif
842    #endif
843              {
844              *errorcodeptr = ERR76;
845              }
846            else if (utf && c >= 0xd800 && c <= 0xdfff) *errorcodeptr = ERR73;
847          }          }
848        }        }
849      else      else
# Line 3155  if (next >= 0) switch(op_code) Line 3168  if (next >= 0) switch(op_code)
3168    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
3169    switch(next)    switch(next)
3170      {      {
3171      case 0x09:      HSPACE_CASES:
     case 0x20:  
     case 0xa0:  
     case 0x1680:  
     case 0x180e:  
     case 0x2000:  
     case 0x2001:  
     case 0x2002:  
     case 0x2003:  
     case 0x2004:  
     case 0x2005:  
     case 0x2006:  
     case 0x2007:  
     case 0x2008:  
     case 0x2009:  
     case 0x200A:  
     case 0x202f:  
     case 0x205f:  
     case 0x3000:  
3172      return op_code == OP_NOT_HSPACE;      return op_code == OP_NOT_HSPACE;
3173    
3174      default:      default:
3175      return op_code != OP_NOT_HSPACE;      return op_code != OP_NOT_HSPACE;
3176      }      }
# Line 3184  if (next >= 0) switch(op_code) Line 3180  if (next >= 0) switch(op_code)
3180    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
3181    switch(next)    switch(next)
3182      {      {
3183      case 0x0a:      VSPACE_CASES:
     case 0x0b:  
     case 0x0c:  
     case 0x0d:  
     case 0x85:  
     case 0x2028:  
     case 0x2029:  
3184      return op_code == OP_NOT_VSPACE;      return op_code == OP_NOT_VSPACE;
3185    
3186      default:      default:
3187      return op_code != OP_NOT_VSPACE;      return op_code != OP_NOT_VSPACE;
3188      }      }
# Line 3248  switch(op_code) Line 3239  switch(op_code)
3239      case ESC_H:      case ESC_H:
3240      switch(c)      switch(c)
3241        {        {
3242        case 0x09:        HSPACE_CASES:
       case 0x20:  
       case 0xa0:  
       case 0x1680:  
       case 0x180e:  
       case 0x2000:  
       case 0x2001:  
       case 0x2002:  
       case 0x2003:  
       case 0x2004:  
       case 0x2005:  
       case 0x2006:  
       case 0x2007:  
       case 0x2008:  
       case 0x2009:  
       case 0x200A:  
       case 0x202f:  
       case 0x205f:  
       case 0x3000:  
3243        return -next != ESC_h;        return -next != ESC_h;
3244    
3245        default:        default:
3246        return -next == ESC_h;        return -next == ESC_h;
3247        }        }
# Line 3276  switch(op_code) Line 3250  switch(op_code)
3250      case ESC_V:      case ESC_V:
3251      switch(c)      switch(c)
3252        {        {
3253        case 0x0a:        VSPACE_CASES:
       case 0x0b:  
       case 0x0c:  
       case 0x0d:  
       case 0x85:  
       case 0x2028:  
       case 0x2029:  
3254        return -next != ESC_v;        return -next != ESC_v;
3255    
3256        default:        default:
3257        return -next == ESC_v;        return -next == ESC_v;
3258        }        }
# Line 4044  for (;; ptr++) Line 4013  for (;; ptr++)
4013    
4014              /* Perl 5.004 onwards omits VT from \s, but we must preserve it              /* Perl 5.004 onwards omits VT from \s, but we must preserve it
4015              if it was previously set by something earlier in the character              if it was previously set by something earlier in the character
4016              class. */              class. Luckily, the value of CHAR_VT is 0x0b in both ASCII and
4017                EBCDIC, so we lazily just adjust the appropriate bit. */
4018    
4019              case ESC_s:              case ESC_s:
4020              classbits[0] |= cbits[cbit_space];              classbits[0] |= cbits[cbit_space];
# Line 4059  for (;; ptr++) Line 4029  for (;; ptr++)
4029              continue;              continue;
4030    
4031              case ESC_h:              case ESC_h:
4032              SETBIT(classbits, 0x09); /* VT */              SETBIT(classbits, CHAR_HT);
4033              SETBIT(classbits, 0x20); /* SPACE */              SETBIT(classbits, CHAR_SPACE);
4034    #ifndef EBCDIC
4035              SETBIT(classbits, 0xa0); /* NSBP */              SETBIT(classbits, 0xa0); /* NSBP */
4036  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4037              xclass = TRUE;              xclass = TRUE;
# Line 4096  for (;; ptr++) Line 4067  for (;; ptr++)
4067                class_uchardata += PRIV(ord2utf)(0x3000, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x3000, class_uchardata);
4068                }                }
4069  #endif  #endif
4070    #endif  /* Not EBCDIC */
4071              continue;              continue;
4072    
4073              case ESC_H:              case ESC_H:
# Line 4104  for (;; ptr++) Line 4076  for (;; ptr++)
4076                int x = 0xff;                int x = 0xff;
4077                switch (c)                switch (c)
4078                  {                  {
4079                  case 0x09/8: x ^= 1 << (0x09%8); break;                  case CHAR_HT/8:    x ^= 1 << (CHAR_HT%8); break;
4080                  case 0x20/8: x ^= 1 << (0x20%8); break;                  case CHAR_SPACE/8: x ^= 1 << (CHAR_SPACE%8); break;
4081                  case 0xa0/8: x ^= 1 << (0xa0%8); break;  #ifndef EBCDIC
4082                    case 0xa0/8: x ^= 1 << (0xa0%8); break;  /* NSBSP */
4083    #endif
4084                  default: break;                  default: break;
4085                  }                  }
4086                classbits[c] |= x;                classbits[c] |= x;
4087                }                }
4088    #ifndef EBCDIC
4089  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4090              xclass = TRUE;              xclass = TRUE;
4091              *class_uchardata++ = XCL_RANGE;              *class_uchardata++ = XCL_RANGE;
# Line 4137  for (;; ptr++) Line 4112  for (;; ptr++)
4112              if (utf)              if (utf)
4113                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);
4114              else              else
4115  #endif  #endif   /* SUPPORT_UTF */
4116                *class_uchardata++ = 0xffff;                *class_uchardata++ = 0xffff;
4117  #elif defined SUPPORT_UTF  #elif defined SUPPORT_UTF
4118              if (utf)              if (utf)
# Line 4166  for (;; ptr++) Line 4141  for (;; ptr++)
4141                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);
4142                }                }
4143  #endif  #endif
4144    #endif  /* Not EBCDIC */
4145              continue;              continue;
4146    
4147              case ESC_v:              case ESC_v:
4148              SETBIT(classbits, 0x0a); /* LF */              SETBIT(classbits, CHAR_LF);
4149              SETBIT(classbits, 0x0b); /* VT */              SETBIT(classbits, CHAR_VT);
4150              SETBIT(classbits, 0x0c); /* FF */              SETBIT(classbits, CHAR_FF);
4151              SETBIT(classbits, 0x0d); /* CR */              SETBIT(classbits, CHAR_CR);
4152              SETBIT(classbits, 0x85); /* NEL */              SETBIT(classbits, CHAR_NEL);
4153    #ifndef EBCDIC
4154  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4155              xclass = TRUE;              xclass = TRUE;
4156              *class_uchardata++ = XCL_RANGE;              *class_uchardata++ = XCL_RANGE;
# Line 4188  for (;; ptr++) Line 4165  for (;; ptr++)
4165                class_uchardata += PRIV(ord2utf)(0x2029, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x2029, class_uchardata);
4166                }                }
4167  #endif  #endif
4168    #endif  /* Not EBCDIC */
4169              continue;              continue;
4170    
4171              case ESC_V:              case ESC_V:
# Line 4196  for (;; ptr++) Line 4174  for (;; ptr++)
4174                int x = 0xff;                int x = 0xff;
4175                switch (c)                switch (c)
4176                  {                  {
4177                  case 0x0a/8: x ^= 1 << (0x0a%8);                  case CHAR_LF/8: x ^= 1 << (CHAR_LF%8);
4178                               x ^= 1 << (0x0b%8);                                  x ^= 1 << (CHAR_VT%8);
4179                               x ^= 1 << (0x0c%8);                                  x ^= 1 << (CHAR_FF%8);
4180                               x ^= 1 << (0x0d%8);                                  x ^= 1 << (CHAR_CR%8);
4181                               break;                                  break;
4182                  case 0x85/8: x ^= 1 << (0x85%8); break;                  case CHAR_NEL/8: x ^= 1 << (CHAR_NEL%8); break;
4183                  default: break;                  default: break;
4184                  }                  }
4185                classbits[c] |= x;                classbits[c] |= x;
4186                }                }
4187    
4188    #ifndef EBCDIC
4189  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4190              xclass = TRUE;              xclass = TRUE;
4191              *class_uchardata++ = XCL_RANGE;              *class_uchardata++ = XCL_RANGE;
# Line 4232  for (;; ptr++) Line 4211  for (;; ptr++)
4211                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);
4212                }                }
4213  #endif  #endif
4214    #endif  /* Not EBCDIC */
4215              continue;              continue;
4216    
4217  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4518  for (;; ptr++) Line 4498  for (;; ptr++)
4498        LONE_SINGLE_CHARACTER:        LONE_SINGLE_CHARACTER:
4499    
4500        /* Only the value of 1 matters for class_single_char. */        /* Only the value of 1 matters for class_single_char. */
4501    
4502        if (class_single_char < 2) class_single_char++;        if (class_single_char < 2) class_single_char++;
4503    
4504        /* If class_charcount is 1, we saw precisely one character. As long as        /* If class_charcount is 1, we saw precisely one character. As long as
# Line 4813  for (;; ptr++) Line 4793  for (;; ptr++)
4793      if (*previous == OP_CHAR || *previous == OP_CHARI      if (*previous == OP_CHAR || *previous == OP_CHARI
4794          || *previous == OP_NOT || *previous == OP_NOTI)          || *previous == OP_NOT || *previous == OP_NOTI)
4795        {        {
4796        switch (*previous)        switch (*previous)
4797          {          {
4798          default: /* Make compiler happy. */          default: /* Make compiler happy. */
4799          case OP_CHAR:  op_type = OP_STAR - OP_STAR; break;          case OP_CHAR:  op_type = OP_STAR - OP_STAR; break;
# Line 5593  for (;; ptr++) Line 5573  for (;; ptr++)
5573        ptr++;        ptr++;
5574        while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_letter) != 0) ptr++;        while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_letter) != 0) ptr++;
5575        namelen = (int)(ptr - name);        namelen = (int)(ptr - name);
5576    
5577        /* It appears that Perl allows any characters whatsoever, other than        /* It appears that Perl allows any characters whatsoever, other than
5578        a closing parenthesis, to appear in arguments, so we no longer insist on        a closing parenthesis, to appear in arguments, so we no longer insist on
5579        letters, digits, and underscores. */        letters, digits, and underscores. */
# Line 5607  for (;; ptr++) Line 5587  for (;; ptr++)
5587            {            {
5588            *errorcodeptr = ERR75;            *errorcodeptr = ERR75;
5589            goto FAILED;            goto FAILED;
5590            }            }
5591          }          }
5592    
5593        if (*ptr != CHAR_RIGHT_PARENTHESIS)        if (*ptr != CHAR_RIGHT_PARENTHESIS)
# Line 5623  for (;; ptr++) Line 5603  for (;; ptr++)
5603          if (namelen == verbs[i].len &&          if (namelen == verbs[i].len &&
5604              STRNCMP_UC_C8(name, vn, namelen) == 0)              STRNCMP_UC_C8(name, vn, namelen) == 0)
5605            {            {
5606              int setverb;
5607    
5608            /* Check for open captures before ACCEPT and convert it to            /* Check for open captures before ACCEPT and convert it to
5609            ASSERT_ACCEPT if in an assertion. */            ASSERT_ACCEPT if in an assertion. */
5610    
# Line 5640  for (;; ptr++) Line 5622  for (;; ptr++)
5622                *code++ = OP_CLOSE;                *code++ = OP_CLOSE;
5623                PUT2INC(code, 0, oc->number);                PUT2INC(code, 0, oc->number);
5624                }                }
5625              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;              setverb = *code++ =
5626                  (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5627    
5628              /* Do not set firstchar after *ACCEPT */              /* Do not set firstchar after *ACCEPT */
5629              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
# Line 5655  for (;; ptr++) Line 5638  for (;; ptr++)
5638                *errorcodeptr = ERR66;                *errorcodeptr = ERR66;
5639                goto FAILED;                goto FAILED;
5640                }                }
5641              *code = verbs[i].op;              setverb = *code++ = verbs[i].op;
             if (*code++ == OP_THEN) cd->external_flags |= PCRE_HASTHEN;  
5642              }              }
5643    
5644            else            else
# Line 5666  for (;; ptr++) Line 5648  for (;; ptr++)
5648                *errorcodeptr = ERR59;                *errorcodeptr = ERR59;
5649                goto FAILED;                goto FAILED;
5650                }                }
5651              *code = verbs[i].op_arg;              setverb = *code++ = verbs[i].op_arg;
             if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;  
5652              *code++ = arglen;              *code++ = arglen;
5653              memcpy(code, arg, IN_UCHARS(arglen));              memcpy(code, arg, IN_UCHARS(arglen));
5654              code += arglen;              code += arglen;
5655              *code++ = 0;              *code++ = 0;
5656              }              }
5657    
5658              switch (setverb)
5659                {
5660                case OP_THEN:
5661                case OP_THEN_ARG:
5662                cd->external_flags |= PCRE_HASTHEN;
5663                break;
5664    
5665                case OP_PRUNE:
5666                case OP_PRUNE_ARG:
5667                case OP_SKIP:
5668                case OP_SKIP_ARG:
5669                cd->had_pruneorskip = TRUE;
5670                break;
5671                }
5672    
5673            break;  /* Found verb, exit loop */            break;  /* Found verb, exit loop */
5674            }            }
5675    
# Line 6859  for (;; ptr++) Line 6855  for (;; ptr++)
6855        /* For the rest (including \X when Unicode properties are supported), we        /* For the rest (including \X when Unicode properties are supported), we
6856        can obtain the OP value by negating the escape value in the default        can obtain the OP value by negating the escape value in the default
6857        situation when PCRE_UCP is not set. When it *is* set, we substitute        situation when PCRE_UCP is not set. When it *is* set, we substitute
6858        Unicode property tests. Note that \b and \B do a one-character        Unicode property tests. Note that \b and \B do a one-character
6859        lookbehind. */        lookbehind. */
6860    
6861        else        else
6862          {          {
6863          if ((-c == ESC_b || -c == ESC_B) && cd->max_lookbehind == 0)          if ((-c == ESC_b || -c == ESC_B) && cd->max_lookbehind == 0)
6864            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6865  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6866          if (-c >= ESC_DU && -c <= ESC_wu)          if (-c >= ESC_DU && -c <= ESC_wu)
6867            {            {
# Line 7173  for (;;) Line 7169  for (;;)
7169          *ptrptr = ptr;          *ptrptr = ptr;
7170          return FALSE;          return FALSE;
7171          }          }
7172        else        else
7173          {          {
7174          if (fixed_length > cd->max_lookbehind)          if (fixed_length > cd->max_lookbehind)
7175            cd->max_lookbehind = fixed_length;            cd->max_lookbehind = fixed_length;
7176          PUT(reverse_count, 0, fixed_length);          PUT(reverse_count, 0, fixed_length);
7177          }          }
7178        }        }
7179      }      }
# Line 7310  and the highest back reference was great Line 7306  and the highest back reference was great
7306  However, by keeping a bitmap of the first 31 back references, we can catch some  However, by keeping a bitmap of the first 31 back references, we can catch some
7307  of the more common cases more precisely.  of the more common cases more precisely.
7308    
7309    ... A second exception is when the .* appears inside an atomic group, because
7310    this prevents the number of characters it matches from being adjusted.
7311    
7312  Arguments:  Arguments:
7313    code           points to start of expression (the bracket)    code           points to start of expression (the bracket)
7314    bracket_map    a bitmap of which brackets we are inside while testing; this    bracket_map    a bitmap of which brackets we are inside while testing; this
7315                    handles up to substring 31; after that we just have to take                    handles up to substring 31; after that we just have to take
7316                    the less precise approach                    the less precise approach
7317    backref_map    the back reference bitmap    cd             points to the compile data block
7318      atomcount      atomic group level
7319    
7320  Returns:     TRUE or FALSE  Returns:     TRUE or FALSE
7321  */  */
7322    
7323  static BOOL  static BOOL
7324  is_anchored(register const pcre_uchar *code, unsigned int bracket_map,  is_anchored(register const pcre_uchar *code, unsigned int bracket_map,
7325    unsigned int backref_map)    compile_data *cd, int atomcount)
7326  {  {
7327  do {  do {
7328     const pcre_uchar *scode = first_significant_code(     const pcre_uchar *scode = first_significant_code(
# Line 7334  do { Line 7334  do {
7334     if (op == OP_BRA  || op == OP_BRAPOS ||     if (op == OP_BRA  || op == OP_BRAPOS ||
7335         op == OP_SBRA || op == OP_SBRAPOS)         op == OP_SBRA || op == OP_SBRAPOS)
7336       {       {
7337       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;       if (!is_anchored(scode, bracket_map, cd, atomcount)) return FALSE;
7338       }       }
7339    
7340     /* Capturing brackets */     /* Capturing brackets */
# Line 7344  do { Line 7344  do {
7344       {       {
7345       int n = GET2(scode, 1+LINK_SIZE);       int n = GET2(scode, 1+LINK_SIZE);
7346       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);
7347       if (!is_anchored(scode, new_map, backref_map)) return FALSE;       if (!is_anchored(scode, new_map, cd, atomcount)) return FALSE;
7348       }       }
7349    
7350     /* Other brackets */     /* Positive forward assertions and conditions */
7351    
7352     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC ||     else if (op == OP_ASSERT || op == OP_COND)
             op == OP_COND)  
7353       {       {
7354       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;       if (!is_anchored(scode, bracket_map, cd, atomcount)) return FALSE;
7355         }
7356    
7357       /* Atomic groups */
7358    
7359       else if (op == OP_ONCE || op == OP_ONCE_NC)
7360         {
7361         if (!is_anchored(scode, bracket_map, cd, atomcount + 1))
7362           return FALSE;
7363       }       }
7364    
7365     /* .* is not anchored unless DOTALL is set (which generates OP_ALLANY) and     /* .* is not anchored unless DOTALL is set (which generates OP_ALLANY) and
7366     it isn't in brackets that are or may be referenced. */     it isn't in brackets that are or may be referenced or inside an atomic
7367       group. */
7368    
7369     else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR ||     else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR ||
7370               op == OP_TYPEPOSSTAR))               op == OP_TYPEPOSSTAR))
7371       {       {
7372       if (scode[1] != OP_ALLANY || (bracket_map & backref_map) != 0)       if (scode[1] != OP_ALLANY || (bracket_map & cd->backref_map) != 0 ||
7373             atomcount > 0 || cd->had_pruneorskip)
7374         return FALSE;         return FALSE;
7375       }       }
7376    
7377     /* Check for explicit anchoring */     /* Check for explicit anchoring */
7378    
7379     else if (op != OP_SOD && op != OP_SOM && op != OP_CIRC) return FALSE;     else if (op != OP_SOD && op != OP_SOM && op != OP_CIRC) return FALSE;
7380    
7381     code += GET(code, 1);     code += GET(code, 1);
7382     }     }
7383  while (*code == OP_ALT);   /* Loop for each alternative */  while (*code == OP_ALT);   /* Loop for each alternative */
# Line 7385  return TRUE; Line 7395  return TRUE;
7395  matching and for non-DOTALL patterns that start with .* (which must start at  matching and for non-DOTALL patterns that start with .* (which must start at
7396  the beginning or after \n). As in the case of is_anchored() (see above), we  the beginning or after \n). As in the case of is_anchored() (see above), we
7397  have to take account of back references to capturing brackets that contain .*  have to take account of back references to capturing brackets that contain .*
7398  because in that case we can't make the assumption.  because in that case we can't make the assumption. Also, the appearance of .*
7399    inside atomic brackets or in a pattern that contains *PRUNE or *SKIP does not
7400    count, because once again the assumption no longer holds.
7401    
7402  Arguments:  Arguments:
7403    code           points to start of expression (the bracket)    code           points to start of expression (the bracket)
7404    bracket_map    a bitmap of which brackets we are inside while testing; this    bracket_map    a bitmap of which brackets we are inside while testing; this
7405                    handles up to substring 31; after that we just have to take                    handles up to substring 31; after that we just have to take
7406                    the less precise approach                    the less precise approach
7407    backref_map    the back reference bitmap    cd             points to the compile data
7408      atomcount      atomic group level
7409    
7410  Returns:         TRUE or FALSE  Returns:         TRUE or FALSE
7411  */  */
7412    
7413  static BOOL  static BOOL
7414  is_startline(const pcre_uchar *code, unsigned int bracket_map,  is_startline(const pcre_uchar *code, unsigned int bracket_map,
7415    unsigned int backref_map)    compile_data *cd, int atomcount)
7416  {  {
7417  do {  do {
7418     const pcre_uchar *scode = first_significant_code(     const pcre_uchar *scode = first_significant_code(
# Line 7425  do { Line 7438  do {
7438         return FALSE;         return FALSE;
7439    
7440         default:     /* Assertion */         default:     /* Assertion */
7441         if (!is_startline(scode, bracket_map, backref_map)) return FALSE;         if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7442         do scode += GET(scode, 1); while (*scode == OP_ALT);         do scode += GET(scode, 1); while (*scode == OP_ALT);
7443         scode += 1 + LINK_SIZE;         scode += 1 + LINK_SIZE;
7444         break;         break;
# Line 7439  do { Line 7452  do {
7452     if (op == OP_BRA  || op == OP_BRAPOS ||     if (op == OP_BRA  || op == OP_BRAPOS ||
7453         op == OP_SBRA || op == OP_SBRAPOS)         op == OP_SBRA || op == OP_SBRAPOS)
7454       {       {
7455       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7456       }       }
7457    
7458     /* Capturing brackets */     /* Capturing brackets */
# Line 7449  do { Line 7462  do {
7462       {       {
7463       int n = GET2(scode, 1+LINK_SIZE);       int n = GET2(scode, 1+LINK_SIZE);
7464       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);
7465       if (!is_startline(scode, new_map, backref_map)) return FALSE;       if (!is_startline(scode, new_map, cd, atomcount)) return FALSE;
7466       }       }
7467    
7468     /* Other brackets */     /* Positive forward assertions */
7469    
7470     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC)     else if (op == OP_ASSERT)
7471       {       {
7472       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7473       }       }
7474    
7475       /* Atomic brackets */
7476    
7477     /* .* means "start at start or after \n" if it isn't in brackets that     else if (op == OP_ONCE || op == OP_ONCE_NC)
7478     may be referenced. */       {
7479         if (!is_startline(scode, bracket_map, cd, atomcount + 1)) return FALSE;
7480         }
7481    
7482       /* .* means "start at start or after \n" if it isn't in atomic brackets or
7483       brackets that may be referenced, as long as the pattern does not contain
7484       *PRUNE or *SKIP, because these break the feature. Consider, for example,
7485       /.*?a(*PRUNE)b/ with the subject "aab", which matches "ab", i.e. not at the
7486       start of a line. */
7487    
7488     else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR || op == OP_TYPEPOSSTAR)     else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR || op == OP_TYPEPOSSTAR)
7489       {       {
7490       if (scode[1] != OP_ANY || (bracket_map & backref_map) != 0) return FALSE;       if (scode[1] != OP_ANY || (bracket_map & cd->backref_map) != 0 ||
7491             atomcount > 0 || cd->had_pruneorskip)
7492           return FALSE;
7493       }       }
7494    
7495     /* Check for explicit circumflex */     /* Check for explicit circumflex; anything else gives a FALSE result. Note
7496       in particular that this includes atomic brackets OP_ONCE and OP_ONCE_NC
7497       because the number of characters matched by .* cannot be adjusted inside
7498       them. */
7499    
7500     else if (op != OP_CIRC && op != OP_CIRCM) return FALSE;     else if (op != OP_CIRC && op != OP_CIRCM) return FALSE;
7501    
# Line 7926  cd->start_code = codestart; Line 7954  cd->start_code = codestart;
7954  cd->hwm = (pcre_uchar *)(cd->start_workspace);  cd->hwm = (pcre_uchar *)(cd->start_workspace);
7955  cd->req_varyopt = 0;  cd->req_varyopt = 0;
7956  cd->had_accept = FALSE;  cd->had_accept = FALSE;
7957    cd->had_pruneorskip = FALSE;
7958  cd->check_lookbehind = FALSE;  cd->check_lookbehind = FALSE;
7959  cd->open_caps = NULL;  cd->open_caps = NULL;
7960    
# Line 8049  if (errorcode != 0) Line 8078  if (errorcode != 0)
8078    }    }
8079    
8080  /* If the anchored option was not passed, set the flag if we can determine that  /* If the anchored option was not passed, set the flag if we can determine that
8081  the pattern is anchored by virtue of ^ characters or \A or anything else (such  the pattern is anchored by virtue of ^ characters or \A or anything else, such
8082  as starting with .* when DOTALL is set).  as starting with non-atomic .* when DOTALL is set and there are no occurrences
8083    of *PRUNE or *SKIP.
8084    
8085  Otherwise, if we know what the first byte has to be, save it, because that  Otherwise, if we know what the first byte has to be, save it, because that
8086  speeds up unanchored matches no end. If not, see if we can set the  speeds up unanchored matches no end. If not, see if we can set the
8087  PCRE_STARTLINE flag. This is helpful for multiline matches when all branches  PCRE_STARTLINE flag. This is helpful for multiline matches when all branches
8088  start with ^. and also when all branches start with .* for non-DOTALL matches.  start with ^. and also when all branches start with non-atomic .* for
8089  */  non-DOTALL matches when *PRUNE and SKIP are not present. */
8090    
8091  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
8092    {    {
8093    if (is_anchored(codestart, 0, cd->backref_map))    if (is_anchored(codestart, 0, cd, 0)) re->options |= PCRE_ANCHORED;
     re->options |= PCRE_ANCHORED;  
8094    else    else
8095      {      {
8096      if (firstchar < 0)      if (firstchar < 0)
# Line 8098  if ((re->options & PCRE_ANCHORED) == 0) Line 8127  if ((re->options & PCRE_ANCHORED) == 0)
8127    
8128        re->flags |= PCRE_FIRSTSET;        re->flags |= PCRE_FIRSTSET;
8129        }        }
8130      else if (is_startline(codestart, 0, cd->backref_map))  
8131        re->flags |= PCRE_STARTLINE;      else if (is_startline(codestart, 0, cd, 0)) re->flags |= PCRE_STARTLINE;
8132      }      }
8133    }    }
8134    

Legend:
Removed from v.964  
changed lines
  Added in v.1041

  ViewVC Help
Powered by ViewVC 1.1.5