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

Diff of /code/trunk/pcre_study.c

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

revision 1221 by ph10, Sun Nov 11 20:27:03 2012 UTC revision 1361 by ph10, Fri Sep 6 17:47:32 2013 UTC
# Line 66  string of that length that matches. In U Line 66  string of that length that matches. In U
66  rather than bytes.  rather than bytes.
67    
68  Arguments:  Arguments:
69      re              compiled pattern block
70    code            pointer to start of group (the bracket)    code            pointer to start of group (the bracket)
71    startcode       pointer to start of the whole pattern    startcode       pointer to start of the whole pattern's code
72    options         the compiling options    options         the compiling options
73    int             RECURSE depth    int             RECURSE depth
74    
# Line 78  Returns:   the minimum length Line 79  Returns:   the minimum length
79  */  */
80    
81  static int  static int
82  find_minlength(const pcre_uchar *code, const pcre_uchar *startcode, int options,  find_minlength(const REAL_PCRE *re, const pcre_uchar *code,
83    int recurse_depth)    const pcre_uchar *startcode, int options, int recurse_depth)
84  {  {
85  int length = -1;  int length = -1;
86  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
# Line 129  for (;;) Line 130  for (;;)
130      case OP_SBRAPOS:      case OP_SBRAPOS:
131      case OP_ONCE:      case OP_ONCE:
132      case OP_ONCE_NC:      case OP_ONCE_NC:
133      d = find_minlength(cc, startcode, options, recurse_depth);      d = find_minlength(re, cc, startcode, options, recurse_depth);
134      if (d < 0) return d;      if (d < 0) return d;
135      branchlength += d;      branchlength += d;
136      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 374  for (;;) Line 375  for (;;)
375      If PCRE_JAVASCRIPT_COMPAT is set, a backreference to an unset bracket      If PCRE_JAVASCRIPT_COMPAT is set, a backreference to an unset bracket
376      matches an empty string (by default it causes a matching failure), so in      matches an empty string (by default it causes a matching failure), so in
377      that case we must set the minimum length to zero. */      that case we must set the minimum length to zero. */
378    
379        case OP_DNREF:     /* Duplicate named pattern back reference */
380        case OP_DNREFI:
381        if ((options & PCRE_JAVASCRIPT_COMPAT) == 0)
382          {
383          int count = GET2(cc, 1+IMM2_SIZE);
384          pcre_uchar *slot = (pcre_uchar *)re +
385            re->name_table_offset + GET2(cc, 1) * re->name_entry_size;
386          d = INT_MAX;
387          while (count-- > 0)
388            {
389            ce = cs = (pcre_uchar *)PRIV(find_bracket)(startcode, utf, GET2(slot, 0));
390            if (cs == NULL) return -2;
391            do ce += GET(ce, 1); while (*ce == OP_ALT);
392            if (cc > cs && cc < ce)
393              {
394              d = 0;
395              had_recurse = TRUE;
396              break;
397              }
398            else
399              {
400              int dd = find_minlength(re, cs, startcode, options, recurse_depth);
401              if (dd < d) d = dd;
402              }
403            slot += re->name_entry_size;
404            }
405          }
406        else d = 0;
407        cc += 1 + 2*IMM2_SIZE;
408        goto REPEAT_BACK_REFERENCE;
409    
410      case OP_REF:      case OP_REF:      /* Single back reference */
411      case OP_REFI:      case OP_REFI:
412      if ((options & PCRE_JAVASCRIPT_COMPAT) == 0)      if ((options & PCRE_JAVASCRIPT_COMPAT) == 0)
413        {        {
# Line 389  for (;;) Line 421  for (;;)
421          }          }
422        else        else
423          {          {
424          d = find_minlength(cs, startcode, options, recurse_depth);          d = find_minlength(re, cs, startcode, options, recurse_depth);
425          }          }
426        }        }
427      else d = 0;      else d = 0;
# Line 397  for (;;) Line 429  for (;;)
429    
430      /* Handle repeated back references */      /* Handle repeated back references */
431    
432        REPEAT_BACK_REFERENCE:
433      switch (*cc)      switch (*cc)
434        {        {
435        case OP_CRSTAR:        case OP_CRSTAR:
# Line 437  for (;;) Line 470  for (;;)
470        had_recurse = TRUE;        had_recurse = TRUE;
471      else      else
472        {        {
473        branchlength += find_minlength(cs, startcode, options, recurse_depth + 1);        branchlength += find_minlength(re, cs, startcode, options,
474            recurse_depth + 1);
475        }        }
476      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
477      break;      break;
# Line 825  do Line 859  do
859        case OP_RECURSE:        case OP_RECURSE:
860        case OP_REF:        case OP_REF:
861        case OP_REFI:        case OP_REFI:
862          case OP_DNREF:
863          case OP_DNREFI:
864        case OP_REVERSE:        case OP_REVERSE:
865        case OP_RREF:        case OP_RREF:
866        case OP_SCOND:        case OP_SCOND:
# Line 1346  pcre_uchar *code; Line 1382  pcre_uchar *code;
1382  compile_data compile_block;  compile_data compile_block;
1383  const REAL_PCRE *re = (const REAL_PCRE *)external_re;  const REAL_PCRE *re = (const REAL_PCRE *)external_re;
1384    
1385    
1386  *errorptr = NULL;  *errorptr = NULL;
1387    
1388  if (re == NULL || re->magic_number != MAGIC_NUMBER)  if (re == NULL || re->magic_number != MAGIC_NUMBER)
# Line 1422  if ((re->options & PCRE_ANCHORED) == 0 & Line 1459  if ((re->options & PCRE_ANCHORED) == 0 &
1459    
1460  /* Find the minimum length of subject string. */  /* Find the minimum length of subject string. */
1461    
1462  switch(min = find_minlength(code, code, re->options, 0))  switch(min = find_minlength(re, code, code, re->options, 0))
1463    {    {
1464    case -2: *errorptr = "internal error: missing capturing bracket"; return NULL;    case -2: *errorptr = "internal error: missing capturing bracket"; return NULL;
1465    case -3: *errorptr = "internal error: opcode not recognized"; return NULL;    case -3: *errorptr = "internal error: opcode not recognized"; return NULL;

Legend:
Removed from v.1221  
changed lines
  Added in v.1361

  ViewVC Help
Powered by ViewVC 1.1.5