/[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 702 by ph10, Tue Sep 20 15:45:06 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 3142  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 4840  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 5045  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 */              /* Do not set firstbyte after *ACCEPT */
5107              if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;              if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;
5108              }              }
# Line 5060  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;  
               cd->external_flags |= PCRE_HASTHEN;  
               }  
5121              }              }
5122    
5123            else            else
# Line 5076  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 5915  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 5937  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 6327  for (;; ptr++) Line 6381  for (;; ptr++)
6381      byte, set it from this character, but revert to none on a zero repeat.      byte, set it from this character, but revert to none on a zero repeat.
6382      Otherwise, leave the firstbyte value alone, and don't change it on a zero      Otherwise, leave the firstbyte value alone, and don't change it on a zero
6383      repeat. */      repeat. */
6384    
6385      if (firstbyte == REQ_UNSET)      if (firstbyte == REQ_UNSET)
6386        {        {
6387        zerofirstbyte = REQ_NONE;        zerofirstbyte = REQ_NONE;
# Line 6736  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 6840  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 6910  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;

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

  ViewVC Help
Powered by ViewVC 1.1.5