/[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 1055 by chpe, Tue Oct 16 15:53:30 2012 UTC revision 1063 by chpe, Tue Oct 16 15:54:09 2012 UTC
# Line 749  return (*p == CHAR_RIGHT_CURLY_BRACKET); Line 749  return (*p == CHAR_RIGHT_CURLY_BRACKET);
749  *************************************************/  *************************************************/
750    
751  /* This function is called when a \ has been encountered. It either returns a  /* This function is called when a \ has been encountered. It either returns a
752  positive value for a simple escape such as \n, or a negative value which  positive value for a simple escape such as \n, or 0 for a data character
753  encodes one of the more complicated things such as \d. A backreference to group  which will be placed in chptr. A backreference to group n is returned as
754  n is returned as -(ESC_REF + n); ESC_REF is the highest ESC_xxx macro. When  negative n. When UTF-8 is enabled, a positive value greater than 255 may
755  UTF-8 is enabled, a positive value greater than 255 may be returned. On entry,  be returned in chptr.
756  ptr is pointing at the \. On exit, it is on the final character of the escape  On entry,ptr is pointing at the \. On exit, it is on the final character of the
757  sequence.  escape sequence.
758    
759  Arguments:  Arguments:
760    ptrptr         points to the pattern position pointer    ptrptr         points to the pattern position pointer
761      chptr          points to the data character
762    errorcodeptr   points to the errorcode variable    errorcodeptr   points to the errorcode variable
763    bracount       number of previous extracting brackets    bracount       number of previous extracting brackets
764    options        the options bits    options        the options bits
765    isclass        TRUE if inside a character class    isclass        TRUE if inside a character class
766    
767  Returns:         zero or positive => a data character  Returns:         zero => a data character
768                   negative => a special escape sequence                   positive => a special escape sequence
769                     negative => a back reference
770                   on error, errorcodeptr is set                   on error, errorcodeptr is set
771  */  */
772    
773  static int  static int
774  check_escape(const pcre_uchar **ptrptr, int *errorcodeptr, int bracount,  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,
775    int options, BOOL isclass)    int bracount, int options, BOOL isclass)
776  {  {
777  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
778  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
779  const pcre_uchar *ptr = *ptrptr + 1;  const pcre_uchar *ptr = *ptrptr + 1;
780  pcre_int32 c;  pcre_uint32 c;
781    int escape = 0;
782  int i;  int i;
783    
784  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */
# Line 792  Otherwise further processing may be requ Line 795  Otherwise further processing may be requ
795  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
796  /* Not alphanumeric */  /* Not alphanumeric */
797  else if (c < CHAR_0 || c > CHAR_z) {}  else if (c < CHAR_0 || c > CHAR_z) {}
798  else if ((i = escapes[c - CHAR_0]) != 0) c = i;  else if ((i = escapes[c - CHAR_0]) != 0) { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
799    
800  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
801  /* Not alphanumeric */  /* Not alphanumeric */
802  else if (c < CHAR_a || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}  else if (c < CHAR_a || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}
803  else if ((i = escapes[c - 0x48]) != 0)  c = i;  else if ((i = escapes[c - 0x48]) != 0)  { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
804  #endif  #endif
805    
806  /* Escapes that need further processing, or are illegal. */  /* Escapes that need further processing, or are illegal. */
# Line 805  else if ((i = escapes[c - 0x48]) != 0) Line 808  else if ((i = escapes[c - 0x48]) != 0)
808  else  else
809    {    {
810    const pcre_uchar *oldptr;    const pcre_uchar *oldptr;
811    BOOL braced, negated;    BOOL braced, negated, overflow;
812      int s;
813    
814    switch (c)    switch (c)
815      {      {
# Line 830  else Line 834  else
834          c = 0;          c = 0;
835          for (i = 0; i < 4; ++i)          for (i = 0; i < 4; ++i)
836            {            {
837            register int cc = *(++ptr);            register pcre_uint32 cc = *(++ptr);
838  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
839            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
840            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 877  else Line 881  else
881      (3) For Oniguruma compatibility we also support \g followed by a name or a      (3) For Oniguruma compatibility we also support \g followed by a name or a
882      number either in angle brackets or in single quotes. However, these are      number either in angle brackets or in single quotes. However, these are
883      (possibly recursive) subroutine calls, _not_ backreferences. Just return      (possibly recursive) subroutine calls, _not_ backreferences. Just return
884      the -ESC_g code (cf \k). */      the ESC_g code (cf \k). */
885    
886      case CHAR_g:      case CHAR_g:
887      if (isclass) break;      if (isclass) break;
888      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)
889        {        {
890        c = -ESC_g;        escape = ESC_g;
891        break;        break;
892        }        }
893    
# Line 896  else Line 900  else
900          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;
901        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)
902          {          {
903          c = -ESC_k;          escape = ESC_k;
904          break;          break;
905          }          }
906        braced = TRUE;        braced = TRUE;
# Line 912  else Line 916  else
916      else negated = FALSE;      else negated = FALSE;
917    
918      /* The integer range is limited by the machine's int representation. */      /* The integer range is limited by the machine's int representation. */
919      c = 0;      s = 0;
920        overflow = FALSE;
921      while (IS_DIGIT(ptr[1]))      while (IS_DIGIT(ptr[1]))
922        {        {
923        if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */        if (s > INT_MAX / 10 - 1) /* Integer overflow */
924          {          {
925          c = -1;          overflow = TRUE;
926          break;          break;
927          }          }
928        c = c * 10 + *(++ptr) - CHAR_0;        s = s * 10 + (int)(*(++ptr) - CHAR_0);
929        }        }
930      if (((unsigned int)c) > INT_MAX) /* Integer overflow */      if (overflow) /* Integer overflow */
931        {        {
932        while (IS_DIGIT(ptr[1]))        while (IS_DIGIT(ptr[1]))
933          ptr++;          ptr++;
# Line 936  else Line 941  else
941        break;        break;
942        }        }
943    
944      if (c == 0)      if (s == 0)
945        {        {
946        *errorcodeptr = ERR58;        *errorcodeptr = ERR58;
947        break;        break;
# Line 944  else Line 949  else
949    
950      if (negated)      if (negated)
951        {        {
952        if (c > bracount)        if (s > bracount)
953          {          {
954          *errorcodeptr = ERR15;          *errorcodeptr = ERR15;
955          break;          break;
956          }          }
957        c = bracount - (c - 1);        s = bracount - (s - 1);
958        }        }
959    
960      c = -(ESC_REF + c);      escape = -s;
961      break;      break;
962    
963      /* The handling of escape sequences consisting of a string of digits      /* The handling of escape sequences consisting of a string of digits
# Line 974  else Line 979  else
979        {        {
980        oldptr = ptr;        oldptr = ptr;
981        /* The integer range is limited by the machine's int representation. */        /* The integer range is limited by the machine's int representation. */
982        c -= CHAR_0;        s = (int)(c -CHAR_0);
983          overflow = FALSE;
984        while (IS_DIGIT(ptr[1]))        while (IS_DIGIT(ptr[1]))
985          {          {
986          if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */          if (s > INT_MAX / 10 - 1) /* Integer overflow */
987            {            {
988            c = -1;            overflow = TRUE;
989            break;            break;
990            }            }
991          c = c * 10 + *(++ptr) - CHAR_0;          s = s * 10 + (int)(*(++ptr) - CHAR_0);
992          }          }
993        if (((unsigned int)c) > INT_MAX) /* Integer overflow */        if (overflow) /* Integer overflow */
994          {          {
995          while (IS_DIGIT(ptr[1]))          while (IS_DIGIT(ptr[1]))
996            ptr++;            ptr++;
997          *errorcodeptr = ERR61;          *errorcodeptr = ERR61;
998          break;          break;
999          }          }
1000        if (c < 10 || c <= bracount)        if (s < 10 || s <= bracount)
1001          {          {
1002          c = -(ESC_REF + c);          escape = -s;
1003          break;          break;
1004          }          }
1005        ptr = oldptr;      /* Put the pointer back and fall through */        ptr = oldptr;      /* Put the pointer back and fall through */
# Line 1040  else Line 1046  else
1046          c = 0;          c = 0;
1047          for (i = 0; i < 2; ++i)          for (i = 0; i < 2; ++i)
1048            {            {
1049            register int cc = *(++ptr);            register pcre_uint32 cc = *(++ptr);
1050  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1051            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
1052            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 1058  else Line 1064  else
1064        const pcre_uchar *pt = ptr + 2;        const pcre_uchar *pt = ptr + 2;
1065    
1066        c = 0;        c = 0;
1067          overflow = FALSE;
1068        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)
1069          {          {
1070          register int cc = *pt++;          register pcre_uint32 cc = *pt++;
1071          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */
1072    
1073    #ifdef COMPILE_PCRE32
1074            if (c >= 0x10000000l) { overflow = TRUE; break; }
1075    #endif
1076    
1077  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1078          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
1079          c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));          c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 1072  else Line 1083  else
1083  #endif  #endif
1084    
1085  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
1086          if (c > (utf ? 0x10ffff : 0xff)) { c = -1; break; }          if (c > (utf ? 0x10ffff : 0xff)) { overflow = TRUE; break; }
1087  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
1088          if (c > (utf ? 0x10ffff : 0xffff)) { c = -1; break; }          if (c > (utf ? 0x10ffff : 0xffff)) { overflow = TRUE; break; }
1089  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
1090          if (utf && c > 0x10ffff) { c = -1; break; }          if (utf && c > 0x10ffff) { overflow = TRUE; break; }
1091  #endif  #endif
1092          }          }
1093    
1094        if (c < 0)        if (overflow)
1095          {          {
1096          while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;          while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;
1097          *errorcodeptr = ERR34;          *errorcodeptr = ERR34;
# Line 1102  else Line 1113  else
1113      c = 0;      c = 0;
1114      while (i++ < 2 && MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0)      while (i++ < 2 && MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0)
1115        {        {
1116        int cc;                                  /* Some compilers don't like */        pcre_uint32 cc;                          /* Some compilers don't like */
1117        cc = *(++ptr);                           /* ++ in initializers */        cc = *(++ptr);                           /* ++ in initializers */
1118  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1119        if (cc >= CHAR_a) cc -= 32;              /* Convert to upper case */        if (cc >= CHAR_a) cc -= 32;              /* Convert to upper case */
# Line 1161  else Line 1172  else
1172  newline". PCRE does not support \N{name}. However, it does support  newline". PCRE does not support \N{name}. However, it does support
1173  quantification such as \N{2,3}. */  quantification such as \N{2,3}. */
1174    
1175  if (c == -ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&  if (escape == ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&
1176       !is_counted_repeat(ptr+2))       !is_counted_repeat(ptr+2))
1177    *errorcodeptr = ERR37;    *errorcodeptr = ERR37;
1178    
1179  /* If PCRE_UCP is set, we change the values for \d etc. */  /* If PCRE_UCP is set, we change the values for \d etc. */
1180    
1181  if ((options & PCRE_UCP) != 0 && c <= -ESC_D && c >= -ESC_w)  if ((options & PCRE_UCP) != 0 && escape >= ESC_D && escape <= ESC_w)
1182    c -= (ESC_DU - ESC_D);    escape += (ESC_DU - ESC_D);
1183    
1184  /* Set the pointer to the final character before returning. */  /* Set the pointer to the final character before returning. */
1185    
1186  *ptrptr = ptr;  *ptrptr = ptr;
1187  return c;  *chptr = c;
1188    return escape;
1189  }  }
1190    
   
   
1191  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1192  /*************************************************  /*************************************************
1193  *               Handle \P and \p                 *  *               Handle \P and \p                 *
# Line 2952  Returns:       TRUE if auto-possessifyin Line 2962  Returns:       TRUE if auto-possessifyin
2962  */  */
2963    
2964  static BOOL  static BOOL
2965  check_char_prop(int c, int ptype, int pdata, BOOL negated)  check_char_prop(pcre_uint32 c, int ptype, int pdata, BOOL negated)
2966  {  {
2967  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2968  const pcre_uint32 *p;  const pcre_uint32 *p;
# Line 3038  static BOOL Line 3048  static BOOL
3048  check_auto_possessive(const pcre_uchar *previous, BOOL utf,  check_auto_possessive(const pcre_uchar *previous, BOOL utf,
3049    const pcre_uchar *ptr, int options, compile_data *cd)    const pcre_uchar *ptr, int options, compile_data *cd)
3050  {  {
3051  pcre_int32 c = NOTACHAR;  pcre_uint32 c = NOTACHAR;
3052  pcre_int32 next;  pcre_uint32 next;
3053    int escape;
3054  int op_code = *previous++;  int op_code = *previous++;
3055    
3056  /* Skip whitespace and comments in extended mode */  /* Skip whitespace and comments in extended mode */
# Line 3071  value is a character, a negative value i Line 3082  value is a character, a negative value i
3082  if (*ptr == CHAR_BACKSLASH)  if (*ptr == CHAR_BACKSLASH)
3083    {    {
3084    int temperrorcode = 0;    int temperrorcode = 0;
3085    next = check_escape(&ptr, &temperrorcode, cd->bracount, options, FALSE);    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options, FALSE);
3086    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
3087    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
3088    }    }
3089  else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)  else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)
3090    {    {
3091      escape = 0;
3092  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3093    if (utf) { GETCHARINC(next, ptr); } else    if (utf) { GETCHARINC(next, ptr); } else
3094  #endif  #endif
# Line 3117  if (*ptr == CHAR_ASTERISK || *ptr == CHA Line 3129  if (*ptr == CHAR_ASTERISK || *ptr == CHA
3129    
3130  if (op_code == OP_CHAR || op_code == OP_CHARI ||  if (op_code == OP_CHAR || op_code == OP_CHARI ||
3131      op_code == OP_NOT || op_code == OP_NOTI)      op_code == OP_NOT || op_code == OP_NOTI)
3132      //if (escape == 0) switch(op_code)
3133    {    {
3134  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3135    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
# Line 3128  if (op_code == OP_CHAR || op_code == OP_ Line 3141  if (op_code == OP_CHAR || op_code == OP_
3141  /* Now compare the next item with the previous opcode. First, handle cases when  /* Now compare the next item with the previous opcode. First, handle cases when
3142  the next item is a character. */  the next item is a character. */
3143    
3144  if (next >= 0)  if (escape == 0)
3145    {    {
3146    /* 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
3147    case, which maps to the special PT_CLIST property. Check this first. */    case, which maps to the special PT_CLIST property. Check this first. */
3148    
3149  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3150    if (utf && (unsigned int)c != NOTACHAR && (options & PCRE_CASELESS) != 0)    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)
3151      {      {
3152      int ocs = UCD_CASESET(next);      int ocs = UCD_CASESET(next);
3153      if (ocs > 0) return check_char_prop(c, PT_CLIST, ocs, op_code >= OP_NOT);      if (ocs > 0) return check_char_prop(c, PT_CLIST, ocs, op_code >= OP_NOT);
# Line 3156  if (next >= 0) Line 3169  if (next >= 0)
3169  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3170      if (utf)      if (utf)
3171        {        {
3172        unsigned int othercase;        pcre_uint32 othercase;
3173        if (next < 128) othercase = cd->fcc[next]; else        if (next < 128) othercase = cd->fcc[next]; else
3174  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3175        othercase = UCD_OTHERCASE((unsigned int)next);        othercase = UCD_OTHERCASE(next);
3176  #else  #else
3177        othercase = NOTACHAR;        othercase = NOTACHAR;
3178  #endif  #endif
3179        return (unsigned int)c != othercase;        return c != othercase;
3180        }        }
3181      else      else
3182  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3183      return (c != TABLE_GET((unsigned int)next, cd->fcc, next));  /* Not UTF */      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3184    
3185      case OP_NOT:      case OP_NOT:
3186      return c == next;      return c == next;
# Line 3177  if (next >= 0) Line 3190  if (next >= 0)
3190  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3191      if (utf)      if (utf)
3192        {        {
3193        unsigned int othercase;        pcre_uint32 othercase;
3194        if (next < 128) othercase = cd->fcc[next]; else        if (next < 128) othercase = cd->fcc[next]; else
3195  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3196        othercase = UCD_OTHERCASE((unsigned int)next);        othercase = UCD_OTHERCASE(next);
3197  #else  #else
3198        othercase = NOTACHAR;        othercase = NOTACHAR;
3199  #endif  #endif
3200        return (unsigned int)c == othercase;        return c == othercase;
3201        }        }
3202      else      else
3203  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3204      return (c == TABLE_GET((unsigned int)next, cd->fcc, next));  /* Not UTF */      return (c == TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3205    
3206      /* 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.
3207      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. */
# Line 3257  switch(op_code) Line 3270  switch(op_code)
3270    {    {
3271    case OP_CHAR:    case OP_CHAR:
3272    case OP_CHARI:    case OP_CHARI:
3273    switch(-next)    switch(escape)
3274      {      {
3275      case ESC_d:      case ESC_d:
3276      return c > 255 || (cd->ctypes[c] & ctype_digit) == 0;      return c > 255 || (cd->ctypes[c] & ctype_digit) == 0;
# Line 3282  switch(op_code) Line 3295  switch(op_code)
3295      switch(c)      switch(c)
3296        {        {
3297        HSPACE_CASES:        HSPACE_CASES:
3298        return -next != ESC_h;        return escape != ESC_h;
3299    
3300        default:        default:
3301        return -next == ESC_h;        return escape == ESC_h;
3302        }        }
3303    
3304      case ESC_v:      case ESC_v:
# Line 3293  switch(op_code) Line 3306  switch(op_code)
3306      switch(c)      switch(c)
3307        {        {
3308        VSPACE_CASES:        VSPACE_CASES:
3309        return -next != ESC_v;        return escape != ESC_v;
3310    
3311        default:        default:
3312        return -next == ESC_v;        return escape == ESC_v;
3313        }        }
3314    
3315      /* When PCRE_UCP is set, these values get generated for \d etc. Find      /* When PCRE_UCP is set, these values get generated for \d etc. Find
3316      their substitutions and process them. The result will always be either      their substitutions and process them. The result will always be either
3317      -ESC_p or -ESC_P. Then fall through to process those values. */      ESC_p or ESC_P. Then fall through to process those values. */
3318    
3319  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3320      case ESC_du:      case ESC_du:
# Line 3312  switch(op_code) Line 3325  switch(op_code)
3325      case ESC_SU:      case ESC_SU:
3326        {        {
3327        int temperrorcode = 0;        int temperrorcode = 0;
3328        ptr = substitutes[-next - ESC_DU];        ptr = substitutes[escape - ESC_DU];
3329        next = check_escape(&ptr, &temperrorcode, 0, options, FALSE);        escape = check_escape(&ptr, &next, &temperrorcode, 0, options, FALSE);
3330        if (temperrorcode != 0) return FALSE;        if (temperrorcode != 0) return FALSE;
3331        ptr++;    /* For compatibility */        ptr++;    /* For compatibility */
3332        }        }
# Line 3340  switch(op_code) Line 3353  switch(op_code)
3353    
3354        /* Do the property check. */        /* Do the property check. */
3355    
3356        return check_char_prop(c, ptype, pdata, (next == -ESC_P) != negated);        return check_char_prop(c, ptype, pdata, (escape == ESC_P) != negated);
3357        }        }
3358  #endif  #endif
3359    
# Line 3355  switch(op_code) Line 3368  switch(op_code)
3368    these op-codes are never generated.) */    these op-codes are never generated.) */
3369    
3370    case OP_DIGIT:    case OP_DIGIT:
3371    return next == -ESC_D || next == -ESC_s || next == -ESC_W ||    return escape == ESC_D || escape == ESC_s || escape == ESC_W ||
3372           next == -ESC_h || next == -ESC_v || next == -ESC_R;           escape == ESC_h || escape == ESC_v || escape == ESC_R;
3373    
3374    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
3375    return next == -ESC_d;    return escape == ESC_d;
3376    
3377    case OP_WHITESPACE:    case OP_WHITESPACE:
3378    return next == -ESC_S || next == -ESC_d || next == -ESC_w;    return escape == ESC_S || escape == ESC_d || escape == ESC_w;
3379    
3380    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
3381    return next == -ESC_s || next == -ESC_h || next == -ESC_v || next == -ESC_R;    return escape == ESC_s || escape == ESC_h || escape == ESC_v || escape == ESC_R;
3382    
3383    case OP_HSPACE:    case OP_HSPACE:
3384    return next == -ESC_S || next == -ESC_H || next == -ESC_d ||    return escape == ESC_S || escape == ESC_H || escape == ESC_d ||
3385           next == -ESC_w || next == -ESC_v || next == -ESC_R;           escape == ESC_w || escape == ESC_v || escape == ESC_R;
3386    
3387    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
3388    return next == -ESC_h;    return escape == ESC_h;
3389    
3390    /* Can't have \S in here because VT matches \S (Perl anomaly) */    /* Can't have \S in here because VT matches \S (Perl anomaly) */
3391    case OP_ANYNL:    case OP_ANYNL:
3392    case OP_VSPACE:    case OP_VSPACE:
3393    return next == -ESC_V || next == -ESC_d || next == -ESC_w;    return escape == ESC_V || escape == ESC_d || escape == ESC_w;
3394    
3395    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
3396    return next == -ESC_v || next == -ESC_R;    return escape == ESC_v || escape == ESC_R;
3397    
3398    case OP_WORDCHAR:    case OP_WORDCHAR:
3399    return next == -ESC_W || next == -ESC_s || next == -ESC_h ||    return escape == ESC_W || escape == ESC_s || escape == ESC_h ||
3400           next == -ESC_v || next == -ESC_R;           escape == ESC_v || escape == ESC_R;
3401    
3402    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
3403    return next == -ESC_w || next == -ESC_d;    return escape == ESC_w || escape == ESC_d;
3404    
3405    default:    default:
3406    return FALSE;    return FALSE;
# Line 3421  Returns:        the number of < 256 char Line 3434  Returns:        the number of < 256 char
3434    
3435  static int  static int
3436  add_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,  add_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,
3437    compile_data *cd, unsigned int start, unsigned int end)    compile_data *cd, pcre_uint32 start, pcre_uint32 end)
3438  {  {
3439  unsigned int c;  pcre_uint32 c;
3440  int n8 = 0;  int n8 = 0;
3441    
3442  /* If caseless matching is required, scan the range and process alternate  /* If caseless matching is required, scan the range and process alternate
# Line 3437  if ((options & PCRE_CASELESS) != 0) Line 3450  if ((options & PCRE_CASELESS) != 0)
3450    if ((options & PCRE_UTF8) != 0)    if ((options & PCRE_UTF8) != 0)
3451      {      {
3452      int rc;      int rc;
3453      unsigned int oc, od;      pcre_uint32 oc, od;
3454    
3455      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */
3456      c = start;      c = start;
# Line 3490  in all cases. */ Line 3503  in all cases. */
3503  #endif  #endif
3504    if (end > 0xffff) end = 0xffff;    if (end > 0xffff) end = 0xffff;
3505    
3506  #elif defined COMPILE_PCRE32  #endif /* COMPILE_PCRE[8|16] */
 #ifdef SUPPORT_UTF  
   if ((options & PCRE_UTF32) == 0)  
     if (end > 0xffffu) end = 0xffffu; // FIXMEchpe rebase fix this  
 #endif  
 #endif /* COMPILE_PCRE[8|16|32] */  
3507    
3508  /* If all characters are less than 256, use the bit map. Otherwise use extra  /* If all characters are less than 256, use the bit map. Otherwise use extra
3509  data. */  data. */
# Line 3625  static int Line 3633  static int
3633  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,
3634    int options, compile_data *cd, const pcre_uint32 *p)    int options, compile_data *cd, const pcre_uint32 *p)
3635  {  {
3636    BOOL utf = (options & PCRE_UTF8) != 0;
3637  int n8 = 0;  int n8 = 0;
3638  if (p[0] > 0)  if (p[0] > 0)
3639    n8 += add_to_class(classbits, uchardptr, options, cd, 0, p[0] - 1);    n8 += add_to_class(classbits, uchardptr, options, cd, 0, p[0] - 1);
3640  while (p[0] < NOTACHAR)  while (p[0] < NOTACHAR)
3641    {    {
3642    while (p[1] == p[0] + 1) p++;    while (p[1] == p[0] + 1) p++;
3643    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,
3644      (p[1] == NOTACHAR)? 0x10ffff : p[1] - 1);      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);
3645    p++;    p++;
3646    }    }
3647  return n8;  return n8;
# Line 3684  int options = *optionsptr; Line 3693  int options = *optionsptr;
3693  int after_manual_callout = 0;  int after_manual_callout = 0;
3694  int length_prevgroup = 0;  int length_prevgroup = 0;
3695  register int c;  register int c;
3696    int escape;
3697  register pcre_uchar *code = *codeptr;  register pcre_uchar *code = *codeptr;
3698  pcre_uchar *last_code = code;  pcre_uchar *last_code = code;
3699  pcre_uchar *orig_code = code;  pcre_uchar *orig_code = code;
# Line 3703  must not do this for other options (e.g. Line 3713  must not do this for other options (e.g.
3713  dynamically as we process the pattern. */  dynamically as we process the pattern. */
3714    
3715  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3716  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */  /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */
3717  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
3718  pcre_uchar utf_chars[6];  pcre_uchar utf_chars[6];
3719  #else  #else
# Line 3771  for (;; ptr++) Line 3781  for (;; ptr++)
3781    int terminator;    int terminator;
3782    int mclength;    int mclength;
3783    int tempbracount;    int tempbracount;
3784      int ec; // FIXMEchpe pcre_uint32
3785    pcre_uchar mcbuffer[8];    pcre_uchar mcbuffer[8];
3786    
3787    /* Get next character in the pattern */    /* Get next character in the pattern */
# Line 4240  for (;; ptr++) Line 4251  for (;; ptr++)
4251    
4252        if (c == CHAR_BACKSLASH)        if (c == CHAR_BACKSLASH)
4253          {          {
4254          c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, TRUE);
4255    
4256          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
4257    
4258          if (-c == ESC_b) c = CHAR_BS;    /* \b is backspace in a class */          if (escape == 0)
4259          else if (-c == ESC_N)            /* \N is not supported in a class */            c = ec;
4260            else if (escape == ESC_b) c = CHAR_BS; /* \b is backspace in a class */
4261            else if (escape == ESC_N)            /* \N is not supported in a class */
4262            {            {
4263            *errorcodeptr = ERR71;            *errorcodeptr = ERR71;
4264            goto FAILED;            goto FAILED;
4265            }            }
4266          else if (-c == ESC_Q)            /* Handle start of quoted string */          else if (escape == ESC_Q)            /* Handle start of quoted string */
4267            {            {
4268            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
4269              {              {
# Line 4258  for (;; ptr++) Line 4272  for (;; ptr++)
4272            else inescq = TRUE;            else inescq = TRUE;
4273            continue;            continue;
4274            }            }
4275          else if (-c == ESC_E) continue;  /* Ignore orphan \E */          else if (escape == ESC_E) continue;  /* Ignore orphan \E */
4276    
4277          if (c < 0)          else
4278            {            {
4279            register const pcre_uint8 *cbits = cd->cbits;            register const pcre_uint8 *cbits = cd->cbits;
4280            /* Every class contains at least two < 256 characters. */            /* Every class contains at least two < 256 characters. */
# Line 4268  for (;; ptr++) Line 4282  for (;; ptr++)
4282            /* Every class contains at least two characters. */            /* Every class contains at least two characters. */
4283            class_one_char += 2;            class_one_char += 2;
4284    
4285            switch (-c)            switch (escape)
4286              {              {
4287  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4288              case ESC_du:     /* These are the values given for \d etc */              case ESC_du:     /* These are the values given for \d etc */
# Line 4278  for (;; ptr++) Line 4292  for (;; ptr++)
4292              case ESC_su:     /* of the default ASCII testing. */              case ESC_su:     /* of the default ASCII testing. */
4293              case ESC_SU:              case ESC_SU:
4294              nestptr = ptr;              nestptr = ptr;
4295              ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */              ptr = substitutes[escape - ESC_DU] - 1;  /* Just before substitute */
4296              class_has_8bitchar--;                /* Undo! */              class_has_8bitchar--;                /* Undo! */
4297              continue;              continue;
4298  #endif  #endif
# Line 4347  for (;; ptr++) Line 4361  for (;; ptr++)
4361                int pdata;                int pdata;
4362                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
4363                if (ptype < 0) goto FAILED;                if (ptype < 0) goto FAILED;
4364                *class_uchardata++ = ((-c == ESC_p) != negated)?                *class_uchardata++ = ((escape == ESC_p) != negated)?
4365                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4366                *class_uchardata++ = ptype;                *class_uchardata++ = ptype;
4367                *class_uchardata++ = pdata;                *class_uchardata++ = pdata;
# Line 4375  for (;; ptr++) Line 4389  for (;; ptr++)
4389          /* Fall through if the escape just defined a single character (c >= 0).          /* Fall through if the escape just defined a single character (c >= 0).
4390          This may be greater than 256. */          This may be greater than 256. */
4391    
4392            escape = 0;
4393    
4394          }   /* End of backslash handling */          }   /* End of backslash handling */
4395    
4396        /* A character may be followed by '-' to form a range. However, Perl does        /* A character may be followed by '-' to form a range. However, Perl does
# Line 4440  for (;; ptr++) Line 4456  for (;; ptr++)
4456    
4457          if (!inescq && d == CHAR_BACKSLASH)          if (!inescq && d == CHAR_BACKSLASH)
4458            {            {
4459            d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);            int descape;
4460              descape = check_escape(&ptr, &d, errorcodeptr, cd->bracount, options, TRUE);
4461            if (*errorcodeptr != 0) goto FAILED;            if (*errorcodeptr != 0) goto FAILED;
4462    
4463            /* \b is backspace; any other special means the '-' was literal. */            /* \b is backspace; any other special means the '-' was literal. */
4464    
4465            if (d < 0)            if (descape != 0)
4466              {              {
4467              if (d == -ESC_b) d = CHAR_BS; else              if (descape == ESC_b) d = CHAR_BS; else
4468                {                {
4469                ptr = oldptr;                ptr = oldptr;
4470                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */
# Line 6659  for (;; ptr++) Line 6676  for (;; ptr++)
6676      /* Handle metasequences introduced by \. For ones like \d, the ESC_ values      /* Handle metasequences introduced by \. For ones like \d, the ESC_ values
6677      are arranged to be the negation of the corresponding OP_values in the      are arranged to be the negation of the corresponding OP_values in the
6678      default case when PCRE_UCP is not set. For the back references, the values      default case when PCRE_UCP is not set. For the back references, the values
6679      are ESC_REF plus the reference number. Only back references and those types      are negative the reference number. Only back references and those types
6680      that consume a character may be repeated. We can test for values between      that consume a character may be repeated. We can test for values between
6681      ESC_b and ESC_Z for the latter; this may have to change if any new ones are      ESC_b and ESC_Z for the latter; this may have to change if any new ones are
6682      ever created. */      ever created. */
6683    
6684      case CHAR_BACKSLASH:      case CHAR_BACKSLASH:
6685      tempptr = ptr;      tempptr = ptr;
6686      c = check_escape(&ptr, errorcodeptr, cd->bracount, options, FALSE);      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);
6687    
6688      if (*errorcodeptr != 0) goto FAILED;      if (*errorcodeptr != 0) goto FAILED;
6689    
6690      if (c < 0)      if (escape == 0)
6691          c = ec;
6692        else
6693        {        {
6694        if (-c == ESC_Q)            /* Handle start of quoted string */        if (escape == ESC_Q)            /* Handle start of quoted string */
6695          {          {
6696          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
6697            ptr += 2;               /* avoid empty string */            ptr += 2;               /* avoid empty string */
# Line 6679  for (;; ptr++) Line 6699  for (;; ptr++)
6699          continue;          continue;
6700          }          }
6701    
6702        if (-c == ESC_E) continue;  /* Perl ignores an orphan \E */        if (escape == ESC_E) continue;  /* Perl ignores an orphan \E */
6703    
6704        /* For metasequences that actually match a character, we disable the        /* For metasequences that actually match a character, we disable the
6705        setting of a first character if it hasn't already been set. */        setting of a first character if it hasn't already been set. */
6706    
6707        if (firstchar == REQ_UNSET && -c > ESC_b && -c < ESC_Z)        if (firstchar == REQ_UNSET && escape > ESC_b && escape < ESC_Z)
6708          firstchar = REQ_NONE;          firstchar = REQ_NONE;
6709    
6710        /* Set values to reset to if this is followed by a zero repeat. */        /* Set values to reset to if this is followed by a zero repeat. */
# Line 6694  for (;; ptr++) Line 6714  for (;; ptr++)
6714    
6715        /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'        /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'
6716        is a subroutine call by number (Oniguruma syntax). In fact, the value        is a subroutine call by number (Oniguruma syntax). In fact, the value
6717        -ESC_g is returned only for these cases. So we don't need to check for <        ESC_g is returned only for these cases. So we don't need to check for <
6718        or ' if the value is -ESC_g. For the Perl syntax \g{n} the value is        or ' if the value is ESC_g. For the Perl syntax \g{n} the value is
6719        -ESC_REF+n, and for the Perl syntax \g{name} the result is -ESC_k (as        -n, and for the Perl syntax \g{name} the result is ESC_k (as
6720        that is a synonym for a named back reference). */        that is a synonym for a named back reference). */
6721    
6722        if (-c == ESC_g)        if (escape == ESC_g)
6723          {          {
6724          const pcre_uchar *p;          const pcre_uchar *p;
6725          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */
# Line 6755  for (;; ptr++) Line 6775  for (;; ptr++)
6775        /* \k<name> or \k'name' is a back reference by name (Perl syntax).        /* \k<name> or \k'name' is a back reference by name (Perl syntax).
6776        We also support \k{name} (.NET syntax).  */        We also support \k{name} (.NET syntax).  */
6777    
6778        if (-c == ESC_k)        if (escape == ESC_k)
6779          {          {
6780          if ((ptr[1] != CHAR_LESS_THAN_SIGN &&          if ((ptr[1] != CHAR_LESS_THAN_SIGN &&
6781            ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))            ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))
# Line 6774  for (;; ptr++) Line 6794  for (;; ptr++)
6794        not set to cope with cases like (?=(\w+))\1: which would otherwise set        not set to cope with cases like (?=(\w+))\1: which would otherwise set
6795        ':' later. */        ':' later. */
6796    
6797        if (-c >= ESC_REF)        if (escape < 0)
6798          {          {
6799          open_capitem *oc;          open_capitem *oc;
6800          recno = -c - ESC_REF;          recno = -escape;
6801    
6802          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
6803          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
# Line 6804  for (;; ptr++) Line 6824  for (;; ptr++)
6824        /* So are Unicode property matches, if supported. */        /* So are Unicode property matches, if supported. */
6825    
6826  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6827        else if (-c == ESC_P || -c == ESC_p)        else if (escape == ESC_P || escape == ESC_p)
6828          {          {
6829          BOOL negated;          BOOL negated;
6830          int pdata;          int pdata;
6831          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
6832          if (ptype < 0) goto FAILED;          if (ptype < 0) goto FAILED;
6833          previous = code;          previous = code;
6834          *code++ = ((-c == ESC_p) != negated)? OP_PROP : OP_NOTPROP;          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;
6835          *code++ = ptype;          *code++ = ptype;
6836          *code++ = pdata;          *code++ = pdata;
6837          }          }
# Line 6820  for (;; ptr++) Line 6840  for (;; ptr++)
6840        /* If Unicode properties are not supported, \X, \P, and \p are not        /* If Unicode properties are not supported, \X, \P, and \p are not
6841        allowed. */        allowed. */
6842    
6843        else if (-c == ESC_X || -c == ESC_P || -c == ESC_p)        else if (escape == ESC_X || escape == ESC_P || escape == ESC_p)
6844          {          {
6845          *errorcodeptr = ERR45;          *errorcodeptr = ERR45;
6846          goto FAILED;          goto FAILED;
# Line 6835  for (;; ptr++) Line 6855  for (;; ptr++)
6855    
6856        else        else
6857          {          {
6858          if ((-c == ESC_b || -c == ESC_B) && cd->max_lookbehind == 0)          if ((escape == ESC_b || escape == ESC_B) && cd->max_lookbehind == 0)
6859            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6860  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6861          if (-c >= ESC_DU && -c <= ESC_wu)          if (escape >= ESC_DU && escape <= ESC_wu)
6862            {            {
6863            nestptr = ptr + 1;                   /* Where to resume */            nestptr = ptr + 1;                   /* Where to resume */
6864            ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */            ptr = substitutes[escape - ESC_DU] - 1;  /* Just before substitute */
6865            }            }
6866          else          else
6867  #endif  #endif
# Line 6849  for (;; ptr++) Line 6869  for (;; ptr++)
6869          so that it works in DFA mode and in lookbehinds. */          so that it works in DFA mode and in lookbehinds. */
6870    
6871            {            {
6872            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;            previous = (escape > ESC_b && escape < ESC_Z)? code : NULL;
6873            *code++ = (!utf && c == -ESC_C)? OP_ALLANY : -c;            *code++ = (!utf && escape == ESC_C)? OP_ALLANY : escape;
6874            }            }
6875          }          }
6876        continue;        continue;

Legend:
Removed from v.1055  
changed lines
  Added in v.1063

  ViewVC Help
Powered by ViewVC 1.1.5