/[pcre]/code/trunk/pcre_exec.c
ViewVC logotype

Diff of /code/trunk/pcre_exec.c

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

revision 1365 by ph10, Sun Oct 6 18:33:56 2013 UTC revision 1376 by ph10, Sat Oct 12 18:02:11 2013 UTC
# Line 1281  for (;;) Line 1281  for (;;)
1281    
1282      case OP_COND:      case OP_COND:
1283      case OP_SCOND:      case OP_SCOND:
1284    
1285      /* The variable codelink will be added to ecode when the condition is      /* The variable codelink will be added to ecode when the condition is
1286      false, to get to the second branch. Setting it to the offset to the ALT      false, to get to the second branch. Setting it to the offset to the ALT
1287      or KET, then incrementing ecode achieves this effect. We now have ecode      or KET, then incrementing ecode achieves this effect. We now have ecode
1288      pointing to the condition or callout. */      pointing to the condition or callout. */
1289    
1290      codelink = GET(ecode, 1);   /* Offset to the second branch */      codelink = GET(ecode, 1);   /* Offset to the second branch */
1291      ecode += 1 + LINK_SIZE;     /* From this opcode */      ecode += 1 + LINK_SIZE;     /* From this opcode */
1292    
# Line 1322  for (;;) Line 1322  for (;;)
1322          if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);          if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);
1323          if (rrc < 0) RRETURN(rrc);          if (rrc < 0) RRETURN(rrc);
1324          }          }
1325    
1326        /* Advance ecode past the callout, so it now points to the condition. We        /* Advance ecode past the callout, so it now points to the condition. We
1327        must adjust codelink so that the value of ecode+codelink is unchanged. */        must adjust codelink so that the value of ecode+codelink is unchanged. */
1328    
1329        ecode += PRIV(OP_lengths)[OP_CALLOUT];        ecode += PRIV(OP_lengths)[OP_CALLOUT];
1330        codelink -= PRIV(OP_lengths)[OP_CALLOUT];        codelink -= PRIV(OP_lengths)[OP_CALLOUT];
1331        }        }
# Line 1334  for (;;) Line 1334  for (;;)
1334    
1335      condition = FALSE;      condition = FALSE;
1336      switch(condcode = *ecode)      switch(condcode = *ecode)
1337        {        {
1338        case OP_RREF:         /* Numbered group recursion test */        case OP_RREF:         /* Numbered group recursion test */
1339        if (md->recursive != NULL)     /* Not recursing => FALSE */        if (md->recursive != NULL)     /* Not recursing => FALSE */
1340          {          {
# Line 1345  for (;;) Line 1345  for (;;)
1345    
1346        case OP_DNRREF:       /* Duplicate named group recursion test */        case OP_DNRREF:       /* Duplicate named group recursion test */
1347        if (md->recursive != NULL)        if (md->recursive != NULL)
1348          {          {
1349          int count = GET2(ecode, 1 + IMM2_SIZE);          int count = GET2(ecode, 1 + IMM2_SIZE);
1350          pcre_uchar *slot = md->name_table + GET2(ecode, 1) * md->name_entry_size;          pcre_uchar *slot = md->name_table + GET2(ecode, 1) * md->name_entry_size;
1351          while (count-- > 0)          while (count-- > 0)
1352            {            {
# Line 1355  for (;;) Line 1355  for (;;)
1355            if (condition) break;            if (condition) break;
1356            slot += md->name_entry_size;            slot += md->name_entry_size;
1357            }            }
1358          }          }
1359        break;        break;
1360    
1361        case OP_CREF:         /* Numbered group used test */        case OP_CREF:         /* Numbered group used test */
# Line 1365  for (;;) Line 1365  for (;;)
1365    
1366        case OP_DNCREF:      /* Duplicate named group used test */        case OP_DNCREF:      /* Duplicate named group used test */
1367          {          {
1368          int count = GET2(ecode, 1 + IMM2_SIZE);          int count = GET2(ecode, 1 + IMM2_SIZE);
1369          pcre_uchar *slot = md->name_table + GET2(ecode, 1) * md->name_entry_size;          pcre_uchar *slot = md->name_table + GET2(ecode, 1) * md->name_entry_size;
1370          while (count-- > 0)          while (count-- > 0)
1371            {            {
# Line 1375  for (;;) Line 1375  for (;;)
1375            slot += md->name_entry_size;            slot += md->name_entry_size;
1376            }            }
1377          }          }
1378        break;        break;
1379    
1380        case OP_DEF:     /* DEFINE - always false */        case OP_DEF:     /* DEFINE - always false */
1381        break;        break;
# Line 1383  for (;;) Line 1383  for (;;)
1383        /* The condition is an assertion. Call match() to evaluate it - setting        /* The condition is an assertion. Call match() to evaluate it - setting
1384        md->match_function_type to MATCH_CONDASSERT causes it to stop at the end        md->match_function_type to MATCH_CONDASSERT causes it to stop at the end
1385        of an assertion. */        of an assertion. */
1386    
1387        default:        default:
1388        md->match_function_type = MATCH_CONDASSERT;        md->match_function_type = MATCH_CONDASSERT;
1389        RMATCH(eptr, ecode, offset_top, md, NULL, RM3);        RMATCH(eptr, ecode, offset_top, md, NULL, RM3);
1390        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
# Line 1392  for (;;) Line 1392  for (;;)
1392          if (md->end_offset_top > offset_top)          if (md->end_offset_top > offset_top)
1393            offset_top = md->end_offset_top;  /* Captures may have happened */            offset_top = md->end_offset_top;  /* Captures may have happened */
1394          condition = TRUE;          condition = TRUE;
1395    
1396          /* Advance ecode past the assertion to the start of the first branch,          /* Advance ecode past the assertion to the start of the first branch,
1397          but adjust it so that the general choosing code below works. */          but adjust it so that the general choosing code below works. */
1398    
1399          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
1400          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1401          ecode += 1 + LINK_SIZE - PRIV(OP_lengths)[condcode];          ecode += 1 + LINK_SIZE - PRIV(OP_lengths)[condcode];
1402          }          }
1403    
1404        /* PCRE doesn't allow the effect of (*THEN) to escape beyond an        /* PCRE doesn't allow the effect of (*THEN) to escape beyond an
1405        assertion; it is therefore treated as NOMATCH. Any other return is an        assertion; it is therefore treated as NOMATCH. Any other return is an
1406        error. */        error. */
1407    
1408        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1409          {          {
1410          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1411          }          }
1412        break;        break;
1413        }        }
1414    
1415      /* Choose branch according to the condition */      /* Choose branch according to the condition */
1416    
1417      ecode += condition? PRIV(OP_lengths)[condcode] : codelink;      ecode += condition? PRIV(OP_lengths)[condcode] : codelink;
1418    
1419      /* We are now at the branch that is to be obeyed. As there is only one, we      /* We are now at the branch that is to be obeyed. As there is only one, we
1420      can use tail recursion to avoid using another stack frame, except when      can use tail recursion to avoid using another stack frame, except when
1421      there is unlimited repeat of a possibly empty group. In the latter case, a      there is unlimited repeat of a possibly empty group. In the latter case, a
# Line 1425  for (;;) Line 1425  for (;;)
1425      creating two alternatives. If a THEN is encountered in the branch, it      creating two alternatives. If a THEN is encountered in the branch, it
1426      propagates out to the enclosing alternative (unless nested in a deeper set      propagates out to the enclosing alternative (unless nested in a deeper set
1427      of alternatives, of course). */      of alternatives, of course). */
1428    
1429      if (condition || ecode[-(1+LINK_SIZE)] == OP_ALT)      if (condition || ecode[-(1+LINK_SIZE)] == OP_ALT)
1430        {        {
1431        if (op != OP_SCOND)        if (op != OP_SCOND)
# Line 2577  for (;;) Line 2577  for (;;)
2577          /* Perl space used to exclude VT, but from Perl 5.18 it is included,          /* Perl space used to exclude VT, but from Perl 5.18 it is included,
2578          which means that Perl space and POSIX space are now identical. PCRE          which means that Perl space and POSIX space are now identical. PCRE
2579          was changed at release 8.34. */          was changed at release 8.34. */
2580    
2581          case PT_SPACE:    /* Perl space */          case PT_SPACE:    /* Perl space */
2582          case PT_PXSPACE:  /* POSIX space */          case PT_PXSPACE:  /* POSIX space */
2583          if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||          switch(c)
2584               c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||            {
2585               c == CHAR_FF || c == CHAR_CR)            HSPACE_CASES:
2586                 == (op == OP_NOTPROP))            VSPACE_CASES:
2587            RRETURN(MATCH_NOMATCH);            if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
2588              break;
2589    
2590              default:
2591              if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z) ==
2592                (op == OP_NOTPROP)) RRETURN(MATCH_NOMATCH);
2593              break;
2594              }
2595          break;          break;
2596    
2597          case PT_WORD:          case PT_WORD:
# Line 2669  for (;;) Line 2676  for (;;)
2676    
2677      Otherwise, set the length to the length of what was matched by the      Otherwise, set the length to the length of what was matched by the
2678      referenced subpattern.      referenced subpattern.
2679    
2680      The OP_REF and OP_REFI opcodes are used for a reference to a numbered group      The OP_REF and OP_REFI opcodes are used for a reference to a numbered group
2681      or to a non-duplicated named group. For a duplicated named group, OP_DNREF      or to a non-duplicated named group. For a duplicated named group, OP_DNREF
2682      and OP_DNREFI are used. In this case we must scan the list of groups to      and OP_DNREFI are used. In this case we must scan the list of groups to
2683      which the name refers, and use the first one that is set. */      which the name refers, and use the first one that is set. */
2684    
2685      case OP_DNREF:      case OP_DNREF:
2686      case OP_DNREFI:      case OP_DNREFI:
2687      caseless = op == OP_DNREFI;      caseless = op == OP_DNREFI;
2688        {        {
2689        int count = GET2(ecode, 1+IMM2_SIZE);        int count = GET2(ecode, 1+IMM2_SIZE);
2690        pcre_uchar *slot = md->name_table + GET2(ecode, 1) * md->name_entry_size;        pcre_uchar *slot = md->name_table + GET2(ecode, 1) * md->name_entry_size;
2691        ecode += 1 + 2*IMM2_SIZE;        ecode += 1 + 2*IMM2_SIZE;
2692    
2693        while (count-- > 0)        while (count-- > 0)
2694          {          {
2695          offset = GET2(slot, 0) << 1;          offset = GET2(slot, 0) << 1;
2696          if (offset < offset_top && md->offset_vector[offset] >= 0) break;          if (offset < offset_top && md->offset_vector[offset] >= 0) break;
2697          slot += md->name_entry_size;          slot += md->name_entry_size;
2698          }          }
2699        if (count < 0)        if (count < 0)
2700          length = (md->jscript_compat)? 0 : -1;          length = (md->jscript_compat)? 0 : -1;
2701        else        else
2702          length = md->offset_vector[offset+1] - md->offset_vector[offset];          length = md->offset_vector[offset+1] - md->offset_vector[offset];
# Line 4200  for (;;) Line 4207  for (;;)
4207            /* Perl space used to exclude VT, but from Perl 5.18 it is included,            /* Perl space used to exclude VT, but from Perl 5.18 it is included,
4208            which means that Perl space and POSIX space are now identical. PCRE            which means that Perl space and POSIX space are now identical. PCRE
4209            was changed at release 8.34. */            was changed at release 8.34. */
4210    
4211            case PT_SPACE:    /* Perl space */            case PT_SPACE:    /* Perl space */
4212            case PT_PXSPACE:  /* POSIX space */            case PT_PXSPACE:  /* POSIX space */
4213            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
# Line 4211  for (;;) Line 4218  for (;;)
4218                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4219                }                }
4220              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4221              if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||              switch(c)
4222                   c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)                {
4223                     == prop_fail_result)                HSPACE_CASES:
4224                RRETURN(MATCH_NOMATCH);                VSPACE_CASES:
4225                  if (prop_fail_result) RRETURN(MATCH_NOMATCH);
4226                  break;
4227    
4228                  default:
4229                  if ((UCD_CATEGORY(c) == ucp_Z) == prop_fail_result)
4230                    RRETURN(MATCH_NOMATCH);
4231                  break;
4232                  }
4233              }              }
4234            break;            break;
4235    
# Line 4937  for (;;) Line 4952  for (;;)
4952            /* Perl space used to exclude VT, but from Perl 5.18 it is included,            /* Perl space used to exclude VT, but from Perl 5.18 it is included,
4953            which means that Perl space and POSIX space are now identical. PCRE            which means that Perl space and POSIX space are now identical. PCRE
4954            was changed at release 8.34. */            was changed at release 8.34. */
4955    
4956            case PT_SPACE:    /* Perl space */            case PT_SPACE:    /* Perl space */
4957            case PT_PXSPACE:  /* POSIX space */            case PT_PXSPACE:  /* POSIX space */
4958            for (fi = min;; fi++)            for (fi = min;; fi++)
# Line 4951  for (;;) Line 4966  for (;;)
4966                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4967                }                }
4968              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4969              if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||              switch(c)
4970                   c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)                {
4971                     == prop_fail_result)                HSPACE_CASES:
4972                RRETURN(MATCH_NOMATCH);                VSPACE_CASES:
4973                  if (prop_fail_result) RRETURN(MATCH_NOMATCH);
4974                  break;
4975    
4976                  default:
4977                  if ((UCD_CATEGORY(c) == ucp_Z) == prop_fail_result)
4978                    RRETURN(MATCH_NOMATCH);
4979                  break;
4980                  }
4981              }              }
4982            /* Control never gets here */            /* Control never gets here */
4983    
# Line 5441  for (;;) Line 5464  for (;;)
5464            /* Perl space used to exclude VT, but from Perl 5.18 it is included,            /* Perl space used to exclude VT, but from Perl 5.18 it is included,
5465            which means that Perl space and POSIX space are now identical. PCRE            which means that Perl space and POSIX space are now identical. PCRE
5466            was changed at release 8.34. */            was changed at release 8.34. */
5467    
5468            case PT_SPACE:    /* Perl space */            case PT_SPACE:    /* Perl space */
5469            case PT_PXSPACE:  /* POSIX space */            case PT_PXSPACE:  /* POSIX space */
5470            for (i = min; i < max; i++)            for (i = min; i < max; i++)
# Line 5453  for (;;) Line 5476  for (;;)
5476                break;                break;
5477                }                }
5478              GETCHARLENTEST(c, eptr, len);              GETCHARLENTEST(c, eptr, len);
5479              if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||              switch(c)
5480                   c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)                {
5481                   == prop_fail_result)                HSPACE_CASES:
5482                  VSPACE_CASES:
5483                  if (prop_fail_result) goto ENDLOOP99;  /* Break the loop */
5484                  break;
5485    
5486                  default:
5487                  if ((UCD_CATEGORY(c) == ucp_Z) == prop_fail_result)
5488                    goto ENDLOOP99;   /* Break the loop */
5489                break;                break;
5490                  }
5491              eptr+= len;              eptr+= len;
5492              }              }
5493              ENDLOOP99:
5494            break;            break;
5495    
5496            case PT_WORD:            case PT_WORD:
# Line 5572  for (;;) Line 5604  for (;;)
5604          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
5605    
5606          if (possessive) continue;    /* No backtracking */          if (possessive) continue;    /* No backtracking */
5607    
5608          for(;;)          for(;;)
5609            {            {
5610            int lgb, rgb;            int lgb, rgb;
5611            PCRE_PUCHAR fptr;            PCRE_PUCHAR fptr;
5612    
5613            if (eptr == pp) goto TAIL_RECURSE;   /* At start of char run */            if (eptr == pp) goto TAIL_RECURSE;   /* At start of char run */
5614            RMATCH(eptr, ecode, offset_top, md, eptrb, RM45);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM45);
5615            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
# Line 5585  for (;;) Line 5617  for (;;)
5617            /* Backtracking over an extended grapheme cluster involves inspecting            /* Backtracking over an extended grapheme cluster involves inspecting
5618            the previous two characters (if present) to see if a break is            the previous two characters (if present) to see if a break is
5619            permitted between them. */            permitted between them. */
5620    
5621            eptr--;            eptr--;
5622            if (!utf) c = *eptr; else            if (!utf) c = *eptr; else
5623              {              {
# Line 5603  for (;;) Line 5635  for (;;)
5635                BACKCHAR(fptr);                BACKCHAR(fptr);
5636                GETCHAR(c, fptr);                GETCHAR(c, fptr);
5637                }                }
5638              lgb = UCD_GRAPHBREAK(c);              lgb = UCD_GRAPHBREAK(c);
5639              if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0) break;              if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0) break;
5640              eptr = fptr;              eptr = fptr;
5641              rgb = lgb;              rgb = lgb;
# Line 6127  for (;;) Line 6159  for (;;)
6159                eptr[-1] == CHAR_CR) eptr--;                eptr[-1] == CHAR_CR) eptr--;
6160            }            }
6161          }          }
6162    
6163        /* Control never gets here */        /* Control never gets here */
6164        }        }
6165    

Legend:
Removed from v.1365  
changed lines
  Added in v.1376

  ViewVC Help
Powered by ViewVC 1.1.5