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

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

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

revision 459 by ph10, Sun Oct 4 09:21:39 2009 UTC revision 602 by ph10, Wed May 25 08:29:03 2011 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2009 University of Cambridge             Copyright (c) 1997-2010 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 48  supporting functions. */ Line 48  supporting functions. */
48    
49  #include "pcre_internal.h"  #include "pcre_internal.h"
50    
51    #define SET_BIT(c) start_bits[c/8] |= (1 << (c&7))
52    
53  /* Returns from set_start_bits() */  /* Returns from set_start_bits() */
54    
# Line 60  enum { SSB_FAIL, SSB_DONE, SSB_CONTINUE Line 61  enum { SSB_FAIL, SSB_DONE, SSB_CONTINUE
61  *************************************************/  *************************************************/
62    
63  /* Scan a parenthesized group and compute the minimum length of subject that  /* Scan a parenthesized group and compute the minimum length of subject that
64  is needed to match it. This is a lower bound; it does not mean there is a  is needed to match it. This is a lower bound; it does not mean there is a
65  string of that length that matches. In UTF8 mode, the result is in characters  string of that length that matches. In UTF8 mode, the result is in characters
66  rather than bytes.  rather than bytes.
67    
68  Arguments:  Arguments:
69    code       pointer to start of group (the bracket)    code       pointer to start of group (the bracket)
70    startcode  pointer to start of the whole pattern    startcode  pointer to start of the whole pattern
71    options    the compiling options    options    the compiling options
72    
73  Returns:   the minimum length  Returns:   the minimum length
74             -1 if \C was encountered             -1 if \C was encountered
75             -2 internal error (missing capturing bracket)             -2 internal error (missing capturing bracket)
76  */  */
77    
78  static int  static int
# Line 91  branch, check the length against that of Line 92  branch, check the length against that of
92  for (;;)  for (;;)
93    {    {
94    int d, min;    int d, min;
95    uschar *cs, *ce;    uschar *cs, *ce;
96    register int op = *cc;    register int op = *cc;
97    
98    switch (op)    switch (op)
99      {      {
100        case OP_COND:
101        case OP_SCOND:
102    
103        /* If there is only one branch in a condition, the implied branch has zero
104        length, so we don't add anything. This covers the DEFINE "condition"
105        automatically. */
106    
107        cs = cc + GET(cc, 1);
108        if (*cs != OP_ALT)
109          {
110          cc = cs + 1 + LINK_SIZE;
111          break;
112          }
113    
114        /* Otherwise we can fall through and treat it the same as any other
115        subpattern. */
116    
117      case OP_CBRA:      case OP_CBRA:
118      case OP_SCBRA:      case OP_SCBRA:
119      case OP_BRA:      case OP_BRA:
120      case OP_SBRA:      case OP_SBRA:
121      case OP_ONCE:      case OP_ONCE:
     case OP_COND:  
     case OP_SCOND:  
122      d = find_minlength(cc, startcode, options);      d = find_minlength(cc, startcode, options);
123      if (d < 0) return d;      if (d < 0) return d;
124      branchlength += d;      branchlength += d;
# Line 119  for (;;) Line 135  for (;;)
135      case OP_KETRMAX:      case OP_KETRMAX:
136      case OP_KETRMIN:      case OP_KETRMIN:
137      case OP_END:      case OP_END:
138      if (length < 0 || (!had_recurse && branchlength < length))      if (length < 0 || (!had_recurse && branchlength < length))
139        length = branchlength;        length = branchlength;
140      if (*cc != OP_ALT) return length;      if (*cc != OP_ALT) return length;
141      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
142      branchlength = 0;      branchlength = 0;
143      had_recurse = FALSE;      had_recurse = FALSE;
144      break;      break;
145    
146      /* Skip over assertive subpatterns */      /* Skip over assertive subpatterns */
# Line 144  for (;;) Line 160  for (;;)
160      case OP_RREF:      case OP_RREF:
161      case OP_NRREF:      case OP_NRREF:
162      case OP_DEF:      case OP_DEF:
     case OP_OPT:  
163      case OP_CALLOUT:      case OP_CALLOUT:
164      case OP_SOD:      case OP_SOD:
165      case OP_SOM:      case OP_SOM:
166      case OP_EOD:      case OP_EOD:
167      case OP_EODN:      case OP_EODN:
168      case OP_CIRC:      case OP_CIRC:
169        case OP_CIRCM:
170      case OP_DOLL:      case OP_DOLL:
171        case OP_DOLLM:
172      case OP_NOT_WORD_BOUNDARY:      case OP_NOT_WORD_BOUNDARY:
173      case OP_WORD_BOUNDARY:      case OP_WORD_BOUNDARY:
174      cc += _pcre_OP_lengths[*cc];      cc += _pcre_OP_lengths[*cc];
175      break;      break;
176    
177      /* Skip over a subpattern that has a {0} or {0,x} quantifier */      /* Skip over a subpattern that has a {0} or {0,x} quantifier */
178    
179      case OP_BRAZERO:      case OP_BRAZERO:
180      case OP_BRAMINZERO:      case OP_BRAMINZERO:
181      case OP_SKIPZERO:      case OP_SKIPZERO:
182      cc += _pcre_OP_lengths[*cc];      cc += _pcre_OP_lengths[*cc];
183      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 170  for (;;) Line 187  for (;;)
187      /* Handle literal characters and + repetitions */      /* Handle literal characters and + repetitions */
188    
189      case OP_CHAR:      case OP_CHAR:
190      case OP_CHARNC:      case OP_CHARI:
191      case OP_NOT:      case OP_NOT:
192        case OP_NOTI:
193      case OP_PLUS:      case OP_PLUS:
194      case OP_MINPLUS:      case OP_MINPLUS:
195      case OP_POSPLUS:      case OP_POSPLUS:
# Line 184  for (;;) Line 202  for (;;)
202      if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];      if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];
203  #endif  #endif
204      break;      break;
205    
206      case OP_TYPEPLUS:      case OP_TYPEPLUS:
207      case OP_TYPEMINPLUS:      case OP_TYPEMINPLUS:
208      case OP_TYPEPOSPLUS:      case OP_TYPEPOSPLUS:
209      branchlength++;      branchlength++;
210      cc += (cc[1] == OP_PROP || cc[1] == OP_NOTPROP)? 4 : 2;      cc += (cc[1] == OP_PROP || cc[1] == OP_NOTPROP)? 4 : 2;
211      break;      break;
# Line 196  for (;;) Line 214  for (;;)
214      need to skip over a multibyte character in UTF8 mode.  */      need to skip over a multibyte character in UTF8 mode.  */
215    
216      case OP_EXACT:      case OP_EXACT:
217      case OP_NOTEXACT:      case OP_NOTEXACT:
218      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
219      cc += 4;      cc += 4;
220  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 225  for (;;) Line 243  for (;;)
243      case OP_ANY:      case OP_ANY:
244      case OP_ALLANY:      case OP_ALLANY:
245      case OP_EXTUNI:      case OP_EXTUNI:
246      case OP_HSPACE:      case OP_HSPACE:
247      case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
248      case OP_VSPACE:      case OP_VSPACE:
249      case OP_NOT_VSPACE:      case OP_NOT_VSPACE:
250      branchlength++;      branchlength++;
251      cc++;      cc++;
252      break;      break;
253    
254      /* "Any newline" might match two characters */      /* "Any newline" might match two characters */
255    
256      case OP_ANYNL:      case OP_ANYNL:
257      branchlength += 2;      branchlength += 2;
258      cc++;      cc++;
259      break;      break;
260    
261      /* The single-byte matcher means we can't proceed in UTF-8 mode */      /* The single-byte matcher means we can't proceed in UTF-8 mode */
262    
# Line 248  for (;;) Line 266  for (;;)
266  #endif  #endif
267      branchlength++;      branchlength++;
268      cc++;      cc++;
269      break;      break;
270    
271      /* For repeated character types, we have to test for \p and \P, which have      /* For repeated character types, we have to test for \p and \P, which have
272      an extra two bytes of parameters. */      an extra two bytes of parameters. */
# Line 287  for (;;) Line 305  for (;;)
305        case OP_CRPLUS:        case OP_CRPLUS:
306        case OP_CRMINPLUS:        case OP_CRMINPLUS:
307        branchlength++;        branchlength++;
308        /* Fall through */        /* Fall through */
309    
310        case OP_CRSTAR:        case OP_CRSTAR:
311        case OP_CRMINSTAR:        case OP_CRMINSTAR:
312        case OP_CRQUERY:        case OP_CRQUERY:
313        case OP_CRMINQUERY:        case OP_CRMINQUERY:
314        cc++;        cc++;
315        break;        break;
316    
317        case OP_CRRANGE:        case OP_CRRANGE:
318        case OP_CRMINRANGE:        case OP_CRMINRANGE:
319        branchlength += GET2(cc,1);        branchlength += GET2(cc,1);
320        cc += 5;        cc += 5;
321        break;        break;
322    
323        default:        default:
324        branchlength++;        branchlength++;
325        break;        break;
326        }        }
327      break;      break;
328    
329      /* Backreferences and subroutine calls are treated in the same way: we find      /* Backreferences and subroutine calls are treated in the same way: we find
330      the minimum length for the subpattern. A recursion, however, causes an      the minimum length for the subpattern. A recursion, however, causes an
331      a flag to be set that causes the length of this branch to be ignored. The      a flag to be set that causes the length of this branch to be ignored. The
332      logic is that a recursion can only make sense if there is another      logic is that a recursion can only make sense if there is another
333      alternation that stops the recursing. That will provide the minimum length      alternation that stops the recursing. That will provide the minimum length
334      (when no recursion happens). A backreference within the group that it is      (when no recursion happens). A backreference within the group that it is
335      referencing behaves in the same way. */      referencing behaves in the same way.
336    
337        If PCRE_JAVASCRIPT_COMPAT is set, a backreference to an unset bracket
338        matches an empty string (by default it causes a matching failure), so in
339        that case we must set the minimum length to zero. */
340    
341      case OP_REF:      case OP_REF:
342      ce = cs = (uschar *)_pcre_find_bracket(startcode, utf8, GET2(cc, 1));      case OP_REFI:
343      if (cs == NULL) return -2;      if ((options & PCRE_JAVASCRIPT_COMPAT) == 0)
     do ce += GET(ce, 1); while (*ce == OP_ALT);  
     if (cc > cs && cc < ce)  
344        {        {
345        d = 0;        ce = cs = (uschar *)_pcre_find_bracket(startcode, utf8, GET2(cc, 1));
346        had_recurse = TRUE;        if (cs == NULL) return -2;
347        }        do ce += GET(ce, 1); while (*ce == OP_ALT);
348      else d = find_minlength(cs, startcode, options);        if (cc > cs && cc < ce)
349      cc += 3;          {
350            d = 0;
351            had_recurse = TRUE;
352            }
353          else d = find_minlength(cs, startcode, options);
354          }
355        else d = 0;
356        cc += 3;
357    
358      /* Handle repeated back references */      /* Handle repeated back references */
359    
360      switch (*cc)      switch (*cc)
361        {        {
362        case OP_CRSTAR:        case OP_CRSTAR:
# Line 339  for (;;) Line 366  for (;;)
366        min = 0;        min = 0;
367        cc++;        cc++;
368        break;        break;
369    
370        case OP_CRRANGE:        case OP_CRRANGE:
371        case OP_CRMINRANGE:        case OP_CRMINRANGE:
372        min = GET2(cc, 1);        min = GET2(cc, 1);
373        cc += 5;        cc += 5;
374        break;        break;
375    
376        default:        default:
377        min = 1;        min = 1;
378        break;        break;
379        }        }
380    
381      branchlength += min * d;      branchlength += min * d;
382      break;      break;
383    
384      case OP_RECURSE:      case OP_RECURSE:
385      cs = ce = (uschar *)startcode + GET(cc, 1);      cs = ce = (uschar *)startcode + GET(cc, 1);
386      if (cs == NULL) return -2;      if (cs == NULL) return -2;
387      do ce += GET(ce, 1); while (*ce == OP_ALT);      do ce += GET(ce, 1); while (*ce == OP_ALT);
388      if (cc > cs && cc < ce)      if (cc > cs && cc < ce)
389        had_recurse = TRUE;        had_recurse = TRUE;
390      else      else
391        branchlength += find_minlength(cs, startcode, options);        branchlength += find_minlength(cs, startcode, options);
392      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
393      break;      break;
394    
395      /* Anything else does not or need not match a character. We can get the      /* Anything else does not or need not match a character. We can get the
396      item's length from the table, but for those that can match zero occurrences      item's length from the table, but for those that can match zero occurrences
397      of a character, we must take special action for UTF-8 characters. */      of a character, we must take special action for UTF-8 characters. As it
398        happens, the "NOT" versions of these opcodes are used at present only for
399        ASCII characters, so they could be omitted from this list. However, in
400        future that may change, so we leave them in this special case. */
401    
402      case OP_UPTO:      case OP_UPTO:
403      case OP_NOTUPTO:      case OP_UPTOI:
404        case OP_NOTUPTO:
405        case OP_NOTUPTOI:
406      case OP_MINUPTO:      case OP_MINUPTO:
407      case OP_NOTMINUPTO:      case OP_MINUPTOI:
408        case OP_NOTMINUPTO:
409        case OP_NOTMINUPTOI:
410      case OP_POSUPTO:      case OP_POSUPTO:
411        case OP_POSUPTOI:
412        case OP_NOTPOSUPTO:
413        case OP_NOTPOSUPTOI:
414    
415      case OP_STAR:      case OP_STAR:
416        case OP_STARI:
417        case OP_NOTSTAR:
418        case OP_NOTSTARI:
419      case OP_MINSTAR:      case OP_MINSTAR:
420      case OP_NOTMINSTAR:      case OP_MINSTARI:
421        case OP_NOTMINSTAR:
422        case OP_NOTMINSTARI:
423      case OP_POSSTAR:      case OP_POSSTAR:
424      case OP_NOTPOSSTAR:      case OP_POSSTARI:
425        case OP_NOTPOSSTAR:
426        case OP_NOTPOSSTARI:
427    
428      case OP_QUERY:      case OP_QUERY:
429        case OP_QUERYI:
430        case OP_NOTQUERY:
431        case OP_NOTQUERYI:
432      case OP_MINQUERY:      case OP_MINQUERY:
433        case OP_MINQUERYI:
434      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
435        case OP_NOTMINQUERYI:
436      case OP_POSQUERY:      case OP_POSQUERY:
437      case OP_NOTPOSQUERY:      case OP_POSQUERYI:
438        case OP_NOTPOSQUERY:
439        case OP_NOTPOSQUERYI:
440    
441      cc += _pcre_OP_lengths[op];      cc += _pcre_OP_lengths[op];
442  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
443      if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];      if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];
444  #endif  #endif
445        break;
446    
447        /* Skip these, but we need to add in the name length. */
448    
449        case OP_MARK:
450        case OP_PRUNE_ARG:
451        case OP_SKIP_ARG:
452        cc += _pcre_OP_lengths[op] + cc[1];
453        break;
454    
455        case OP_THEN_ARG:
456        cc += _pcre_OP_lengths[op] + cc[1+LINK_SIZE];
457      break;      break;
458    
459      /* For the record, these are the opcodes that are matched by "default":      /* For the record, these are the opcodes that are matched by "default":
460      OP_ACCEPT, OP_CLOSE, OP_COMMIT, OP_FAIL, OP_PRUNE, OP_SET_SOM, OP_SKIP,      OP_ACCEPT, OP_CLOSE, OP_COMMIT, OP_FAIL, OP_PRUNE, OP_SET_SOM, OP_SKIP,
461      OP_THEN. */      OP_THEN. */
462    
463      default:      default:
464      cc += _pcre_OP_lengths[op];      cc += _pcre_OP_lengths[op];
465      break;      break;
# Line 408  for (;;) Line 474  for (;;)
474  *      Set a bit and maybe its alternate case    *  *      Set a bit and maybe its alternate case    *
475  *************************************************/  *************************************************/
476    
477  /* Given a character, set its bit in the table, and also the bit for the other  /* Given a character, set its first byte's bit in the table, and also the
478  version of a letter if we are caseless.  corresponding bit for the other version of a letter if we are caseless. In
479    UTF-8 mode, for characters greater than 127, we can only do the caseless thing
480    when Unicode property support is available.
481    
482  Arguments:  Arguments:
483    start_bits    points to the bit map    start_bits    points to the bit map
484    c             is the character    p             points to the character
485    caseless      the caseless flag    caseless      the caseless flag
486    cd            the block with char table pointers    cd            the block with char table pointers
487      utf8          TRUE for UTF-8 mode
488    
489    Returns:        pointer after the character
490    */
491    
492    static const uschar *
493    set_table_bit(uschar *start_bits, const uschar *p, BOOL caseless,
494      compile_data *cd, BOOL utf8)
495    {
496    unsigned int c = *p;
497    
498    SET_BIT(c);
499    
500    #ifdef SUPPORT_UTF8
501    if (utf8 && c > 127)
502      {
503      GETCHARINC(c, p);
504    #ifdef SUPPORT_UCP
505      if (caseless)
506        {
507        uschar buff[8];
508        c = UCD_OTHERCASE(c);
509        (void)_pcre_ord2utf8(c, buff);
510        SET_BIT(buff[0]);
511        }
512    #endif
513      return p;
514      }
515    #endif
516    
517    /* Not UTF-8 mode, or character is less than 127. */
518    
519    if (caseless && (cd->ctypes[c] & ctype_letter) != 0) SET_BIT(cd->fcc[c]);
520    return p + 1;
521    }
522    
523    
524    
525    /*************************************************
526    *     Set bits for a positive character type     *
527    *************************************************/
528    
529    /* This function sets starting bits for a character type. In UTF-8 mode, we can
530    only do a direct setting for bytes less than 128, as otherwise there can be
531    confusion with bytes in the middle of UTF-8 characters. In a "traditional"
532    environment, the tables will only recognize ASCII characters anyway, but in at
533    least one Windows environment, some higher bytes bits were set in the tables.
534    So we deal with that case by considering the UTF-8 encoding.
535    
536    Arguments:
537      start_bits     the starting bitmap
538      cbit type      the type of character wanted
539      table_limit    32 for non-UTF-8; 16 for UTF-8
540      cd             the block with char table pointers
541    
542    Returns:         nothing
543    */
544    
545  Returns:        nothing  static void
546    set_type_bits(uschar *start_bits, int cbit_type, int table_limit,
547      compile_data *cd)
548    {
549    register int c;
550    for (c = 0; c < table_limit; c++) start_bits[c] |= cd->cbits[c+cbit_type];
551    if (table_limit == 32) return;
552    for (c = 128; c < 256; c++)
553      {
554      if ((cd->cbits[c/8] & (1 << (c&7))) != 0)
555        {
556        uschar buff[8];
557        (void)_pcre_ord2utf8(c, buff);
558        SET_BIT(buff[0]);
559        }
560      }
561    }
562    
563    
564    /*************************************************
565    *     Set bits for a negative character type     *
566    *************************************************/
567    
568    /* This function sets starting bits for a negative character type such as \D.
569    In UTF-8 mode, we can only do a direct setting for bytes less than 128, as
570    otherwise there can be confusion with bytes in the middle of UTF-8 characters.
571    Unlike in the positive case, where we can set appropriate starting bits for
572    specific high-valued UTF-8 characters, in this case we have to set the bits for
573    all high-valued characters. The lowest is 0xc2, but we overkill by starting at
574    0xc0 (192) for simplicity.
575    
576    Arguments:
577      start_bits     the starting bitmap
578      cbit type      the type of character wanted
579      table_limit    32 for non-UTF-8; 16 for UTF-8
580      cd             the block with char table pointers
581    
582    Returns:         nothing
583  */  */
584    
585  static void  static void
586  set_bit(uschar *start_bits, unsigned int c, BOOL caseless, compile_data *cd)  set_nottype_bits(uschar *start_bits, int cbit_type, int table_limit,
587      compile_data *cd)
588  {  {
589  start_bits[c/8] |= (1 << (c&7));  register int c;
590  if (caseless && (cd->ctypes[c] & ctype_letter) != 0)  for (c = 0; c < table_limit; c++) start_bits[c] |= ~cd->cbits[c+cbit_type];
591    start_bits[cd->fcc[c]/8] |= (1 << (cd->fcc[c]&7));  if (table_limit != 32) for (c = 24; c < 32; c++) start_bits[c] = 0xff;
592  }  }
593    
594    
# Line 460  set_start_bits(const uschar *code, uscha Line 623  set_start_bits(const uschar *code, uscha
623  {  {
624  register int c;  register int c;
625  int yield = SSB_DONE;  int yield = SSB_DONE;
626    int table_limit = utf8? 16:32;
627    
628  #if 0  #if 0
629  /* ========================================================================= */  /* ========================================================================= */
# Line 545  do Line 709  do
709        tcode += 1 + LINK_SIZE;        tcode += 1 + LINK_SIZE;
710        break;        break;
711    
       /* Skip over an option setting, changing the caseless flag */  
   
       case OP_OPT:  
       caseless = (tcode[1] & PCRE_CASELESS) != 0;  
       tcode += 2;  
       break;  
   
712        /* BRAZERO does the bracket, but carries on. */        /* BRAZERO does the bracket, but carries on. */
713    
714        case OP_BRAZERO:        case OP_BRAZERO:
# Line 583  do Line 740  do
740        case OP_QUERY:        case OP_QUERY:
741        case OP_MINQUERY:        case OP_MINQUERY:
742        case OP_POSQUERY:        case OP_POSQUERY:
743        set_bit(start_bits, tcode[1], caseless, cd);        tcode = set_table_bit(start_bits, tcode + 1, caseless, cd, utf8);
744        tcode += 2;        break;
745  #ifdef SUPPORT_UTF8  
746        if (utf8 && tcode[-1] >= 0xc0)        case OP_STARI:
747          tcode += _pcre_utf8_table4[tcode[-1] & 0x3f];        case OP_MINSTARI:
748  #endif        case OP_POSSTARI:
749          case OP_QUERYI:
750          case OP_MINQUERYI:
751          case OP_POSQUERYI:
752          tcode = set_table_bit(start_bits, tcode + 1, TRUE, cd, utf8);
753        break;        break;
754    
755        /* Single-char upto sets the bit and tries the next */        /* Single-char upto sets the bit and tries the next */
# Line 596  do Line 757  do
757        case OP_UPTO:        case OP_UPTO:
758        case OP_MINUPTO:        case OP_MINUPTO:
759        case OP_POSUPTO:        case OP_POSUPTO:
760        set_bit(start_bits, tcode[3], caseless, cd);        tcode = set_table_bit(start_bits, tcode + 3, caseless, cd, utf8);
761        tcode += 4;        break;
762  #ifdef SUPPORT_UTF8  
763        if (utf8 && tcode[-1] >= 0xc0)        case OP_UPTOI:
764          tcode += _pcre_utf8_table4[tcode[-1] & 0x3f];        case OP_MINUPTOI:
765  #endif        case OP_POSUPTOI:
766          tcode = set_table_bit(start_bits, tcode + 3, TRUE, cd, utf8);
767        break;        break;
768    
769        /* At least one single char sets the bit and stops */        /* At least one single char sets the bit and stops */
770    
771        case OP_EXACT:       /* Fall through */        case OP_EXACT:
772        tcode += 2;        tcode += 2;
773          /* Fall through */
774        case OP_CHAR:        case OP_CHAR:
       case OP_CHARNC:  
775        case OP_PLUS:        case OP_PLUS:
776        case OP_MINPLUS:        case OP_MINPLUS:
777        case OP_POSPLUS:        case OP_POSPLUS:
778        set_bit(start_bits, tcode[1], caseless, cd);        (void)set_table_bit(start_bits, tcode + 1, caseless, cd, utf8);
779          try_next = FALSE;
780          break;
781    
782          case OP_CHARI:
783          case OP_PLUSI:
784          case OP_MINPLUSI:
785          case OP_POSPLUSI:
786          (void)set_table_bit(start_bits, tcode + 1, TRUE, cd, utf8);
787          try_next = FALSE;
788          break;
789    
790          /* Special spacing and line-terminating items. These recognize specific
791          lists of characters. The difference between VSPACE and ANYNL is that the
792          latter can match the two-character CRLF sequence, but that is not
793          relevant for finding the first character, so their code here is
794          identical. */
795    
796          case OP_HSPACE:
797          SET_BIT(0x09);
798          SET_BIT(0x20);
799          if (utf8)
800            {
801            SET_BIT(0xC2);  /* For U+00A0 */
802            SET_BIT(0xE1);  /* For U+1680, U+180E */
803            SET_BIT(0xE2);  /* For U+2000 - U+200A, U+202F, U+205F */
804            SET_BIT(0xE3);  /* For U+3000 */
805            }
806          else SET_BIT(0xA0);
807          try_next = FALSE;
808          break;
809    
810          case OP_ANYNL:
811          case OP_VSPACE:
812          SET_BIT(0x0A);
813          SET_BIT(0x0B);
814          SET_BIT(0x0C);
815          SET_BIT(0x0D);
816          if (utf8)
817            {
818            SET_BIT(0xC2);  /* For U+0085 */
819            SET_BIT(0xE2);  /* For U+2028, U+2029 */
820            }
821          else SET_BIT(0x85);
822        try_next = FALSE;        try_next = FALSE;
823        break;        break;
824    
825        /* Single character type sets the bits and stops */        /* Single character types set the bits and stop. Note that if PCRE_UCP
826          is set, we do not see these op codes because \d etc are converted to
827          properties. Therefore, these apply in the case when only characters less
828          than 256 are recognized to match the types. */
829    
830        case OP_NOT_DIGIT:        case OP_NOT_DIGIT:
831        for (c = 0; c < 32; c++)        set_nottype_bits(start_bits, cbit_digit, table_limit, cd);
         start_bits[c] |= ~cd->cbits[c+cbit_digit];  
832        try_next = FALSE;        try_next = FALSE;
833        break;        break;
834    
835        case OP_DIGIT:        case OP_DIGIT:
836        for (c = 0; c < 32; c++)        set_type_bits(start_bits, cbit_digit, table_limit, cd);
         start_bits[c] |= cd->cbits[c+cbit_digit];  
837        try_next = FALSE;        try_next = FALSE;
838        break;        break;
839    
840        /* The cbit_space table has vertical tab as whitespace; we have to        /* The cbit_space table has vertical tab as whitespace; we have to
841        discard it. */        ensure it is set as not whitespace. */
842    
843        case OP_NOT_WHITESPACE:        case OP_NOT_WHITESPACE:
844        for (c = 0; c < 32; c++)        set_nottype_bits(start_bits, cbit_space, table_limit, cd);
845          {        start_bits[1] |= 0x08;
         int d = cd->cbits[c+cbit_space];  
         if (c == 1) d &= ~0x08;  
         start_bits[c] |= ~d;  
         }  
846        try_next = FALSE;        try_next = FALSE;
847        break;        break;
848    
849        /* The cbit_space table has vertical tab as whitespace; we have to        /* The cbit_space table has vertical tab as whitespace; we have to
850        discard it. */        not set it from the table. */
851    
852        case OP_WHITESPACE:        case OP_WHITESPACE:
853        for (c = 0; c < 32; c++)        c = start_bits[1];    /* Save in case it was already set */
854          {        set_type_bits(start_bits, cbit_space, table_limit, cd);
855          int d = cd->cbits[c+cbit_space];        start_bits[1] = (start_bits[1] & ~0x08) | c;
         if (c == 1) d &= ~0x08;  
         start_bits[c] |= d;  
         }  
856        try_next = FALSE;        try_next = FALSE;
857        break;        break;
858    
859        case OP_NOT_WORDCHAR:        case OP_NOT_WORDCHAR:
860        for (c = 0; c < 32; c++)        set_nottype_bits(start_bits, cbit_word, table_limit, cd);
         start_bits[c] |= ~cd->cbits[c+cbit_word];  
861        try_next = FALSE;        try_next = FALSE;
862        break;        break;
863    
864        case OP_WORDCHAR:        case OP_WORDCHAR:
865        for (c = 0; c < 32; c++)        set_type_bits(start_bits, cbit_word, table_limit, cd);
         start_bits[c] |= cd->cbits[c+cbit_word];  
866        try_next = FALSE;        try_next = FALSE;
867        break;        break;
868    
# Line 675  do Line 871  do
871    
872        case OP_TYPEPLUS:        case OP_TYPEPLUS:
873        case OP_TYPEMINPLUS:        case OP_TYPEMINPLUS:
874          case OP_TYPEPOSPLUS:
875        tcode++;        tcode++;
876        break;        break;
877    
# Line 698  do Line 895  do
895        case OP_TYPEPOSQUERY:        case OP_TYPEPOSQUERY:
896        switch(tcode[1])        switch(tcode[1])
897          {          {
898            default:
899          case OP_ANY:          case OP_ANY:
900          case OP_ALLANY:          case OP_ALLANY:
901          return SSB_FAIL;          return SSB_FAIL;
902    
903            case OP_HSPACE:
904            SET_BIT(0x09);
905            SET_BIT(0x20);
906            if (utf8)
907              {
908              SET_BIT(0xC2);  /* For U+00A0 */
909              SET_BIT(0xE1);  /* For U+1680, U+180E */
910              SET_BIT(0xE2);  /* For U+2000 - U+200A, U+202F, U+205F */
911              SET_BIT(0xE3);  /* For U+3000 */
912              }
913            else SET_BIT(0xA0);
914            break;
915    
916            case OP_ANYNL:
917            case OP_VSPACE:
918            SET_BIT(0x0A);
919            SET_BIT(0x0B);
920            SET_BIT(0x0C);
921            SET_BIT(0x0D);
922            if (utf8)
923              {
924              SET_BIT(0xC2);  /* For U+0085 */
925              SET_BIT(0xE2);  /* For U+2028, U+2029 */
926              }
927            else SET_BIT(0x85);
928            break;
929    
930          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
931          for (c = 0; c < 32; c++)          set_nottype_bits(start_bits, cbit_digit, table_limit, cd);
           start_bits[c] |= ~cd->cbits[c+cbit_digit];  
932          break;          break;
933    
934          case OP_DIGIT:          case OP_DIGIT:
935          for (c = 0; c < 32; c++)          set_type_bits(start_bits, cbit_digit, table_limit, cd);
           start_bits[c] |= cd->cbits[c+cbit_digit];  
936          break;          break;
937    
938          /* The cbit_space table has vertical tab as whitespace; we have to          /* The cbit_space table has vertical tab as whitespace; we have to
939          discard it. */          ensure it gets set as not whitespace. */
940    
941          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
942          for (c = 0; c < 32; c++)          set_nottype_bits(start_bits, cbit_space, table_limit, cd);
943            {          start_bits[1] |= 0x08;
           int d = cd->cbits[c+cbit_space];  
           if (c == 1) d &= ~0x08;  
           start_bits[c] |= ~d;  
           }  
944          break;          break;
945    
946          /* The cbit_space table has vertical tab as whitespace; we have to          /* The cbit_space table has vertical tab as whitespace; we have to
947          discard it. */          avoid setting it. */
948    
949          case OP_WHITESPACE:          case OP_WHITESPACE:
950          for (c = 0; c < 32; c++)          c = start_bits[1];    /* Save in case it was already set */
951            {          set_type_bits(start_bits, cbit_space, table_limit, cd);
952            int d = cd->cbits[c+cbit_space];          start_bits[1] = (start_bits[1] & ~0x08) | c;
           if (c == 1) d &= ~0x08;  
           start_bits[c] |= d;  
           }  
953          break;          break;
954    
955          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
956          for (c = 0; c < 32; c++)          set_nottype_bits(start_bits, cbit_word, table_limit, cd);
           start_bits[c] |= ~cd->cbits[c+cbit_word];  
957          break;          break;
958    
959          case OP_WORDCHAR:          case OP_WORDCHAR:
960          for (c = 0; c < 32; c++)          set_type_bits(start_bits, cbit_word, table_limit, cd);
           start_bits[c] |= cd->cbits[c+cbit_word];  
961          break;          break;
962          }          }
963    
# Line 885  code = (uschar *)re + re->name_table_off Line 1099  code = (uschar *)re + re->name_table_off
1099    (re->name_count * re->name_entry_size);    (re->name_count * re->name_entry_size);
1100    
1101  /* For an anchored pattern, or an unanchored pattern that has a first char, or  /* For an anchored pattern, or an unanchored pattern that has a first char, or
1102  a multiline pattern that matches only at "line starts", there is no point in  a multiline pattern that matches only at "line starts", there is no point in
1103  seeking a list of starting bytes. */  seeking a list of starting bytes. */
1104    
1105  if ((re->options & PCRE_ANCHORED) == 0 &&  if ((re->options & PCRE_ANCHORED) == 0 &&
1106      (re->flags & (PCRE_FIRSTSET|PCRE_STARTLINE)) == 0)      (re->flags & (PCRE_FIRSTSET|PCRE_STARTLINE)) == 0)
1107    {    {
1108    /* Set the character tables in the block that is passed around */    /* Set the character tables in the block that is passed around */
1109    
1110    tables = re->tables;    tables = re->tables;
1111    if (tables == NULL)    if (tables == NULL)
1112      (void)pcre_fullinfo(external_re, NULL, PCRE_INFO_DEFAULT_TABLES,      (void)pcre_fullinfo(external_re, NULL, PCRE_INFO_DEFAULT_TABLES,
1113      (void *)(&tables));      (void *)(&tables));
1114    
1115    compile_block.lcc = tables + lcc_offset;    compile_block.lcc = tables + lcc_offset;
1116    compile_block.fcc = tables + fcc_offset;    compile_block.fcc = tables + fcc_offset;
1117    compile_block.cbits = tables + cbits_offset;    compile_block.cbits = tables + cbits_offset;
1118    compile_block.ctypes = tables + ctypes_offset;    compile_block.ctypes = tables + ctypes_offset;
1119    
1120    /* See if we can find a fixed set of initial characters for the pattern. */    /* See if we can find a fixed set of initial characters for the pattern. */
1121    
1122    memset(start_bits, 0, 32 * sizeof(uschar));    memset(start_bits, 0, 32 * sizeof(uschar));
1123    bits_set = set_start_bits(code, start_bits,    bits_set = set_start_bits(code, start_bits,
1124      (re->options & PCRE_CASELESS) != 0, (re->options & PCRE_UTF8) != 0,      (re->options & PCRE_CASELESS) != 0, (re->options & PCRE_UTF8) != 0,
1125      &compile_block) == SSB_DONE;      &compile_block) == SSB_DONE;
1126    }    }
1127    
1128  /* Find the minimum length of subject string. */  /* Find the minimum length of subject string. */
1129    
1130  min = find_minlength(code, code, re->options);  min = find_minlength(code, code, re->options);
# Line 947  if (bits_set) Line 1161  if (bits_set)
1161    study->flags |= PCRE_STUDY_MAPPED;    study->flags |= PCRE_STUDY_MAPPED;
1162    memcpy(study->start_bits, start_bits, sizeof(start_bits));    memcpy(study->start_bits, start_bits, sizeof(start_bits));
1163    }    }
1164    
1165  if (min >= 0)  if (min >= 0)
1166    {    {
1167    study->flags |= PCRE_STUDY_MINLEN;    study->flags |= PCRE_STUDY_MINLEN;
1168    study->minlength = min;    study->minlength = min;
1169    }    }
1170    
1171  return extra;  return extra;
1172  }  }

Legend:
Removed from v.459  
changed lines
  Added in v.602

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12