/[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 1219 by ph10, Sun Nov 11 18:04:37 2012 UTC revision 1221 by ph10, Sun Nov 11 20:27:03 2012 UTC
# Line 80  to check them every time. */ Line 80  to check them every time. */
80  /* Definitions to allow mutual recursion */  /* Definitions to allow mutual recursion */
81    
82  static int  static int
83    add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,    add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,
84      const pcre_uint32 *, unsigned int);      const pcre_uint32 *, unsigned int);
85    
86  static BOOL  static BOOL
87    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,
88      pcre_uint32 *, pcre_int32 *, pcre_uint32 *, pcre_int32 *, branch_chain *,      pcre_uint32 *, pcre_int32 *, pcre_uint32 *, pcre_int32 *, branch_chain *,
89      compile_data *, int *);      compile_data *, int *);
90    
91    
# Line 773  Returns:         zero => a data characte Line 773  Returns:         zero => a data characte
773  */  */
774    
775  static int  static int
776  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,
777    int bracount, int options, BOOL isclass)    int bracount, int options, BOOL isclass)
778  {  {
779  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
# Line 1211  Returns:         TRUE if the type value Line 1211  Returns:         TRUE if the type value
1211  */  */
1212    
1213  static BOOL  static BOOL
1214  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, unsigned int *ptypeptr,  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, unsigned int *ptypeptr,
1215    unsigned int *pdataptr, int *errorcodeptr)    unsigned int *pdataptr, int *errorcodeptr)
1216  {  {
1217  pcre_uchar c;  pcre_uchar c;
# Line 1432  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1432  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1432    
1433    else if (ptr[2] == CHAR_NUMBER_SIGN)    else if (ptr[2] == CHAR_NUMBER_SIGN)
1434      {      {
1435      for (ptr += 3; *ptr != CHAR_NULL; ptr++)      for (ptr += 3; *ptr != CHAR_NULL; ptr++)
1436        if (*ptr == CHAR_RIGHT_PARENTHESIS) break;        if (*ptr == CHAR_RIGHT_PARENTHESIS) break;
1437      goto FAIL_EXIT;      goto FAIL_EXIT;
1438      }      }
# Line 1879  for (;;) Line 1879  for (;;)
1879    
1880      case OP_TYPEEXACT:      case OP_TYPEEXACT:
1881      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1882      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP)      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP)
1883        cc += 2;        cc += 2;
1884      cc += 1 + IMM2_SIZE + 1;      cc += 1 + IMM2_SIZE + 1;
1885      break;      break;
# Line 2122  for (;;) Line 2122  for (;;)
2122        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2123        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2124        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
2125        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2126          code += 2;          code += 2;
2127        break;        break;
2128    
# Line 2242  for (;;) Line 2242  for (;;)
2242        case OP_TYPEUPTO:        case OP_TYPEUPTO:
2243        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2244        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2245        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2246          code += 2;          code += 2;
2247        break;        break;
2248    
# Line 2568  for (code = first_significant_code(code Line 2568  for (code = first_significant_code(code
2568      case OP_TYPEUPTO:      case OP_TYPEUPTO:
2569      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
2570      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
2571      if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)      if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2572        code += 2;        code += 2;
2573      break;      break;
2574    
# Line 2903  PUT(previous_callout, 2 + LINK_SIZE, len Line 2903  PUT(previous_callout, 2 + LINK_SIZE, len
2903  /* 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
2904  with UCP support. It searches up the characters, looking for ranges of  with UCP support. It searches up the characters, looking for ranges of
2905  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
2906  start address. A character with multiple other cases is returned on its own  start address. A character with multiple other cases is returned on its own
2907  with a special return value.  with a special return value.
2908    
2909  Arguments:  Arguments:
# Line 2915  Arguments: Line 2915  Arguments:
2915  Yield:        -1 when no more  Yield:        -1 when no more
2916                 0 when a range is returned                 0 when a range is returned
2917                >0 the CASESET offset for char with multiple other cases                >0 the CASESET offset for char with multiple other cases
2918                  in this case, ocptr contains the original                  in this case, ocptr contains the original
2919  */  */
2920    
2921  static int  static int
# Line 2925  get_othercase_range(pcre_uint32 *cptr, p Line 2925  get_othercase_range(pcre_uint32 *cptr, p
2925  pcre_uint32 c, othercase, next;  pcre_uint32 c, othercase, next;
2926  unsigned int co;  unsigned int co;
2927    
2928  /* Find the first character that has an other case. If it has multiple other  /* Find the first character that has an other case. If it has multiple other
2929  cases, return its case offset value. */  cases, return its case offset value. */
2930    
2931  for (c = *cptr; c <= d; c++)  for (c = *cptr; c <= d; c++)
2932    {    {
2933    if ((co = UCD_CASESET(c)) != 0)    if ((co = UCD_CASESET(c)) != 0)
2934      {      {
2935      *ocptr = c++;   /* Character that has the set */      *ocptr = c++;   /* Character that has the set */
2936      *cptr = c;      /* Rest of input range */      *cptr = c;      /* Rest of input range */
2937      return (int)co;      return (int)co;
2938      }      }
2939    if ((othercase = UCD_OTHERCASE(c)) != c) break;    if ((othercase = UCD_OTHERCASE(c)) != c) break;
2940    }    }
2941    
2942  if (c > d) return -1;  /* Reached end of range */  if (c > d) return -1;  /* Reached end of range */
# Line 3019  switch(ptype) Line 3019  switch(ptype)
3019    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
3020            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
3021            c == CHAR_UNDERSCORE) == negated;            c == CHAR_UNDERSCORE) == negated;
3022    
3023  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3024    case PT_CLIST:    case PT_CLIST:
3025    p = PRIV(ucd_caseless_sets) + prop->caseset;    p = PRIV(ucd_caseless_sets) + prop->caseset;
# Line 3139  if (*ptr == CHAR_ASTERISK || *ptr == CHA Line 3139  if (*ptr == CHAR_ASTERISK || *ptr == CHA
3139    
3140  /* If the previous item is a character, get its value. */  /* If the previous item is a character, get its value. */
3141    
3142  if (op_code == OP_CHAR || op_code == OP_CHARI ||  if (op_code == OP_CHAR || op_code == OP_CHARI ||
3143      op_code == OP_NOT || op_code == OP_NOTI)      op_code == OP_NOT || op_code == OP_NOTI)
3144    {    {
3145  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 3156  if (escape == 0) Line 3156  if (escape == 0)
3156    {    {
3157    /* For a caseless UTF match, the next character may have more than one other    /* For a caseless UTF match, the next character may have more than one other
3158    case, which maps to the special PT_CLIST property. Check this first. */    case, which maps to the special PT_CLIST property. Check this first. */
3159    
3160  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3161    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)
3162      {      {
# Line 3172  if (escape == 0) Line 3172  if (escape == 0)
3172    
3173      /* For CHARI (caseless character) we must check the other case. If we have      /* For CHARI (caseless character) we must check the other case. If we have
3174      Unicode property support, we can use it to test the other case of      Unicode property support, we can use it to test the other case of
3175      high-valued characters. We know that next can have only one other case,      high-valued characters. We know that next can have only one other case,
3176      because multi-other-case characters are dealt with above. */      because multi-other-case characters are dealt with above. */
3177    
3178      case OP_CHARI:      case OP_CHARI:
# Line 3192  if (escape == 0) Line 3192  if (escape == 0)
3192      else      else
3193  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3194      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3195    
3196      case OP_NOT:      case OP_NOT:
3197      return c == next;      return c == next;
3198    
3199      case OP_NOTI:      case OP_NOTI:
3200      if (c == next) return TRUE;      if (c == next) return TRUE;
3201  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 3239  if (escape == 0) Line 3239  if (escape == 0)
3239      case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
3240      switch(next)      switch(next)
3241        {        {
3242        HSPACE_CASES:        HSPACE_CASES:
3243        return op_code == OP_NOT_HSPACE;        return op_code == OP_NOT_HSPACE;
3244    
3245        default:        default:
# Line 3251  if (escape == 0) Line 3251  if (escape == 0)
3251      case OP_NOT_VSPACE:      case OP_NOT_VSPACE:
3252      switch(next)      switch(next)
3253        {        {
3254        VSPACE_CASES:        VSPACE_CASES:
3255        return op_code == OP_NOT_VSPACE;        return op_code == OP_NOT_VSPACE;
3256    
3257        default:        default:
# Line 3305  switch(op_code) Line 3305  switch(op_code)
3305      case ESC_H:      case ESC_H:
3306      switch(c)      switch(c)
3307        {        {
3308        HSPACE_CASES:        HSPACE_CASES:
3309        return escape != ESC_h;        return escape != ESC_h;
3310    
3311        default:        default:
3312        return escape == ESC_h;        return escape == ESC_h;
3313        }        }
# Line 3316  switch(op_code) Line 3316  switch(op_code)
3316      case ESC_V:      case ESC_V:
3317      switch(c)      switch(c)
3318        {        {
3319        VSPACE_CASES:        VSPACE_CASES:
3320        return escape != ESC_v;        return escape != ESC_v;
3321    
3322        default:        default:
# Line 3428  switch(op_code) Line 3428  switch(op_code)
3428  *************************************************/  *************************************************/
3429    
3430  /* This function packages up the logic of adding a character or range of  /* This function packages up the logic of adding a character or range of
3431  characters to a class. The character values in the arguments will be within the  characters to a class. The character values in the arguments will be within the
3432  valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is  valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is
3433  mutually recursive with the function immediately below.  mutually recursive with the function immediately below.
3434    
3435  Arguments:  Arguments:
3436    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3437    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3438    options       the options word    options       the options word
3439    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3440    start         start of range character    start         start of range character
3441    end           end of range character    end           end of range character
3442    
3443  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3444                  the pointer to extra data is updated                  the pointer to extra data is updated
3445  */  */
# Line 3451  add_to_class(pcre_uint8 *classbits, pcre Line 3451  add_to_class(pcre_uint8 *classbits, pcre
3451  pcre_uint32 c;  pcre_uint32 c;
3452  int n8 = 0;  int n8 = 0;
3453    
3454  /* If caseless matching is required, scan the range and process alternate  /* If caseless matching is required, scan the range and process alternate
3455  cases. In Unicode, there are 8-bit characters that have alternate cases that  cases. In Unicode, there are 8-bit characters that have alternate cases that
3456  are greater than 255 and vice-versa. Sometimes we can just extend the original  are greater than 255 and vice-versa. Sometimes we can just extend the original
3457  range. */  range. */
3458    
3459  if ((options & PCRE_CASELESS) != 0)  if ((options & PCRE_CASELESS) != 0)
3460    {    {
3461  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3462    if ((options & PCRE_UTF8) != 0)    if ((options & PCRE_UTF8) != 0)
3463      {      {
3464      int rc;      int rc;
3465      pcre_uint32 oc, od;      pcre_uint32 oc, od;
3466    
3467      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */
3468      c = start;      c = start;
3469    
3470      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)
3471        {        {
3472        /* Handle a single character that has more than one other case. */        /* Handle a single character that has more than one other case. */
3473    
3474        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,
3475          PRIV(ucd_caseless_sets) + rc, oc);          PRIV(ucd_caseless_sets) + rc, oc);
3476    
3477        /* Do nothing if the other case range is within the original range. */        /* Do nothing if the other case range is within the original range. */
3478    
3479        else if (oc >= start && od <= end) continue;        else if (oc >= start && od <= end) continue;
3480    
3481        /* Extend the original range if there is overlap, noting that if oc < c, we        /* Extend the original range if there is overlap, noting that if oc < c, we
3482        can't have od > end because a subrange is always shorter than the basic        can't have od > end because a subrange is always shorter than the basic
3483        range. Otherwise, use a recursive call to add the additional range. */        range. Otherwise, use a recursive call to add the additional range. */
3484    
3485        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */
3486        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */
3487        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);
# Line 3491  if ((options & PCRE_CASELESS) != 0) Line 3491  if ((options & PCRE_CASELESS) != 0)
3491  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3492    
3493    /* Not UTF-mode, or no UCP */    /* Not UTF-mode, or no UCP */
3494    
3495    for (c = start; c <= end && c < 256; c++)    for (c = start; c <= end && c < 256; c++)
3496      {      {
3497      SETBIT(classbits, cd->fcc[c]);      SETBIT(classbits, cd->fcc[c]);
3498      n8++;      n8++;
3499      }      }
3500    }    }
3501    
3502  /* Now handle the original range. Adjust the final value according to the bit  /* Now handle the original range. Adjust the final value according to the bit
3503  length - this means that the same lists of (e.g.) horizontal spaces can be used  length - this means that the same lists of (e.g.) horizontal spaces can be used
3504  in all cases. */  in all cases. */
# Line 3524  if (end < 0x100) Line 3524  if (end < 0x100)
3524    {    {
3525    for (c = start; c <= end; c++)    for (c = start; c <= end; c++)
3526      {      {
3527      n8++;      n8++;
3528      SETBIT(classbits, c);      SETBIT(classbits, c);
3529      }      }
3530    }    }
3531    
3532  else  else
3533    {    {
3534    pcre_uchar *uchardata = *uchardptr;    pcre_uchar *uchardata = *uchardptr;
3535    
3536  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3537    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */
3538      {      {
3539      if (start < end)      if (start < end)
3540        {        {
3541        *uchardata++ = XCL_RANGE;        *uchardata++ = XCL_RANGE;
3542        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3543        uchardata += PRIV(ord2utf)(end, uchardata);        uchardata += PRIV(ord2utf)(end, uchardata);
3544        }        }
3545      else if (start == end)      else if (start == end)
3546        {        {
3547        *uchardata++ = XCL_SINGLE;        *uchardata++ = XCL_SINGLE;
3548        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3549        }        }
3550      }      }
3551    else    else
3552  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3553    
3554    /* Without UTF support, character values are constrained by the bit length,    /* Without UTF support, character values are constrained by the bit length,
3555    and can only be > 256 for 16-bit and 32-bit libraries. */    and can only be > 256 for 16-bit and 32-bit libraries. */
3556    
3557  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3558      {}      {}
3559  #else  #else
3560    if (start < end)    if (start < end)
3561      {      {
3562      *uchardata++ = XCL_RANGE;      *uchardata++ = XCL_RANGE;
# Line 3567  else Line 3567  else
3567      {      {
3568      *uchardata++ = XCL_SINGLE;      *uchardata++ = XCL_SINGLE;
3569      *uchardata++ = start;      *uchardata++ = start;
3570      }      }
3571  #endif  #endif
3572    
3573    *uchardptr = uchardata;   /* Updata extra data pointer */    *uchardptr = uchardata;   /* Updata extra data pointer */
3574    }    }
3575    
3576  return n8;    /* Number of 8-bit characters */  return n8;    /* Number of 8-bit characters */
3577  }  }
3578    
3579    
3580    
3581    
3582  /*************************************************  /*************************************************
3583  *        Add a list of characters to a class     *  *        Add a list of characters to a class     *
3584  *************************************************/  *************************************************/
3585    
3586  /* This function is used for adding a list of case-equivalent characters to a  /* This function is used for adding a list of case-equivalent characters to a
3587  class, and also for adding a list of horizontal or vertical whitespace. If the  class, and also for adding a list of horizontal or vertical whitespace. If the
3588  list is in order (which it should be), ranges of characters are detected and  list is in order (which it should be), ranges of characters are detected and
3589  handled appropriately. This function is mutually recursive with the function  handled appropriately. This function is mutually recursive with the function
# Line 3593  Arguments: Line 3593  Arguments:
3593    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3594    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3595    options       the options word    options       the options word
3596    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3597    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3598    except        character to omit; this is used when adding lists of    except        character to omit; this is used when adding lists of
3599                    case-equivalent characters to avoid including the one we                    case-equivalent characters to avoid including the one we
3600                    already know about                    already know about
3601    
3602  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3603                  the pointer to extra data is updated                  the pointer to extra data is updated
3604  */  */
# Line 3612  while (p[0] < NOTACHAR) Line 3612  while (p[0] < NOTACHAR)
3612    {    {
3613    int n = 0;    int n = 0;
3614    if (p[0] != except)    if (p[0] != except)
3615      {      {
3616      while(p[n+1] == p[0] + n + 1) n++;      while(p[n+1] == p[0] + n + 1) n++;
3617      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);
3618      }      }
3619    p += n + 1;    p += n + 1;
3620    }    }
3621  return n8;  return n8;
3622  }  }
3623    
3624    
3625    
# Line 3634  Arguments: Line 3634  Arguments:
3634    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3635    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3636    options       the options word    options       the options word
3637    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3638    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3639    
3640  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3641                  the pointer to extra data is updated                  the pointer to extra data is updated
3642  */  */
3643    
3644  static int  static int
3645  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,
3646    int options, compile_data *cd, const pcre_uint32 *p)    int options, compile_data *cd, const pcre_uint32 *p)
3647  {  {
3648  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
# Line 3654  while (p[0] < NOTACHAR) Line 3654  while (p[0] < NOTACHAR)
3654    while (p[1] == p[0] + 1) p++;    while (p[1] == p[0] + 1) p++;
3655    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,
3656      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);
3657    p++;    p++;
3658    }    }
3659  return n8;  return n8;
3660  }  }
3661    
3662    
3663    
# Line 3741  BOOL utf = FALSE; Line 3741  BOOL utf = FALSE;
3741  #endif  #endif
3742    
3743  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define
3744  class_uchardata always so that it can be passed to add_to_class() always,  class_uchardata always so that it can be passed to add_to_class() always,
3745  though it will not be used in non-UTF 8-bit cases. This avoids having to supply  though it will not be used in non-UTF 8-bit cases. This avoids having to supply
3746  alternative calls for the different cases. */  alternative calls for the different cases. */
3747    
3748  pcre_uchar *class_uchardata;  pcre_uchar *class_uchardata;
# Line 4136  for (;; ptr++) Line 4136  for (;; ptr++)
4136        /* In the pre-compile phase, accumulate the length of any extra        /* In the pre-compile phase, accumulate the length of any extra
4137        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
4138        contain a zillion > 255 characters no longer overwrite the work space        contain a zillion > 255 characters no longer overwrite the work space
4139        (which is on the stack). We have to remember that there was XCLASS data,        (which is on the stack). We have to remember that there was XCLASS data,
4140        however. */        however. */
4141    
4142        if (lengthptr != NULL && class_uchardata > class_uchardata_base)        if (lengthptr != NULL && class_uchardata > class_uchardata_base)
# Line 4200  for (;; ptr++) Line 4200  for (;; ptr++)
4200          alpha. This relies on the fact that the class table starts with          alpha. This relies on the fact that the class table starts with
4201          alpha, lower, upper as the first 3 entries. */          alpha, lower, upper as the first 3 entries. */
4202    
4203          if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)          if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)
4204            posix_class = 0;            posix_class = 0;
4205    
4206          /* 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 4356  for (;; ptr++) Line 4356  for (;; ptr++)
4356              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];
4357              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */
4358              continue;              continue;
4359    
4360              /* The rest apply in both UCP and non-UCP cases. */              /* The rest apply in both UCP and non-UCP cases. */
4361    
4362              case ESC_h:              case ESC_h:
4363              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4364                PRIV(hspace_list), NOTACHAR);                PRIV(hspace_list), NOTACHAR);
4365              continue;              continue;
4366    
4367              case ESC_H:              case ESC_H:
4368              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4369                cd, PRIV(hspace_list));                cd, PRIV(hspace_list));
4370              continue;              continue;
4371    
4372              case ESC_v:              case ESC_v:
4373              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4374                PRIV(vspace_list), NOTACHAR);                PRIV(vspace_list), NOTACHAR);
4375              continue;              continue;
4376    
4377              case ESC_V:              case ESC_V:
4378              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4379                cd, PRIV(vspace_list));                cd, PRIV(vspace_list));
4380              continue;              continue;
4381    
4382  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4414  for (;; ptr++) Line 4414  for (;; ptr++)
4414    
4415          /* Fall through if the escape just defined a single character (c >= 0).          /* Fall through if the escape just defined a single character (c >= 0).
4416          This may be greater than 256. */          This may be greater than 256. */
4417    
4418          escape = 0;          escape = 0;
4419    
4420          }   /* End of backslash handling */          }   /* End of backslash handling */
# Line 4455  for (;; ptr++) Line 4455  for (;; ptr++)
4455            inescq = TRUE;            inescq = TRUE;
4456            break;            break;
4457            }            }
4458    
4459          /* Minus (hyphen) at the end of a class is treated as a literal, so put          /* Minus (hyphen) at the end of a class is treated as a literal, so put
4460          back the pointer and jump to handle the character that preceded it. */          back the pointer and jump to handle the character that preceded it. */
4461    
# Line 4464  for (;; ptr++) Line 4464  for (;; ptr++)
4464            ptr = oldptr;            ptr = oldptr;
4465            goto CLASS_SINGLE_CHARACTER;            goto CLASS_SINGLE_CHARACTER;
4466            }            }
4467    
4468          /* Otherwise, we have a potential range; pick up the next character */          /* Otherwise, we have a potential range; pick up the next character */
4469    
4470  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 4511  for (;; ptr++) Line 4511  for (;; ptr++)
4511          /* We have found a character range, so single character optimizations          /* We have found a character range, so single character optimizations
4512          cannot be done anymore. Any value greater than 1 indicates that there          cannot be done anymore. Any value greater than 1 indicates that there
4513          is more than one character. */          is more than one character. */
4514    
4515          class_one_char = 2;          class_one_char = 2;
4516    
4517          /* Remember an explicit \r or \n, and add the range to the class. */          /* Remember an explicit \r or \n, and add the range to the class. */
4518    
4519          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;
4520    
4521          class_has_8bitchar +=          class_has_8bitchar +=
4522            add_to_class(classbits, &class_uchardata, options, cd, c, d);            add_to_class(classbits, &class_uchardata, options, cd, c, d);
4523    
4524          continue;   /* Go get the next char in the class */          continue;   /* Go get the next char in the class */
4525          }          }
4526    
4527        /* Handle a single character - we can get here for a normal non-escape        /* Handle a single character - we can get here for a normal non-escape
4528        char, or after \ that introduces a single character or for an apparent        char, or after \ that introduces a single character or for an apparent
4529        range that isn't. Only the value 1 matters for class_one_char, so don't        range that isn't. Only the value 1 matters for class_one_char, so don't
4530        increase it if it is already 2 or more ... just in case there's a class        increase it if it is already 2 or more ... just in case there's a class
4531        with a zillion characters in it. */        with a zillion characters in it. */
4532    
4533        CLASS_SINGLE_CHARACTER:        CLASS_SINGLE_CHARACTER:
# Line 4550  for (;; ptr++) Line 4550  for (;; ptr++)
4550    
4551          if (negate_class)          if (negate_class)
4552            {            {
4553  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4554            int d;            int d;
4555  #endif  #endif
4556            if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;            if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4557            zerofirstchar = firstchar;            zerofirstchar = firstchar;
4558            zerofirstcharflags = firstcharflags;            zerofirstcharflags = firstcharflags;
# Line 4560  for (;; ptr++) Line 4560  for (;; ptr++)
4560            /* For caseless UTF-8 mode when UCP support is available, check            /* For caseless UTF-8 mode when UCP support is available, check
4561            whether this character has more than one other case. If so, generate            whether this character has more than one other case. If so, generate
4562            a special OP_NOTPROP item instead of OP_NOTI. */            a special OP_NOTPROP item instead of OP_NOTI. */
4563    
4564  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4565            if (utf && (options & PCRE_CASELESS) != 0 &&            if (utf && (options & PCRE_CASELESS) != 0 &&
4566                (d = UCD_CASESET(c)) != 0)                (d = UCD_CASESET(c)) != 0)
4567              {              {
4568              *code++ = OP_NOTPROP;              *code++ = OP_NOTPROP;
4569              *code++ = PT_CLIST;              *code++ = PT_CLIST;
4570              *code++ = d;              *code++ = d;
4571              }              }
4572            else            else
4573  #endif  #endif
4574            /* Char has only one other case, or UCP not available */            /* Char has only one other case, or UCP not available */
4575    
# Line 4582  for (;; ptr++) Line 4582  for (;; ptr++)
4582  #endif  #endif
4583                *code++ = c;                *code++ = c;
4584              }              }
4585    
4586            /* We are finished with this character class */            /* We are finished with this character class */
4587    
4588            goto END_CLASS;            goto END_CLASS;
4589            }            }
4590    
# Line 4602  for (;; ptr++) Line 4602  for (;; ptr++)
4602            }            }
4603          goto ONE_CHAR;          goto ONE_CHAR;
4604          }       /* End of 1-char optimization */          }       /* End of 1-char optimization */
4605    
4606        /* There is more than one character in the class, or an XCLASS item        /* There is more than one character in the class, or an XCLASS item
4607        has been generated. Add this character to the class. */        has been generated. Add this character to the class. */
4608    
4609        class_has_8bitchar +=        class_has_8bitchar +=
4610          add_to_class(classbits, &class_uchardata, options, cd, c, c);          add_to_class(classbits, &class_uchardata, options, cd, c, c);
4611        }        }
4612    
# Line 4627  for (;; ptr++) Line 4627  for (;; ptr++)
4627        goto FAILED;        goto FAILED;
4628        }        }
4629    
4630      /* We will need an XCLASS if data has been placed in class_uchardata. In      /* We will need an XCLASS if data has been placed in class_uchardata. In
4631      the second phase this is a sufficient test. However, in the pre-compile      the second phase this is a sufficient test. However, in the pre-compile
4632      phase, class_uchardata gets emptied to prevent workspace overflow, so it      phase, class_uchardata gets emptied to prevent workspace overflow, so it
4633      only if the very last character in the class needs XCLASS will it contain      only if the very last character in the class needs XCLASS will it contain
4634      anything at this point. For this reason, xclass gets set TRUE above when      anything at this point. For this reason, xclass gets set TRUE above when
4635      uchar_classdata is emptied, and that's why this code is the way it is here      uchar_classdata is emptied, and that's why this code is the way it is here
4636      instead of just doing a test on class_uchardata below. */      instead of just doing a test on class_uchardata below. */
4637    
4638  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4639      if (class_uchardata > class_uchardata_base) xclass = TRUE;      if (class_uchardata > class_uchardata_base) xclass = TRUE;
4640  #endif  #endif
# Line 4703  for (;; ptr++) Line 4703  for (;; ptr++)
4703        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4704        }        }
4705      code += 32 / sizeof(pcre_uchar);      code += 32 / sizeof(pcre_uchar);
4706    
4707      END_CLASS:      END_CLASS:
4708      break;      break;
4709    
# Line 6703  for (;; ptr++) Line 6703  for (;; ptr++)
6703        /* If the subpattern set a required byte (or set a first byte that isn't        /* If the subpattern set a required byte (or set a first byte that isn't
6704        really the first byte - see above), set it. */        really the first byte - see above), set it. */
6705    
6706        if (subreqcharflags >= 0)        if (subreqcharflags >= 0)
6707          {          {
6708          reqchar = subreqchar;          reqchar = subreqchar;
6709          reqcharflags = subreqcharflags;          reqcharflags = subreqcharflags;
# Line 6969  for (;; ptr++) Line 6969  for (;; ptr++)
6969    
6970      ONE_CHAR:      ONE_CHAR:
6971      previous = code;      previous = code;
6972    
6973      /* For caseless UTF-8 mode when UCP support is available, check whether      /* For caseless UTF-8 mode when UCP support is available, check whether
6974      this character has more than one other case. If so, generate a special      this character has more than one other case. If so, generate a special
6975      OP_PROP item instead of OP_CHARI. */      OP_PROP item instead of OP_CHARI. */
6976    
6977  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6978      if (utf && (options & PCRE_CASELESS) != 0)      if (utf && (options & PCRE_CASELESS) != 0)
6979        {        {
# Line 6983  for (;; ptr++) Line 6983  for (;; ptr++)
6983          *code++ = OP_PROP;          *code++ = OP_PROP;
6984          *code++ = PT_CLIST;          *code++ = PT_CLIST;
6985          *code++ = c;          *code++ = c;
6986          if (firstcharflags == REQ_UNSET) firstcharflags = zerofirstcharflags = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = zerofirstcharflags = REQ_NONE;
6987          break;          break;
6988          }          }
6989        }        }
6990  #endif  #endif
6991    
6992      /* Caseful matches, or not one of the multicase characters. */      /* Caseful matches, or not one of the multicase characters. */
6993    
6994      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;
6995      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];
6996    
# Line 7180  for (;;) Line 7180  for (;;)
7180    into the length. */    into the length. */
7181    
7182    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,
7183          &branchfirstcharflags, &branchreqchar, &branchreqcharflags, &bc,          &branchfirstcharflags, &branchreqchar, &branchreqcharflags, &bc,
7184          cond_depth, cd, (lengthptr == NULL)? NULL : &length))          cond_depth, cd, (lengthptr == NULL)? NULL : &length))
7185      {      {
7186      *ptrptr = ptr;      *ptrptr = ptr;
# Line 7218  for (;;) Line 7218  for (;;)
7218        we have to abandon the firstchar for the regex, but if there was        we have to abandon the firstchar for the regex, but if there was
7219        previously no reqchar, it takes on the value of the old firstchar. */        previously no reqchar, it takes on the value of the old firstchar. */
7220    
7221        if (firstcharflags >= 0 &&        if (firstcharflags >= 0 &&
7222            (firstcharflags != branchfirstcharflags || firstchar != branchfirstchar))            (firstcharflags != branchfirstcharflags || firstchar != branchfirstchar))
7223          {          {
7224          if (reqcharflags < 0)          if (reqcharflags < 0)
7225            {            {
7226            reqchar = firstchar;            reqchar = firstchar;
7227            reqcharflags = firstcharflags;            reqcharflags = firstcharflags;
# Line 7580  do { Line 7580  do {
7580       {       {
7581       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7582       }       }
7583    
7584     /* Atomic brackets */     /* Atomic brackets */
7585    
7586     else if (op == OP_ONCE || op == OP_ONCE_NC)     else if (op == OP_ONCE || op == OP_ONCE_NC)
# Line 7848  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7848  while (ptr[skipatstart] == CHAR_LEFT_PAR
7848    {    {
7849    int newnl = 0;    int newnl = 0;
7850    int newbsr = 0;    int newbsr = 0;
7851    
7852  /* For completeness and backward compatibility, (*UTFn) is supported in the  /* For completeness and backward compatibility, (*UTFn) is supported in the
7853  relevant libraries, but (*UTF) is generic and always supported. Note that  relevant libraries, but (*UTF) is generic and always supported. Note that
7854  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. */  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. */
7855    
7856  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
7857    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)
# Line 7867  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. * Line 7867  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. *
7867  #endif  #endif
7868    
7869    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 4) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 4) == 0)
7870      { skipatstart += 6; options |= PCRE_UTF8; continue; }      { skipatstart += 6; options |= PCRE_UTF8; continue; }
7871    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)
7872      { skipatstart += 6; options |= PCRE_UCP; continue; }      { skipatstart += 6; options |= PCRE_UCP; continue; }
7873    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)
# Line 8139  if (code - codestart > length) errorcode Line 8139  if (code - codestart > length) errorcode
8139    
8140  #ifdef SUPPORT_VALGRIND  #ifdef SUPPORT_VALGRIND
8141  /* If the estimated length exceeds the really used length, mark the extra  /* If the estimated length exceeds the really used length, mark the extra
8142  allocated memory as unadressable, so that any out-of-bound reads can be  allocated memory as unadressable, so that any out-of-bound reads can be
8143  detected. */  detected. */
8144  VALGRIND_MAKE_MEM_NOACCESS(code, (length - (code - codestart)) * sizeof(pcre_uchar));  VALGRIND_MAKE_MEM_NOACCESS(code, (length - (code - codestart)) * sizeof(pcre_uchar));
8145  #endif  #endif

Legend:
Removed from v.1219  
changed lines
  Added in v.1221

  ViewVC Help
Powered by ViewVC 1.1.5