/[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 915 by zherczeg, Tue Feb 14 13:05:39 2012 UTC revision 916 by ph10, Wed Feb 15 09:50:53 2012 UTC
# Line 140  Arguments: Line 140  Arguments:
140    md          points to match data block    md          points to match data block
141    caseless    TRUE if caseless    caseless    TRUE if caseless
142    
143  Returns:      < 0 if not matched, otherwise the number of subject bytes matched  Returns:      >= 0 the number of subject bytes matched
144                  -1 no match
145                  -2 partial match; always given if at end subject
146  */  */
147    
148  static int  static int
149  match_ref(int offset, register PCRE_PUCHAR eptr, int length, match_data *md,  match_ref(int offset, register PCRE_PUCHAR eptr, int length, match_data *md,
150    BOOL caseless)    BOOL caseless)
151  {  {
152  int matched_length = length;  PCRE_PUCHAR eptr_start = eptr;
153  register PCRE_PUCHAR p = md->start_subject + md->offset_vector[offset];  register PCRE_PUCHAR p = md->start_subject + md->offset_vector[offset];
154    
155  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
# Line 163  pchars(p, length, FALSE, md); Line 165  pchars(p, length, FALSE, md);
165  printf("\n");  printf("\n");
166  #endif  #endif
167    
168  /* Always fail if reference not set (and not JavaScript compatible). */  /* Always fail if reference not set (and not JavaScript compatible - in that
169    case the length is passed as zero). */
170    
171  if (length < 0) return -1;  if (length < 0) return -1;
172    
# Line 186  if (caseless) Line 189  if (caseless)
189      reference, not along the subject (earlier code did this wrong). */      reference, not along the subject (earlier code did this wrong). */
190    
191      PCRE_PUCHAR endptr = p + length;      PCRE_PUCHAR endptr = p + length;
     PCRE_PUCHAR eptr_start = eptr;  
192      while (p < endptr)      while (p < endptr)
193        {        {
194        int c, d;        int c, d;
195        if (eptr >= md->end_subject) return -((int)(eptr - eptr_start) + 1);        if (eptr >= md->end_subject) return -2;   /* Partial match */
196        GETCHARINC(c, eptr);        GETCHARINC(c, eptr);
197        GETCHARINC(d, p);        GETCHARINC(d, p);
198        if (c != d && c != UCD_OTHERCASE(d)) return -1;        if (c != d && c != UCD_OTHERCASE(d)) return -1;
199        }        }
     matched_length = (int)(eptr - eptr_start);  
200      }      }
201    else    else
202  #endif  #endif
# Line 204  if (caseless) Line 205  if (caseless)
205    /* The same code works when not in UTF-8 mode and in UTF-8 mode when there    /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
206    is no UCP support. */    is no UCP support. */
207      {      {
     if (eptr + length > md->end_subject)  
       {  
       if (md->partial == 0)  
         return -1;  
       length = (int)(md->end_subject - eptr);  
       matched_length = -(length + 1);  
       }  
208      while (length-- > 0)      while (length-- > 0)
209        {        {
210          if (eptr >= md->end_subject) return -2;   /* Partial match */
211        if (TABLE_GET(*p, md->lcc, *p) != TABLE_GET(*eptr, md->lcc, *eptr)) return -1;        if (TABLE_GET(*p, md->lcc, *p) != TABLE_GET(*eptr, md->lcc, *eptr)) return -1;
212        p++;        p++;
213        eptr++;        eptr++;
# Line 225  are in UTF-8 mode. */ Line 220  are in UTF-8 mode. */
220    
221  else  else
222    {    {
223    if (eptr + length > md->end_subject)    while (length-- > 0)
224      {      {
225      if (md->partial == 0)      if (eptr >= md->end_subject) return -2;   /* Partial match */
226        return -1;      if (*p++ != *eptr++) return -1;
227      length = (int)(md->end_subject - eptr);      }
     matched_length = -(length + 1);  
     }  
   while (length-- > 0) if (*p++ != *eptr++) return -1;  
228    }    }
229    
230  return matched_length;  return (int)(eptr - eptr_start);
231  }  }
232    
233    
# Line 2073  for (;;) Line 2065  for (;;)
2065    
2066      case OP_DOLLM:      case OP_DOLLM:
2067      if (eptr < md->end_subject)      if (eptr < md->end_subject)
2068        { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }        {
2069          if (!IS_NEWLINE(eptr))
2070            {
2071            if (eptr + 1 >= md->end_subject &&
2072                md->partial != 0 &&
2073                NLBLOCK->nltype == NLTYPE_FIXED &&
2074                NLBLOCK->nllen == 2 &&
2075                *eptr == NLBLOCK->nl[0])
2076              {
2077              md->hitend = TRUE;
2078              if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2079              }
2080            RRETURN(MATCH_NOMATCH);
2081            }
2082          }
2083      else      else
2084        {        {
2085        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
# Line 2105  for (;;) Line 2111  for (;;)
2111      ASSERT_NL_OR_EOS:      ASSERT_NL_OR_EOS:
2112      if (eptr < md->end_subject &&      if (eptr < md->end_subject &&
2113          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
2114          {
2115          if (eptr + 1 >= md->end_subject &&
2116              md->partial != 0 &&
2117              NLBLOCK->nltype == NLTYPE_FIXED &&
2118              NLBLOCK->nllen == 2 &&
2119              *eptr == NLBLOCK->nl[0])
2120            {
2121            md->hitend = TRUE;
2122            if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2123            }
2124        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2125          }
2126    
2127      /* Either at end of string or \n before end. */      /* Either at end of string or \n before end. */
2128    
# Line 2379  for (;;) Line 2396  for (;;)
2396        default: RRETURN(MATCH_NOMATCH);        default: RRETURN(MATCH_NOMATCH);
2397    
2398        case 0x000d:        case 0x000d:
2399        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr >= md->end_subject)
2400            {
2401            SCHECK_PARTIAL();
2402            }
2403          else if (*eptr == 0x0a) eptr++;
2404        break;        break;
2405    
2406        case 0x000a:        case 0x000a:
# Line 2609  for (;;) Line 2630  for (;;)
2630        if (UCD_CATEGORY(c) != ucp_M) break;        if (UCD_CATEGORY(c) != ucp_M) break;
2631        eptr += len;        eptr += len;
2632        }        }
2633      if (md->partial != 0 && eptr >= md->end_subject)      CHECK_PARTIAL();
       {  
       SCHECK_PARTIAL();  
       }  
2634      ecode++;      ecode++;
2635      break;      break;
2636  #endif  #endif
# Line 2678  for (;;) Line 2696  for (;;)
2696        default:               /* No repeat follows */        default:               /* No repeat follows */
2697        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)
2698          {          {
2699          eptr += -(length + 1);          if (length == -2) eptr = md->end_subject;   /* Partial match */
2700          CHECK_PARTIAL();          CHECK_PARTIAL();
2701          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2702          }          }
# Line 2704  for (;;) Line 2722  for (;;)
2722        int slength;        int slength;
2723        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2724          {          {
2725          eptr += -(slength + 1);          if (slength == -2) eptr = md->end_subject;   /* Partial match */
2726          CHECK_PARTIAL();          CHECK_PARTIAL();
2727          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2728          }          }
# Line 2728  for (;;) Line 2746  for (;;)
2746          if (fi >= max) RRETURN(MATCH_NOMATCH);          if (fi >= max) RRETURN(MATCH_NOMATCH);
2747          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2748            {            {
2749            eptr += -(slength + 1);            if (slength == -2) eptr = md->end_subject;   /* Partial match */
2750            CHECK_PARTIAL();            CHECK_PARTIAL();
2751            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2752            }            }
# Line 2747  for (;;) Line 2765  for (;;)
2765          int slength;          int slength;
2766          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2767            {            {
2768            /* Restore the eptr after the check. */            /* Can't use CHECK_PARTIAL because we don't want to update eptr in
2769            eptr += -(slength + 1);            the soft partial matching case. */
2770            CHECK_PARTIAL();  
2771            eptr -= -(slength + 1);            if (slength == -2 && md->partial != 0 &&
2772                  md->end_subject > md->start_used_ptr)
2773                {
2774                md->hitend = TRUE;
2775                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2776                }
2777            break;            break;
2778            }            }
2779          eptr += slength;          eptr += slength;
2780          }          }
2781    
2782        while (eptr >= pp)        while (eptr >= pp)
2783          {          {
2784          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);
# Line 4188  for (;;) Line 4212  for (;;)
4212              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
4213              eptr += len;              eptr += len;
4214              }              }
4215            }            CHECK_PARTIAL();
         if (md->partial != 0 && eptr >= md->end_subject)  
           {  
           SCHECK_PARTIAL();  
4216            }            }
4217          }          }
4218    
# Line 4976  for (;;) Line 4997  for (;;)
4997              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
4998              eptr += len;              eptr += len;
4999              }              }
5000            if (md->partial != 0 && eptr >= md->end_subject)            CHECK_PARTIAL();
             {  
             SCHECK_PARTIAL();  
             }  
5001            }            }
5002          }          }
5003        else        else
# Line 5523  for (;;) Line 5541  for (;;)
5541              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
5542              eptr += len;              eptr += len;
5543              }              }
5544            if (eptr >= md->end_subject)            CHECK_PARTIAL();
             {  
             SCHECK_PARTIAL();  
             }  
5545            }            }
5546    
5547          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
# Line 6318  if (utf && (options & PCRE_NO_UTF8_CHECK Line 6333  if (utf && (options & PCRE_NO_UTF8_CHECK
6333  /* If the pattern was successfully studied with JIT support, run the JIT  /* If the pattern was successfully studied with JIT support, run the JIT
6334  executable instead of the rest of this function. Most options must be set at  executable instead of the rest of this function. Most options must be set at
6335  compile time for the JIT code to be usable. Fallback to the normal code path if  compile time for the JIT code to be usable. Fallback to the normal code path if
6336  an unsupported flag is set. In particular, JIT does not support partial  an unsupported flag is set. */
 matching. */  
6337    
6338  #ifdef SUPPORT_JIT  #ifdef SUPPORT_JIT
6339  if (extra_data != NULL  if (extra_data != NULL
# Line 6334  if (extra_data != NULL Line 6348  if (extra_data != NULL
6348      (const pcre_uchar *)subject, length, start_offset, options,      (const pcre_uchar *)subject, length, start_offset, options,
6349      ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)      ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)
6350      ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount);      ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount);
6351    
6352    /* PCRE_ERROR_NULL means that the selected normal or partial matching    /* PCRE_ERROR_NULL means that the selected normal or partial matching
6353    mode is not compiled. In this case we simply fallback to interpreter. */    mode is not compiled. In this case we simply fallback to interpreter. */
6354    if (rc != PCRE_ERROR_NULL)  
6355      return rc;    if (rc != PCRE_ERROR_NULL) return rc;
6356    }    }
6357  #endif  #endif
6358    

Legend:
Removed from v.915  
changed lines
  Added in v.916

  ViewVC Help
Powered by ViewVC 1.1.5