/[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 1046 by ph10, Tue Sep 25 16:27:58 2012 UTC
# Line 68  COMPILE_PCREx macro will already be appr Line 68  COMPILE_PCREx macro will already be appr
68    
69  /* Macro for setting individual bits in class bitmaps. */  /* Macro for setting individual bits in class bitmaps. */
70    
71  #define SETBIT(a,b) a[b/8] |= (1 << (b%8))  #define SETBIT(a,b) a[(b)/8] |= (1 << ((b)&7))
72    
73  /* Maximum length value to check against when making sure that the integer that  /* Maximum length value to check against when making sure that the integer that
74  holds the compiled pattern length does not overflow. We make it a bit less than  holds the compiled pattern length does not overflow. We make it a bit less than
# Line 77  to check them every time. */ Line 77  to check them every time. */
77    
78  #define OFLOW_MAX (INT_MAX - 20)  #define OFLOW_MAX (INT_MAX - 20)
79    
80    /* Definitions to allow mutual recursion */
81    
82    static int
83      add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,
84        const pcre_uint32 *, unsigned int);
85    
86    static BOOL
87      compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL,
88        int, int, int *, int *, branch_chain *, compile_data *, int *);
89    
90    
91    
92  /*************************************************  /*************************************************
93  *      Code parameters and static tables         *  *      Code parameters and static tables         *
# Line 490  static const char error_texts[] = Line 501  static const char error_texts[] =
501    "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)\0"    "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)\0"
502    "invalid UTF-16 string\0"    "invalid UTF-16 string\0"
503    /* 75 */    /* 75 */
504    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"
505      "character value in \\u.... sequence is too large\0"
506    ;    ;
507    
508  /* 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 630  static const pcre_uint8 ebcdic_chartab[] Line 642  static const pcre_uint8 ebcdic_chartab[]
642  #endif  #endif
643    
644    
 /* Definition to allow mutual recursion */  
   
 static BOOL  
   compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,  
     int *, int *, branch_chain *, compile_data *, int *);  
   
645    
646    
647  /*************************************************  /*************************************************
# Line 788  else if ((i = escapes[c - CHAR_0]) != 0) Line 794  else if ((i = escapes[c - CHAR_0]) != 0)
794    
795  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
796  /* Not alphanumeric */  /* Not alphanumeric */
797  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)) {}
798  else if ((i = escapes[c - 0x48]) != 0)  c = i;  else if ((i = escapes[c - 0x48]) != 0)  c = i;
799  #endif  #endif
800    
# Line 831  else Line 837  else
837            c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
838  #endif  #endif
839            }            }
840    
841    #ifdef COMPILE_PCRE8
842            if (c > (utf ? 0x10ffff : 0xff))
843    #else
844    #ifdef COMPILE_PCRE16
845            if (c > (utf ? 0x10ffff : 0xffff))
846    #endif
847    #endif
848              {
849              *errorcodeptr = ERR76;
850              }
851            else if (utf && c >= 0xd800 && c <= 0xdfff) *errorcodeptr = ERR73;
852          }          }
853        }        }
854      else      else
# Line 1841  for (;;) Line 1859  for (;;)
1859    
1860      case OP_TYPEEXACT:      case OP_TYPEEXACT:
1861      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1862      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP) cc += 2;      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP)
1863          cc += 2;
1864      cc += 1 + IMM2_SIZE + 1;      cc += 1 + IMM2_SIZE + 1;
1865      break;      break;
1866    
# Line 2079  for (;;) Line 2098  for (;;)
2098        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2099        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2100        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
2101        if (code[1 + IMM2_SIZE] == OP_PROP        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2102          || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;          code += 2;
2103        break;        break;
2104    
2105        case OP_MARK:        case OP_MARK:
# Line 2199  for (;;) Line 2218  for (;;)
2218        case OP_TYPEUPTO:        case OP_TYPEUPTO:
2219        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2220        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2221        if (code[1 + IMM2_SIZE] == OP_PROP        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2222          || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;          code += 2;
2223        break;        break;
2224    
2225        case OP_MARK:        case OP_MARK:
# Line 2525  for (code = first_significant_code(code Line 2544  for (code = first_significant_code(code
2544      case OP_TYPEUPTO:      case OP_TYPEUPTO:
2545      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
2546      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
2547      if (code[1 + IMM2_SIZE] == OP_PROP      if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2548        || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;        code += 2;
2549      break;      break;
2550    
2551      /* End of branch */      /* End of branch */
# Line 2858  PUT(previous_callout, 2 + LINK_SIZE, len Line 2877  PUT(previous_callout, 2 + LINK_SIZE, len
2877  *************************************************/  *************************************************/
2878    
2879  /* This function is passed the start and end of a class range, in UTF-8 mode  /* This function is passed the start and end of a class range, in UTF-8 mode
2880  with UCP support. It searches up the characters, looking for internal ranges of  with UCP support. It searches up the characters, looking for ranges of
2881  characters in the "other" case. Each call returns the next one, updating the  characters in the "other" case. Each call returns the next one, updating the
2882  start address.  start address. A character with multiple other cases is returned on its own
2883    with a special return value.
2884    
2885  Arguments:  Arguments:
2886    cptr        points to starting character value; updated    cptr        points to starting character value; updated
# Line 2868  Arguments: Line 2888  Arguments:
2888    ocptr       where to put start of othercase range    ocptr       where to put start of othercase range
2889    odptr       where to put end of othercase range    odptr       where to put end of othercase range
2890    
2891  Yield:        TRUE when range returned; FALSE when no more  Yield:        -1 when no more
2892                   0 when a range is returned
2893                  >0 the CASESET offset for char with multiple other cases
2894                    in this case, ocptr contains the original
2895  */  */
2896    
2897  static BOOL  static int
2898  get_othercase_range(unsigned int *cptr, unsigned int d, unsigned int *ocptr,  get_othercase_range(unsigned int *cptr, unsigned int d, unsigned int *ocptr,
2899    unsigned int *odptr)    unsigned int *odptr)
2900  {  {
2901  unsigned int c, othercase, next;  unsigned int c, othercase, next;
2902    int co;
2903    
2904    /* Find the first character that has an other case. If it has multiple other
2905    cases, return its case offset value. */
2906    
2907  for (c = *cptr; c <= d; c++)  for (c = *cptr; c <= d; c++)
2908    { if ((othercase = UCD_OTHERCASE(c)) != c) break; }    {
2909      if ((co = UCD_CASESET(c)) != 0)
2910        {
2911        *ocptr = c++;   /* Character that has the set */
2912        *cptr = c;      /* Rest of input range */
2913        return co;
2914        }
2915      if ((othercase = UCD_OTHERCASE(c)) != c) break;
2916      }
2917    
2918  if (c > d) return FALSE;  if (c > d) return -1;  /* Reached end of range */
2919    
2920  *ocptr = othercase;  *ocptr = othercase;
2921  next = othercase + 1;  next = othercase + 1;
# Line 2891  for (++c; c <= d; c++) Line 2926  for (++c; c <= d; c++)
2926    next++;    next++;
2927    }    }
2928    
2929  *odptr = next - 1;  *odptr = next - 1;     /* End of othercase range */
2930  *cptr = c;  *cptr = c;             /* Rest of input range */
2931    return 0;
 return TRUE;  
2932  }  }
2933    
2934    
# Line 2918  Returns:       TRUE if auto-possessifyin Line 2952  Returns:       TRUE if auto-possessifyin
2952  static BOOL  static BOOL
2953  check_char_prop(int c, int ptype, int pdata, BOOL negated)  check_char_prop(int c, int ptype, int pdata, BOOL negated)
2954  {  {
2955    #ifdef SUPPORT_UCP
2956    const pcre_uint32 *p;
2957    #endif
2958    
2959  const ucd_record *prop = GET_UCD(c);  const ucd_record *prop = GET_UCD(c);
2960    
2961  switch(ptype)  switch(ptype)
2962    {    {
2963    case PT_LAMP:    case PT_LAMP:
# Line 2956  switch(ptype) Line 2995  switch(ptype)
2995    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
2996            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
2997            c == CHAR_UNDERSCORE) == negated;            c == CHAR_UNDERSCORE) == negated;
2998    
2999    #ifdef SUPPORT_UCP
3000      case PT_CLIST:
3001      p = PRIV(ucd_caseless_sets) + prop->caseset;
3002      for (;;)
3003        {
3004        if ((unsigned int)c < *p) return !negated;
3005        if ((unsigned int)c == *p++) return negated;
3006        }
3007      break;  /* Control never reaches here */
3008    #endif
3009    }    }
3010    
3011  return FALSE;  return FALSE;
3012  }  }
3013  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 3058  if ((options & PCRE_EXTENDED) != 0) Line 3109  if ((options & PCRE_EXTENDED) != 0)
3109  if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||  if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||
3110    STRNCMP_UC_C8(ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)    STRNCMP_UC_C8(ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)
3111      return FALSE;      return FALSE;
3112    
3113    /* If the previous item is a character, get its value. */
3114    
3115  /* Now compare the next item with the previous opcode. First, handle cases when  if (op_code == OP_CHAR || op_code == OP_CHARI ||
3116  the next item is a character. */      op_code == OP_NOT || op_code == OP_NOTI)
3117      {
 if (next >= 0) switch(op_code)  
   {  
   case OP_CHAR:  
3118  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3119    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
3120  #else  #else
3121    c = *previous;    c = *previous;
3122  #endif  #endif
3123    return c != next;    }
3124    
3125    /* For CHARI (caseless character) we must check the other case. If we have  /* Now compare the next item with the previous opcode. First, handle cases when
3126    Unicode property support, we can use it to test the other case of  the next item is a character. For a caseless UTF match, the next character may
3127    high-valued characters. */  have more than one other case; convert this to a special property. */
3128    
3129    case OP_CHARI:  if (next >= 0)
3130  #ifdef SUPPORT_UTF    {
   GETCHARTEST(c, previous);  
 #else  
   c = *previous;  
 #endif  
   if (c == next) return FALSE;  
 #ifdef SUPPORT_UTF  
   if (utf)  
     {  
     unsigned int othercase;  
     if (next < 128) othercase = cd->fcc[next]; else  
3131  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3132      othercase = UCD_OTHERCASE((unsigned int)next);    if (utf && (options & PCRE_CASELESS) != 0)
3133  #else      {
3134      othercase = NOTACHAR;      int ocs = UCD_CASESET(next);
3135  #endif      if (ocs > 0) return check_char_prop(c, PT_CLIST, ocs, FALSE);
3136      return (unsigned int)c != othercase;      }
     }  
   else  
 #endif  /* SUPPORT_UTF */  
   return (c != TABLE_GET((unsigned int)next, cd->fcc, next));  /* Non-UTF-8 mode */  
   
   case OP_NOT:  
 #ifdef SUPPORT_UTF  
   GETCHARTEST(c, previous);  
 #else  
   c = *previous;  
3137  #endif  #endif
   return c == next;  
3138    
3139    case OP_NOTI:    switch(op_code)
3140        {
3141        case OP_CHAR:
3142        return c != next;
3143    
3144        /* For CHARI (caseless character) we must check the other case. If we have
3145        Unicode property support, we can use it to test the other case of
3146        high-valued characters. We know that next can have only one other case,
3147        because multi-other-case characters are dealt with above. */
3148    
3149        case OP_CHARI:
3150        if (c == next) return FALSE;
3151  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3152    GETCHARTEST(c, previous);      if (utf)
3153          {
3154          unsigned int othercase;
3155          if (next < 128) othercase = cd->fcc[next]; else
3156    #ifdef SUPPORT_UCP
3157          othercase = UCD_OTHERCASE((unsigned int)next);
3158  #else  #else
3159    c = *previous;        othercase = NOTACHAR;
3160  #endif  #endif
3161    if (c == next) return TRUE;        return (unsigned int)c != othercase;
3162          }
3163        else
3164    #endif  /* SUPPORT_UTF */
3165        return (c != TABLE_GET((unsigned int)next, cd->fcc, next));  /* Not UTF */
3166    
3167        case OP_NOT:
3168        return c == next;
3169    
3170        case OP_NOTI:
3171        if (c == next) return TRUE;
3172  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3173    if (utf)      if (utf)
3174      {        {
3175      unsigned int othercase;        unsigned int othercase;
3176      if (next < 128) othercase = cd->fcc[next]; else        if (next < 128) othercase = cd->fcc[next]; else
3177  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3178      othercase = UCD_OTHERCASE((unsigned int)next);        othercase = UCD_OTHERCASE((unsigned int)next);
3179  #else  #else
3180      othercase = NOTACHAR;        othercase = NOTACHAR;
3181  #endif  #endif
3182      return (unsigned int)c == othercase;        return (unsigned int)c == othercase;
3183      }        }
3184    else      else
3185  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3186    return (c == TABLE_GET((unsigned int)next, cd->fcc, next));  /* Non-UTF-8 mode */      return (c == TABLE_GET((unsigned int)next, cd->fcc, next));  /* Not UTF */
3187    
3188    /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.      /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.
3189    When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */      When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */
3190    
3191    case OP_DIGIT:      case OP_DIGIT:
3192    return next > 255 || (cd->ctypes[next] & ctype_digit) == 0;      return next > 255 || (cd->ctypes[next] & ctype_digit) == 0;
3193    
3194    case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
3195    return next <= 255 && (cd->ctypes[next] & ctype_digit) != 0;      return next <= 255 && (cd->ctypes[next] & ctype_digit) != 0;
3196    
3197    case OP_WHITESPACE:      case OP_WHITESPACE:
3198    return next > 255 || (cd->ctypes[next] & ctype_space) == 0;      return next > 255 || (cd->ctypes[next] & ctype_space) == 0;
3199    
3200    case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
3201    return next <= 255 && (cd->ctypes[next] & ctype_space) != 0;      return next <= 255 && (cd->ctypes[next] & ctype_space) != 0;
3202    
3203    case OP_WORDCHAR:      case OP_WORDCHAR:
3204    return next > 255 || (cd->ctypes[next] & ctype_word) == 0;      return next > 255 || (cd->ctypes[next] & ctype_word) == 0;
3205    
3206    case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
3207    return next <= 255 && (cd->ctypes[next] & ctype_word) != 0;      return next <= 255 && (cd->ctypes[next] & ctype_word) != 0;
3208    
3209    case OP_HSPACE:      case OP_HSPACE:
3210    case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
3211    switch(next)      switch(next)
3212      {        {
3213      case 0x09:        HSPACE_CASES:
3214      case 0x20:        return op_code == OP_NOT_HSPACE;
3215      case 0xa0:  
3216      case 0x1680:        default:
3217      case 0x180e:        return op_code != OP_NOT_HSPACE;
3218      case 0x2000:        }
3219      case 0x2001:  
3220      case 0x2002:      case OP_ANYNL:
3221      case 0x2003:      case OP_VSPACE:
3222      case 0x2004:      case OP_NOT_VSPACE:
3223      case 0x2005:      switch(next)
3224      case 0x2006:        {
3225      case 0x2007:        VSPACE_CASES:
3226      case 0x2008:        return op_code == OP_NOT_VSPACE;
3227      case 0x2009:  
3228      case 0x200A:        default:
3229      case 0x202f:        return op_code != OP_NOT_VSPACE;
3230      case 0x205f:        }
3231      case 0x3000:  
     return op_code == OP_NOT_HSPACE;  
     default:  
     return op_code != OP_NOT_HSPACE;  
     }  
   
   case OP_ANYNL:  
   case OP_VSPACE:  
   case OP_NOT_VSPACE:  
   switch(next)  
     {  
     case 0x0a:  
     case 0x0b:  
     case 0x0c:  
     case 0x0d:  
     case 0x85:  
     case 0x2028:  
     case 0x2029:  
     return op_code == OP_NOT_VSPACE;  
     default:  
     return op_code != OP_NOT_VSPACE;  
     }  
   
3232  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3233    case OP_PROP:      case OP_PROP:
3234    return check_char_prop(next, previous[0], previous[1], FALSE);      return check_char_prop(next, previous[0], previous[1], FALSE);
3235    
3236    case OP_NOTPROP:      case OP_NOTPROP:
3237    return check_char_prop(next, previous[0], previous[1], TRUE);      return check_char_prop(next, previous[0], previous[1], TRUE);
3238  #endif  #endif
3239    
3240    default:      default:
3241    return FALSE;      return FALSE;
3242    }      }
3243      }
3244    
3245  /* Handle the case when the next item is \d, \s, etc. Note that when PCRE_UCP  /* Handle the case when the next item is \d, \s, etc. Note that when PCRE_UCP
3246  is set, \d turns into ESC_du rather than ESC_d, etc., so ESC_d etc. are  is set, \d turns into ESC_du rather than ESC_d, etc., so ESC_d etc. are
# Line 3219  switch(op_code) Line 3252  switch(op_code)
3252    {    {
3253    case OP_CHAR:    case OP_CHAR:
3254    case OP_CHARI:    case OP_CHARI:
 #ifdef SUPPORT_UTF  
   GETCHARTEST(c, previous);  
 #else  
   c = *previous;  
 #endif  
3255    switch(-next)    switch(-next)
3256      {      {
3257      case ESC_d:      case ESC_d:
# Line 3248  switch(op_code) Line 3276  switch(op_code)
3276      case ESC_H:      case ESC_H:
3277      switch(c)      switch(c)
3278        {        {
3279        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:  
3280        return -next != ESC_h;        return -next != ESC_h;
3281    
3282        default:        default:
3283        return -next == ESC_h;        return -next == ESC_h;
3284        }        }
# Line 3276  switch(op_code) Line 3287  switch(op_code)
3287      case ESC_V:      case ESC_V:
3288      switch(c)      switch(c)
3289        {        {
3290        case 0x0a:        VSPACE_CASES:
       case 0x0b:  
       case 0x0c:  
       case 0x0d:  
       case 0x85:  
       case 0x2028:  
       case 0x2029:  
3291        return -next != ESC_v;        return -next != ESC_v;
3292    
3293        default:        default:
3294        return -next == ESC_v;        return -next == ESC_v;
3295        }        }
# Line 3388  switch(op_code) Line 3394  switch(op_code)
3394    
3395    
3396  /*************************************************  /*************************************************
3397    *        Add a character or range to a class     *
3398    *************************************************/
3399    
3400    /* This function packages up the logic of adding a character or range of
3401    characters to a class. The character values in the arguments will be within the
3402    valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is
3403    mutually recursive with the function immediately below.
3404    
3405    Arguments:
3406      classbits     the bit map for characters < 256
3407      uchardptr     points to the pointer for extra data
3408      options       the options word
3409      cd            contains pointers to tables etc.
3410      start         start of range character
3411      end           end of range character
3412    
3413    Returns:        the number of < 256 characters added
3414                    the pointer to extra data is updated
3415    */
3416    
3417    static int
3418    add_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,
3419      compile_data *cd, unsigned int start, unsigned int end)
3420    {
3421    unsigned int c;
3422    int n8 = 0;
3423    
3424    /* If caseless matching is required, scan the range and process alternate
3425    cases. In Unicode, there are 8-bit characters that have alternate cases that
3426    are greater than 255 and vice-versa. Sometimes we can just extend the original
3427    range. */
3428    
3429    if ((options & PCRE_CASELESS) != 0)
3430      {
3431    #ifdef SUPPORT_UCP
3432      if ((options & PCRE_UTF8) != 0)
3433        {
3434        int rc;
3435        unsigned int oc, od;
3436    
3437        options &= ~PCRE_CASELESS;   /* Remove for recursive calls */
3438        c = start;
3439    
3440        while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)
3441          {
3442          /* Handle a single character that has more than one other case. */
3443    
3444          if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,
3445            PRIV(ucd_caseless_sets) + rc, oc);
3446    
3447          /* Do nothing if the other case range is within the original range. */
3448    
3449          else if (oc >= start && od <= end) continue;
3450    
3451          /* Extend the original range if there is overlap, noting that if oc < c, we
3452          can't have od > end because a subrange is always shorter than the basic
3453          range. Otherwise, use a recursive call to add the additional range. */
3454    
3455          else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */
3456          else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */
3457          else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);
3458          }
3459        }
3460      else
3461    #endif  /* SUPPORT_UCP */
3462    
3463      /* Not UTF-mode, or no UCP */
3464    
3465      for (c = start; c <= end && c < 256; c++)
3466        {
3467        SETBIT(classbits, cd->fcc[c]);
3468        n8++;
3469        }
3470      }
3471    
3472    /* Now handle the original range. Adjust the final value according to the bit
3473    length - this means that the same lists of (e.g.) horizontal spaces can be used
3474    in all cases. */
3475    
3476    #ifdef COMPILE_PCRE8
3477    #ifdef SUPPORT_UTF
3478      if ((options & PCRE_UTF8) == 0)
3479    #endif
3480      if (end > 0xff) end = 0xff;
3481    #endif
3482    
3483    #ifdef COMPILE_PCRE16
3484    #ifdef SUPPORT_UTF
3485      if ((options & PCRE_UTF16) == 0)
3486    #endif
3487      if (end > 0xffff) end = 0xffff;
3488    #endif
3489    
3490    /* If all characters are less than 256, use the bit map. Otherwise use extra
3491    data. */
3492    
3493    if (end < 0x100)
3494      {
3495      for (c = start; c <= end; c++)
3496        {
3497        n8++;
3498        SETBIT(classbits, c);
3499        }
3500      }
3501    
3502    else
3503      {
3504      pcre_uchar *uchardata = *uchardptr;
3505    
3506    #ifdef SUPPORT_UTF
3507      if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */
3508        {
3509        if (start < end)
3510          {
3511          *uchardata++ = XCL_RANGE;
3512          uchardata += PRIV(ord2utf)(start, uchardata);
3513          uchardata += PRIV(ord2utf)(end, uchardata);
3514          }
3515        else if (start == end)
3516          {
3517          *uchardata++ = XCL_SINGLE;
3518          uchardata += PRIV(ord2utf)(start, uchardata);
3519          }
3520        }
3521      else
3522    #endif  /* SUPPORT_UTF */
3523    
3524      /* Without UTF support, character values are constrained by the bit length,
3525      and can only be > 256 for 16-bit and 32-bit libraries. */
3526    
3527    #ifdef COMPILE_PCRE8
3528        {}
3529    #else
3530      if (start < end)
3531        {
3532        *uchardata++ = XCL_RANGE;
3533        *uchardata++ = start;
3534        *uchardata++ = end;
3535        }
3536      else if (start == end)
3537        {
3538        *uchardata++ = XCL_SINGLE;
3539        *uchardata++ = start;
3540        }
3541    #endif
3542    
3543      *uchardptr = uchardata;   /* Updata extra data pointer */
3544      }
3545    
3546    return n8;    /* Number of 8-bit characters */
3547    }
3548    
3549    
3550    
3551    
3552    /*************************************************
3553    *        Add a list of characters to a class     *
3554    *************************************************/
3555    
3556    /* This function is used for adding a list of case-equivalent characters to a
3557    class, and also for adding a list of horizontal or vertical whitespace. If the
3558    list is in order (which it should be), ranges of characters are detected and
3559    handled appropriately. This function is mutually recursive with the function
3560    above.
3561    
3562    Arguments:
3563      classbits     the bit map for characters < 256
3564      uchardptr     points to the pointer for extra data
3565      options       the options word
3566      cd            contains pointers to tables etc.
3567      p             points to row of 32-bit values, terminated by NOTACHAR
3568      except        character to omit; this is used when adding lists of
3569                      case-equivalent characters to avoid including the one we
3570                      already know about
3571    
3572    Returns:        the number of < 256 characters added
3573                    the pointer to extra data is updated
3574    */
3575    
3576    static int
3577    add_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,
3578      compile_data *cd, const pcre_uint32 *p, unsigned int except)
3579    {
3580    int n8 = 0;
3581    while (p[0] < NOTACHAR)
3582      {
3583      int n = 0;
3584      if (p[0] != except)
3585        {
3586        while(p[n+1] == p[0] + n + 1) n++;
3587        n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);
3588        }
3589      p += n + 1;
3590      }
3591    return n8;
3592    }
3593    
3594    
3595    
3596    /*************************************************
3597    *    Add characters not in a list to a class     *
3598    *************************************************/
3599    
3600    /* This function is used for adding the complement of a list of horizontal or
3601    vertical whitespace to a class. The list must be in order.
3602    
3603    Arguments:
3604      classbits     the bit map for characters < 256
3605      uchardptr     points to the pointer for extra data
3606      options       the options word
3607      cd            contains pointers to tables etc.
3608      p             points to row of 32-bit values, terminated by NOTACHAR
3609    
3610    Returns:        the number of < 256 characters added
3611                    the pointer to extra data is updated
3612    */
3613    
3614    static int
3615    add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,
3616      int options, compile_data *cd, const pcre_uint32 *p)
3617    {
3618    int n8 = 0;
3619    if (p[0] > 0)
3620      n8 += add_to_class(classbits, uchardptr, options, cd, 0, p[0] - 1);
3621    while (p[0] < NOTACHAR)
3622      {
3623      while (p[1] == p[0] + 1) p++;
3624      n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,
3625        (p[1] == NOTACHAR)? 0x10ffff : p[1] - 1);
3626      p++;
3627      }
3628    return n8;
3629    }
3630    
3631    
3632    
3633    /*************************************************
3634  *           Compile one branch                   *  *           Compile one branch                   *
3635  *************************************************/  *************************************************/
3636    
# Line 3457  pcre_uchar utf_chars[6]; Line 3700  pcre_uchar utf_chars[6];
3700  BOOL utf = FALSE;  BOOL utf = FALSE;
3701  #endif  #endif
3702    
3703  /* Helper variables for OP_XCLASS opcode (for characters > 255). */  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define
3704    class_uchardata always so that it can be passed to add_to_class() always,
3705    though it will not be used in non-UTF 8-bit cases. This avoids having to supply
3706    alternative calls for the different cases. */
3707    
3708    pcre_uchar *class_uchardata;
3709  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3710  BOOL xclass;  BOOL xclass;
 pcre_uchar *class_uchardata;  
3711  pcre_uchar *class_uchardata_base;  pcre_uchar *class_uchardata_base;
3712  #endif  #endif
3713    
# Line 3505  for (;; ptr++) Line 3751  for (;; ptr++)
3751    BOOL is_recurse;    BOOL is_recurse;
3752    BOOL reset_bracount;    BOOL reset_bracount;
3753    int class_has_8bitchar;    int class_has_8bitchar;
3754    int class_single_char;    int class_one_char;
3755    int newoptions;    int newoptions;
3756    int recno;    int recno;
3757    int refsign;    int refsign;
# Line 3803  for (;; ptr++) Line 4049  for (;; ptr++)
4049    
4050      should_flip_negation = FALSE;      should_flip_negation = FALSE;
4051    
4052      /* For optimization purposes, we track some properties of the class.      /* For optimization purposes, we track some properties of the class:
4053      class_has_8bitchar will be non-zero, if the class contains at least one      class_has_8bitchar will be non-zero if the class contains at least one <
4054      < 256 character. class_single_char will be 1 if the class contains only      256 character; class_one_char will be 1 if the class contains just one
4055      a single character. */      character. */
4056    
4057      class_has_8bitchar = 0;      class_has_8bitchar = 0;
4058      class_single_char = 0;      class_one_char = 0;
4059    
4060      /* Initialize the 32-char bit map to all zeros. We build the map in a      /* Initialize the 32-char bit map to all zeros. We build the map in a
4061      temporary bit of memory, in case the class contains only 1 character (less      temporary bit of memory, in case the class contains fewer than two
4062      than 256), because in that case the compiled code doesn't use the bit map.      8-bit characters because in that case the compiled code doesn't use the bit
4063      */      map. */
4064    
4065      memset(classbits, 0, 32 * sizeof(pcre_uint8));      memset(classbits, 0, 32 * sizeof(pcre_uint8));
4066    
4067  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4068      xclass = FALSE;                           /* No chars >= 256 */      xclass = FALSE;
4069      class_uchardata = code + LINK_SIZE + 2;   /* For UTF-8 items */      class_uchardata = code + LINK_SIZE + 2;   /* For XCLASS items */
4070      class_uchardata_base = class_uchardata;   /* For resetting in pass 1 */      class_uchardata_base = class_uchardata;   /* Save the start */
4071  #endif  #endif
4072    
4073      /* Process characters until ] is reached. By writing this as a "do" it      /* Process characters until ] is reached. By writing this as a "do" it
# Line 3843  for (;; ptr++) Line 4089  for (;; ptr++)
4089        /* In the pre-compile phase, accumulate the length of any extra        /* In the pre-compile phase, accumulate the length of any extra
4090        data and reset the pointer. This is so that very large classes that        data and reset the pointer. This is so that very large classes that
4091        contain a zillion > 255 characters no longer overwrite the work space        contain a zillion > 255 characters no longer overwrite the work space
4092        (which is on the stack). */        (which is on the stack). We have to remember that there was XCLASS data,
4093          however. */
4094    
4095        if (lengthptr != NULL)        if (lengthptr != NULL && class_uchardata > class_uchardata_base)
4096          {          {
4097            xclass = TRUE;
4098          *lengthptr += class_uchardata - class_uchardata_base;          *lengthptr += class_uchardata - class_uchardata_base;
4099          class_uchardata = class_uchardata_base;          class_uchardata = class_uchardata_base;
4100          }          }
# Line 3905  for (;; ptr++) Line 4153  for (;; ptr++)
4153          alpha. This relies on the fact that the class table starts with          alpha. This relies on the fact that the class table starts with
4154          alpha, lower, upper as the first 3 entries. */          alpha, lower, upper as the first 3 entries. */
4155    
4156          if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)          if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)
4157            posix_class = 0;            posix_class = 0;
4158    
4159          /* When PCRE_UCP is set, some of the POSIX classes are converted to          /* When PCRE_UCP is set, some of the POSIX classes are converted to
# Line 3948  for (;; ptr++) Line 4196  for (;; ptr++)
4196              for (c = 0; c < 32; c++) pbits[c] &= ~cbits[c + taboffset];              for (c = 0; c < 32; c++) pbits[c] &= ~cbits[c + taboffset];
4197            }            }
4198    
4199          /* Not see if we need to remove any special characters. An option          /* Now see if we need to remove any special characters. An option
4200          value of 1 removes vertical space and 2 removes underscore. */          value of 1 removes vertical space and 2 removes underscore. */
4201    
4202          if (tabopt < 0) tabopt = -tabopt;          if (tabopt < 0) tabopt = -tabopt;
# Line 3964  for (;; ptr++) Line 4212  for (;; ptr++)
4212            for (c = 0; c < 32; c++) classbits[c] |= pbits[c];            for (c = 0; c < 32; c++) classbits[c] |= pbits[c];
4213    
4214          ptr = tempptr + 1;          ptr = tempptr + 1;
4215          /* Every class contains at least one < 256 characters. */          /* Every class contains at least one < 256 character. */
4216          class_has_8bitchar = 1;          class_has_8bitchar = 1;
4217          /* Every class contains at least two characters. */          /* Every class contains at least two characters. */
4218          class_single_char = 2;          class_one_char = 2;
4219          continue;    /* End of POSIX syntax handling */          continue;    /* End of POSIX syntax handling */
4220          }          }
4221    
# Line 3975  for (;; ptr++) Line 4223  for (;; ptr++)
4223        of the specials, which just set a flag. The sequence \b is a special        of the specials, which just set a flag. The sequence \b is a special
4224        case. Inside a class (and only there) it is treated as backspace. We        case. Inside a class (and only there) it is treated as backspace. We
4225        assume that other escapes have more than one character in them, so        assume that other escapes have more than one character in them, so
4226        speculatively set both class_has_8bitchar and class_single_char bigger        speculatively set both class_has_8bitchar and class_one_char bigger
4227        than one. Unrecognized escapes fall through and are either treated        than one. Unrecognized escapes fall through and are either treated
4228        as literal characters (by default), or are faulted if        as literal characters (by default), or are faulted if
4229        PCRE_EXTRA is set. */        PCRE_EXTRA is set. */
# Line 4008  for (;; ptr++) Line 4256  for (;; ptr++)
4256            /* Every class contains at least two < 256 characters. */            /* Every class contains at least two < 256 characters. */
4257            class_has_8bitchar++;            class_has_8bitchar++;
4258            /* Every class contains at least two characters. */            /* Every class contains at least two characters. */
4259            class_single_char += 2;            class_one_char += 2;
4260    
4261            switch (-c)            switch (-c)
4262              {              {
# Line 4044  for (;; ptr++) Line 4292  for (;; ptr++)
4292    
4293              /* 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
4294              if it was previously set by something earlier in the character              if it was previously set by something earlier in the character
4295              class. */              class. Luckily, the value of CHAR_VT is 0x0b in both ASCII and
4296                EBCDIC, so we lazily just adjust the appropriate bit. */
4297    
4298              case ESC_s:              case ESC_s:
4299              classbits[0] |= cbits[cbit_space];              classbits[0] |= cbits[cbit_space];
# Line 4057  for (;; ptr++) Line 4306  for (;; ptr++)
4306              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];
4307              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */
4308              continue;              continue;
4309    
4310                /* The rest apply in both UCP and non-UCP cases. */
4311    
4312              case ESC_h:              case ESC_h:
4313              SETBIT(classbits, 0x09); /* VT */              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4314              SETBIT(classbits, 0x20); /* SPACE */                PRIV(hspace_list), NOTACHAR);
             SETBIT(classbits, 0xa0); /* NSBP */  
 #ifndef COMPILE_PCRE8  
             xclass = TRUE;  
             *class_uchardata++ = XCL_SINGLE;  
             *class_uchardata++ = 0x1680;  
             *class_uchardata++ = XCL_SINGLE;  
             *class_uchardata++ = 0x180e;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x2000;  
             *class_uchardata++ = 0x200a;  
             *class_uchardata++ = XCL_SINGLE;  
             *class_uchardata++ = 0x202f;  
             *class_uchardata++ = XCL_SINGLE;  
             *class_uchardata++ = 0x205f;  
             *class_uchardata++ = XCL_SINGLE;  
             *class_uchardata++ = 0x3000;  
 #elif defined SUPPORT_UTF  
             if (utf)  
               {  
               xclass = TRUE;  
               *class_uchardata++ = XCL_SINGLE;  
               class_uchardata += PRIV(ord2utf)(0x1680, class_uchardata);  
               *class_uchardata++ = XCL_SINGLE;  
               class_uchardata += PRIV(ord2utf)(0x180e, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x2000, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x200a, class_uchardata);  
               *class_uchardata++ = XCL_SINGLE;  
               class_uchardata += PRIV(ord2utf)(0x202f, class_uchardata);  
               *class_uchardata++ = XCL_SINGLE;  
               class_uchardata += PRIV(ord2utf)(0x205f, class_uchardata);  
               *class_uchardata++ = XCL_SINGLE;  
               class_uchardata += PRIV(ord2utf)(0x3000, class_uchardata);  
               }  
 #endif  
4315              continue;              continue;
4316    
4317              case ESC_H:              case ESC_H:
4318              for (c = 0; c < 32; c++)              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4319                {                cd, PRIV(hspace_list));
               int x = 0xff;  
               switch (c)  
                 {  
                 case 0x09/8: x ^= 1 << (0x09%8); break;  
                 case 0x20/8: x ^= 1 << (0x20%8); break;  
                 case 0xa0/8: x ^= 1 << (0xa0%8); break;  
                 default: break;  
                 }  
               classbits[c] |= x;  
               }  
 #ifndef COMPILE_PCRE8  
             xclass = TRUE;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x0100;  
             *class_uchardata++ = 0x167f;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x1681;  
             *class_uchardata++ = 0x180d;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x180f;  
             *class_uchardata++ = 0x1fff;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x200b;  
             *class_uchardata++ = 0x202e;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x2030;  
             *class_uchardata++ = 0x205e;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x2060;  
             *class_uchardata++ = 0x2fff;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x3001;  
 #ifdef SUPPORT_UTF  
             if (utf)  
               class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);  
             else  
 #endif  
               *class_uchardata++ = 0xffff;  
 #elif defined SUPPORT_UTF  
             if (utf)  
               {  
               xclass = TRUE;  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x0100, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x167f, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x1681, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x180d, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x180f, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x1fff, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x200b, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x202e, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x2030, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x205e, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x2060, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x2fff, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x3001, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);  
               }  
 #endif  
4320              continue;              continue;
4321    
4322              case ESC_v:              case ESC_v:
4323              SETBIT(classbits, 0x0a); /* LF */              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4324              SETBIT(classbits, 0x0b); /* VT */                PRIV(vspace_list), NOTACHAR);
             SETBIT(classbits, 0x0c); /* FF */  
             SETBIT(classbits, 0x0d); /* CR */  
             SETBIT(classbits, 0x85); /* NEL */  
 #ifndef COMPILE_PCRE8  
             xclass = TRUE;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x2028;  
             *class_uchardata++ = 0x2029;  
 #elif defined SUPPORT_UTF  
             if (utf)  
               {  
               xclass = TRUE;  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x2028, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x2029, class_uchardata);  
               }  
 #endif  
4325              continue;              continue;
4326    
4327              case ESC_V:              case ESC_V:
4328              for (c = 0; c < 32; c++)              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4329                {                cd, PRIV(vspace_list));
               int x = 0xff;  
               switch (c)  
                 {  
                 case 0x0a/8: x ^= 1 << (0x0a%8);  
                              x ^= 1 << (0x0b%8);  
                              x ^= 1 << (0x0c%8);  
                              x ^= 1 << (0x0d%8);  
                              break;  
                 case 0x85/8: x ^= 1 << (0x85%8); break;  
                 default: break;  
                 }  
               classbits[c] |= x;  
               }  
   
 #ifndef COMPILE_PCRE8  
             xclass = TRUE;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x0100;  
             *class_uchardata++ = 0x2027;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x202a;  
 #ifdef SUPPORT_UTF  
             if (utf)  
               class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);  
             else  
 #endif  
               *class_uchardata++ = 0xffff;  
 #elif defined SUPPORT_UTF  
             if (utf)  
               {  
               xclass = TRUE;  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x0100, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x2027, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x202a, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);  
               }  
 #endif  
4330              continue;              continue;
4331    
4332  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4242  for (;; ptr++) Line 4337  for (;; ptr++)
4337                int pdata;                int pdata;
4338                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
4339                if (ptype < 0) goto FAILED;                if (ptype < 0) goto FAILED;
               xclass = TRUE;  
4340                *class_uchardata++ = ((-c == ESC_p) != negated)?                *class_uchardata++ = ((-c == ESC_p) != negated)?
4341                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4342                *class_uchardata++ = ptype;                *class_uchardata++ = ptype;
# Line 4262  for (;; ptr++) Line 4356  for (;; ptr++)
4356                goto FAILED;                goto FAILED;
4357                }                }
4358              class_has_8bitchar--;    /* Undo the speculative increase. */              class_has_8bitchar--;    /* Undo the speculative increase. */
4359              class_single_char -= 2;  /* Undo the speculative increase. */              class_one_char -= 2;     /* Undo the speculative increase. */
4360              c = *ptr;                /* Get the final character and fall through */              c = *ptr;                /* Get the final character and fall through */
4361              break;              break;
4362              }              }
4363            }            }
4364    
4365          /* Fall through if we have a single character (c >= 0). This may be          /* Fall through if the escape just defined a single character (c >= 0).
4366          greater than 256. */          This may be greater than 256. */
4367    
4368          }   /* End of backslash handling */          }   /* End of backslash handling */
4369    
4370        /* A single character may be followed by '-' to form a range. However,        /* A character may be followed by '-' to form a range. However, Perl does
4371        Perl does not permit ']' to be the end of the range. A '-' character        not permit ']' to be the end of the range. A '-' character at the end is
4372        at the end is treated as a literal. Perl ignores orphaned \E sequences        treated as a literal. Perl ignores orphaned \E sequences entirely. The
4373        entirely. The code for handling \Q and \E is messy. */        code for handling \Q and \E is messy. */
4374    
4375        CHECK_RANGE:        CHECK_RANGE:
4376        while (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)        while (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
# Line 4284  for (;; ptr++) Line 4378  for (;; ptr++)
4378          inescq = FALSE;          inescq = FALSE;
4379          ptr += 2;          ptr += 2;
4380          }          }
   
4381        oldptr = ptr;        oldptr = ptr;
4382    
4383        /* Remember \r or \n */        /* Remember if \r or \n were explicitly used */
4384    
4385        if (c == CHAR_CR || c == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;        if (c == CHAR_CR || c == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;
4386    
# Line 4310  for (;; ptr++) Line 4403  for (;; ptr++)
4403            inescq = TRUE;            inescq = TRUE;
4404            break;            break;
4405            }            }
4406    
4407            /* Minus (hyphen) at the end of a class is treated as a literal, so put
4408            back the pointer and jump to handle the character that preceded it. */
4409    
4410          if (*ptr == 0 || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))          if (*ptr == 0 || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))
4411            {            {
4412            ptr = oldptr;            ptr = oldptr;
4413            goto LONE_SINGLE_CHARACTER;            goto CLASS_SINGLE_CHARACTER;
4414            }            }
4415    
4416            /* Otherwise, we have a potential range; pick up the next character */
4417    
4418  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4419          if (utf)          if (utf)
# Line 4335  for (;; ptr++) Line 4433  for (;; ptr++)
4433            d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);            d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);
4434            if (*errorcodeptr != 0) goto FAILED;            if (*errorcodeptr != 0) goto FAILED;
4435    
4436            /* \b is backspace; any other special means the '-' was literal */            /* \b is backspace; any other special means the '-' was literal. */
4437    
4438            if (d < 0)            if (d < 0)
4439              {              {
4440              if (d == -ESC_b) d = CHAR_BS; else              if (d == -ESC_b) d = CHAR_BS; else
4441                {                {
4442                ptr = oldptr;                ptr = oldptr;
4443                goto LONE_SINGLE_CHARACTER;  /* A few lines below */                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */
4444                }                }
4445              }              }
4446            }            }
4447    
4448          /* Check that the two values are in the correct order. Optimize          /* Check that the two values are in the correct order. Optimize
4449          one-character ranges */          one-character ranges. */
4450    
4451          if (d < c)          if (d < c)
4452            {            {
4453            *errorcodeptr = ERR8;            *errorcodeptr = ERR8;
4454            goto FAILED;            goto FAILED;
4455            }            }
4456            if (d == c) goto CLASS_SINGLE_CHARACTER;  /* A few lines below */
4457    
4458          if (d == c) goto LONE_SINGLE_CHARACTER;  /* A few lines below */          /* We have found a character range, so single character optimizations
4459            cannot be done anymore. Any value greater than 1 indicates that there
4460            is more than one character. */
4461    
4462            class_one_char = 2;
4463    
4464          /* Remember \r or \n */          /* Remember an explicit \r or \n, and add the range to the class. */
4465    
4466          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;
4467    
4468          /* Since we found a character range, single character optimizations          class_has_8bitchar +=
4469          cannot be done anymore. */            add_to_class(classbits, &class_uchardata, options, cd, c, d);
4470          class_single_char = 2;  
   
         /* In UTF-8 mode, if the upper limit is > 255, or > 127 for caseless  
         matching, we have to use an XCLASS with extra data items. Caseless  
         matching for characters > 127 is available only if UCP support is  
         available. */  
   
 #if defined SUPPORT_UTF && !(defined COMPILE_PCRE8)  
         if ((d > 255) || (utf && ((options & PCRE_CASELESS) != 0 && d > 127)))  
 #elif defined  SUPPORT_UTF  
         if (utf && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))  
 #elif !(defined COMPILE_PCRE8)  
         if (d > 255)  
 #endif  
 #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)  
           {  
           xclass = TRUE;  
   
           /* With UCP support, we can find the other case equivalents of  
           the relevant characters. There may be several ranges. Optimize how  
           they fit with the basic range. */  
   
 #ifdef SUPPORT_UCP  
 #ifndef COMPILE_PCRE8  
           if (utf && (options & PCRE_CASELESS) != 0)  
 #else  
           if ((options & PCRE_CASELESS) != 0)  
 #endif  
             {  
             unsigned int occ, ocd;  
             unsigned int cc = c;  
             unsigned int origd = d;  
             while (get_othercase_range(&cc, origd, &occ, &ocd))  
               {  
               if (occ >= (unsigned int)c &&  
                   ocd <= (unsigned int)d)  
                 continue;                          /* Skip embedded ranges */  
   
               if (occ < (unsigned int)c  &&  
                   ocd >= (unsigned int)c - 1)      /* Extend the basic range */  
                 {                                  /* if there is overlap,   */  
                 c = occ;                           /* noting that if occ < c */  
                 continue;                          /* we can't have ocd > d  */  
                 }                                  /* because a subrange is  */  
               if (ocd > (unsigned int)d &&  
                   occ <= (unsigned int)d + 1)      /* always shorter than    */  
                 {                                  /* the basic range.       */  
                 d = ocd;  
                 continue;  
                 }  
   
               if (occ == ocd)  
                 {  
                 *class_uchardata++ = XCL_SINGLE;  
                 }  
               else  
                 {  
                 *class_uchardata++ = XCL_RANGE;  
                 class_uchardata += PRIV(ord2utf)(occ, class_uchardata);  
                 }  
               class_uchardata += PRIV(ord2utf)(ocd, class_uchardata);  
               }  
             }  
 #endif  /* SUPPORT_UCP */  
   
           /* Now record the original range, possibly modified for UCP caseless  
           overlapping ranges. */  
   
           *class_uchardata++ = XCL_RANGE;  
 #ifdef SUPPORT_UTF  
 #ifndef COMPILE_PCRE8  
           if (utf)  
             {  
             class_uchardata += PRIV(ord2utf)(c, class_uchardata);  
             class_uchardata += PRIV(ord2utf)(d, class_uchardata);  
             }  
           else  
             {  
             *class_uchardata++ = c;  
             *class_uchardata++ = d;  
             }  
 #else  
           class_uchardata += PRIV(ord2utf)(c, class_uchardata);  
           class_uchardata += PRIV(ord2utf)(d, class_uchardata);  
 #endif  
 #else /* SUPPORT_UTF */  
           *class_uchardata++ = c;  
           *class_uchardata++ = d;  
 #endif /* SUPPORT_UTF */  
   
           /* With UCP support, we are done. Without UCP support, there is no  
           caseless matching for UTF characters > 127; we can use the bit map  
           for the smaller ones. As for 16 bit characters without UTF, we  
           can still use  */  
   
 #ifdef SUPPORT_UCP  
 #ifndef COMPILE_PCRE8  
           if (utf)  
 #endif  
             continue;    /* With next character in the class */  
 #endif  /* SUPPORT_UCP */  
   
 #if defined SUPPORT_UTF && !defined(SUPPORT_UCP) && !(defined COMPILE_PCRE8)  
           if (utf)  
             {  
             if ((options & PCRE_CASELESS) == 0 || c > 127) continue;  
             /* Adjust upper limit and fall through to set up the map */  
             d = 127;  
             }  
           else  
             {  
             if (c > 255) continue;  
             /* Adjust upper limit and fall through to set up the map */  
             d = 255;  
             }  
 #elif defined SUPPORT_UTF && !defined(SUPPORT_UCP)  
           if ((options & PCRE_CASELESS) == 0 || c > 127) continue;  
           /* Adjust upper limit and fall through to set up the map */  
           d = 127;  
 #else  
           if (c > 255) continue;  
           /* Adjust upper limit and fall through to set up the map */  
           d = 255;  
 #endif  /* SUPPORT_UTF && !SUPPORT_UCP && !COMPILE_PCRE8 */  
           }  
 #endif  /* SUPPORT_UTF || !COMPILE_PCRE8 */  
   
         /* We use the bit map for 8 bit mode, or when the characters fall  
         partially or entirely to [0-255] ([0-127] for UCP) ranges. */  
   
         class_has_8bitchar = 1;  
   
         /* We can save a bit of time by skipping this in the pre-compile. */  
   
         if (lengthptr == NULL) for (; c <= d; c++)  
           {  
           classbits[c/8] |= (1 << (c&7));  
           if ((options & PCRE_CASELESS) != 0)  
             {  
             int uc = cd->fcc[c]; /* flip case */  
             classbits[uc/8] |= (1 << (uc&7));  
             }  
           }  
   
4471          continue;   /* Go get the next char in the class */          continue;   /* Go get the next char in the class */
4472          }          }
4473    
4474        /* Handle a lone single character - we can get here for a normal        /* Handle a single character - we can get here for a normal non-escape
4475        non-escape char, or after \ that introduces a single character or for an        char, or after \ that introduces a single character or for an apparent
4476        apparent range that isn't. */        range that isn't. Only the value 1 matters for class_one_char, so don't
4477          increase it if it is already 2 or more ... just in case there's a class
4478          with a zillion characters in it. */
4479    
4480          CLASS_SINGLE_CHARACTER:
4481          if (class_one_char < 2) class_one_char++;
4482    
4483          /* If class_one_char is 1, we have the first single character in the
4484          class, and there have been no prior ranges, or XCLASS items generated by
4485          escapes. If this is the final character in the class, we can optimize by
4486          turning the item into a 1-character OP_CHAR[I] if it's positive, or
4487          OP_NOT[I] if it's negative. In the positive case, it can cause firstchar
4488          to be set. Otherwise, there can be no first char if this item is first,
4489          whatever repeat count may follow. In the case of reqchar, save the
4490          previous value for reinstating. */
4491    
4492        LONE_SINGLE_CHARACTER:        if (class_one_char == 1 && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
   
       /* Only the value of 1 matters for class_single_char. */  
   
       if (class_single_char < 2) class_single_char++;  
   
       /* If class_charcount is 1, we saw precisely one character. As long as  
       there was no use of \p or \P, in other words, no use of any XCLASS  
       features, we can optimize.  
   
       The optimization throws away the bit map. We turn the item into a  
       1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.  
       In the positive case, it can cause firstchar to be set. Otherwise, there  
       can be no first char if this item is first, whatever repeat count may  
       follow. In the case of reqchar, save the previous value for reinstating. */  
   
       if (class_single_char == 1 && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)  
4493          {          {
4494          ptr++;          ptr++;
4495          zeroreqchar = reqchar;          zeroreqchar = reqchar;
4496    
4497          if (negate_class)          if (negate_class)
4498            {            {
4499    #ifdef SUPPORT_UCP
4500              int d;
4501    #endif
4502            if (firstchar == REQ_UNSET) firstchar = REQ_NONE;            if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
4503            zerofirstchar = firstchar;            zerofirstchar = firstchar;
4504            *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;  
4505              /* For caseless UTF-8 mode when UCP support is available, check
4506              whether this character has more than one other case. If so, generate
4507              a special OP_NOTPROP item instead of OP_NOTI. */
4508    
4509    #ifdef SUPPORT_UCP
4510              if (utf && (options & PCRE_CASELESS) != 0 &&
4511                  (d = UCD_CASESET(c)) != 0)
4512                {
4513                *code++ = OP_NOTPROP;
4514                *code++ = PT_CLIST;
4515                *code++ = d;
4516                }
4517              else
4518    #endif
4519              /* Char has only one other case, or UCP not available */
4520    
4521                {
4522                *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;
4523  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4524            if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)              if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
4525              code += PRIV(ord2utf)(c, code);                code += PRIV(ord2utf)(c, code);
4526            else              else
4527  #endif  #endif
4528              *code++ = c;                *code++ = c;
4529            goto NOT_CHAR;              }
4530    
4531              /* We are finished with this character class */
4532    
4533              goto END_CLASS;
4534            }            }
4535    
4536          /* For a single, positive character, get the value into mcbuffer, and          /* For a single, positive character, get the value into mcbuffer, and
# Line 4564  for (;; ptr++) Line 4547  for (;; ptr++)
4547            }            }
4548          goto ONE_CHAR;          goto ONE_CHAR;
4549          }       /* End of 1-char optimization */          }       /* End of 1-char optimization */
4550    
4551        /* Handle a character that cannot go in the bit map. */        /* There is more than one character in the class, or an XCLASS item
4552          has been generated. Add this character to the class. */
4553  #if defined SUPPORT_UTF && !(defined COMPILE_PCRE8)  
4554        if ((c > 255) || (utf && ((options & PCRE_CASELESS) != 0 && c > 127)))        class_has_8bitchar +=
4555  #elif defined SUPPORT_UTF          add_to_class(classbits, &class_uchardata, options, cd, c, c);
       if (utf && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))  
 #elif !(defined COMPILE_PCRE8)  
       if (c > 255)  
 #endif  
   
 #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)  
         {  
         xclass = TRUE;  
         *class_uchardata++ = XCL_SINGLE;  
 #ifdef SUPPORT_UTF  
 #ifndef COMPILE_PCRE8  
         /* In non 8 bit mode, we can get here even if we are not in UTF mode. */  
         if (!utf)  
           *class_uchardata++ = c;  
         else  
 #endif  
           class_uchardata += PRIV(ord2utf)(c, class_uchardata);  
 #else /* SUPPORT_UTF */  
         *class_uchardata++ = c;  
 #endif /* SUPPORT_UTF */  
   
 #ifdef SUPPORT_UCP  
 #ifdef COMPILE_PCRE8  
         if ((options & PCRE_CASELESS) != 0)  
 #else  
         /* In non 8 bit mode, we can get here even if we are not in UTF mode. */  
         if (utf && (options & PCRE_CASELESS) != 0)  
 #endif  
           {  
           unsigned int othercase;  
           if ((int)(othercase = UCD_OTHERCASE(c)) != c)  
             {  
             *class_uchardata++ = XCL_SINGLE;  
             class_uchardata += PRIV(ord2utf)(othercase, class_uchardata);  
             }  
           }  
 #endif  /* SUPPORT_UCP */  
   
         }  
       else  
 #endif  /* SUPPORT_UTF || COMPILE_PCRE16 */  
   
       /* Handle a single-byte character */  
         {  
         class_has_8bitchar = 1;  
         classbits[c/8] |= (1 << (c&7));  
         if ((options & PCRE_CASELESS) != 0)  
           {  
           c = cd->fcc[c]; /* flip case */  
           classbits[c/8] |= (1 << (c&7));  
           }  
         }  
4556        }        }
4557    
4558      /* Loop until ']' reached. This "while" is the end of the "do" far above.      /* Loop until ']' reached. This "while" is the end of the "do" far above.
# Line 4641  for (;; ptr++) Line 4572  for (;; ptr++)
4572        goto FAILED;        goto FAILED;
4573        }        }
4574    
4575        /* We will need an XCLASS if data has been placed in class_uchardata. In
4576        the second phase this is a sufficient test. However, in the pre-compile
4577        phase, class_uchardata gets emptied to prevent workspace overflow, so it
4578        only if the very last character in the class needs XCLASS will it contain
4579        anything at this point. For this reason, xclass gets set TRUE above when
4580        uchar_classdata is emptied, and that's why this code is the way it is here
4581        instead of just doing a test on class_uchardata below. */
4582    
4583    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4584        if (class_uchardata > class_uchardata_base) xclass = TRUE;
4585    #endif
4586    
4587      /* If this is the first thing in the branch, there can be no first char      /* If this is the first thing in the branch, there can be no first char
4588      setting, whatever the repeat count. Any reqchar setting must remain      setting, whatever the repeat count. Any reqchar setting must remain
4589      unchanged after any kind of repeat. */      unchanged after any kind of repeat. */
# Line 4703  for (;; ptr++) Line 4646  for (;; ptr++)
4646        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4647        }        }
4648      code += 32 / sizeof(pcre_uchar);      code += 32 / sizeof(pcre_uchar);
4649      NOT_CHAR:  
4650        END_CLASS:
4651      break;      break;
4652    
4653    
# Line 4813  for (;; ptr++) Line 4757  for (;; ptr++)
4757      if (*previous == OP_CHAR || *previous == OP_CHARI      if (*previous == OP_CHAR || *previous == OP_CHARI
4758          || *previous == OP_NOT || *previous == OP_NOTI)          || *previous == OP_NOT || *previous == OP_NOTI)
4759        {        {
4760        switch (*previous)        switch (*previous)
4761          {          {
4762          default: /* Make compiler happy. */          default: /* Make compiler happy. */
4763          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 5537  for (;; ptr++)
5537        ptr++;        ptr++;
5538        while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_letter) != 0) ptr++;        while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_letter) != 0) ptr++;
5539        namelen = (int)(ptr - name);        namelen = (int)(ptr - name);
5540    
5541        /* It appears that Perl allows any characters whatsoever, other than        /* It appears that Perl allows any characters whatsoever, other than
5542        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
5543        letters, digits, and underscores. */        letters, digits, and underscores. */
# Line 5607  for (;; ptr++) Line 5551  for (;; ptr++)
5551            {            {
5552            *errorcodeptr = ERR75;            *errorcodeptr = ERR75;
5553            goto FAILED;            goto FAILED;
5554            }            }
5555          }          }
5556    
5557        if (*ptr != CHAR_RIGHT_PARENTHESIS)        if (*ptr != CHAR_RIGHT_PARENTHESIS)
# Line 5623  for (;; ptr++) Line 5567  for (;; ptr++)
5567          if (namelen == verbs[i].len &&          if (namelen == verbs[i].len &&
5568              STRNCMP_UC_C8(name, vn, namelen) == 0)              STRNCMP_UC_C8(name, vn, namelen) == 0)
5569            {            {
5570              int setverb;
5571    
5572            /* Check for open captures before ACCEPT and convert it to            /* Check for open captures before ACCEPT and convert it to
5573            ASSERT_ACCEPT if in an assertion. */            ASSERT_ACCEPT if in an assertion. */
5574    
# Line 5640  for (;; ptr++) Line 5586  for (;; ptr++)
5586                *code++ = OP_CLOSE;                *code++ = OP_CLOSE;
5587                PUT2INC(code, 0, oc->number);                PUT2INC(code, 0, oc->number);
5588                }                }
5589              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;              setverb = *code++ =
5590                  (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5591    
5592              /* Do not set firstchar after *ACCEPT */              /* Do not set firstchar after *ACCEPT */
5593              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
# Line 5655  for (;; ptr++) Line 5602  for (;; ptr++)
5602                *errorcodeptr = ERR66;                *errorcodeptr = ERR66;
5603                goto FAILED;                goto FAILED;
5604                }                }
5605              *code = verbs[i].op;              setverb = *code++ = verbs[i].op;
             if (*code++ == OP_THEN) cd->external_flags |= PCRE_HASTHEN;  
5606              }              }
5607    
5608            else            else
# Line 5666  for (;; ptr++) Line 5612  for (;; ptr++)
5612                *errorcodeptr = ERR59;                *errorcodeptr = ERR59;
5613                goto FAILED;                goto FAILED;
5614                }                }
5615              *code = verbs[i].op_arg;              setverb = *code++ = verbs[i].op_arg;
             if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;  
5616              *code++ = arglen;              *code++ = arglen;
5617              memcpy(code, arg, IN_UCHARS(arglen));              memcpy(code, arg, IN_UCHARS(arglen));
5618              code += arglen;              code += arglen;
5619              *code++ = 0;              *code++ = 0;
5620              }              }
5621    
5622              switch (setverb)
5623                {
5624                case OP_THEN:
5625                case OP_THEN_ARG:
5626                cd->external_flags |= PCRE_HASTHEN;
5627                break;
5628    
5629                case OP_PRUNE:
5630                case OP_PRUNE_ARG:
5631                case OP_SKIP:
5632                case OP_SKIP_ARG:
5633                cd->had_pruneorskip = TRUE;
5634                break;
5635                }
5636    
5637            break;  /* Found verb, exit loop */            break;  /* Found verb, exit loop */
5638            }            }
5639    
# Line 6859  for (;; ptr++) Line 6819  for (;; ptr++)
6819        /* For the rest (including \X when Unicode properties are supported), we        /* For the rest (including \X when Unicode properties are supported), we
6820        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
6821        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
6822        Unicode property tests. Note that \b and \B do a one-character        Unicode property tests. Note that \b and \B do a one-character
6823        lookbehind. */        lookbehind. */
6824    
6825        else        else
6826          {          {
6827          if ((-c == ESC_b || -c == ESC_B) && cd->max_lookbehind == 0)          if ((-c == ESC_b || -c == ESC_B) && cd->max_lookbehind == 0)
6828            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6829  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6830          if (-c >= ESC_DU && -c <= ESC_wu)          if (-c >= ESC_DU && -c <= ESC_wu)
6831            {            {
# Line 6922  for (;; ptr++) Line 6882  for (;; ptr++)
6882    
6883      ONE_CHAR:      ONE_CHAR:
6884      previous = code;      previous = code;
6885    
6886        /* For caseless UTF-8 mode when UCP support is available, check whether
6887        this character has more than one other case. If so, generate a special
6888        OP_PROP item instead of OP_CHARI. */
6889    
6890    #ifdef SUPPORT_UCP
6891        if (utf && (options & PCRE_CASELESS) != 0)
6892          {
6893          GETCHAR(c, mcbuffer);
6894          if ((c = UCD_CASESET(c)) != 0)
6895            {
6896            *code++ = OP_PROP;
6897            *code++ = PT_CLIST;
6898            *code++ = c;
6899            if (firstchar == REQ_UNSET) firstchar = zerofirstchar = REQ_NONE;
6900            break;
6901            }
6902          }
6903    #endif
6904    
6905        /* Caseful matches, or not one of the multicase characters. */
6906    
6907      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;
6908      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];
6909    
# Line 7173  for (;;) Line 7155  for (;;)
7155          *ptrptr = ptr;          *ptrptr = ptr;
7156          return FALSE;          return FALSE;
7157          }          }
7158        else        else
7159          {          {
7160          if (fixed_length > cd->max_lookbehind)          if (fixed_length > cd->max_lookbehind)
7161            cd->max_lookbehind = fixed_length;            cd->max_lookbehind = fixed_length;
7162          PUT(reverse_count, 0, fixed_length);          PUT(reverse_count, 0, fixed_length);
7163          }          }
7164        }        }
7165      }      }
# Line 7310  and the highest back reference was great Line 7292  and the highest back reference was great
7292  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
7293  of the more common cases more precisely.  of the more common cases more precisely.
7294    
7295    ... A second exception is when the .* appears inside an atomic group, because
7296    this prevents the number of characters it matches from being adjusted.
7297    
7298  Arguments:  Arguments:
7299    code           points to start of expression (the bracket)    code           points to start of expression (the bracket)
7300    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
7301                    handles up to substring 31; after that we just have to take                    handles up to substring 31; after that we just have to take
7302                    the less precise approach                    the less precise approach
7303    backref_map    the back reference bitmap    cd             points to the compile data block
7304      atomcount      atomic group level
7305    
7306  Returns:     TRUE or FALSE  Returns:     TRUE or FALSE
7307  */  */
7308    
7309  static BOOL  static BOOL
7310  is_anchored(register const pcre_uchar *code, unsigned int bracket_map,  is_anchored(register const pcre_uchar *code, unsigned int bracket_map,
7311    unsigned int backref_map)    compile_data *cd, int atomcount)
7312  {  {
7313  do {  do {
7314     const pcre_uchar *scode = first_significant_code(     const pcre_uchar *scode = first_significant_code(
# Line 7334  do { Line 7320  do {
7320     if (op == OP_BRA  || op == OP_BRAPOS ||     if (op == OP_BRA  || op == OP_BRAPOS ||
7321         op == OP_SBRA || op == OP_SBRAPOS)         op == OP_SBRA || op == OP_SBRAPOS)
7322       {       {
7323       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;       if (!is_anchored(scode, bracket_map, cd, atomcount)) return FALSE;
7324       }       }
7325    
7326     /* Capturing brackets */     /* Capturing brackets */
# Line 7344  do { Line 7330  do {
7330       {       {
7331       int n = GET2(scode, 1+LINK_SIZE);       int n = GET2(scode, 1+LINK_SIZE);
7332       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);
7333       if (!is_anchored(scode, new_map, backref_map)) return FALSE;       if (!is_anchored(scode, new_map, cd, atomcount)) return FALSE;
7334       }       }
7335    
7336     /* Other brackets */     /* Positive forward assertions and conditions */
7337    
7338     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC ||     else if (op == OP_ASSERT || op == OP_COND)
             op == OP_COND)  
7339       {       {
7340       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;       if (!is_anchored(scode, bracket_map, cd, atomcount)) return FALSE;
7341         }
7342    
7343       /* Atomic groups */
7344    
7345       else if (op == OP_ONCE || op == OP_ONCE_NC)
7346         {
7347         if (!is_anchored(scode, bracket_map, cd, atomcount + 1))
7348           return FALSE;
7349       }       }
7350    
7351     /* .* is not anchored unless DOTALL is set (which generates OP_ALLANY) and     /* .* is not anchored unless DOTALL is set (which generates OP_ALLANY) and
7352     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
7353       group. */
7354    
7355     else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR ||     else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR ||
7356               op == OP_TYPEPOSSTAR))               op == OP_TYPEPOSSTAR))
7357       {       {
7358       if (scode[1] != OP_ALLANY || (bracket_map & backref_map) != 0)       if (scode[1] != OP_ALLANY || (bracket_map & cd->backref_map) != 0 ||
7359             atomcount > 0 || cd->had_pruneorskip)
7360         return FALSE;         return FALSE;
7361       }       }
7362    
7363     /* Check for explicit anchoring */     /* Check for explicit anchoring */
7364    
7365     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;
7366    
7367     code += GET(code, 1);     code += GET(code, 1);
7368     }     }
7369  while (*code == OP_ALT);   /* Loop for each alternative */  while (*code == OP_ALT);   /* Loop for each alternative */
# Line 7385  return TRUE; Line 7381  return TRUE;
7381  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
7382  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
7383  have to take account of back references to capturing brackets that contain .*  have to take account of back references to capturing brackets that contain .*
7384  because in that case we can't make the assumption.  because in that case we can't make the assumption. Also, the appearance of .*
7385    inside atomic brackets or in a pattern that contains *PRUNE or *SKIP does not
7386    count, because once again the assumption no longer holds.
7387    
7388  Arguments:  Arguments:
7389    code           points to start of expression (the bracket)    code           points to start of expression (the bracket)
7390    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
7391                    handles up to substring 31; after that we just have to take                    handles up to substring 31; after that we just have to take
7392                    the less precise approach                    the less precise approach
7393    backref_map    the back reference bitmap    cd             points to the compile data
7394      atomcount      atomic group level
7395    
7396  Returns:         TRUE or FALSE  Returns:         TRUE or FALSE
7397  */  */
7398    
7399  static BOOL  static BOOL
7400  is_startline(const pcre_uchar *code, unsigned int bracket_map,  is_startline(const pcre_uchar *code, unsigned int bracket_map,
7401    unsigned int backref_map)    compile_data *cd, int atomcount)
7402  {  {
7403  do {  do {
7404     const pcre_uchar *scode = first_significant_code(     const pcre_uchar *scode = first_significant_code(
# Line 7425  do { Line 7424  do {
7424         return FALSE;         return FALSE;
7425    
7426         default:     /* Assertion */         default:     /* Assertion */
7427         if (!is_startline(scode, bracket_map, backref_map)) return FALSE;         if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7428         do scode += GET(scode, 1); while (*scode == OP_ALT);         do scode += GET(scode, 1); while (*scode == OP_ALT);
7429         scode += 1 + LINK_SIZE;         scode += 1 + LINK_SIZE;
7430         break;         break;
# Line 7439  do { Line 7438  do {
7438     if (op == OP_BRA  || op == OP_BRAPOS ||     if (op == OP_BRA  || op == OP_BRAPOS ||
7439         op == OP_SBRA || op == OP_SBRAPOS)         op == OP_SBRA || op == OP_SBRAPOS)
7440       {       {
7441       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7442       }       }
7443    
7444     /* Capturing brackets */     /* Capturing brackets */
# Line 7449  do { Line 7448  do {
7448       {       {
7449       int n = GET2(scode, 1+LINK_SIZE);       int n = GET2(scode, 1+LINK_SIZE);
7450       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);
7451       if (!is_startline(scode, new_map, backref_map)) return FALSE;       if (!is_startline(scode, new_map, cd, atomcount)) return FALSE;
7452       }       }
7453    
7454     /* Other brackets */     /* Positive forward assertions */
7455    
7456     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC)     else if (op == OP_ASSERT)
7457       {       {
7458       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7459       }       }
7460    
7461       /* Atomic brackets */
7462    
7463     /* .* means "start at start or after \n" if it isn't in brackets that     else if (op == OP_ONCE || op == OP_ONCE_NC)
7464     may be referenced. */       {
7465         if (!is_startline(scode, bracket_map, cd, atomcount + 1)) return FALSE;
7466         }
7467    
7468       /* .* means "start at start or after \n" if it isn't in atomic brackets or
7469       brackets that may be referenced, as long as the pattern does not contain
7470       *PRUNE or *SKIP, because these break the feature. Consider, for example,
7471       /.*?a(*PRUNE)b/ with the subject "aab", which matches "ab", i.e. not at the
7472       start of a line. */
7473    
7474     else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR || op == OP_TYPEPOSSTAR)     else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR || op == OP_TYPEPOSSTAR)
7475       {       {
7476       if (scode[1] != OP_ANY || (bracket_map & backref_map) != 0) return FALSE;       if (scode[1] != OP_ANY || (bracket_map & cd->backref_map) != 0 ||
7477             atomcount > 0 || cd->had_pruneorskip)
7478           return FALSE;
7479       }       }
7480    
7481     /* Check for explicit circumflex */     /* Check for explicit circumflex; anything else gives a FALSE result. Note
7482       in particular that this includes atomic brackets OP_ONCE and OP_ONCE_NC
7483       because the number of characters matched by .* cannot be adjusted inside
7484       them. */
7485    
7486     else if (op != OP_CIRC && op != OP_CIRCM) return FALSE;     else if (op != OP_CIRC && op != OP_CIRCM) return FALSE;
7487    
# Line 7926  cd->start_code = codestart; Line 7940  cd->start_code = codestart;
7940  cd->hwm = (pcre_uchar *)(cd->start_workspace);  cd->hwm = (pcre_uchar *)(cd->start_workspace);
7941  cd->req_varyopt = 0;  cd->req_varyopt = 0;
7942  cd->had_accept = FALSE;  cd->had_accept = FALSE;
7943    cd->had_pruneorskip = FALSE;
7944  cd->check_lookbehind = FALSE;  cd->check_lookbehind = FALSE;
7945  cd->open_caps = NULL;  cd->open_caps = NULL;
7946    
# Line 8049  if (errorcode != 0) Line 8064  if (errorcode != 0)
8064    }    }
8065    
8066  /* 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
8067  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
8068  as starting with .* when DOTALL is set).  as starting with non-atomic .* when DOTALL is set and there are no occurrences
8069    of *PRUNE or *SKIP.
8070    
8071  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
8072  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
8073  PCRE_STARTLINE flag. This is helpful for multiline matches when all branches  PCRE_STARTLINE flag. This is helpful for multiline matches when all branches
8074  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
8075  */  non-DOTALL matches when *PRUNE and SKIP are not present. */
8076    
8077  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
8078    {    {
8079    if (is_anchored(codestart, 0, cd->backref_map))    if (is_anchored(codestart, 0, cd, 0)) re->options |= PCRE_ANCHORED;
     re->options |= PCRE_ANCHORED;  
8080    else    else
8081      {      {
8082      if (firstchar < 0)      if (firstchar < 0)
# Line 8098  if ((re->options & PCRE_ANCHORED) == 0) Line 8113  if ((re->options & PCRE_ANCHORED) == 0)
8113    
8114        re->flags |= PCRE_FIRSTSET;        re->flags |= PCRE_FIRSTSET;
8115        }        }
8116      else if (is_startline(codestart, 0, cd->backref_map))  
8117        re->flags |= PCRE_STARTLINE;      else if (is_startline(codestart, 0, cd, 0)) re->flags |= PCRE_STARTLINE;
8118      }      }
8119    }    }
8120    

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

  ViewVC Help
Powered by ViewVC 1.1.5