/[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 1056 by chpe, Tue Oct 16 15:53:41 2012 UTC revision 1059 by chpe, Tue Oct 16 15:53:53 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
754  n is returned as -(ESC_REF + n); ESC_REF is the highest ESC_xxx macro. When  n is returned as ESC_REF + n; ESC_REF is the highest ESC_xxx macro. When
755  UTF-8 is enabled, a positive value greater than 255 may be returned. On entry,  UTF-8 is enabled, a positive value greater than 255 may 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                   on error, errorcodeptr is set                   on error, errorcodeptr is set
770  */  */
771    
772  static int  static int
773  check_escape(const pcre_uchar **ptrptr, int *errorcodeptr, int bracount,  check_escape(const pcre_uchar **ptrptr, int *chptr, int *errorcodeptr,
774    int options, BOOL isclass)    int bracount, int options, BOOL isclass)
775  {  {
776  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
777  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
778  const pcre_uchar *ptr = *ptrptr + 1;  const pcre_uchar *ptr = *ptrptr + 1;
779  pcre_int32 c;  pcre_int32 c;
780    int escape = 0;
781  int i;  int i;
782    
783  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 794  Otherwise further processing may be requ
794  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
795  /* Not alphanumeric */  /* Not alphanumeric */
796  else if (c < CHAR_0 || c > CHAR_z) {}  else if (c < CHAR_0 || c > CHAR_z) {}
797  else if ((i = escapes[c - CHAR_0]) != 0) c = i;  else if ((i = escapes[c - CHAR_0]) != 0) { if (i > 0) c = i; else escape = -i; }
798    
799  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
800  /* Not alphanumeric */  /* Not alphanumeric */
801  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)) {}
802  else if ((i = escapes[c - 0x48]) != 0)  c = i;  else if ((i = escapes[c - 0x48]) != 0)  { if (i > 0) c = i; else escape = -i; }
803  #endif  #endif
804    
805  /* Escapes that need further processing, or are illegal. */  /* Escapes that need further processing, or are illegal. */
# Line 877  else Line 879  else
879      (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
880      number either in angle brackets or in single quotes. However, these are      number either in angle brackets or in single quotes. However, these are
881      (possibly recursive) subroutine calls, _not_ backreferences. Just return      (possibly recursive) subroutine calls, _not_ backreferences. Just return
882      the -ESC_g code (cf \k). */      the ESC_g code (cf \k). */
883    
884      case CHAR_g:      case CHAR_g:
885      if (isclass) break;      if (isclass) break;
886      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)
887        {        {
888        c = -ESC_g;        escape = ESC_g;
889        break;        break;
890        }        }
891    
# Line 896  else Line 898  else
898          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;
899        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)
900          {          {
901          c = -ESC_k;          escape = ESC_k;
902          break;          break;
903          }          }
904        braced = TRUE;        braced = TRUE;
# Line 952  else Line 954  else
954        c = bracount - (c - 1);        c = bracount - (c - 1);
955        }        }
956    
957      c = -(ESC_REF + c);      escape = ESC_REF + c;
958      break;      break;
959    
960      /* The handling of escape sequences consisting of a string of digits      /* The handling of escape sequences consisting of a string of digits
# Line 993  else Line 995  else
995          }          }
996        if (c < 10 || c <= bracount)        if (c < 10 || c <= bracount)
997          {          {
998          c = -(ESC_REF + c);          escape = ESC_REF + c;
999          break;          break;
1000          }          }
1001        ptr = oldptr;      /* Put the pointer back and fall through */        ptr = oldptr;      /* Put the pointer back and fall through */
# Line 1161  else Line 1163  else
1163  newline". PCRE does not support \N{name}. However, it does support  newline". PCRE does not support \N{name}. However, it does support
1164  quantification such as \N{2,3}. */  quantification such as \N{2,3}. */
1165    
1166  if (c == -ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&  if (escape == ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&
1167       !is_counted_repeat(ptr+2))       !is_counted_repeat(ptr+2))
1168    *errorcodeptr = ERR37;    *errorcodeptr = ERR37;
1169    
1170  /* If PCRE_UCP is set, we change the values for \d etc. */  /* If PCRE_UCP is set, we change the values for \d etc. */
1171    
1172  if ((options & PCRE_UCP) != 0 && c <= -ESC_D && c >= -ESC_w)  if ((options & PCRE_UCP) != 0 && escape >= ESC_D && escape <= ESC_w)
1173    c -= (ESC_DU - ESC_D);    escape += (ESC_DU - ESC_D);
1174    
1175  /* Set the pointer to the final character before returning. */  /* Set the pointer to the final character before returning. */
1176    
1177  *ptrptr = ptr;  *ptrptr = ptr;
1178  return c;  *chptr = c;
1179    return escape;
1180  }  }
1181    
   
   
1182  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1183  /*************************************************  /*************************************************
1184  *               Handle \P and \p                 *  *               Handle \P and \p                 *
# Line 3038  static BOOL Line 3039  static BOOL
3039  check_auto_possessive(const pcre_uchar *previous, BOOL utf,  check_auto_possessive(const pcre_uchar *previous, BOOL utf,
3040    const pcre_uchar *ptr, int options, compile_data *cd)    const pcre_uchar *ptr, int options, compile_data *cd)
3041  {  {
3042  pcre_int32 c = NOTACHAR;  pcre_int32 c = NOTACHAR; // FIXMEchpe pcre_uint32
3043  pcre_int32 next;  pcre_int32 next;
3044    int escape;
3045  int op_code = *previous++;  int op_code = *previous++;
3046    
3047  /* 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 3073  value is a character, a negative value i
3073  if (*ptr == CHAR_BACKSLASH)  if (*ptr == CHAR_BACKSLASH)
3074    {    {
3075    int temperrorcode = 0;    int temperrorcode = 0;
3076    next = check_escape(&ptr, &temperrorcode, cd->bracount, options, FALSE);    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options, FALSE);
3077    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
3078    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
3079    }    }
3080  else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)  else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)
3081    {    {
3082      escape = 0;
3083  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3084    if (utf) { GETCHARINC(next, ptr); } else    if (utf) { GETCHARINC(next, ptr); } else
3085  #endif  #endif
# Line 3117  if (*ptr == CHAR_ASTERISK || *ptr == CHA Line 3120  if (*ptr == CHAR_ASTERISK || *ptr == CHA
3120    
3121  if (op_code == OP_CHAR || op_code == OP_CHARI ||  if (op_code == OP_CHAR || op_code == OP_CHARI ||
3122      op_code == OP_NOT || op_code == OP_NOTI)      op_code == OP_NOT || op_code == OP_NOTI)
3123      //if (escape == 0) switch(op_code)
3124    {    {
3125  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3126    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
# Line 3128  if (op_code == OP_CHAR || op_code == OP_ Line 3132  if (op_code == OP_CHAR || op_code == OP_
3132  /* 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
3133  the next item is a character. */  the next item is a character. */
3134    
3135  if (next >= 0)  if (escape == 0)
3136    {    {
3137    /* 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
3138    case, which maps to the special PT_CLIST property. Check this first. */    case, which maps to the special PT_CLIST property. Check this first. */
# Line 3257  switch(op_code) Line 3261  switch(op_code)
3261    {    {
3262    case OP_CHAR:    case OP_CHAR:
3263    case OP_CHARI:    case OP_CHARI:
3264    switch(-next)    switch(escape)
3265      {      {
3266      case ESC_d:      case ESC_d:
3267      return c > 255 || (cd->ctypes[c] & ctype_digit) == 0;      return c > 255 || (cd->ctypes[c] & ctype_digit) == 0;
# Line 3282  switch(op_code) Line 3286  switch(op_code)
3286      switch(c)      switch(c)
3287        {        {
3288        HSPACE_CASES:        HSPACE_CASES:
3289        return -next != ESC_h;        return escape != ESC_h;
3290    
3291        default:        default:
3292        return -next == ESC_h;        return escape == ESC_h;
3293        }        }
3294    
3295      case ESC_v:      case ESC_v:
# Line 3293  switch(op_code) Line 3297  switch(op_code)
3297      switch(c)      switch(c)
3298        {        {
3299        VSPACE_CASES:        VSPACE_CASES:
3300        return -next != ESC_v;        return escape != ESC_v;
3301    
3302        default:        default:
3303        return -next == ESC_v;        return escape == ESC_v;
3304        }        }
3305    
3306      /* 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
3307      their substitutions and process them. The result will always be either      their substitutions and process them. The result will always be either
3308      -ESC_p or -ESC_P. Then fall through to process those values. */      ESC_p or ESC_P. Then fall through to process those values. */
3309    
3310  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3311      case ESC_du:      case ESC_du:
# Line 3312  switch(op_code) Line 3316  switch(op_code)
3316      case ESC_SU:      case ESC_SU:
3317        {        {
3318        int temperrorcode = 0;        int temperrorcode = 0;
3319        ptr = substitutes[-next - ESC_DU];        ptr = substitutes[escape - ESC_DU];
3320        next = check_escape(&ptr, &temperrorcode, 0, options, FALSE);        escape = check_escape(&ptr, &next, &temperrorcode, 0, options, FALSE);
3321        if (temperrorcode != 0) return FALSE;        if (temperrorcode != 0) return FALSE;
3322        ptr++;    /* For compatibility */        ptr++;    /* For compatibility */
3323        }        }
# Line 3340  switch(op_code) Line 3344  switch(op_code)
3344    
3345        /* Do the property check. */        /* Do the property check. */
3346    
3347        return check_char_prop(c, ptype, pdata, (next == -ESC_P) != negated);        return check_char_prop(c, ptype, pdata, (escape == ESC_P) != negated);
3348        }        }
3349  #endif  #endif
3350    
# Line 3355  switch(op_code) Line 3359  switch(op_code)
3359    these op-codes are never generated.) */    these op-codes are never generated.) */
3360    
3361    case OP_DIGIT:    case OP_DIGIT:
3362    return next == -ESC_D || next == -ESC_s || next == -ESC_W ||    return escape == ESC_D || escape == ESC_s || escape == ESC_W ||
3363           next == -ESC_h || next == -ESC_v || next == -ESC_R;           escape == ESC_h || escape == ESC_v || escape == ESC_R;
3364    
3365    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
3366    return next == -ESC_d;    return escape == ESC_d;
3367    
3368    case OP_WHITESPACE:    case OP_WHITESPACE:
3369    return next == -ESC_S || next == -ESC_d || next == -ESC_w;    return escape == ESC_S || escape == ESC_d || escape == ESC_w;
3370    
3371    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
3372    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;
3373    
3374    case OP_HSPACE:    case OP_HSPACE:
3375    return next == -ESC_S || next == -ESC_H || next == -ESC_d ||    return escape == ESC_S || escape == ESC_H || escape == ESC_d ||
3376           next == -ESC_w || next == -ESC_v || next == -ESC_R;           escape == ESC_w || escape == ESC_v || escape == ESC_R;
3377    
3378    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
3379    return next == -ESC_h;    return escape == ESC_h;
3380    
3381    /* Can't have \S in here because VT matches \S (Perl anomaly) */    /* Can't have \S in here because VT matches \S (Perl anomaly) */
3382    case OP_ANYNL:    case OP_ANYNL:
3383    case OP_VSPACE:    case OP_VSPACE:
3384    return next == -ESC_V || next == -ESC_d || next == -ESC_w;    return escape == ESC_V || escape == ESC_d || escape == ESC_w;
3385    
3386    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
3387    return next == -ESC_v || next == -ESC_R;    return escape == ESC_v || escape == ESC_R;
3388    
3389    case OP_WORDCHAR:    case OP_WORDCHAR:
3390    return next == -ESC_W || next == -ESC_s || next == -ESC_h ||    return escape == ESC_W || escape == ESC_s || escape == ESC_h ||
3391           next == -ESC_v || next == -ESC_R;           escape == ESC_v || escape == ESC_R;
3392    
3393    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
3394    return next == -ESC_w || next == -ESC_d;    return escape == ESC_w || escape == ESC_d;
3395    
3396    default:    default:
3397    return FALSE;    return FALSE;
# Line 3680  int options = *optionsptr; Line 3684  int options = *optionsptr;
3684  int after_manual_callout = 0;  int after_manual_callout = 0;
3685  int length_prevgroup = 0;  int length_prevgroup = 0;
3686  register int c;  register int c;
3687    int escape;
3688  register pcre_uchar *code = *codeptr;  register pcre_uchar *code = *codeptr;
3689  pcre_uchar *last_code = code;  pcre_uchar *last_code = code;
3690  pcre_uchar *orig_code = code;  pcre_uchar *orig_code = code;
# Line 3699  must not do this for other options (e.g. Line 3704  must not do this for other options (e.g.
3704  dynamically as we process the pattern. */  dynamically as we process the pattern. */
3705    
3706  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3707  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */  /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */
3708  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
3709  pcre_uchar utf_chars[6];  pcre_uchar utf_chars[6];
3710  #else  #else
# Line 3767  for (;; ptr++) Line 3772  for (;; ptr++)
3772    int terminator;    int terminator;
3773    int mclength;    int mclength;
3774    int tempbracount;    int tempbracount;
3775      int ec; // FIXMEchpe pcre_uint32
3776    pcre_uchar mcbuffer[8];    pcre_uchar mcbuffer[8];
3777    
3778    /* Get next character in the pattern */    /* Get next character in the pattern */
# Line 4236  for (;; ptr++) Line 4242  for (;; ptr++)
4242    
4243        if (c == CHAR_BACKSLASH)        if (c == CHAR_BACKSLASH)
4244          {          {
4245          c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, TRUE);
4246    
4247          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
4248    
4249          if (-c == ESC_b) c = CHAR_BS;    /* \b is backspace in a class */          if (escape == 0)
4250          else if (-c == ESC_N)            /* \N is not supported in a class */            c = ec;
4251            else if (escape == ESC_b) c = CHAR_BS; /* \b is backspace in a class */
4252            else if (escape == ESC_N)            /* \N is not supported in a class */
4253            {            {
4254            *errorcodeptr = ERR71;            *errorcodeptr = ERR71;
4255            goto FAILED;            goto FAILED;
4256            }            }
4257          else if (-c == ESC_Q)            /* Handle start of quoted string */          else if (escape == ESC_Q)            /* Handle start of quoted string */
4258            {            {
4259            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
4260              {              {
# Line 4254  for (;; ptr++) Line 4263  for (;; ptr++)
4263            else inescq = TRUE;            else inescq = TRUE;
4264            continue;            continue;
4265            }            }
4266          else if (-c == ESC_E) continue;  /* Ignore orphan \E */          else if (escape == ESC_E) continue;  /* Ignore orphan \E */
4267    
4268          if (c < 0)          else
4269            {            {
4270            register const pcre_uint8 *cbits = cd->cbits;            register const pcre_uint8 *cbits = cd->cbits;
4271            /* Every class contains at least two < 256 characters. */            /* Every class contains at least two < 256 characters. */
# Line 4264  for (;; ptr++) Line 4273  for (;; ptr++)
4273            /* Every class contains at least two characters. */            /* Every class contains at least two characters. */
4274            class_one_char += 2;            class_one_char += 2;
4275    
4276            switch (-c)            switch (escape)
4277              {              {
4278  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4279              case ESC_du:     /* These are the values given for \d etc */              case ESC_du:     /* These are the values given for \d etc */
# Line 4274  for (;; ptr++) Line 4283  for (;; ptr++)
4283              case ESC_su:     /* of the default ASCII testing. */              case ESC_su:     /* of the default ASCII testing. */
4284              case ESC_SU:              case ESC_SU:
4285              nestptr = ptr;              nestptr = ptr;
4286              ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */              ptr = substitutes[escape - ESC_DU] - 1;  /* Just before substitute */
4287              class_has_8bitchar--;                /* Undo! */              class_has_8bitchar--;                /* Undo! */
4288              continue;              continue;
4289  #endif  #endif
# Line 4343  for (;; ptr++) Line 4352  for (;; ptr++)
4352                int pdata;                int pdata;
4353                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
4354                if (ptype < 0) goto FAILED;                if (ptype < 0) goto FAILED;
4355                *class_uchardata++ = ((-c == ESC_p) != negated)?                *class_uchardata++ = ((escape == ESC_p) != negated)?
4356                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4357                *class_uchardata++ = ptype;                *class_uchardata++ = ptype;
4358                *class_uchardata++ = pdata;                *class_uchardata++ = pdata;
# Line 4371  for (;; ptr++) Line 4380  for (;; ptr++)
4380          /* Fall through if the escape just defined a single character (c >= 0).          /* Fall through if the escape just defined a single character (c >= 0).
4381          This may be greater than 256. */          This may be greater than 256. */
4382    
4383            escape = 0;
4384    
4385          }   /* End of backslash handling */          }   /* End of backslash handling */
4386    
4387        /* 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 4436  for (;; ptr++) Line 4447  for (;; ptr++)
4447    
4448          if (!inescq && d == CHAR_BACKSLASH)          if (!inescq && d == CHAR_BACKSLASH)
4449            {            {
4450            d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);            int descape;
4451              descape = check_escape(&ptr, &d, errorcodeptr, cd->bracount, options, TRUE);
4452            if (*errorcodeptr != 0) goto FAILED;            if (*errorcodeptr != 0) goto FAILED;
4453    
4454            /* \b is backspace; any other special means the '-' was literal. */            /* \b is backspace; any other special means the '-' was literal. */
4455    
4456            if (d < 0)            if (descape > 0)
4457              {              {
4458              if (d == -ESC_b) d = CHAR_BS; else              if (descape == ESC_b) d = CHAR_BS; else
4459                {                {
4460                ptr = oldptr;                ptr = oldptr;
4461                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */
# Line 6662  for (;; ptr++) Line 6674  for (;; ptr++)
6674    
6675      case CHAR_BACKSLASH:      case CHAR_BACKSLASH:
6676      tempptr = ptr;      tempptr = ptr;
6677      c = check_escape(&ptr, errorcodeptr, cd->bracount, options, FALSE);      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);
6678    
6679      if (*errorcodeptr != 0) goto FAILED;      if (*errorcodeptr != 0) goto FAILED;
6680    
6681      if (c < 0)      if (escape == 0)
6682          c = ec;
6683        else
6684        {        {
6685        if (-c == ESC_Q)            /* Handle start of quoted string */        if (escape == ESC_Q)            /* Handle start of quoted string */
6686          {          {
6687          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
6688            ptr += 2;               /* avoid empty string */            ptr += 2;               /* avoid empty string */
# Line 6675  for (;; ptr++) Line 6690  for (;; ptr++)
6690          continue;          continue;
6691          }          }
6692    
6693        if (-c == ESC_E) continue;  /* Perl ignores an orphan \E */        if (escape == ESC_E) continue;  /* Perl ignores an orphan \E */
6694    
6695        /* For metasequences that actually match a character, we disable the        /* For metasequences that actually match a character, we disable the
6696        setting of a first character if it hasn't already been set. */        setting of a first character if it hasn't already been set. */
6697    
6698        if (firstchar == REQ_UNSET && -c > ESC_b && -c < ESC_Z)        if (firstchar == REQ_UNSET && escape > ESC_b && escape < ESC_Z)
6699          firstchar = REQ_NONE;          firstchar = REQ_NONE;
6700    
6701        /* 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 6690  for (;; ptr++) Line 6705  for (;; ptr++)
6705    
6706        /* \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'
6707        is a subroutine call by number (Oniguruma syntax). In fact, the value        is a subroutine call by number (Oniguruma syntax). In fact, the value
6708        -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 <
6709        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
6710        -ESC_REF+n, and for the Perl syntax \g{name} the result is -ESC_k (as        ESC_REF+n, and for the Perl syntax \g{name} the result is ESC_k (as
6711        that is a synonym for a named back reference). */        that is a synonym for a named back reference). */
6712    
6713        if (-c == ESC_g)        if (escape == ESC_g)
6714          {          {
6715          const pcre_uchar *p;          const pcre_uchar *p;
6716          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */
# Line 6751  for (;; ptr++) Line 6766  for (;; ptr++)
6766        /* \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).
6767        We also support \k{name} (.NET syntax).  */        We also support \k{name} (.NET syntax).  */
6768    
6769        if (-c == ESC_k)        if (escape == ESC_k)
6770          {          {
6771          if ((ptr[1] != CHAR_LESS_THAN_SIGN &&          if ((ptr[1] != CHAR_LESS_THAN_SIGN &&
6772            ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))            ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))
# Line 6770  for (;; ptr++) Line 6785  for (;; ptr++)
6785        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
6786        ':' later. */        ':' later. */
6787    
6788        if (-c >= ESC_REF)        if (escape >= ESC_REF)
6789          {          {
6790          open_capitem *oc;          open_capitem *oc;
6791          recno = -c - ESC_REF;          recno = escape - ESC_REF;
6792    
6793          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
6794          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
# Line 6800  for (;; ptr++) Line 6815  for (;; ptr++)
6815        /* So are Unicode property matches, if supported. */        /* So are Unicode property matches, if supported. */
6816    
6817  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6818        else if (-c == ESC_P || -c == ESC_p)        else if (escape == ESC_P || escape == ESC_p)
6819          {          {
6820          BOOL negated;          BOOL negated;
6821          int pdata;          int pdata;
6822          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
6823          if (ptype < 0) goto FAILED;          if (ptype < 0) goto FAILED;
6824          previous = code;          previous = code;
6825          *code++ = ((-c == ESC_p) != negated)? OP_PROP : OP_NOTPROP;          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;
6826          *code++ = ptype;          *code++ = ptype;
6827          *code++ = pdata;          *code++ = pdata;
6828          }          }
# Line 6816  for (;; ptr++) Line 6831  for (;; ptr++)
6831        /* If Unicode properties are not supported, \X, \P, and \p are not        /* If Unicode properties are not supported, \X, \P, and \p are not
6832        allowed. */        allowed. */
6833    
6834        else if (-c == ESC_X || -c == ESC_P || -c == ESC_p)        else if (escape == ESC_X || escape == ESC_P || escape == ESC_p)
6835          {          {
6836          *errorcodeptr = ERR45;          *errorcodeptr = ERR45;
6837          goto FAILED;          goto FAILED;
# Line 6831  for (;; ptr++) Line 6846  for (;; ptr++)
6846    
6847        else        else
6848          {          {
6849          if ((-c == ESC_b || -c == ESC_B) && cd->max_lookbehind == 0)          if ((escape == ESC_b || escape == ESC_B) && cd->max_lookbehind == 0)
6850            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6851  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6852          if (-c >= ESC_DU && -c <= ESC_wu)          if (escape >= ESC_DU && escape <= ESC_wu)
6853            {            {
6854            nestptr = ptr + 1;                   /* Where to resume */            nestptr = ptr + 1;                   /* Where to resume */
6855            ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */            ptr = substitutes[escape - ESC_DU] - 1;  /* Just before substitute */
6856            }            }
6857          else          else
6858  #endif  #endif
# Line 6845  for (;; ptr++) Line 6860  for (;; ptr++)
6860          so that it works in DFA mode and in lookbehinds. */          so that it works in DFA mode and in lookbehinds. */
6861    
6862            {            {
6863            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;            previous = (escape > ESC_b && escape < ESC_Z)? code : NULL;
6864            *code++ = (!utf && c == -ESC_C)? OP_ALLANY : -c;            *code++ = (!utf && escape == ESC_C)? OP_ALLANY : escape;
6865            }            }
6866          }          }
6867        continue;        continue;

Legend:
Removed from v.1056  
changed lines
  Added in v.1059

  ViewVC Help
Powered by ViewVC 1.1.5