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-2008 University of Cambridge |
Copyright (c) 1997-2009 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 |
158 |
|
|
159 |
if (length > md->end_subject - eptr) return FALSE; |
if (length > md->end_subject - eptr) return FALSE; |
160 |
|
|
161 |
/* Separate the caselesss case for speed */ |
/* Separate the caseless case for speed. In UTF-8 mode we can only do this |
162 |
|
properly if Unicode properties are supported. Otherwise, we can check only |
163 |
|
ASCII characters. */ |
164 |
|
|
165 |
if ((ims & PCRE_CASELESS) != 0) |
if ((ims & PCRE_CASELESS) != 0) |
166 |
{ |
{ |
167 |
|
#ifdef SUPPORT_UTF8 |
168 |
|
#ifdef SUPPORT_UCP |
169 |
|
if (md->utf8) |
170 |
|
{ |
171 |
|
USPTR endptr = eptr + length; |
172 |
|
while (eptr < endptr) |
173 |
|
{ |
174 |
|
int c, d; |
175 |
|
GETCHARINC(c, eptr); |
176 |
|
GETCHARINC(d, p); |
177 |
|
if (c != d && c != UCD_OTHERCASE(d)) return FALSE; |
178 |
|
} |
179 |
|
} |
180 |
|
else |
181 |
|
#endif |
182 |
|
#endif |
183 |
|
|
184 |
|
/* The same code works when not in UTF-8 mode and in UTF-8 mode when there |
185 |
|
is no UCP support. */ |
186 |
|
|
187 |
while (length-- > 0) |
while (length-- > 0) |
188 |
if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; |
{ if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; } |
189 |
} |
} |
190 |
|
|
191 |
|
/* In the caseful case, we can just compare the bytes, whether or not we |
192 |
|
are in UTF-8 mode. */ |
193 |
|
|
194 |
else |
else |
195 |
{ while (length-- > 0) if (*p++ != *eptr++) return FALSE; } |
{ while (length-- > 0) if (*p++ != *eptr++) return FALSE; } |
196 |
|
|
322 |
|
|
323 |
/* Function arguments that may change */ |
/* Function arguments that may change */ |
324 |
|
|
325 |
const uschar *Xeptr; |
USPTR Xeptr; |
326 |
const uschar *Xecode; |
const uschar *Xecode; |
327 |
const uschar *Xmstart; |
USPTR Xmstart; |
328 |
int Xoffset_top; |
int Xoffset_top; |
329 |
long int Xims; |
long int Xims; |
330 |
eptrblock *Xeptrb; |
eptrblock *Xeptrb; |
333 |
|
|
334 |
/* Function local variables */ |
/* Function local variables */ |
335 |
|
|
336 |
const uschar *Xcallpat; |
USPTR Xcallpat; |
337 |
const uschar *Xcharptr; |
#ifdef SUPPORT_UTF8 |
338 |
const uschar *Xdata; |
USPTR Xcharptr; |
339 |
const uschar *Xnext; |
#endif |
340 |
const uschar *Xpp; |
USPTR Xdata; |
341 |
const uschar *Xprev; |
USPTR Xnext; |
342 |
const uschar *Xsaved_eptr; |
USPTR Xpp; |
343 |
|
USPTR Xprev; |
344 |
|
USPTR Xsaved_eptr; |
345 |
|
|
346 |
recursion_info Xnew_recursive; |
recursion_info Xnew_recursive; |
347 |
|
|
362 |
uschar Xocchars[8]; |
uschar Xocchars[8]; |
363 |
#endif |
#endif |
364 |
|
|
365 |
|
int Xcodelink; |
366 |
int Xctype; |
int Xctype; |
367 |
unsigned int Xfc; |
unsigned int Xfc; |
368 |
int Xfi; |
int Xfi; |
428 |
*/ |
*/ |
429 |
|
|
430 |
static int |
static int |
431 |
match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart, |
match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart, |
432 |
int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, |
int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, |
433 |
int flags, unsigned int rdepth) |
int flags, unsigned int rdepth) |
434 |
{ |
{ |
442 |
register BOOL utf8; /* Local copy of UTF-8 flag for speed */ |
register BOOL utf8; /* Local copy of UTF-8 flag for speed */ |
443 |
|
|
444 |
BOOL minimize, possessive; /* Quantifier options */ |
BOOL minimize, possessive; /* Quantifier options */ |
445 |
|
int condcode; |
446 |
|
|
447 |
/* When recursion is not being used, all "local" variables that have to be |
/* When recursion is not being used, all "local" variables that have to be |
448 |
preserved over calls to RMATCH() are part of a "frame" which is obtained from |
preserved over calls to RMATCH() are part of a "frame" which is obtained from |
485 |
#define charptr frame->Xcharptr |
#define charptr frame->Xcharptr |
486 |
#endif |
#endif |
487 |
#define callpat frame->Xcallpat |
#define callpat frame->Xcallpat |
488 |
|
#define codelink frame->Xcodelink |
489 |
#define data frame->Xdata |
#define data frame->Xdata |
490 |
#define next frame->Xnext |
#define next frame->Xnext |
491 |
#define pp frame->Xpp |
#define pp frame->Xpp |
566 |
uschar occhars[8]; |
uschar occhars[8]; |
567 |
#endif |
#endif |
568 |
|
|
569 |
|
int codelink; |
570 |
int ctype; |
int ctype; |
571 |
int length; |
int length; |
572 |
int max; |
int max; |
793 |
|
|
794 |
case OP_COND: |
case OP_COND: |
795 |
case OP_SCOND: |
case OP_SCOND: |
796 |
if (ecode[LINK_SIZE+1] == OP_RREF) /* Recursion test */ |
codelink= GET(ecode, 1); |
797 |
|
|
798 |
|
/* Because of the way auto-callout works during compile, a callout item is |
799 |
|
inserted between OP_COND and an assertion condition. */ |
800 |
|
|
801 |
|
if (ecode[LINK_SIZE+1] == OP_CALLOUT) |
802 |
|
{ |
803 |
|
if (pcre_callout != NULL) |
804 |
|
{ |
805 |
|
pcre_callout_block cb; |
806 |
|
cb.version = 1; /* Version 1 of the callout block */ |
807 |
|
cb.callout_number = ecode[LINK_SIZE+2]; |
808 |
|
cb.offset_vector = md->offset_vector; |
809 |
|
cb.subject = (PCRE_SPTR)md->start_subject; |
810 |
|
cb.subject_length = md->end_subject - md->start_subject; |
811 |
|
cb.start_match = mstart - md->start_subject; |
812 |
|
cb.current_position = eptr - md->start_subject; |
813 |
|
cb.pattern_position = GET(ecode, LINK_SIZE + 3); |
814 |
|
cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE); |
815 |
|
cb.capture_top = offset_top/2; |
816 |
|
cb.capture_last = md->capture_last; |
817 |
|
cb.callout_data = md->callout_data; |
818 |
|
if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH); |
819 |
|
if (rrc < 0) RRETURN(rrc); |
820 |
|
} |
821 |
|
ecode += _pcre_OP_lengths[OP_CALLOUT]; |
822 |
|
} |
823 |
|
|
824 |
|
condcode = ecode[LINK_SIZE+1]; |
825 |
|
|
826 |
|
/* Now see what the actual condition is */ |
827 |
|
|
828 |
|
if (condcode == OP_RREF) /* Recursion test */ |
829 |
{ |
{ |
830 |
offset = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ |
offset = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ |
831 |
condition = md->recursive != NULL && |
condition = md->recursive != NULL && |
833 |
ecode += condition? 3 : GET(ecode, 1); |
ecode += condition? 3 : GET(ecode, 1); |
834 |
} |
} |
835 |
|
|
836 |
else if (ecode[LINK_SIZE+1] == OP_CREF) /* Group used test */ |
else if (condcode == OP_CREF) /* Group used test */ |
837 |
{ |
{ |
838 |
offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ |
offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ |
839 |
condition = offset < offset_top && md->offset_vector[offset] >= 0; |
condition = offset < offset_top && md->offset_vector[offset] >= 0; |
840 |
ecode += condition? 3 : GET(ecode, 1); |
ecode += condition? 3 : GET(ecode, 1); |
841 |
} |
} |
842 |
|
|
843 |
else if (ecode[LINK_SIZE+1] == OP_DEF) /* DEFINE - always false */ |
else if (condcode == OP_DEF) /* DEFINE - always false */ |
844 |
{ |
{ |
845 |
condition = FALSE; |
condition = FALSE; |
846 |
ecode += GET(ecode, 1); |
ecode += GET(ecode, 1); |
867 |
else |
else |
868 |
{ |
{ |
869 |
condition = FALSE; |
condition = FALSE; |
870 |
ecode += GET(ecode, 1); |
ecode += codelink; |
871 |
} |
} |
872 |
} |
} |
873 |
|
|
890 |
goto TAIL_RECURSE; |
goto TAIL_RECURSE; |
891 |
} |
} |
892 |
} |
} |
893 |
else /* Condition false & no 2nd alternative */ |
else /* Condition false & no alternative */ |
894 |
{ |
{ |
895 |
ecode += 1 + LINK_SIZE; |
ecode += 1 + LINK_SIZE; |
896 |
} |
} |
1113 |
else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
1114 |
{ |
{ |
1115 |
DPRINTF(("Recursion gave error %d\n", rrc)); |
DPRINTF(("Recursion gave error %d\n", rrc)); |
1116 |
|
if (new_recursive.offset_save != stacksave) |
1117 |
|
(pcre_free)(new_recursive.offset_save); |
1118 |
RRETURN(rrc); |
RRETURN(rrc); |
1119 |
} |
} |
1120 |
|
|
1461 |
{ |
{ |
1462 |
if (eptr == md->start_subject) prev_is_word = FALSE; else |
if (eptr == md->start_subject) prev_is_word = FALSE; else |
1463 |
{ |
{ |
1464 |
const uschar *lastptr = eptr - 1; |
USPTR lastptr = eptr - 1; |
1465 |
while((*lastptr & 0xc0) == 0x80) lastptr--; |
while((*lastptr & 0xc0) == 0x80) lastptr--; |
1466 |
GETCHAR(c, lastptr); |
GETCHAR(c, lastptr); |
1467 |
prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0; |
1719 |
if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
1720 |
GETCHARINCTEST(c, eptr); |
GETCHARINCTEST(c, eptr); |
1721 |
{ |
{ |
1722 |
const ucd_record * prop = GET_UCD(c); |
const ucd_record *prop = GET_UCD(c); |
1723 |
|
|
1724 |
switch(ecode[1]) |
switch(ecode[1]) |
1725 |
{ |
{ |
1735 |
break; |
break; |
1736 |
|
|
1737 |
case PT_GC: |
case PT_GC: |
1738 |
if ((ecode[2] != ucp_gentype[prop->chartype]) == (op == OP_PROP)) |
if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP)) |
1739 |
RRETURN(MATCH_NOMATCH); |
RRETURN(MATCH_NOMATCH); |
1740 |
break; |
break; |
1741 |
|
|
2087 |
|
|
2088 |
|
|
2089 |
/* Match an extended character class. This opcode is encountered only |
/* Match an extended character class. This opcode is encountered only |
2090 |
in UTF-8 mode, because that's the only time it is compiled. */ |
when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8 |
2091 |
|
mode, because Unicode properties are supported in non-UTF-8 mode. */ |
2092 |
|
|
2093 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
2094 |
case OP_XCLASS: |
case OP_XCLASS: |
2130 |
for (i = 1; i <= min; i++) |
for (i = 1; i <= min; i++) |
2131 |
{ |
{ |
2132 |
if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
2133 |
GETCHARINC(c, eptr); |
GETCHARINCTEST(c, eptr); |
2134 |
if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
2135 |
} |
} |
2136 |
|
|
2149 |
RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20); |
RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20); |
2150 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2151 |
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
2152 |
GETCHARINC(c, eptr); |
GETCHARINCTEST(c, eptr); |
2153 |
if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH); |
2154 |
} |
} |
2155 |
/* Control never gets here */ |
/* Control never gets here */ |
2164 |
{ |
{ |
2165 |
int len = 1; |
int len = 1; |
2166 |
if (eptr >= md->end_subject) break; |
if (eptr >= md->end_subject) break; |
2167 |
GETCHARLEN(c, eptr, len); |
GETCHARLENTEST(c, eptr, len); |
2168 |
if (!_pcre_xclass(c, data)) break; |
if (!_pcre_xclass(c, data)) break; |
2169 |
eptr += len; |
eptr += len; |
2170 |
} |
} |
2650 |
{ |
{ |
2651 |
RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28); |
RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28); |
2652 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2653 |
|
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
2654 |
GETCHARINC(d, eptr); |
GETCHARINC(d, eptr); |
2655 |
if (d < 256) d = md->lcc[d]; |
if (d < 256) d = md->lcc[d]; |
2656 |
if (fi >= max || eptr >= md->end_subject || fc == d) |
if (fc == d) RRETURN(MATCH_NOMATCH); |
2657 |
RRETURN(MATCH_NOMATCH); |
|
2658 |
} |
} |
2659 |
} |
} |
2660 |
else |
else |
2760 |
{ |
{ |
2761 |
RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32); |
RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32); |
2762 |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
if (rrc != MATCH_NOMATCH) RRETURN(rrc); |
2763 |
|
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); |
2764 |
GETCHARINC(d, eptr); |
GETCHARINC(d, eptr); |
2765 |
if (fi >= max || eptr >= md->end_subject || fc == d) |
if (fc == d) RRETURN(MATCH_NOMATCH); |
|
RRETURN(MATCH_NOMATCH); |
|
2766 |
} |
} |
2767 |
} |
} |
2768 |
else |
else |
4426 |
< -1 => some kind of unexpected problem |
< -1 => some kind of unexpected problem |
4427 |
*/ |
*/ |
4428 |
|
|
4429 |
PCRE_EXP_DEFN int |
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
4430 |
pcre_exec(const pcre *argument_re, const pcre_extra *extra_data, |
pcre_exec(const pcre *argument_re, const pcre_extra *extra_data, |
4431 |
PCRE_SPTR subject, int length, int start_offset, int options, int *offsets, |
PCRE_SPTR subject, int length, int start_offset, int options, int *offsets, |
4432 |
int offsetcount) |
int offsetcount) |
4574 |
(pcre_uint32)options) & PCRE_NEWLINE_BITS) |
(pcre_uint32)options) & PCRE_NEWLINE_BITS) |
4575 |
{ |
{ |
4576 |
case 0: newline = NEWLINE; break; /* Compile-time default */ |
case 0: newline = NEWLINE; break; /* Compile-time default */ |
4577 |
case PCRE_NEWLINE_CR: newline = '\r'; break; |
case PCRE_NEWLINE_CR: newline = CHAR_CR; break; |
4578 |
case PCRE_NEWLINE_LF: newline = '\n'; break; |
case PCRE_NEWLINE_LF: newline = CHAR_NL; break; |
4579 |
case PCRE_NEWLINE_CR+ |
case PCRE_NEWLINE_CR+ |
4580 |
PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break; |
PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break; |
4581 |
case PCRE_NEWLINE_ANY: newline = -1; break; |
case PCRE_NEWLINE_ANY: newline = -1; break; |
4582 |
case PCRE_NEWLINE_ANYCRLF: newline = -2; break; |
case PCRE_NEWLINE_ANYCRLF: newline = -2; break; |
4583 |
default: return PCRE_ERROR_BADNEWLINE; |
default: return PCRE_ERROR_BADNEWLINE; |
4619 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
4620 |
if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) |
if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) |
4621 |
{ |
{ |
4622 |
if (_pcre_valid_utf8((uschar *)subject, length) >= 0) |
if (_pcre_valid_utf8((USPTR)subject, length) >= 0) |
4623 |
return PCRE_ERROR_BADUTF8; |
return PCRE_ERROR_BADUTF8; |
4624 |
if (start_offset > 0 && start_offset < length) |
if (start_offset > 0 && start_offset < length) |
4625 |
{ |
{ |
4626 |
int tb = ((uschar *)subject)[start_offset]; |
int tb = ((USPTR)subject)[start_offset]; |
4627 |
if (tb > 127) |
if (tb > 127) |
4628 |
{ |
{ |
4629 |
tb &= 0xc0; |
tb &= 0xc0; |
4729 |
while (iptr < iend) *iptr++ = -1; |
while (iptr < iend) *iptr++ = -1; |
4730 |
} |
} |
4731 |
|
|
4732 |
/* Advance to a unique first char if possible. If firstline is TRUE, the |
/* If firstline is TRUE, the start of the match is constrained to the first |
4733 |
start of the match is constrained to the first line of a multiline string. |
line of a multiline string. That is, the match must be before or at the first |
4734 |
That is, the match must be before or at the first newline. Implement this by |
newline. Implement this by temporarily adjusting end_subject so that we stop |
4735 |
temporarily adjusting end_subject so that we stop scanning at a newline. If |
scanning at a newline. If the match fails at the newline, later code breaks |
4736 |
the match fails at the newline, later code breaks this loop. */ |
this loop. */ |
4737 |
|
|
4738 |
if (firstline) |
if (firstline) |
4739 |
{ |
{ |
4740 |
USPTR t = start_match; |
USPTR t = start_match; |
4741 |
|
#ifdef SUPPORT_UTF8 |
4742 |
|
if (utf8) |
4743 |
|
{ |
4744 |
|
while (t < md->end_subject && !IS_NEWLINE(t)) |
4745 |
|
{ |
4746 |
|
t++; |
4747 |
|
while (t < end_subject && (*t & 0xc0) == 0x80) t++; |
4748 |
|
} |
4749 |
|
} |
4750 |
|
else |
4751 |
|
#endif |
4752 |
while (t < md->end_subject && !IS_NEWLINE(t)) t++; |
while (t < md->end_subject && !IS_NEWLINE(t)) t++; |
4753 |
end_subject = t; |
end_subject = t; |
4754 |
} |
} |
4755 |
|
|
4756 |
/* Now test for a unique first byte */ |
/* There are some optimizations that avoid running the match if a known |
4757 |
|
starting point is not found, or if a known later character is not present. |
4758 |
|
However, there is an option that disables these, for testing and for ensuring |
4759 |
|
that all callouts do actually occur. */ |
4760 |
|
|
4761 |
if (first_byte >= 0) |
if ((options & PCRE_NO_START_OPTIMIZE) == 0) |
4762 |
{ |
{ |
4763 |
if (first_byte_caseless) |
/* Advance to a unique first byte if there is one. */ |
4764 |
while (start_match < end_subject && |
|
4765 |
md->lcc[*start_match] != first_byte) |
if (first_byte >= 0) |
4766 |
{ NEXTCHAR(start_match); } |
{ |
4767 |
else |
if (first_byte_caseless) |
4768 |
while (start_match < end_subject && *start_match != first_byte) |
while (start_match < end_subject && md->lcc[*start_match] != first_byte) |
4769 |
{ NEXTCHAR(start_match); } |
start_match++; |
4770 |
} |
else |
4771 |
|
while (start_match < end_subject && *start_match != first_byte) |
4772 |
|
start_match++; |
4773 |
|
} |
4774 |
|
|
4775 |
/* Or to just after a linebreak for a multiline match if possible */ |
/* Or to just after a linebreak for a multiline match */ |
4776 |
|
|
4777 |
else if (startline) |
else if (startline) |
|
{ |
|
|
if (start_match > md->start_subject + start_offset) |
|
4778 |
{ |
{ |
4779 |
while (start_match <= end_subject && !WAS_NEWLINE(start_match)) |
if (start_match > md->start_subject + start_offset) |
4780 |
{ NEXTCHAR(start_match); } |
{ |
4781 |
|
#ifdef SUPPORT_UTF8 |
4782 |
|
if (utf8) |
4783 |
|
{ |
4784 |
|
while (start_match < end_subject && !WAS_NEWLINE(start_match)) |
4785 |
|
{ |
4786 |
|
start_match++; |
4787 |
|
while(start_match < end_subject && (*start_match & 0xc0) == 0x80) |
4788 |
|
start_match++; |
4789 |
|
} |
4790 |
|
} |
4791 |
|
else |
4792 |
|
#endif |
4793 |
|
while (start_match < end_subject && !WAS_NEWLINE(start_match)) |
4794 |
|
start_match++; |
4795 |
|
|
4796 |
|
/* If we have just passed a CR and the newline option is ANY or ANYCRLF, |
4797 |
|
and we are now at a LF, advance the match position by one more character. |
4798 |
|
*/ |
4799 |
|
|
4800 |
/* If we have just passed a CR and the newline option is ANY or ANYCRLF, |
if (start_match[-1] == CHAR_CR && |
4801 |
and we are now at a LF, advance the match position by one more character. |
(md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) && |
4802 |
*/ |
start_match < end_subject && |
4803 |
|
*start_match == CHAR_NL) |
4804 |
if (start_match[-1] == '\r' && |
start_match++; |
4805 |
(md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) && |
} |
|
start_match < end_subject && |
|
|
*start_match == '\n') |
|
|
start_match++; |
|
4806 |
} |
} |
|
} |
|
4807 |
|
|
4808 |
/* Or to a non-unique first char after study */ |
/* Or to a non-unique first byte after study */ |
4809 |
|
|
4810 |
else if (start_bits != NULL) |
else if (start_bits != NULL) |
|
{ |
|
|
while (start_match < end_subject) |
|
4811 |
{ |
{ |
4812 |
register unsigned int c = *start_match; |
while (start_match < end_subject) |
4813 |
if ((start_bits[c/8] & (1 << (c&7))) == 0) |
{ |
4814 |
{ NEXTCHAR(start_match); } |
register unsigned int c = *start_match; |
4815 |
else break; |
if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; |
4816 |
|
else break; |
4817 |
|
} |
4818 |
} |
} |
4819 |
} |
} /* Starting optimizations */ |
4820 |
|
|
4821 |
/* Restore fudged end_subject */ |
/* Restore fudged end_subject */ |
4822 |
|
|
4828 |
printf("\n"); |
printf("\n"); |
4829 |
#endif |
#endif |
4830 |
|
|
4831 |
/* If req_byte is set, we know that that character must appear in the subject |
/* If req_byte is set, we know that that character must appear in the |
4832 |
for the match to succeed. If the first character is set, req_byte must be |
subject for the match to succeed. If the first character is set, req_byte |
4833 |
later in the subject; otherwise the test starts at the match point. This |
must be later in the subject; otherwise the test starts at the match point. |
4834 |
optimization can save a huge amount of backtracking in patterns with nested |
This optimization can save a huge amount of backtracking in patterns with |
4835 |
unlimited repeats that aren't going to match. Writing separate code for |
nested unlimited repeats that aren't going to match. Writing separate code |
4836 |
cased/caseless versions makes it go faster, as does using an autoincrement |
for cased/caseless versions makes it go faster, as does using an |
4837 |
and backing off on a match. |
autoincrement and backing off on a match. |
4838 |
|
|
4839 |
HOWEVER: when the subject string is very, very long, searching to its end can |
HOWEVER: when the subject string is very, very long, searching to its end |
4840 |
take a long time, and give bad performance on quite ordinary patterns. This |
can take a long time, and give bad performance on quite ordinary patterns. |
4841 |
showed up when somebody was matching something like /^\d+C/ on a 32-megabyte |
This showed up when somebody was matching something like /^\d+C/ on a |
4842 |
string... so we don't do this when the string is sufficiently long. |
32-megabyte string... so we don't do this when the string is sufficiently |
4843 |
|
long. |
4844 |
|
|
4845 |
ALSO: this processing is disabled when partial matching is requested. |
ALSO: this processing is disabled when partial matching is requested, or if |
4846 |
*/ |
disabling is explicitly requested. */ |
4847 |
|
|
4848 |
if (req_byte >= 0 && |
if ((options & PCRE_NO_START_OPTIMIZE) == 0 && |
4849 |
|
req_byte >= 0 && |
4850 |
end_subject - start_match < REQ_BYTE_MAX && |
end_subject - start_match < REQ_BYTE_MAX && |
4851 |
!md->partial) |
!md->partial) |
4852 |
{ |
{ |
4954 |
not contain any explicit matches for \r or \n, and the newline option is CRLF |
not contain any explicit matches for \r or \n, and the newline option is CRLF |
4955 |
or ANY or ANYCRLF, advance the match position by one more character. */ |
or ANY or ANYCRLF, advance the match position by one more character. */ |
4956 |
|
|
4957 |
if (start_match[-1] == '\r' && |
if (start_match[-1] == CHAR_CR && |
4958 |
start_match < end_subject && |
start_match < end_subject && |
4959 |
*start_match == '\n' && |
*start_match == CHAR_NL && |
4960 |
(re->flags & PCRE_HASCRORLF) == 0 && |
(re->flags & PCRE_HASCRORLF) == 0 && |
4961 |
(md->nltype == NLTYPE_ANY || |
(md->nltype == NLTYPE_ANY || |
4962 |
md->nltype == NLTYPE_ANYCRLF || |
md->nltype == NLTYPE_ANYCRLF || |