/[pcre]/code/branches/pcre16/pcre_compile.c
ViewVC logotype

Diff of /code/branches/pcre16/pcre_compile.c

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

revision 654 by ph10, Tue Aug 2 11:00:40 2011 UTC revision 746 by ph10, Tue Nov 15 15:07:02 2011 UTC
# Line 676  else Line 676  else
676    
677      case CHAR_l:      case CHAR_l:
678      case CHAR_L:      case CHAR_L:
679        *errorcodeptr = ERR37;
680        break;
681    
682      case CHAR_u:      case CHAR_u:
683        if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
684          {
685          /* In JavaScript, \u must be followed by four hexadecimal numbers.
686          Otherwise it is a lowercase u letter. */
687          if ((digitab[ptr[1]] & ctype_xdigit) != 0 && (digitab[ptr[2]] & ctype_xdigit) != 0
688               && (digitab[ptr[3]] & ctype_xdigit) != 0 && (digitab[ptr[4]] & ctype_xdigit) != 0)
689            {
690            c = 0;
691            for (i = 0; i < 4; ++i)
692              {
693              register int cc = *(++ptr);
694    #ifndef EBCDIC  /* ASCII/UTF-8 coding */
695              if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
696              c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
697    #else           /* EBCDIC coding */
698              if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
699              c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
700    #endif
701              }
702            }
703          }
704        else
705          *errorcodeptr = ERR37;
706        break;
707    
708      case CHAR_U:      case CHAR_U:
709      *errorcodeptr = ERR37;      /* In JavaScript, \U is an uppercase U letter. */
710        if ((options & PCRE_JAVASCRIPT_COMPAT) == 0) *errorcodeptr = ERR37;
711      break;      break;
712    
713      /* In a character class, \g is just a literal "g". Outside a character      /* In a character class, \g is just a literal "g". Outside a character
# Line 828  else Line 857  else
857      treated as a data character. */      treated as a data character. */
858    
859      case CHAR_x:      case CHAR_x:
860        if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
861          {
862          /* In JavaScript, \x must be followed by two hexadecimal numbers.
863          Otherwise it is a lowercase x letter. */
864          if ((digitab[ptr[1]] & ctype_xdigit) != 0 && (digitab[ptr[2]] & ctype_xdigit) != 0)
865            {
866            c = 0;
867            for (i = 0; i < 2; ++i)
868              {
869              register int cc = *(++ptr);
870    #ifndef EBCDIC  /* ASCII/UTF-8 coding */
871              if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
872              c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
873    #else           /* EBCDIC coding */
874              if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
875              c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
876    #endif
877              }
878            }
879          break;
880          }
881    
882      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
883        {        {
884        const uschar *pt = ptr + 2;        const uschar *pt = ptr + 2;
# Line 1506  for (;;) Line 1557  for (;;)
1557      case OP_CBRA:      case OP_CBRA:
1558      case OP_BRA:      case OP_BRA:
1559      case OP_ONCE:      case OP_ONCE:
1560        case OP_ONCE_NC:
1561      case OP_COND:      case OP_COND:
1562      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd);      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd);
1563      if (d < 0) return d;      if (d < 0) return d;
# Line 1594  for (;;) Line 1646  for (;;)
1646      need to skip over a multibyte character in UTF8 mode.  */      need to skip over a multibyte character in UTF8 mode.  */
1647    
1648      case OP_EXACT:      case OP_EXACT:
1649        case OP_EXACTI:
1650      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1651      cc += 4;      cc += 4;
1652  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1761  for (;;) Line 1814  for (;;)
1814        break;        break;
1815    
1816        case OP_THEN_ARG:        case OP_THEN_ARG:
1817        code += code[1+LINK_SIZE];        code += code[1];
1818        break;        break;
1819        }        }
1820    
# Line 1880  for (;;) Line 1933  for (;;)
1933        break;        break;
1934    
1935        case OP_THEN_ARG:        case OP_THEN_ARG:
1936        code += code[1+LINK_SIZE];        code += code[1];
1937        break;        break;
1938        }        }
1939    
# Line 2045  for (code = first_significant_code(code Line 2098  for (code = first_significant_code(code
2098    
2099    if (c == OP_BRA  || c == OP_BRAPOS ||    if (c == OP_BRA  || c == OP_BRAPOS ||
2100        c == OP_CBRA || c == OP_CBRAPOS ||        c == OP_CBRA || c == OP_CBRAPOS ||
2101        c == OP_ONCE || c == OP_COND)        c == OP_ONCE || c == OP_ONCE_NC ||
2102          c == OP_COND)
2103      {      {
2104      BOOL empty_branch;      BOOL empty_branch;
2105      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */
# Line 2217  for (code = first_significant_code(code Line 2271  for (code = first_significant_code(code
2271      break;      break;
2272    
2273      case OP_THEN_ARG:      case OP_THEN_ARG:
2274      code += code[1+LINK_SIZE];      code += code[1];
2275      break;      break;
2276    
2277      /* None of the remaining opcodes are required to match a character. */      /* None of the remaining opcodes are required to match a character. */
# Line 2295  I think. Line 2349  I think.
2349  A user pointed out that PCRE was rejecting [:a[:digit:]] whereas Perl was not.  A user pointed out that PCRE was rejecting [:a[:digit:]] whereas Perl was not.
2350  It seems that the appearance of a nested POSIX class supersedes an apparent  It seems that the appearance of a nested POSIX class supersedes an apparent
2351  external class. For example, [:a[:digit:]b:] matches "a", "b", ":", or  external class. For example, [:a[:digit:]b:] matches "a", "b", ":", or
2352  a digit. Also, unescaped square brackets may also appear as part of class  a digit.
2353  names. For example, [:a[:abc]b:] gives unknown class "[:abc]b:]"in Perl.  
2354    In Perl, unescaped square brackets may also appear as part of class names. For
2355    example, [:a[:abc]b:] gives unknown POSIX class "[:abc]b:]". However, for
2356    [:a[:abc]b][b:] it gives unknown POSIX class "[:abc]b][b:]", which does not
2357    seem right at all. PCRE does not allow closing square brackets in POSIX class
2358    names.
2359    
2360  Arguments:  Arguments:
2361    ptr      pointer to the initial [    ptr      pointer to the initial [
# Line 2314  for (++ptr; *ptr != 0; ptr++) Line 2373  for (++ptr; *ptr != 0; ptr++)
2373    {    {
2374    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
2375      ptr++;      ptr++;
2376      else if (*ptr == CHAR_RIGHT_SQUARE_BRACKET) return FALSE;
2377    else    else
2378      {      {
2379      if (*ptr == terminator && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)      if (*ptr == terminator && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
# Line 3086  uschar *class_utf8data_base; Line 3146  uschar *class_utf8data_base;
3146  uschar utf8_char[6];  uschar utf8_char[6];
3147  #else  #else
3148  BOOL utf8 = FALSE;  BOOL utf8 = FALSE;
 uschar *utf8_char = NULL;  
3149  #endif  #endif
3150    
3151  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
# Line 3137  for (;; ptr++) Line 3196  for (;; ptr++)
3196    int subfirstbyte;    int subfirstbyte;
3197    int terminator;    int terminator;
3198    int mclength;    int mclength;
3199      int tempbracount;
3200    uschar mcbuffer[8];    uschar mcbuffer[8];
3201    
3202    /* Get next byte in the pattern */    /* Get next byte in the pattern */
# Line 4835  for (;; ptr++) Line 4895  for (;; ptr++)
4895          uschar *ketcode = code - 1 - LINK_SIZE;          uschar *ketcode = code - 1 - LINK_SIZE;
4896          uschar *bracode = ketcode - GET(ketcode, 1);          uschar *bracode = ketcode - GET(ketcode, 1);
4897    
4898          if (*bracode == OP_ONCE && possessive_quantifier) *bracode = OP_BRA;          if ((*bracode == OP_ONCE || *bracode == OP_ONCE_NC) &&
4899          if (*bracode == OP_ONCE)              possessive_quantifier) *bracode = OP_BRA;
4900    
4901            if (*bracode == OP_ONCE || *bracode == OP_ONCE_NC)
4902            *ketcode = OP_KETRMAX + repeat_type;            *ketcode = OP_KETRMAX + repeat_type;
4903          else          else
4904            {            {
# Line 5040  for (;; ptr++) Line 5102  for (;; ptr++)
5102                PUT2INC(code, 0, oc->number);                PUT2INC(code, 0, oc->number);
5103                }                }
5104              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5105    
5106                /* Do not set firstbyte after *ACCEPT */
5107                if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;
5108              }              }
5109    
5110            /* Handle other cases with/without an argument */            /* Handle other cases with/without an argument */
# Line 5052  for (;; ptr++) Line 5117  for (;; ptr++)
5117                goto FAILED;                goto FAILED;
5118                }                }
5119              *code = verbs[i].op;              *code = verbs[i].op;
5120              if (*code++ == OP_THEN)              if (*code++ == OP_THEN) cd->external_flags |= PCRE_HASTHEN;
               {  
               PUT(code, 0, code - bcptr->current_branch - 1);  
               code += LINK_SIZE;  
               }  
5121              }              }
5122    
5123            else            else
# Line 5067  for (;; ptr++) Line 5128  for (;; ptr++)
5128                goto FAILED;                goto FAILED;
5129                }                }
5130              *code = verbs[i].op_arg;              *code = verbs[i].op_arg;
5131              if (*code++ == OP_THEN_ARG)              if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;
               {  
               PUT(code, 0, code - bcptr->current_branch - 1);  
               code += LINK_SIZE;  
               }  
5132              *code++ = arglen;              *code++ = arglen;
5133              memcpy(code, arg, arglen);              memcpy(code, arg, arglen);
5134              code += arglen;              code += arglen;
# Line 5906  for (;; ptr++) Line 5963  for (;; ptr++)
5963      *code = bravalue;      *code = bravalue;
5964      tempcode = code;      tempcode = code;
5965      tempreqvary = cd->req_varyopt;        /* Save value before bracket */      tempreqvary = cd->req_varyopt;        /* Save value before bracket */
5966        tempbracount = cd->bracount;          /* Save value before bracket */
5967      length_prevgroup = 0;                 /* Initialize for pre-compile phase */      length_prevgroup = 0;                 /* Initialize for pre-compile phase */
5968    
5969      if (!compile_regex(      if (!compile_regex(
# Line 5928  for (;; ptr++) Line 5986  for (;; ptr++)
5986           ))           ))
5987        goto FAILED;        goto FAILED;
5988    
5989        /* If this was an atomic group and there are no capturing groups within it,
5990        generate OP_ONCE_NC instead of OP_ONCE. */
5991    
5992        if (bravalue == OP_ONCE && cd->bracount <= tempbracount)
5993          *code = OP_ONCE_NC;
5994    
5995      if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERTBACK_NOT)      if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERTBACK_NOT)
5996        cd->assert_depth -= 1;        cd->assert_depth -= 1;
5997    
5998      /* At the end of compiling, code is still pointing to the start of the      /* At the end of compiling, code is still pointing to the start of the
5999      group, while tempcode has been updated to point past the end of the group      group, while tempcode has been updated to point past the end of the group.
6000      and any option resetting that may follow it. The pattern pointer (ptr)      The pattern pointer (ptr) is on the bracket.
     is on the bracket. */  
6001    
6002      /* If this is a conditional bracket, check that there are no more than      If this is a conditional bracket, check that there are no more than
6003      two branches in the group, or just one if it's a DEFINE group. We do this      two branches in the group, or just one if it's a DEFINE group. We do this
6004      in the real compile phase, not in the pre-pass, where the whole group may      in the real compile phase, not in the pre-pass, where the whole group may
6005      not be available. */      not be available. */
# Line 6335  for (;; ptr++) Line 6398  for (;; ptr++)
6398        else firstbyte = reqbyte = REQ_NONE;        else firstbyte = reqbyte = REQ_NONE;
6399        }        }
6400    
6401      /* firstbyte was previously set; we can set reqbyte only the length is      /* firstbyte was previously set; we can set reqbyte only if the length is
6402      1 or the matching is caseful. */      1 or the matching is caseful. */
6403    
6404      else      else
# Line 6727  do { Line 6790  do {
6790    
6791     /* Other brackets */     /* Other brackets */
6792    
6793     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_COND)     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC ||
6794                op == OP_COND)
6795       {       {
6796       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;
6797       }       }
# Line 6831  do { Line 6895  do {
6895    
6896     /* Other brackets */     /* Other brackets */
6897    
6898     else if (op == OP_ASSERT || op == OP_ONCE)     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC)
6899       {       {
6900       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;
6901       }       }
# Line 6901  do { Line 6965  do {
6965       case OP_SCBRAPOS:       case OP_SCBRAPOS:
6966       case OP_ASSERT:       case OP_ASSERT:
6967       case OP_ONCE:       case OP_ONCE:
6968         case OP_ONCE_NC:
6969       case OP_COND:       case OP_COND:
6970       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)
6971         return -1;         return -1;
# Line 7282  re->top_bracket = cd->bracount; Line 7347  re->top_bracket = cd->bracount;
7347  re->top_backref = cd->top_backref;  re->top_backref = cd->top_backref;
7348  re->flags = cd->external_flags;  re->flags = cd->external_flags;
7349    
7350  if (cd->had_accept) reqbyte = -1;   /* Must disable after (*ACCEPT) */  if (cd->had_accept) reqbyte = REQ_NONE;   /* Must disable after (*ACCEPT) */
7351    
7352  /* If not reached end of pattern on success, there's an excess bracket. */  /* If not reached end of pattern on success, there's an excess bracket. */
7353    

Legend:
Removed from v.654  
changed lines
  Added in v.746

  ViewVC Help
Powered by ViewVC 1.1.5