| 3 |
*************************************************/ |
*************************************************/ |
| 4 |
|
|
| 5 |
/* PCRE is a library of functions to support regular expressions whose syntax |
/* PCRE is a library of functions to support regular expressions whose syntax |
| 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 (but see |
| 7 |
|
below for why this module is different). |
| 8 |
|
|
| 9 |
Written by Philip Hazel |
Written by Philip Hazel |
| 10 |
Copyright (c) 1997-2007 University of Cambridge |
Copyright (c) 1997-2010 University of Cambridge |
| 11 |
|
|
| 12 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
| 13 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
| 45 |
applications. */ |
applications. */ |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
/* NOTE ABOUT PERFORMANCE: A user of this function sent some code that improved |
| 49 |
|
the performance of his patterns greatly. I could not use it as it stood, as it |
| 50 |
|
was not thread safe, and made assumptions about pattern sizes. Also, it caused |
| 51 |
|
test 7 to loop, and test 9 to crash with a segfault. |
| 52 |
|
|
| 53 |
|
The issue is the check for duplicate states, which is done by a simple linear |
| 54 |
|
search up the state list. (Grep for "duplicate" below to find the code.) For |
| 55 |
|
many patterns, there will never be many states active at one time, so a simple |
| 56 |
|
linear search is fine. In patterns that have many active states, it might be a |
| 57 |
|
bottleneck. The suggested code used an indexing scheme to remember which states |
| 58 |
|
had previously been used for each character, and avoided the linear search when |
| 59 |
|
it knew there was no chance of a duplicate. This was implemented when adding |
| 60 |
|
states to the state lists. |
| 61 |
|
|
| 62 |
|
I wrote some thread-safe, not-limited code to try something similar at the time |
| 63 |
|
of checking for duplicates (instead of when adding states), using index vectors |
| 64 |
|
on the stack. It did give a 13% improvement with one specially constructed |
| 65 |
|
pattern for certain subject strings, but on other strings and on many of the |
| 66 |
|
simpler patterns in the test suite it did worse. The major problem, I think, |
| 67 |
|
was the extra time to initialize the index. This had to be done for each call |
| 68 |
|
of internal_dfa_exec(). (The supplied patch used a static vector, initialized |
| 69 |
|
only once - I suspect this was the cause of the problems with the tests.) |
| 70 |
|
|
| 71 |
|
Overall, I concluded that the gains in some cases did not outweigh the losses |
| 72 |
|
in others, so I abandoned this code. */ |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
#ifdef HAVE_CONFIG_H |
| 77 |
|
#include "config.h" |
| 78 |
|
#endif |
| 79 |
|
|
| 80 |
#define NLBLOCK md /* Block containing newline information */ |
#define NLBLOCK md /* Block containing newline information */ |
| 81 |
#define PSSTART start_subject /* Field containing processed string start */ |
#define PSSTART start_subject /* Field containing processed string start */ |
| 82 |
#define PSEND end_subject /* Field containing processed string end */ |
#define PSEND end_subject /* Field containing processed string end */ |
| 89 |
#define SP " " |
#define SP " " |
| 90 |
|
|
| 91 |
|
|
|
|
|
| 92 |
/************************************************* |
/************************************************* |
| 93 |
* Code parameters and static tables * |
* Code parameters and static tables * |
| 94 |
*************************************************/ |
*************************************************/ |
| 95 |
|
|
| 96 |
/* These are offsets that are used to turn the OP_TYPESTAR and friends opcodes |
/* These are offsets that are used to turn the OP_TYPESTAR and friends opcodes |
| 97 |
into others, under special conditions. A gap of 20 between the blocks should be |
into others, under special conditions. A gap of 20 between the blocks should be |
| 98 |
enough. The resulting opcodes don't have to be less than 256 because they are |
enough. The resulting opcodes don't have to be less than 256 because they are |
| 99 |
never stored, so we push them well clear of the normal opcodes. */ |
never stored, so we push them well clear of the normal opcodes. */ |
| 100 |
|
|
| 101 |
#define OP_PROP_EXTRA 300 |
#define OP_PROP_EXTRA 300 |
| 106 |
|
|
| 107 |
|
|
| 108 |
/* This table identifies those opcodes that are followed immediately by a |
/* This table identifies those opcodes that are followed immediately by a |
| 109 |
character that is to be tested in some way. This makes is possible to |
character that is to be tested in some way. This makes it possible to |
| 110 |
centralize the loading of these characters. In the case of Type * etc, the |
centralize the loading of these characters. In the case of Type * etc, the |
| 111 |
"character" is the opcode for \D, \d, \S, \s, \W, or \w, which will always be a |
"character" is the opcode for \D, \d, \S, \s, \W, or \w, which will always be a |
| 112 |
small value. ***NOTE*** If the start of this table is modified, the two tables |
small value. Non-zero values in the table are the offsets from the opcode where |
| 113 |
that follow must also be modified. */ |
the character is to be found. ***NOTE*** If the start of this table is |
| 114 |
|
modified, the three tables that follow must also be modified. */ |
| 115 |
|
|
| 116 |
static uschar coptable[] = { |
static const uschar coptable[] = { |
| 117 |
0, /* End */ |
0, /* End */ |
| 118 |
0, 0, 0, 0, 0, /* \A, \G, \K, \B, \b */ |
0, 0, 0, 0, 0, /* \A, \G, \K, \B, \b */ |
| 119 |
0, 0, 0, 0, 0, 0, /* \D, \d, \S, \s, \W, \w */ |
0, 0, 0, 0, 0, 0, /* \D, \d, \S, \s, \W, \w */ |
| 120 |
0, 0, /* Any, Anybyte */ |
0, 0, 0, /* Any, AllAny, Anybyte */ |
| 121 |
0, 0, 0, /* NOTPROP, PROP, EXTUNI */ |
0, 0, /* \P, \p */ |
| 122 |
0, 0, 0, 0, 0, /* \R, \H, \h, \V, \v */ |
0, 0, 0, 0, 0, /* \R, \H, \h, \V, \v */ |
| 123 |
|
0, /* \X */ |
| 124 |
0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */ |
0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */ |
| 125 |
1, /* Char */ |
1, /* Char */ |
| 126 |
1, /* Charnc */ |
1, /* Charnc */ |
| 157 |
0, /* Reverse */ |
0, /* Reverse */ |
| 158 |
0, 0, 0, 0, /* ONCE, BRA, CBRA, COND */ |
0, 0, 0, 0, /* ONCE, BRA, CBRA, COND */ |
| 159 |
0, 0, 0, /* SBRA, SCBRA, SCOND */ |
0, 0, 0, /* SBRA, SCBRA, SCOND */ |
| 160 |
0, /* CREF */ |
0, 0, /* CREF, NCREF */ |
| 161 |
0, /* RREF */ |
0, 0, /* RREF, NRREF */ |
| 162 |
|
0, /* DEF */ |
| 163 |
|
0, 0, /* BRAZERO, BRAMINZERO */ |
| 164 |
|
0, 0, 0, /* MARK, PRUNE, PRUNE_ARG, */ |
| 165 |
|
0, 0, 0, 0, /* SKIP, SKIP_ARG, THEN, THEN_ARG, */ |
| 166 |
|
0, 0, 0, 0, 0 /* COMMIT, FAIL, ACCEPT, CLOSE, SKIPZERO */ |
| 167 |
|
}; |
| 168 |
|
|
| 169 |
|
/* This table identifies those opcodes that inspect a character. It is used to |
| 170 |
|
remember the fact that a character could have been inspected when the end of |
| 171 |
|
the subject is reached. ***NOTE*** If the start of this table is modified, the |
| 172 |
|
two tables that follow must also be modified. */ |
| 173 |
|
|
| 174 |
|
static const uschar poptable[] = { |
| 175 |
|
0, /* End */ |
| 176 |
|
0, 0, 0, 1, 1, /* \A, \G, \K, \B, \b */ |
| 177 |
|
1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */ |
| 178 |
|
1, 1, 1, /* Any, AllAny, Anybyte */ |
| 179 |
|
1, 1, /* \P, \p */ |
| 180 |
|
1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */ |
| 181 |
|
1, /* \X */ |
| 182 |
|
0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */ |
| 183 |
|
1, /* Char */ |
| 184 |
|
1, /* Charnc */ |
| 185 |
|
1, /* not */ |
| 186 |
|
/* Positive single-char repeats */ |
| 187 |
|
1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ |
| 188 |
|
1, 1, 1, /* upto, minupto, exact */ |
| 189 |
|
1, 1, 1, 1, /* *+, ++, ?+, upto+ */ |
| 190 |
|
/* Negative single-char repeats - only for chars < 256 */ |
| 191 |
|
1, 1, 1, 1, 1, 1, /* NOT *, *?, +, +?, ?, ?? */ |
| 192 |
|
1, 1, 1, /* NOT upto, minupto, exact */ |
| 193 |
|
1, 1, 1, 1, /* NOT *+, ++, ?+, upto+ */ |
| 194 |
|
/* Positive type repeats */ |
| 195 |
|
1, 1, 1, 1, 1, 1, /* Type *, *?, +, +?, ?, ?? */ |
| 196 |
|
1, 1, 1, /* Type upto, minupto, exact */ |
| 197 |
|
1, 1, 1, 1, /* Type *+, ++, ?+, upto+ */ |
| 198 |
|
/* Character class & ref repeats */ |
| 199 |
|
1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ |
| 200 |
|
1, 1, /* CRRANGE, CRMINRANGE */ |
| 201 |
|
1, /* CLASS */ |
| 202 |
|
1, /* NCLASS */ |
| 203 |
|
1, /* XCLASS - variable length */ |
| 204 |
|
0, /* REF */ |
| 205 |
|
0, /* RECURSE */ |
| 206 |
|
0, /* CALLOUT */ |
| 207 |
|
0, /* Alt */ |
| 208 |
|
0, /* Ket */ |
| 209 |
|
0, /* KetRmax */ |
| 210 |
|
0, /* KetRmin */ |
| 211 |
|
0, /* Assert */ |
| 212 |
|
0, /* Assert not */ |
| 213 |
|
0, /* Assert behind */ |
| 214 |
|
0, /* Assert behind not */ |
| 215 |
|
0, /* Reverse */ |
| 216 |
|
0, 0, 0, 0, /* ONCE, BRA, CBRA, COND */ |
| 217 |
|
0, 0, 0, /* SBRA, SCBRA, SCOND */ |
| 218 |
|
0, 0, /* CREF, NCREF */ |
| 219 |
|
0, 0, /* RREF, NRREF */ |
| 220 |
0, /* DEF */ |
0, /* DEF */ |
| 221 |
0, 0 /* BRAZERO, BRAMINZERO */ |
0, 0, /* BRAZERO, BRAMINZERO */ |
| 222 |
|
0, 0, 0, /* MARK, PRUNE, PRUNE_ARG, */ |
| 223 |
|
0, 0, 0, 0, /* SKIP, SKIP_ARG, THEN, THEN_ARG, */ |
| 224 |
|
0, 0, 0, 0, 0 /* COMMIT, FAIL, ACCEPT, CLOSE, SKIPZERO */ |
| 225 |
}; |
}; |
| 226 |
|
|
| 227 |
/* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W, |
/* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W, |
| 228 |
and \w */ |
and \w */ |
| 229 |
|
|
| 230 |
static uschar toptable1[] = { |
static const uschar toptable1[] = { |
| 231 |
0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, |
| 232 |
ctype_digit, ctype_digit, |
ctype_digit, ctype_digit, |
| 233 |
ctype_space, ctype_space, |
ctype_space, ctype_space, |
| 234 |
ctype_word, ctype_word, |
ctype_word, ctype_word, |
| 235 |
0 /* OP_ANY */ |
0, 0 /* OP_ANY, OP_ALLANY */ |
| 236 |
}; |
}; |
| 237 |
|
|
| 238 |
static uschar toptable2[] = { |
static const uschar toptable2[] = { |
| 239 |
0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, |
| 240 |
ctype_digit, 0, |
ctype_digit, 0, |
| 241 |
ctype_space, 0, |
ctype_space, 0, |
| 242 |
ctype_word, 0, |
ctype_word, 0, |
| 243 |
1 /* OP_ANY */ |
1, 1 /* OP_ANY, OP_ALLANY */ |
| 244 |
}; |
}; |
| 245 |
|
|
| 246 |
|
|
| 259 |
#define INTS_PER_STATEBLOCK (sizeof(stateblock)/sizeof(int)) |
#define INTS_PER_STATEBLOCK (sizeof(stateblock)/sizeof(int)) |
| 260 |
|
|
| 261 |
|
|
| 262 |
#ifdef DEBUG |
#ifdef PCRE_DEBUG |
| 263 |
/************************************************* |
/************************************************* |
| 264 |
* Print character string * |
* Print character string * |
| 265 |
*************************************************/ |
*************************************************/ |
| 312 |
rlevel function call recursion level |
rlevel function call recursion level |
| 313 |
recursing regex recursive call level |
recursing regex recursive call level |
| 314 |
|
|
| 315 |
Returns: > 0 => |
Returns: > 0 => number of match offset pairs placed in offsets |
| 316 |
= 0 => |
= 0 => offsets overflowed; longest matches are present |
| 317 |
-1 => failed to match |
-1 => failed to match |
| 318 |
< -1 => some kind of unexpected problem |
< -1 => some kind of unexpected problem |
| 319 |
|
|
| 475 |
|
|
| 476 |
{ |
{ |
| 477 |
gone_back = (current_subject - max_back < start_subject)? |
gone_back = (current_subject - max_back < start_subject)? |
| 478 |
current_subject - start_subject : max_back; |
(int)(current_subject - start_subject) : max_back; |
| 479 |
current_subject -= gone_back; |
current_subject -= gone_back; |
| 480 |
} |
} |
| 481 |
|
|
| 482 |
|
/* Save the earliest consulted character */ |
| 483 |
|
|
| 484 |
|
if (current_subject < md->start_used_ptr) |
| 485 |
|
md->start_used_ptr = current_subject; |
| 486 |
|
|
| 487 |
/* Now we can process the individual branches. */ |
/* Now we can process the individual branches. */ |
| 488 |
|
|
| 489 |
end_code = this_start_code; |
end_code = this_start_code; |
| 492 |
int back = GET(end_code, 2+LINK_SIZE); |
int back = GET(end_code, 2+LINK_SIZE); |
| 493 |
if (back <= gone_back) |
if (back <= gone_back) |
| 494 |
{ |
{ |
| 495 |
int bstate = end_code - start_code + 2 + 2*LINK_SIZE; |
int bstate = (int)(end_code - start_code + 2 + 2*LINK_SIZE); |
| 496 |
ADD_NEW_DATA(-bstate, 0, gone_back - back); |
ADD_NEW_DATA(-bstate, 0, gone_back - back); |
| 497 |
} |
} |
| 498 |
end_code += GET(end_code, 1); |
end_code += GET(end_code, 1); |
| 528 |
((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0); |
((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0); |
| 529 |
do |
do |
| 530 |
{ |
{ |
| 531 |
ADD_NEW(end_code - start_code + length, 0); |
ADD_NEW((int)(end_code - start_code + length), 0); |
| 532 |
end_code += GET(end_code, 1); |
end_code += GET(end_code, 1); |
| 533 |
length = 1 + LINK_SIZE; |
length = 1 + LINK_SIZE; |
| 534 |
} |
} |
| 548 |
int i, j; |
int i, j; |
| 549 |
int clen, dlen; |
int clen, dlen; |
| 550 |
unsigned int c, d; |
unsigned int c, d; |
| 551 |
|
int forced_fail = 0; |
| 552 |
|
BOOL could_continue = FALSE; |
| 553 |
|
|
| 554 |
/* Make the new state list into the active state list and empty the |
/* Make the new state list into the active state list and empty the |
| 555 |
new state list. */ |
new state list. */ |
| 563 |
workspace[0] ^= 1; /* Remember for the restarting feature */ |
workspace[0] ^= 1; /* Remember for the restarting feature */ |
| 564 |
workspace[1] = active_count; |
workspace[1] = active_count; |
| 565 |
|
|
| 566 |
#ifdef DEBUG |
#ifdef PCRE_DEBUG |
| 567 |
printf("%.*sNext character: rest of subject = \"", rlevel*2-2, SP); |
printf("%.*sNext character: rest of subject = \"", rlevel*2-2, SP); |
| 568 |
pchars((uschar *)ptr, strlen((char *)ptr), stdout); |
pchars((uschar *)ptr, strlen((char *)ptr), stdout); |
| 569 |
printf("\"\n"); |
printf("\"\n"); |
| 607 |
stateblock *current_state = active_states + i; |
stateblock *current_state = active_states + i; |
| 608 |
const uschar *code; |
const uschar *code; |
| 609 |
int state_offset = current_state->offset; |
int state_offset = current_state->offset; |
| 610 |
int count, codevalue; |
int count, codevalue, rrc; |
|
#ifdef SUPPORT_UCP |
|
|
int chartype, script; |
|
|
#endif |
|
| 611 |
|
|
| 612 |
#ifdef DEBUG |
#ifdef PCRE_DEBUG |
| 613 |
printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset); |
printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset); |
| 614 |
if (clen == 0) printf("EOL\n"); |
if (clen == 0) printf("EOL\n"); |
| 615 |
else if (c > 32 && c < 127) printf("'%c'\n", c); |
else if (c > 32 && c < 127) printf("'%c'\n", c); |
| 639 |
} |
} |
| 640 |
} |
} |
| 641 |
|
|
| 642 |
/* Check for a duplicate state with the same count, and skip if found. */ |
/* Check for a duplicate state with the same count, and skip if found. |
| 643 |
|
See the note at the head of this module about the possibility of improving |
| 644 |
|
performance here. */ |
| 645 |
|
|
| 646 |
for (j = 0; j < i; j++) |
for (j = 0; j < i; j++) |
| 647 |
{ |
{ |
| 658 |
code = start_code + state_offset; |
code = start_code + state_offset; |
| 659 |
codevalue = *code; |
codevalue = *code; |
| 660 |
|
|
| 661 |
|
/* If this opcode inspects a character, but we are at the end of the |
| 662 |
|
subject, remember the fact for use when testing for a partial match. */ |
| 663 |
|
|
| 664 |
|
if (clen == 0 && poptable[codevalue] != 0) |
| 665 |
|
could_continue = TRUE; |
| 666 |
|
|
| 667 |
/* If this opcode is followed by an inline character, load it. It is |
/* If this opcode is followed by an inline character, load it. It is |
| 668 |
tempting to test for the presence of a subject character here, but that |
tempting to test for the presence of a subject character here, but that |
| 669 |
is wrong, because sometimes zero repetitions of the subject are |
is wrong, because sometimes zero repetitions of the subject are |
| 692 |
case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break; |
case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break; |
| 693 |
case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break; |
case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break; |
| 694 |
case OP_NOT_HSPACE: |
case OP_NOT_HSPACE: |
| 695 |
case OP_HSPACE: codevalue += OP_HSPACE_EXTRA; break; |
case OP_HSPACE: codevalue += OP_HSPACE_EXTRA; break; |
| 696 |
case OP_NOT_VSPACE: |
case OP_NOT_VSPACE: |
| 697 |
case OP_VSPACE: codevalue += OP_VSPACE_EXTRA; break; |
case OP_VSPACE: codevalue += OP_VSPACE_EXTRA; break; |
| 698 |
default: break; |
default: break; |
| 699 |
} |
} |
| 700 |
} |
} |
| 710 |
|
|
| 711 |
switch (codevalue) |
switch (codevalue) |
| 712 |
{ |
{ |
| 713 |
|
/* ========================================================================== */ |
| 714 |
|
/* These cases are never obeyed. This is a fudge that causes a compile- |
| 715 |
|
time error if the vectors coptable or poptable, which are indexed by |
| 716 |
|
opcode, are not the correct length. It seems to be the only way to do |
| 717 |
|
such a check at compile time, as the sizeof() operator does not work |
| 718 |
|
in the C preprocessor. */ |
| 719 |
|
|
| 720 |
|
case OP_TABLE_LENGTH: |
| 721 |
|
case OP_TABLE_LENGTH + |
| 722 |
|
((sizeof(coptable) == OP_TABLE_LENGTH) && |
| 723 |
|
(sizeof(poptable) == OP_TABLE_LENGTH)): |
| 724 |
|
break; |
| 725 |
|
|
| 726 |
/* ========================================================================== */ |
/* ========================================================================== */ |
| 727 |
/* Reached a closing bracket. If not at the end of the pattern, carry |
/* Reached a closing bracket. If not at the end of the pattern, carry |
| 728 |
on with the next opcode. Otherwise, unless we have an empty string and |
on with the next opcode. Otherwise, unless we have an empty string and |
| 729 |
PCRE_NOTEMPTY is set, save the match data, shifting up all previous |
PCRE_NOTEMPTY is set, or PCRE_NOTEMPTY_ATSTART is set and we are at the |
| 730 |
|
start of the subject, save the match data, shifting up all previous |
| 731 |
matches so we always have the longest first. */ |
matches so we always have the longest first. */ |
| 732 |
|
|
| 733 |
case OP_KET: |
case OP_KET: |
| 741 |
ADD_ACTIVE(state_offset - GET(code, 1), 0); |
ADD_ACTIVE(state_offset - GET(code, 1), 0); |
| 742 |
} |
} |
| 743 |
} |
} |
| 744 |
else if (ptr > current_subject || (md->moptions & PCRE_NOTEMPTY) == 0) |
else |
| 745 |
{ |
{ |
| 746 |
if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0; |
if (ptr > current_subject || |
| 747 |
else if (match_count > 0 && ++match_count * 2 >= offsetcount) |
((md->moptions & PCRE_NOTEMPTY) == 0 && |
| 748 |
match_count = 0; |
((md->moptions & PCRE_NOTEMPTY_ATSTART) == 0 || |
| 749 |
count = ((match_count == 0)? offsetcount : match_count * 2) - 2; |
current_subject > start_subject + md->start_offset))) |
| 750 |
if (count > 0) memmove(offsets + 2, offsets, count * sizeof(int)); |
{ |
| 751 |
if (offsetcount >= 2) |
if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0; |
| 752 |
{ |
else if (match_count > 0 && ++match_count * 2 >= offsetcount) |
| 753 |
offsets[0] = current_subject - start_subject; |
match_count = 0; |
| 754 |
offsets[1] = ptr - start_subject; |
count = ((match_count == 0)? offsetcount : match_count * 2) - 2; |
| 755 |
DPRINTF(("%.*sSet matched string = \"%.*s\"\n", rlevel*2-2, SP, |
if (count > 0) memmove(offsets + 2, offsets, count * sizeof(int)); |
| 756 |
offsets[1] - offsets[0], current_subject)); |
if (offsetcount >= 2) |
| 757 |
} |
{ |
| 758 |
if ((md->moptions & PCRE_DFA_SHORTEST) != 0) |
offsets[0] = (int)(current_subject - start_subject); |
| 759 |
{ |
offsets[1] = (int)(ptr - start_subject); |
| 760 |
DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n" |
DPRINTF(("%.*sSet matched string = \"%.*s\"\n", rlevel*2-2, SP, |
| 761 |
"%.*s---------------------\n\n", rlevel*2-2, SP, rlevel, |
offsets[1] - offsets[0], current_subject)); |
| 762 |
match_count, rlevel*2-2, SP)); |
} |
| 763 |
return match_count; |
if ((md->moptions & PCRE_DFA_SHORTEST) != 0) |
| 764 |
|
{ |
| 765 |
|
DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n" |
| 766 |
|
"%.*s---------------------\n\n", rlevel*2-2, SP, rlevel, |
| 767 |
|
match_count, rlevel*2-2, SP)); |
| 768 |
|
return match_count; |
| 769 |
|
} |
| 770 |
} |
} |
| 771 |
} |
} |
| 772 |
break; |
break; |
| 778 |
/*-----------------------------------------------------------------*/ |
/*-----------------------------------------------------------------*/ |
| 779 |
case OP_ALT: |
case OP_ALT: |
| 780 |
do { code += GET(code, 1); } while (*code == OP_ALT); |
do { code += GET(code, 1); } while (*code == OP_ALT); |
| 781 |
ADD_ACTIVE(code - start_code, 0); |
ADD_ACTIVE((int)(code - start_code), 0); |
| 782 |
break; |
break; |
| 783 |
|
|
| 784 |
/*-----------------------------------------------------------------*/ |
/*-----------------------------------------------------------------*/ |
| 786 |
case OP_SBRA: |
case OP_SBRA: |
| 787 |
do |
do |
| 788 |
{ |
{ |
| 789 |
ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0); |
ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0); |
| 790 |
code += GET(code, 1); |
code += GET(code, 1); |
| 791 |
} |
} |
| 792 |
while (*code == OP_ALT); |
while (*code == OP_ALT); |
| 795 |
/*-----------------------------------------------------------------*/ |
/*-----------------------------------------------------------------*/ |
| 796 |
case OP_CBRA: |
case OP_CBRA: |
| 797 |
case OP_SCBRA: |
case OP_SCBRA: |
| 798 |
ADD_ACTIVE(code - start_code + 3 + LINK_SIZE, 0); |
ADD_ACTIVE((int)(code - start_code + 3 + LINK_SIZE), 0); |
| 799 |
code += GET(code, 1); |
code += GET(code, 1); |
| 800 |
while (*code == OP_ALT) |
while (*code == OP_ALT) |
| 801 |
{ |
{ |
| 802 |
ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0); |
ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0); |
| 803 |
code += GET(code, 1); |
code += GET(code, 1); |
| 804 |
} |
} |
| 805 |
break; |
break; |
| 810 |
ADD_ACTIVE(state_offset + 1, 0); |
ADD_ACTIVE(state_offset + 1, 0); |
| 811 |
code += 1 + GET(code, 2); |
code += 1 + GET(code, 2); |
| 812 |
while (*code == OP_ALT) code += GET(code, 1); |
while (*code == OP_ALT) code += GET(code, 1); |
| 813 |
ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0); |
ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0); |
| 814 |
|
break; |
| 815 |
|
|
| 816 |
|
/*-----------------------------------------------------------------*/ |
| 817 |
|
case OP_SKIPZERO: |
| 818 |
|
code += 1 + GET(code, 2); |
| 819 |
|
while (*code == OP_ALT) code += GET(code, 1); |
| 820 |
|
ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0); |
| 821 |
break; |
break; |
| 822 |
|
|
| 823 |
/*-----------------------------------------------------------------*/ |
/*-----------------------------------------------------------------*/ |
| 831 |
|
|
| 832 |
/*-----------------------------------------------------------------*/ |
/*-----------------------------------------------------------------*/ |
| 833 |
case OP_EOD: |
case OP_EOD: |
| 834 |
if (ptr >= end_subject) { ADD_ACTIVE(state_offset + 1, 0); } |
if (ptr >= end_subject) |
| 835 |
|
{ |
| 836 |
|
if ((md->moptions & PCRE_PARTIAL_HARD) != 0) |
| 837 |
|
could_continue = TRUE; |
| 838 |
|
else { ADD_ACTIVE(state_offset + 1, 0); } |
| 839 |
|
} |
| 840 |
break; |
break; |
| 841 |
|
|
| 842 |
/*-----------------------------------------------------------------*/ |
/*-----------------------------------------------------------------*/ |
| 864 |
|
|
| 865 |
/*-----------------------------------------------------------------*/ |
/*-----------------------------------------------------------------*/ |
| 866 |
case OP_ANY: |
case OP_ANY: |
| 867 |
if (clen > 0 && ((ims & PCRE_DOTALL) != 0 || !IS_NEWLINE(ptr))) |
if (clen > 0 && !IS_NEWLINE(ptr)) |
| 868 |
|
{ ADD_NEW(state_offset + 1, 0); } |
| 869 |
|
break; |
| 870 |
|
|
| 871 |
|
/*-----------------------------------------------------------------*/ |
| 872 |
|
case OP_ALLANY: |
| 873 |
|
if (clen > 0) |
| 874 |
{ ADD_NEW(state_offset + 1, 0); } |
{ ADD_NEW(state_offset + 1, 0); } |
| 875 |
break; |
break; |
| 876 |
|
|
| 877 |
/*-----------------------------------------------------------------*/ |
/*-----------------------------------------------------------------*/ |
| 878 |
case OP_EODN: |
case OP_EODN: |
| 879 |
if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - md->nllen)) |
if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0) |
| 880 |
|
could_continue = TRUE; |
| 881 |
|
else if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - md->nllen)) |
| 882 |
{ ADD_ACTIVE(state_offset + 1, 0); } |
{ ADD_ACTIVE(state_offset + 1, 0); } |
| 883 |
break; |
break; |
| 884 |
|
|
| 886 |
case OP_DOLL: |
case OP_DOLL: |
| 887 |
if ((md->moptions & PCRE_NOTEOL) == 0) |
if ((md->moptions & PCRE_NOTEOL) == 0) |
| 888 |
{ |
{ |
| 889 |
if (clen == 0 || |
if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0) |
| 890 |
(IS_NEWLINE(ptr) && |
could_continue = TRUE; |
| 891 |
|
else if (clen == 0 || |
| 892 |
|
((md->poptions & PCRE_DOLLAR_ENDONLY) == 0 && IS_NEWLINE(ptr) && |
| 893 |
((ims & PCRE_MULTILINE) != 0 || ptr == end_subject - md->nllen) |
((ims & PCRE_MULTILINE) != 0 || ptr == end_subject - md->nllen) |
| 894 |
)) |
)) |
| 895 |
{ ADD_ACTIVE(state_offset + 1, 0); } |
{ ADD_ACTIVE(state_offset + 1, 0); } |
| 926 |
if (ptr > start_subject) |
if (ptr > start_subject) |
| 927 |
{ |
{ |
| 928 |
const uschar *temp = ptr - 1; |
const uschar *temp = ptr - 1; |
| 929 |
|
if (temp < md->start_used_ptr) md->start_used_ptr = temp; |
| 930 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 931 |
if (utf8) BACKCHAR(temp); |
if (utf8) BACKCHAR(temp); |
| 932 |
#endif |
#endif |
| 933 |
GETCHARTEST(d, temp); |
GETCHARTEST(d, temp); |
| 934 |
|
#ifdef SUPPORT_UCP |
| 935 |
|
if ((md->poptions & PCRE_UCP) != 0) |
| 936 |
|
{ |
| 937 |
|
if (d == '_') left_word = TRUE; else |
| 938 |
|
{ |
| 939 |
|
int cat = UCD_CATEGORY(d); |
| 940 |
|
left_word = (cat == ucp_L || cat == ucp_N); |
| 941 |
|
} |
| 942 |
|
} |
| 943 |
|
else |
| 944 |
|
#endif |
| 945 |
left_word = d < 256 && (ctypes[d] & ctype_word) != 0; |
left_word = d < 256 && (ctypes[d] & ctype_word) != 0; |
| 946 |
} |
} |
| 947 |
else left_word = 0; |
else left_word = FALSE; |
| 948 |
|
|
| 949 |
if (clen > 0) right_word = c < 256 && (ctypes[c] & ctype_word) != 0; |
if (clen > 0) |
| 950 |
else right_word = 0; |
{ |
| 951 |
|
#ifdef SUPPORT_UCP |
| 952 |
|
if ((md->poptions & PCRE_UCP) != 0) |
| 953 |
|
{ |
| 954 |
|
if (c == '_') right_word = TRUE; else |
| 955 |
|
{ |
| 956 |
|
int cat = UCD_CATEGORY(c); |
| 957 |
|
right_word = (cat == ucp_L || cat == ucp_N); |
| 958 |
|
} |
| 959 |
|
} |
| 960 |
|
else |
| 961 |
|
#endif |
| 962 |
|
right_word = c < 256 && (ctypes[c] & ctype_word) != 0; |
| 963 |
|
} |
| 964 |
|
else right_word = FALSE; |
| 965 |
|
|
| 966 |
if ((left_word == right_word) == (codevalue == OP_NOT_WORD_BOUNDARY)) |
if ((left_word == right_word) == (codevalue == OP_NOT_WORD_BOUNDARY)) |
| 967 |
{ ADD_ACTIVE(state_offset + 1, 0); } |
{ ADD_ACTIVE(state_offset + 1, 0); } |
| 980 |
if (clen > 0) |
if (clen > 0) |
| 981 |
{ |
{ |
| 982 |
BOOL OK; |
BOOL OK; |
| 983 |
int category = _pcre_ucp_findprop(c, &chartype, &script); |
const ucd_record * prop = GET_UCD(c); |
| 984 |
switch(code[1]) |
switch(code[1]) |
| 985 |
{ |
{ |
| 986 |
case PT_ANY: |
case PT_ANY: |
| 988 |
break; |
break; |
| 989 |
|
|
| 990 |
case PT_LAMP: |
case PT_LAMP: |
| 991 |
OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt; |
OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll || |
| 992 |
|
prop->chartype == ucp_Lt; |
| 993 |
break; |
break; |
| 994 |
|
|
| 995 |
case PT_GC: |
case PT_GC: |
| 996 |
OK = category == code[2]; |
OK = _pcre_ucp_gentype[prop->chartype] == code[2]; |
| 997 |
break; |
break; |
| 998 |
|
|
| 999 |
case PT_PC: |
case PT_PC: |
| 1000 |
OK = chartype == code[2]; |
OK = prop->chartype == code[2]; |
| 1001 |
break; |
break; |
| 1002 |
|
|
| 1003 |
case PT_SC: |
case PT_SC: |
| 1004 |
OK = script == code[2]; |
OK = prop->script == code[2]; |
| 1005 |
|
break; |
| 1006 |
|
|
| 1007 |
|
/* These are specials for combination cases. */ |
| 1008 |
|
|
| 1009 |
|
case PT_ALNUM: |
| 1010 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_L || |
| 1011 |
|
_pcre_ucp_gentype[prop->chartype] == ucp_N; |
| 1012 |
|
break; |
| 1013 |
|
|
| 1014 |
|
case PT_SPACE: /* Perl space */ |
| 1015 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z || |
| 1016 |
|
c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR; |
| 1017 |
|
break; |
| 1018 |
|
|
| 1019 |
|
case PT_PXSPACE: /* POSIX space */ |
| 1020 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z || |
| 1021 |
|
c == CHAR_HT || c == CHAR_NL || c == CHAR_VT || |
| 1022 |
|
c == CHAR_FF || c == CHAR_CR; |
| 1023 |
|
break; |
| 1024 |
|
|
| 1025 |
|
case PT_WORD: |
| 1026 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_L || |
| 1027 |
|
_pcre_ucp_gentype[prop->chartype] == ucp_N || |
| 1028 |
|
c == CHAR_UNDERSCORE; |
| 1029 |
break; |
break; |
| 1030 |
|
|
| 1031 |
/* Should never occur, but keep compilers from grumbling. */ |
/* Should never occur, but keep compilers from grumbling. */ |
| 1045 |
/* ========================================================================== */ |
/* ========================================================================== */ |
| 1046 |
/* These opcodes likewise inspect the subject character, but have an |
/* These opcodes likewise inspect the subject character, but have an |
| 1047 |
argument that is not a data character. It is one of these opcodes: |
argument that is not a data character. It is one of these opcodes: |
| 1048 |
OP_ANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE, OP_WORDCHAR, |
OP_ANY, OP_ALLANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE, |
| 1049 |
OP_NOT_WORDCHAR. The value is loaded into d. */ |
OP_WORDCHAR, OP_NOT_WORDCHAR. The value is loaded into d. */ |
| 1050 |
|
|
| 1051 |
case OP_TYPEPLUS: |
case OP_TYPEPLUS: |
| 1052 |
case OP_TYPEMINPLUS: |
case OP_TYPEMINPLUS: |
| 1057 |
{ |
{ |
| 1058 |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
| 1059 |
(c < 256 && |
(c < 256 && |
| 1060 |
(d != OP_ANY || |
(d != OP_ANY || !IS_NEWLINE(ptr)) && |
|
(ims & PCRE_DOTALL) != 0 || |
|
|
!IS_NEWLINE(ptr) |
|
|
) && |
|
| 1061 |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
| 1062 |
{ |
{ |
| 1063 |
if (count > 0 && codevalue == OP_TYPEPOSPLUS) |
if (count > 0 && codevalue == OP_TYPEPOSPLUS) |
| 1080 |
{ |
{ |
| 1081 |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
| 1082 |
(c < 256 && |
(c < 256 && |
| 1083 |
(d != OP_ANY || |
(d != OP_ANY || !IS_NEWLINE(ptr)) && |
|
(ims & PCRE_DOTALL) != 0 || |
|
|
!IS_NEWLINE(ptr) |
|
|
) && |
|
| 1084 |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
| 1085 |
{ |
{ |
| 1086 |
if (codevalue == OP_TYPEPOSQUERY) |
if (codevalue == OP_TYPEPOSQUERY) |
| 1102 |
{ |
{ |
| 1103 |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
| 1104 |
(c < 256 && |
(c < 256 && |
| 1105 |
(d != OP_ANY || |
(d != OP_ANY || !IS_NEWLINE(ptr)) && |
|
(ims & PCRE_DOTALL) != 0 || |
|
|
!IS_NEWLINE(ptr) |
|
|
) && |
|
| 1106 |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
| 1107 |
{ |
{ |
| 1108 |
if (codevalue == OP_TYPEPOSSTAR) |
if (codevalue == OP_TYPEPOSSTAR) |
| 1122 |
{ |
{ |
| 1123 |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
| 1124 |
(c < 256 && |
(c < 256 && |
| 1125 |
(d != OP_ANY || |
(d != OP_ANY || !IS_NEWLINE(ptr)) && |
|
(ims & PCRE_DOTALL) != 0 || |
|
|
!IS_NEWLINE(ptr) |
|
|
) && |
|
| 1126 |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
| 1127 |
{ |
{ |
| 1128 |
if (++count >= GET2(code, 1)) |
if (++count >= GET2(code, 1)) |
| 1143 |
{ |
{ |
| 1144 |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
| 1145 |
(c < 256 && |
(c < 256 && |
| 1146 |
(d != OP_ANY || |
(d != OP_ANY || !IS_NEWLINE(ptr)) && |
|
(ims & PCRE_DOTALL) != 0 || |
|
|
!IS_NEWLINE(ptr) |
|
|
) && |
|
| 1147 |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
| 1148 |
{ |
{ |
| 1149 |
if (codevalue == OP_TYPEPOSUPTO) |
if (codevalue == OP_TYPEPOSUPTO) |
| 1174 |
if (clen > 0) |
if (clen > 0) |
| 1175 |
{ |
{ |
| 1176 |
BOOL OK; |
BOOL OK; |
| 1177 |
int category = _pcre_ucp_findprop(c, &chartype, &script); |
const ucd_record * prop = GET_UCD(c); |
| 1178 |
switch(code[2]) |
switch(code[2]) |
| 1179 |
{ |
{ |
| 1180 |
case PT_ANY: |
case PT_ANY: |
| 1182 |
break; |
break; |
| 1183 |
|
|
| 1184 |
case PT_LAMP: |
case PT_LAMP: |
| 1185 |
OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt; |
OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll || |
| 1186 |
|
prop->chartype == ucp_Lt; |
| 1187 |
break; |
break; |
| 1188 |
|
|
| 1189 |
case PT_GC: |
case PT_GC: |
| 1190 |
OK = category == code[3]; |
OK = _pcre_ucp_gentype[prop->chartype] == code[3]; |
| 1191 |
break; |
break; |
| 1192 |
|
|
| 1193 |
case PT_PC: |
case PT_PC: |
| 1194 |
OK = chartype == code[3]; |
OK = prop->chartype == code[3]; |
| 1195 |
break; |
break; |
| 1196 |
|
|
| 1197 |
case PT_SC: |
case PT_SC: |
| 1198 |
OK = script == code[3]; |
OK = prop->script == code[3]; |
| 1199 |
|
break; |
| 1200 |
|
|
| 1201 |
|
/* These are specials for combination cases. */ |
| 1202 |
|
|
| 1203 |
|
case PT_ALNUM: |
| 1204 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_L || |
| 1205 |
|
_pcre_ucp_gentype[prop->chartype] == ucp_N; |
| 1206 |
|
break; |
| 1207 |
|
|
| 1208 |
|
case PT_SPACE: /* Perl space */ |
| 1209 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z || |
| 1210 |
|
c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR; |
| 1211 |
|
break; |
| 1212 |
|
|
| 1213 |
|
case PT_PXSPACE: /* POSIX space */ |
| 1214 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z || |
| 1215 |
|
c == CHAR_HT || c == CHAR_NL || c == CHAR_VT || |
| 1216 |
|
c == CHAR_FF || c == CHAR_CR; |
| 1217 |
|
break; |
| 1218 |
|
|
| 1219 |
|
case PT_WORD: |
| 1220 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_L || |
| 1221 |
|
_pcre_ucp_gentype[prop->chartype] == ucp_N || |
| 1222 |
|
c == CHAR_UNDERSCORE; |
| 1223 |
break; |
break; |
| 1224 |
|
|
| 1225 |
/* Should never occur, but keep compilers from grumbling. */ |
/* Should never occur, but keep compilers from grumbling. */ |
| 1248 |
case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS: |
case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS: |
| 1249 |
count = current_state->count; /* Already matched */ |
count = current_state->count; /* Already matched */ |
| 1250 |
if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } |
if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } |
| 1251 |
if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M) |
if (clen > 0 && UCD_CATEGORY(c) != ucp_M) |
| 1252 |
{ |
{ |
| 1253 |
const uschar *nptr = ptr + clen; |
const uschar *nptr = ptr + clen; |
| 1254 |
int ncount = 0; |
int ncount = 0; |
| 1262 |
int nd; |
int nd; |
| 1263 |
int ndlen = 1; |
int ndlen = 1; |
| 1264 |
GETCHARLEN(nd, nptr, ndlen); |
GETCHARLEN(nd, nptr, ndlen); |
| 1265 |
if (_pcre_ucp_findprop(nd, &chartype, &script) != ucp_M) break; |
if (UCD_CATEGORY(nd) != ucp_M) break; |
| 1266 |
ncount++; |
ncount++; |
| 1267 |
nptr += ndlen; |
nptr += ndlen; |
| 1268 |
} |
} |
| 1283 |
int ncount = 0; |
int ncount = 0; |
| 1284 |
switch (c) |
switch (c) |
| 1285 |
{ |
{ |
|
case 0x000d: |
|
|
if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; |
|
|
/* Fall through */ |
|
|
case 0x000a: |
|
| 1286 |
case 0x000b: |
case 0x000b: |
| 1287 |
case 0x000c: |
case 0x000c: |
| 1288 |
case 0x0085: |
case 0x0085: |
| 1289 |
case 0x2028: |
case 0x2028: |
| 1290 |
case 0x2029: |
case 0x2029: |
| 1291 |
|
if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; |
| 1292 |
|
goto ANYNL01; |
| 1293 |
|
|
| 1294 |
|
case 0x000d: |
| 1295 |
|
if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; |
| 1296 |
|
/* Fall through */ |
| 1297 |
|
|
| 1298 |
|
ANYNL01: |
| 1299 |
|
case 0x000a: |
| 1300 |
if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS) |
if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS) |
| 1301 |
{ |
{ |
| 1302 |
active_count--; /* Remove non-match possibility */ |
active_count--; /* Remove non-match possibility */ |
| 1305 |
count++; |
count++; |
| 1306 |
ADD_NEW_DATA(-state_offset, count, ncount); |
ADD_NEW_DATA(-state_offset, count, ncount); |
| 1307 |
break; |
break; |
| 1308 |
|
|
| 1309 |
default: |
default: |
| 1310 |
break; |
break; |
| 1311 |
} |
} |
| 1320 |
if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } |
if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } |
| 1321 |
if (clen > 0) |
if (clen > 0) |
| 1322 |
{ |
{ |
| 1323 |
BOOL OK; |
BOOL OK; |
| 1324 |
switch (c) |
switch (c) |
| 1325 |
{ |
{ |
| 1326 |
case 0x000a: |
case 0x000a: |
| 1331 |
case 0x2028: |
case 0x2028: |
| 1332 |
case 0x2029: |
case 0x2029: |
| 1333 |
OK = TRUE; |
OK = TRUE; |
| 1334 |
break; |
break; |
| 1335 |
|
|
| 1336 |
default: |
default: |
| 1337 |
OK = FALSE; |
OK = FALSE; |
| 1338 |
break; |
break; |
| 1339 |
} |
} |
| 1340 |
|
|
| 1341 |
if (OK == (d == OP_VSPACE)) |
if (OK == (d == OP_VSPACE)) |
| 1342 |
{ |
{ |
| 1343 |
if (count > 0 && codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSPLUS) |
if (count > 0 && codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSPLUS) |
| 1344 |
{ |
{ |
| 1345 |
active_count--; /* Remove non-match possibility */ |
active_count--; /* Remove non-match possibility */ |
| 1359 |
if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } |
if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } |
| 1360 |
if (clen > 0) |
if (clen > 0) |
| 1361 |
{ |
{ |
| 1362 |
BOOL OK; |
BOOL OK; |
| 1363 |
switch (c) |
switch (c) |
| 1364 |
{ |
{ |
| 1365 |
case 0x09: /* HT */ |
case 0x09: /* HT */ |
| 1383 |
case 0x3000: /* IDEOGRAPHIC SPACE */ |
case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 1384 |
OK = TRUE; |
OK = TRUE; |
| 1385 |
break; |
break; |
| 1386 |
|
|
| 1387 |
default: |
default: |
| 1388 |
OK = FALSE; |
OK = FALSE; |
| 1389 |
break; |
break; |
| 1390 |
} |
} |
| 1391 |
|
|
| 1392 |
if (OK == (d == OP_HSPACE)) |
if (OK == (d == OP_HSPACE)) |
| 1393 |
{ |
{ |
| 1394 |
if (count > 0 && codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSPLUS) |
if (count > 0 && codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSPLUS) |
| 1395 |
{ |
{ |
| 1396 |
active_count--; /* Remove non-match possibility */ |
active_count--; /* Remove non-match possibility */ |
| 1421 |
if (clen > 0) |
if (clen > 0) |
| 1422 |
{ |
{ |
| 1423 |
BOOL OK; |
BOOL OK; |
| 1424 |
int category = _pcre_ucp_findprop(c, &chartype, &script); |
const ucd_record * prop = GET_UCD(c); |
| 1425 |
switch(code[2]) |
switch(code[2]) |
| 1426 |
{ |
{ |
| 1427 |
case PT_ANY: |
case PT_ANY: |
| 1429 |
break; |
break; |
| 1430 |
|
|
| 1431 |
case PT_LAMP: |
case PT_LAMP: |
| 1432 |
OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt; |
OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll || |
| 1433 |
|
prop->chartype == ucp_Lt; |
| 1434 |
break; |
break; |
| 1435 |
|
|
| 1436 |
case PT_GC: |
case PT_GC: |
| 1437 |
OK = category == code[3]; |
OK = _pcre_ucp_gentype[prop->chartype] == code[3]; |
| 1438 |
break; |
break; |
| 1439 |
|
|
| 1440 |
case PT_PC: |
case PT_PC: |
| 1441 |
OK = chartype == code[3]; |
OK = prop->chartype == code[3]; |
| 1442 |
break; |
break; |
| 1443 |
|
|
| 1444 |
case PT_SC: |
case PT_SC: |
| 1445 |
OK = script == code[3]; |
OK = prop->script == code[3]; |
| 1446 |
|
break; |
| 1447 |
|
|
| 1448 |
|
/* These are specials for combination cases. */ |
| 1449 |
|
|
| 1450 |
|
case PT_ALNUM: |
| 1451 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_L || |
| 1452 |
|
_pcre_ucp_gentype[prop->chartype] == ucp_N; |
| 1453 |
|
break; |
| 1454 |
|
|
| 1455 |
|
case PT_SPACE: /* Perl space */ |
| 1456 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z || |
| 1457 |
|
c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR; |
| 1458 |
|
break; |
| 1459 |
|
|
| 1460 |
|
case PT_PXSPACE: /* POSIX space */ |
| 1461 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z || |
| 1462 |
|
c == CHAR_HT || c == CHAR_NL || c == CHAR_VT || |
| 1463 |
|
c == CHAR_FF || c == CHAR_CR; |
| 1464 |
|
break; |
| 1465 |
|
|
| 1466 |
|
case PT_WORD: |
| 1467 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_L || |
| 1468 |
|
_pcre_ucp_gentype[prop->chartype] == ucp_N || |
| 1469 |
|
c == CHAR_UNDERSCORE; |
| 1470 |
break; |
break; |
| 1471 |
|
|
| 1472 |
/* Should never occur, but keep compilers from grumbling. */ |
/* Should never occur, but keep compilers from grumbling. */ |
| 1504 |
QS2: |
QS2: |
| 1505 |
|
|
| 1506 |
ADD_ACTIVE(state_offset + 2, 0); |
ADD_ACTIVE(state_offset + 2, 0); |
| 1507 |
if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M) |
if (clen > 0 && UCD_CATEGORY(c) != ucp_M) |
| 1508 |
{ |
{ |
| 1509 |
const uschar *nptr = ptr + clen; |
const uschar *nptr = ptr + clen; |
| 1510 |
int ncount = 0; |
int ncount = 0; |
| 1519 |
int nd; |
int nd; |
| 1520 |
int ndlen = 1; |
int ndlen = 1; |
| 1521 |
GETCHARLEN(nd, nptr, ndlen); |
GETCHARLEN(nd, nptr, ndlen); |
| 1522 |
if (_pcre_ucp_findprop(nd, &chartype, &script) != ucp_M) break; |
if (UCD_CATEGORY(nd) != ucp_M) break; |
| 1523 |
ncount++; |
ncount++; |
| 1524 |
nptr += ndlen; |
nptr += ndlen; |
| 1525 |
} |
} |
| 1547 |
int ncount = 0; |
int ncount = 0; |
| 1548 |
switch (c) |
switch (c) |
| 1549 |
{ |
{ |
|
case 0x000d: |
|
|
if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; |
|
|
/* Fall through */ |
|
|
case 0x000a: |
|
| 1550 |
case 0x000b: |
case 0x000b: |
| 1551 |
case 0x000c: |
case 0x000c: |
| 1552 |
case 0x0085: |
case 0x0085: |
| 1553 |
case 0x2028: |
case 0x2028: |
| 1554 |
case 0x2029: |
case 0x2029: |
| 1555 |
|
if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; |
| 1556 |
|
goto ANYNL02; |
| 1557 |
|
|
| 1558 |
|
case 0x000d: |
| 1559 |
|
if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; |
| 1560 |
|
/* Fall through */ |
| 1561 |
|
|
| 1562 |
|
ANYNL02: |
| 1563 |
|
case 0x000a: |
| 1564 |
if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSSTAR || |
if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSSTAR || |
| 1565 |
codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSQUERY) |
codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSQUERY) |
| 1566 |
{ |
{ |
| 1569 |
} |
} |
| 1570 |
ADD_NEW_DATA(-(state_offset + count), 0, ncount); |
ADD_NEW_DATA(-(state_offset + count), 0, ncount); |
| 1571 |
break; |
break; |
| 1572 |
|
|
| 1573 |
default: |
default: |
| 1574 |
break; |
break; |
| 1575 |
} |
} |
| 1592 |
ADD_ACTIVE(state_offset + 2, 0); |
ADD_ACTIVE(state_offset + 2, 0); |
| 1593 |
if (clen > 0) |
if (clen > 0) |
| 1594 |
{ |
{ |
| 1595 |
BOOL OK; |
BOOL OK; |
| 1596 |
switch (c) |
switch (c) |
| 1597 |
{ |
{ |
| 1598 |
case 0x000a: |
case 0x000a: |
| 1604 |
case 0x2029: |
case 0x2029: |
| 1605 |
OK = TRUE; |
OK = TRUE; |
| 1606 |
break; |
break; |
| 1607 |
|
|
| 1608 |
default: |
default: |
| 1609 |
OK = FALSE; |
OK = FALSE; |
| 1610 |
break; |
break; |
| 1611 |
} |
} |
| 1612 |
if (OK == (d == OP_VSPACE)) |
if (OK == (d == OP_VSPACE)) |
| 1613 |
{ |
{ |
| 1614 |
if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSSTAR || |
if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSSTAR || |
| 1615 |
codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSQUERY) |
codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSQUERY) |
| 1616 |
{ |
{ |
| 1638 |
ADD_ACTIVE(state_offset + 2, 0); |
ADD_ACTIVE(state_offset + 2, 0); |
| 1639 |
if (clen > 0) |
if (clen > 0) |
| 1640 |
{ |
{ |
| 1641 |
BOOL OK; |
BOOL OK; |
| 1642 |
switch (c) |
switch (c) |
| 1643 |
{ |
{ |
| 1644 |
case 0x09: /* HT */ |
case 0x09: /* HT */ |
| 1662 |
case 0x3000: /* IDEOGRAPHIC SPACE */ |
case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 1663 |
OK = TRUE; |
OK = TRUE; |
| 1664 |
break; |
break; |
| 1665 |
|
|
| 1666 |
default: |
default: |
| 1667 |
OK = FALSE; |
OK = FALSE; |
| 1668 |
break; |
break; |
| 1669 |
} |
} |
| 1670 |
|
|
| 1671 |
if (OK == (d == OP_HSPACE)) |
if (OK == (d == OP_HSPACE)) |
| 1672 |
{ |
{ |
| 1673 |
if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSSTAR || |
if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSSTAR || |
| 1674 |
codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSQUERY) |
codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSQUERY) |
| 1675 |
{ |
{ |
| 1693 |
if (clen > 0) |
if (clen > 0) |
| 1694 |
{ |
{ |
| 1695 |
BOOL OK; |
BOOL OK; |
| 1696 |
int category = _pcre_ucp_findprop(c, &chartype, &script); |
const ucd_record * prop = GET_UCD(c); |
| 1697 |
switch(code[4]) |
switch(code[4]) |
| 1698 |
{ |
{ |
| 1699 |
case PT_ANY: |
case PT_ANY: |
| 1701 |
break; |
break; |
| 1702 |
|
|
| 1703 |
case PT_LAMP: |
case PT_LAMP: |
| 1704 |
OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt; |
OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll || |
| 1705 |
|
prop->chartype == ucp_Lt; |
| 1706 |
break; |
break; |
| 1707 |
|
|
| 1708 |
case PT_GC: |
case PT_GC: |
| 1709 |
OK = category == code[5]; |
OK = _pcre_ucp_gentype[prop->chartype] == code[5]; |
| 1710 |
break; |
break; |
| 1711 |
|
|
| 1712 |
case PT_PC: |
case PT_PC: |
| 1713 |
OK = chartype == code[5]; |
OK = prop->chartype == code[5]; |
| 1714 |
break; |
break; |
| 1715 |
|
|
| 1716 |
case PT_SC: |
case PT_SC: |
| 1717 |
OK = script == code[5]; |
OK = prop->script == code[5]; |
| 1718 |
|
break; |
| 1719 |
|
|
| 1720 |
|
/* These are specials for combination cases. */ |
| 1721 |
|
|
| 1722 |
|
case PT_ALNUM: |
| 1723 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_L || |
| 1724 |
|
_pcre_ucp_gentype[prop->chartype] == ucp_N; |
| 1725 |
|
break; |
| 1726 |
|
|
| 1727 |
|
case PT_SPACE: /* Perl space */ |
| 1728 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z || |
| 1729 |
|
c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR; |
| 1730 |
|
break; |
| 1731 |
|
|
| 1732 |
|
case PT_PXSPACE: /* POSIX space */ |
| 1733 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z || |
| 1734 |
|
c == CHAR_HT || c == CHAR_NL || c == CHAR_VT || |
| 1735 |
|
c == CHAR_FF || c == CHAR_CR; |
| 1736 |
|
break; |
| 1737 |
|
|
| 1738 |
|
case PT_WORD: |
| 1739 |
|
OK = _pcre_ucp_gentype[prop->chartype] == ucp_L || |
| 1740 |
|
_pcre_ucp_gentype[prop->chartype] == ucp_N || |
| 1741 |
|
c == CHAR_UNDERSCORE; |
| 1742 |
break; |
break; |
| 1743 |
|
|
| 1744 |
/* Should never occur, but keep compilers from grumbling. */ |
/* Should never occur, but keep compilers from grumbling. */ |
| 1771 |
if (codevalue != OP_EXTUNI_EXTRA + OP_TYPEEXACT) |
if (codevalue != OP_EXTUNI_EXTRA + OP_TYPEEXACT) |
| 1772 |
{ ADD_ACTIVE(state_offset + 4, 0); } |
{ ADD_ACTIVE(state_offset + 4, 0); } |
| 1773 |
count = current_state->count; /* Number already matched */ |
count = current_state->count; /* Number already matched */ |
| 1774 |
if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M) |
if (clen > 0 && UCD_CATEGORY(c) != ucp_M) |
| 1775 |
{ |
{ |
| 1776 |
const uschar *nptr = ptr + clen; |
const uschar *nptr = ptr + clen; |
| 1777 |
int ncount = 0; |
int ncount = 0; |
| 1785 |
int nd; |
int nd; |
| 1786 |
int ndlen = 1; |
int ndlen = 1; |
| 1787 |
GETCHARLEN(nd, nptr, ndlen); |
GETCHARLEN(nd, nptr, ndlen); |
| 1788 |
if (_pcre_ucp_findprop(nd, &chartype, &script) != ucp_M) break; |
if (UCD_CATEGORY(nd) != ucp_M) break; |
| 1789 |
ncount++; |
ncount++; |
| 1790 |
nptr += ndlen; |
nptr += ndlen; |
| 1791 |
} |
} |
| 1810 |
int ncount = 0; |
int ncount = 0; |
| 1811 |
switch (c) |
switch (c) |
| 1812 |
{ |
{ |
|
case 0x000d: |
|
|
if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; |
|
|
/* Fall through */ |
|
|
case 0x000a: |
|
| 1813 |
case 0x000b: |
case 0x000b: |
| 1814 |
case 0x000c: |
case 0x000c: |
| 1815 |
case 0x0085: |
case 0x0085: |
| 1816 |
case 0x2028: |
case 0x2028: |
| 1817 |
case 0x2029: |
case 0x2029: |
| 1818 |
|
if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; |
| 1819 |
|
goto ANYNL03; |
| 1820 |
|
|
| 1821 |
|
case 0x000d: |
| 1822 |
|
if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; |
| 1823 |
|
/* Fall through */ |
| 1824 |
|
|
| 1825 |
|
ANYNL03: |
| 1826 |
|
case 0x000a: |
| 1827 |
if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSUPTO) |
if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSUPTO) |
| 1828 |
{ |
{ |
| 1829 |
active_count--; /* Remove non-match possibility */ |
active_count--; /* Remove non-match possibility */ |
| 1834 |
else |
else |
| 1835 |
{ ADD_NEW_DATA(-state_offset, count, ncount); } |
{ ADD_NEW_DATA(-state_offset, count, ncount); } |
| 1836 |
break; |
break; |
| 1837 |
|
|
| 1838 |
default: |
default: |
| 1839 |
break; |
break; |
| 1840 |
} |
} |
| 1851 |
count = current_state->count; /* Number already matched */ |
count = current_state->count; /* Number already matched */ |
| 1852 |
if (clen > 0) |
if (clen > 0) |
| 1853 |
{ |
{ |
| 1854 |
BOOL OK; |
BOOL OK; |
| 1855 |
switch (c) |
switch (c) |
| 1856 |
{ |
{ |
| 1857 |
case 0x000a: |
case 0x000a: |
| 1863 |
case 0x2029: |
case 0x2029: |
| 1864 |
OK = TRUE; |
OK = TRUE; |
| 1865 |
break; |
break; |
| 1866 |
|
|
| 1867 |
default: |
default: |
| 1868 |
OK = FALSE; |
OK = FALSE; |
| 1869 |
} |
} |
| 1870 |
|
|
| 1871 |
if (OK == (d == OP_VSPACE)) |
if (OK == (d == OP_VSPACE)) |
| 1872 |
{ |
{ |
| 1873 |
if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSUPTO) |
if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSUPTO) |
| 1874 |
{ |
{ |
| 1875 |
active_count--; /* Remove non-match possibility */ |
active_count--; /* Remove non-match possibility */ |
| 1893 |
count = current_state->count; /* Number already matched */ |
count = current_state->count; /* Number already matched */ |
| 1894 |
if (clen > 0) |
if (clen > 0) |
| 1895 |
{ |
{ |
| 1896 |
BOOL OK; |
BOOL OK; |
| 1897 |
switch (c) |
switch (c) |
| 1898 |
{ |
{ |
| 1899 |
case 0x09: /* HT */ |
case 0x09: /* HT */ |
| 1917 |
case 0x3000: /* IDEOGRAPHIC SPACE */ |
case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 1918 |
OK = TRUE; |
OK = TRUE; |
| 1919 |
break; |
break; |
| 1920 |
|
|
| 1921 |
default: |
default: |
| 1922 |
OK = FALSE; |
OK = FALSE; |
| 1923 |
break; |
break; |
| 1924 |
} |
} |
| 1925 |
|
|
| 1926 |
if (OK == (d == OP_HSPACE)) |
if (OK == (d == OP_HSPACE)) |
| 1927 |
{ |
{ |
| 1928 |
if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSUPTO) |
if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSUPTO) |
| 1929 |
{ |
{ |
| 1930 |
active_count--; /* Remove non-match possibility */ |
active_count--; /* Remove non-match possibility */ |
| 1965 |
other case of the character. */ |
other case of the character. */ |
| 1966 |
|
|
| 1967 |
#ifdef SUPPORT_UCP |
#ifdef SUPPORT_UCP |
| 1968 |
othercase = _pcre_ucp_othercase(c); |
othercase = UCD_OTHERCASE(c); |
| 1969 |
#else |
#else |
| 1970 |
othercase = NOTACHAR; |
othercase = NOTACHAR; |
| 1971 |
#endif |
#endif |
| 1990 |
to wait for them to pass before continuing. */ |
to wait for them to pass before continuing. */ |
| 1991 |
|
|
| 1992 |
case OP_EXTUNI: |
case OP_EXTUNI: |
| 1993 |
if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M) |
if (clen > 0 && UCD_CATEGORY(c) != ucp_M) |
| 1994 |
{ |
{ |
| 1995 |
const uschar *nptr = ptr + clen; |
const uschar *nptr = ptr + clen; |
| 1996 |
int ncount = 0; |
int ncount = 0; |
| 1998 |
{ |
{ |
| 1999 |
int nclen = 1; |
int nclen = 1; |
| 2000 |
GETCHARLEN(c, nptr, nclen); |
GETCHARLEN(c, nptr, nclen); |
| 2001 |
if (_pcre_ucp_findprop(c, &chartype, &script) != ucp_M) break; |
if (UCD_CATEGORY(c) != ucp_M) break; |
| 2002 |
ncount++; |
ncount++; |
| 2003 |
nptr += nclen; |
nptr += nclen; |
| 2004 |
} |
} |
| 2015 |
case OP_ANYNL: |
case OP_ANYNL: |
| 2016 |
if (clen > 0) switch(c) |
if (clen > 0) switch(c) |
| 2017 |
{ |
{ |
|
case 0x000a: |
|
| 2018 |
case 0x000b: |
case 0x000b: |
| 2019 |
case 0x000c: |
case 0x000c: |
| 2020 |
case 0x0085: |
case 0x0085: |
| 2021 |
case 0x2028: |
case 0x2028: |
| 2022 |
case 0x2029: |
case 0x2029: |
| 2023 |
|
if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; |
| 2024 |
|
|
| 2025 |
|
case 0x000a: |
| 2026 |
ADD_NEW(state_offset + 1, 0); |
ADD_NEW(state_offset + 1, 0); |
| 2027 |
break; |
break; |
| 2028 |
|
|
| 2029 |
case 0x000d: |
case 0x000d: |
| 2030 |
if (ptr + 1 < end_subject && ptr[1] == 0x0a) |
if (ptr + 1 < end_subject && ptr[1] == 0x0a) |
| 2031 |
{ |
{ |
| 2051 |
case 0x2028: |
case 0x2028: |
| 2052 |
case 0x2029: |
case 0x2029: |
| 2053 |
break; |
break; |
| 2054 |
|
|
| 2055 |
default: |
default: |
| 2056 |
ADD_NEW(state_offset + 1, 0); |
ADD_NEW(state_offset + 1, 0); |
| 2057 |
break; |
break; |
| 2058 |
} |
} |
| 2071 |
case 0x2029: |
case 0x2029: |
| 2072 |
ADD_NEW(state_offset + 1, 0); |
ADD_NEW(state_offset + 1, 0); |
| 2073 |
break; |
break; |
| 2074 |
|
|
| 2075 |
default: break; |
default: break; |
| 2076 |
} |
} |
| 2077 |
break; |
break; |
| 2100 |
case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ |
| 2101 |
case 0x3000: /* IDEOGRAPHIC SPACE */ |
case 0x3000: /* IDEOGRAPHIC SPACE */ |
| 2102 |
break; |
break; |
| 2103 |
|
|
| 2104 |
default: |
default: |
| 2105 |
ADD_NEW(state_offset + 1, 0); |
ADD_NEW(state_offset + 1, 0); |
| 2106 |
break; |
break; |
| 2107 |
} |
} |
| 2166 |
if (utf8 && d >= 128) |
if (utf8 && d >= 128) |
| 2167 |
{ |
{ |
| 2168 |
#ifdef SUPPORT_UCP |
#ifdef SUPPORT_UCP |
| 2169 |
otherd = _pcre_ucp_othercase(d); |
otherd = UCD_OTHERCASE(d); |
| 2170 |
#endif /* SUPPORT_UCP */ |
#endif /* SUPPORT_UCP */ |
| 2171 |
} |
} |
| 2172 |
else |
else |
| 2204 |
if (utf8 && d >= 128) |
if (utf8 && d >= 128) |
| 2205 |
{ |
{ |
| 2206 |
#ifdef SUPPORT_UCP |
#ifdef SUPPORT_UCP |
| 2207 |
otherd = _pcre_ucp_othercase(d); |
otherd = UCD_OTHERCASE(d); |
| 2208 |
#endif /* SUPPORT_UCP */ |
#endif /* SUPPORT_UCP */ |
| 2209 |
} |
} |
| 2210 |
else |
else |
| 2240 |
if (utf8 && d >= 128) |
if (utf8 && d >= 128) |
| 2241 |
{ |
{ |
| 2242 |
#ifdef SUPPORT_UCP |
#ifdef SUPPORT_UCP |
| 2243 |
otherd = _pcre_ucp_othercase(d); |
otherd = UCD_OTHERCASE(d); |
| 2244 |
#endif /* SUPPORT_UCP */ |
#endif /* SUPPORT_UCP */ |
| 2245 |
} |
} |
| 2246 |
else |
else |
| 2272 |
if (utf8 && d >= 128) |
if (utf8 && d >= 128) |
| 2273 |
{ |
{ |
| 2274 |
#ifdef SUPPORT_UCP |
#ifdef SUPPORT_UCP |
| 2275 |
otherd = _pcre_ucp_othercase(d); |
otherd = UCD_OTHERCASE(d); |
| 2276 |
#endif /* SUPPORT_UCP */ |
#endif /* SUPPORT_UCP */ |
| 2277 |
} |
} |
| 2278 |
else |
else |
| 2307 |
if (utf8 && d >= 128) |
if (utf8 && d >= 128) |
| 2308 |
{ |
{ |
| 2309 |
#ifdef SUPPORT_UCP |
#ifdef SUPPORT_UCP |
| 2310 |
otherd = _pcre_ucp_othercase(d); |
otherd = UCD_OTHERCASE(d); |
| 2311 |
#endif /* SUPPORT_UCP */ |
#endif /* SUPPORT_UCP */ |
| 2312 |
} |
} |
| 2313 |
else |
else |
| 2368 |
points to the byte after the end of the class. If there is a |
points to the byte after the end of the class. If there is a |
| 2369 |
quantifier, this is where it will be. */ |
quantifier, this is where it will be. */ |
| 2370 |
|
|
| 2371 |
next_state_offset = ecode - start_code; |
next_state_offset = (int)(ecode - start_code); |
| 2372 |
|
|
| 2373 |
switch (*ecode) |
switch (*ecode) |
| 2374 |
{ |
{ |
| 2415 |
|
|
| 2416 |
/* ========================================================================== */ |
/* ========================================================================== */ |
| 2417 |
/* These are the opcodes for fancy brackets of various kinds. We have |
/* These are the opcodes for fancy brackets of various kinds. We have |
| 2418 |
to use recursion in order to handle them. */ |
to use recursion in order to handle them. The "always failing" assertion |
| 2419 |
|
(?!) is optimised to OP_FAIL when compiling, so we have to support that, |
| 2420 |
|
though the other "backtracking verbs" are not supported. */ |
| 2421 |
|
|
| 2422 |
|
case OP_FAIL: |
| 2423 |
|
forced_fail++; /* Count FAILs for multiple states */ |
| 2424 |
|
break; |
| 2425 |
|
|
| 2426 |
case OP_ASSERT: |
case OP_ASSERT: |
| 2427 |
case OP_ASSERT_NOT: |
case OP_ASSERT_NOT: |
| 2439 |
md, /* static match data */ |
md, /* static match data */ |
| 2440 |
code, /* this subexpression's code */ |
code, /* this subexpression's code */ |
| 2441 |
ptr, /* where we currently are */ |
ptr, /* where we currently are */ |
| 2442 |
ptr - start_subject, /* start offset */ |
(int)(ptr - start_subject), /* start offset */ |
| 2443 |
local_offsets, /* offset vector */ |
local_offsets, /* offset vector */ |
| 2444 |
sizeof(local_offsets)/sizeof(int), /* size of same */ |
sizeof(local_offsets)/sizeof(int), /* size of same */ |
| 2445 |
local_workspace, /* workspace vector */ |
local_workspace, /* workspace vector */ |
| 2448 |
rlevel, /* function recursion level */ |
rlevel, /* function recursion level */ |
| 2449 |
recursing); /* pass on regex recursion */ |
recursing); /* pass on regex recursion */ |
| 2450 |
|
|
| 2451 |
|
if (rc == PCRE_ERROR_DFA_UITEM) return rc; |
| 2452 |
if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK)) |
if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK)) |
| 2453 |
{ ADD_ACTIVE(endasscode + LINK_SIZE + 1 - start_code, 0); } |
{ ADD_ACTIVE((int)(endasscode + LINK_SIZE + 1 - start_code), 0); } |
| 2454 |
} |
} |
| 2455 |
break; |
break; |
| 2456 |
|
|
| 2460 |
{ |
{ |
| 2461 |
int local_offsets[1000]; |
int local_offsets[1000]; |
| 2462 |
int local_workspace[1000]; |
int local_workspace[1000]; |
| 2463 |
int condcode = code[LINK_SIZE+1]; |
int codelink = GET(code, 1); |
| 2464 |
|
int condcode; |
| 2465 |
|
|
| 2466 |
|
/* Because of the way auto-callout works during compile, a callout item |
| 2467 |
|
is inserted between OP_COND and an assertion condition. This does not |
| 2468 |
|
happen for the other conditions. */ |
| 2469 |
|
|
| 2470 |
|
if (code[LINK_SIZE+1] == OP_CALLOUT) |
| 2471 |
|
{ |
| 2472 |
|
rrc = 0; |
| 2473 |
|
if (pcre_callout != NULL) |
| 2474 |
|
{ |
| 2475 |
|
pcre_callout_block cb; |
| 2476 |
|
cb.version = 1; /* Version 1 of the callout block */ |
| 2477 |
|
cb.callout_number = code[LINK_SIZE+2]; |
| 2478 |
|
cb.offset_vector = offsets; |
| 2479 |
|
cb.subject = (PCRE_SPTR)start_subject; |
| 2480 |
|
cb.subject_length = (int)(end_subject - start_subject); |
| 2481 |
|
cb.start_match = (int)(current_subject - start_subject); |
| 2482 |
|
cb.current_position = (int)(ptr - start_subject); |
| 2483 |
|
cb.pattern_position = GET(code, LINK_SIZE + 3); |
| 2484 |
|
cb.next_item_length = GET(code, 3 + 2*LINK_SIZE); |
| 2485 |
|
cb.capture_top = 1; |
| 2486 |
|
cb.capture_last = -1; |
| 2487 |
|
cb.callout_data = md->callout_data; |
| 2488 |
|
if ((rrc = (*pcre_callout)(&cb)) < 0) return rrc; /* Abandon */ |
| 2489 |
|
} |
| 2490 |
|
if (rrc > 0) break; /* Fail this thread */ |
| 2491 |
|
code += _pcre_OP_lengths[OP_CALLOUT]; /* Skip callout data */ |
| 2492 |
|
} |
| 2493 |
|
|
| 2494 |
|
condcode = code[LINK_SIZE+1]; |
| 2495 |
|
|
| 2496 |
/* Back reference conditions are not supported */ |
/* Back reference conditions are not supported */ |
| 2497 |
|
|
| 2498 |
if (condcode == OP_CREF) return PCRE_ERROR_DFA_UCOND; |
if (condcode == OP_CREF || condcode == OP_NCREF) |
| 2499 |
|
return PCRE_ERROR_DFA_UCOND; |
| 2500 |
|
|
| 2501 |
/* The DEFINE condition is always false */ |
/* The DEFINE condition is always false */ |
| 2502 |
|
|
| 2503 |
if (condcode == OP_DEF) |
if (condcode == OP_DEF) |
| 2504 |
{ |
{ ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); } |
|
ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); |
|
|
} |
|
| 2505 |
|
|
| 2506 |
/* The only supported version of OP_RREF is for the value RREF_ANY, |
/* The only supported version of OP_RREF is for the value RREF_ANY, |
| 2507 |
which means "test if in any recursion". We can't test for specifically |
which means "test if in any recursion". We can't test for specifically |
| 2508 |
recursed groups. */ |
recursed groups. */ |
| 2509 |
|
|
| 2510 |
else if (condcode == OP_RREF) |
else if (condcode == OP_RREF || condcode == OP_NRREF) |
| 2511 |
{ |
{ |
| 2512 |
int value = GET2(code, LINK_SIZE+2); |
int value = GET2(code, LINK_SIZE+2); |
| 2513 |
if (value != RREF_ANY) return PCRE_ERROR_DFA_UCOND; |
if (value != RREF_ANY) return PCRE_ERROR_DFA_UCOND; |
| 2514 |
if (recursing > 0) { ADD_ACTIVE(state_offset + LINK_SIZE + 4, 0); } |
if (recursing > 0) |
| 2515 |
else { ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); } |
{ ADD_ACTIVE(state_offset + LINK_SIZE + 4, 0); } |
| 2516 |
|
else { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); } |
| 2517 |
} |
} |
| 2518 |
|
|
| 2519 |
/* Otherwise, the condition is an assertion */ |
/* Otherwise, the condition is an assertion */ |
| 2530 |
md, /* fixed match data */ |
md, /* fixed match data */ |
| 2531 |
asscode, /* this subexpression's code */ |
asscode, /* this subexpression's code */ |
| 2532 |
ptr, /* where we currently are */ |
ptr, /* where we currently are */ |
| 2533 |
ptr - start_subject, /* start offset */ |
(int)(ptr - start_subject), /* start offset */ |
| 2534 |
local_offsets, /* offset vector */ |
local_offsets, /* offset vector */ |
| 2535 |
sizeof(local_offsets)/sizeof(int), /* size of same */ |
sizeof(local_offsets)/sizeof(int), /* size of same */ |
| 2536 |
local_workspace, /* workspace vector */ |
local_workspace, /* workspace vector */ |
| 2539 |
rlevel, /* function recursion level */ |
rlevel, /* function recursion level */ |
| 2540 |
recursing); /* pass on regex recursion */ |
recursing); /* pass on regex recursion */ |
| 2541 |
|
|
| 2542 |
|
if (rc == PCRE_ERROR_DFA_UITEM) return rc; |
| 2543 |
if ((rc >= 0) == |
if ((rc >= 0) == |
| 2544 |
(condcode == OP_ASSERT || condcode == OP_ASSERTBACK)) |
(condcode == OP_ASSERT || condcode == OP_ASSERTBACK)) |
| 2545 |
{ ADD_ACTIVE(endasscode + LINK_SIZE + 1 - start_code, 0); } |
{ ADD_ACTIVE((int)(endasscode + LINK_SIZE + 1 - start_code), 0); } |
| 2546 |
else |
else |
| 2547 |
{ ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); } |
{ ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); } |
| 2548 |
} |
} |
| 2549 |
} |
} |
| 2550 |
break; |
break; |
| 2563 |
md, /* fixed match data */ |
md, /* fixed match data */ |
| 2564 |
start_code + GET(code, 1), /* this subexpression's code */ |
start_code + GET(code, 1), /* this subexpression's code */ |
| 2565 |
ptr, /* where we currently are */ |
ptr, /* where we currently are */ |
| 2566 |
ptr - start_subject, /* start offset */ |
(int)(ptr - start_subject), /* start offset */ |
| 2567 |
local_offsets, /* offset vector */ |
local_offsets, /* offset vector */ |
| 2568 |
sizeof(local_offsets)/sizeof(int), /* size of same */ |
sizeof(local_offsets)/sizeof(int), /* size of same */ |
| 2569 |
local_workspace, /* workspace vector */ |
local_workspace, /* workspace vector */ |
| 2615 |
md, /* fixed match data */ |
md, /* fixed match data */ |
| 2616 |
code, /* this subexpression's code */ |
code, /* this subexpression's code */ |
| 2617 |
ptr, /* where we currently are */ |
ptr, /* where we currently are */ |
| 2618 |
ptr - start_subject, /* start offset */ |
(int)(ptr - start_subject), /* start offset */ |
| 2619 |
local_offsets, /* offset vector */ |
local_offsets, /* offset vector */ |
| 2620 |
sizeof(local_offsets)/sizeof(int), /* size of same */ |
sizeof(local_offsets)/sizeof(int), /* size of same */ |
| 2621 |
local_workspace, /* workspace vector */ |
local_workspace, /* workspace vector */ |
| 2632 |
|
|
| 2633 |
do { end_subpattern += GET(end_subpattern, 1); } |
do { end_subpattern += GET(end_subpattern, 1); } |
| 2634 |
while (*end_subpattern == OP_ALT); |
while (*end_subpattern == OP_ALT); |
| 2635 |
next_state_offset = end_subpattern - start_code + LINK_SIZE + 1; |
next_state_offset = |
| 2636 |
|
(int)(end_subpattern - start_code + LINK_SIZE + 1); |
| 2637 |
|
|
| 2638 |
/* If the end of this subpattern is KETRMAX or KETRMIN, we must |
/* If the end of this subpattern is KETRMAX or KETRMIN, we must |
| 2639 |
arrange for the repeat state also to be added to the relevant list. |
arrange for the repeat state also to be added to the relevant list. |
| 2641 |
|
|
| 2642 |
repeat_state_offset = (*end_subpattern == OP_KETRMAX || |
repeat_state_offset = (*end_subpattern == OP_KETRMAX || |
| 2643 |
*end_subpattern == OP_KETRMIN)? |
*end_subpattern == OP_KETRMIN)? |
| 2644 |
end_subpattern - start_code - GET(end_subpattern, 1) : -1; |
(int)(end_subpattern - start_code - GET(end_subpattern, 1)) : -1; |
| 2645 |
|
|
| 2646 |
/* If we have matched an empty string, add the next state at the |
/* If we have matched an empty string, add the next state at the |
| 2647 |
current character pointer. This is important so that the duplicate |
current character pointer. This is important so that the duplicate |
| 2697 |
/* Handle callouts */ |
/* Handle callouts */ |
| 2698 |
|
|
| 2699 |
case OP_CALLOUT: |
case OP_CALLOUT: |
| 2700 |
|
rrc = 0; |
| 2701 |
if (pcre_callout != NULL) |
if (pcre_callout != NULL) |
| 2702 |
{ |
{ |
|
int rrc; |
|
| 2703 |
pcre_callout_block cb; |
pcre_callout_block cb; |
| 2704 |
cb.version = 1; /* Version 1 of the callout block */ |
cb.version = 1; /* Version 1 of the callout block */ |
| 2705 |
cb.callout_number = code[1]; |
cb.callout_number = code[1]; |
| 2706 |
cb.offset_vector = offsets; |
cb.offset_vector = offsets; |
| 2707 |
cb.subject = (PCRE_SPTR)start_subject; |
cb.subject = (PCRE_SPTR)start_subject; |
| 2708 |
cb.subject_length = end_subject - start_subject; |
cb.subject_length = (int)(end_subject - start_subject); |
| 2709 |
cb.start_match = current_subject - start_subject; |
cb.start_match = (int)(current_subject - start_subject); |
| 2710 |
cb.current_position = ptr - start_subject; |
cb.current_position = (int)(ptr - start_subject); |
| 2711 |
cb.pattern_position = GET(code, 2); |
cb.pattern_position = GET(code, 2); |
| 2712 |
cb.next_item_length = GET(code, 2 + LINK_SIZE); |
cb.next_item_length = GET(code, 2 + LINK_SIZE); |
| 2713 |
cb.capture_top = 1; |
cb.capture_top = 1; |
| 2714 |
cb.capture_last = -1; |
cb.capture_last = -1; |
| 2715 |
cb.callout_data = md->callout_data; |
cb.callout_data = md->callout_data; |
| 2716 |
if ((rrc = (*pcre_callout)(&cb)) < 0) return rrc; /* Abandon */ |
if ((rrc = (*pcre_callout)(&cb)) < 0) return rrc; /* Abandon */ |
|
if (rrc == 0) { ADD_ACTIVE(state_offset + 2 + 2*LINK_SIZE, 0); } |
|
| 2717 |
} |
} |
| 2718 |
|
if (rrc == 0) |
| 2719 |
|
{ ADD_ACTIVE(state_offset + _pcre_OP_lengths[OP_CALLOUT], 0); } |
| 2720 |
break; |
break; |
| 2721 |
|
|
| 2722 |
|
|
| 2732 |
/* We have finished the processing at the current subject character. If no |
/* We have finished the processing at the current subject character. If no |
| 2733 |
new states have been set for the next character, we have found all the |
new states have been set for the next character, we have found all the |
| 2734 |
matches that we are going to find. If we are at the top level and partial |
matches that we are going to find. If we are at the top level and partial |
| 2735 |
matching has been requested, check for appropriate conditions. */ |
matching has been requested, check for appropriate conditions. |
| 2736 |
|
|
| 2737 |
|
The "forced_ fail" variable counts the number of (*F) encountered for the |
| 2738 |
|
character. If it is equal to the original active_count (saved in |
| 2739 |
|
workspace[1]) it means that (*F) was found on every active state. In this |
| 2740 |
|
case we don't want to give a partial match. |
| 2741 |
|
|
| 2742 |
|
The "could_continue" variable is true if a state could have continued but |
| 2743 |
|
for the fact that the end of the subject was reached. */ |
| 2744 |
|
|
| 2745 |
if (new_count <= 0) |
if (new_count <= 0) |
| 2746 |
{ |
{ |
| 2747 |
if (match_count < 0 && /* No matches found */ |
if (rlevel == 1 && /* Top level, and */ |
| 2748 |
rlevel == 1 && /* Top level match function */ |
could_continue && /* Some could go on */ |
| 2749 |
(md->moptions & PCRE_PARTIAL) != 0 && /* Want partial matching */ |
forced_fail != workspace[1] && /* Not all forced fail & */ |
| 2750 |
|
( /* either... */ |
| 2751 |
|
(md->moptions & PCRE_PARTIAL_HARD) != 0 /* Hard partial */ |
| 2752 |
|
|| /* or... */ |
| 2753 |
|
((md->moptions & PCRE_PARTIAL_SOFT) != 0 && /* Soft partial and */ |
| 2754 |
|
match_count < 0) /* no matches */ |
| 2755 |
|
) && /* And... */ |
| 2756 |
ptr >= end_subject && /* Reached end of subject */ |
ptr >= end_subject && /* Reached end of subject */ |
| 2757 |
ptr > current_subject) /* Matched non-empty string */ |
ptr > md->start_used_ptr) /* Inspected non-empty string */ |
| 2758 |
{ |
{ |
| 2759 |
if (offsetcount >= 2) |
if (offsetcount >= 2) |
| 2760 |
{ |
{ |
| 2761 |
offsets[0] = current_subject - start_subject; |
offsets[0] = (int)(md->start_used_ptr - start_subject); |
| 2762 |
offsets[1] = end_subject - start_subject; |
offsets[1] = (int)(end_subject - start_subject); |
| 2763 |
} |
} |
| 2764 |
match_count = PCRE_ERROR_PARTIAL; |
match_count = PCRE_ERROR_PARTIAL; |
| 2765 |
} |
} |
| 2813 |
< -1 => some kind of unexpected problem |
< -1 => some kind of unexpected problem |
| 2814 |
*/ |
*/ |
| 2815 |
|
|
| 2816 |
PCRE_EXP_DEFN int |
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
| 2817 |
pcre_dfa_exec(const pcre *argument_re, const pcre_extra *extra_data, |
pcre_dfa_exec(const pcre *argument_re, const pcre_extra *extra_data, |
| 2818 |
const char *subject, int length, int start_offset, int options, int *offsets, |
const char *subject, int length, int start_offset, int options, int *offsets, |
| 2819 |
int offsetcount, int *workspace, int wscount) |
int offsetcount, int *workspace, int wscount) |
| 2844 |
(offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL; |
(offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL; |
| 2845 |
if (offsetcount < 0) return PCRE_ERROR_BADCOUNT; |
if (offsetcount < 0) return PCRE_ERROR_BADCOUNT; |
| 2846 |
if (wscount < 20) return PCRE_ERROR_DFA_WSSIZE; |
if (wscount < 20) return PCRE_ERROR_DFA_WSSIZE; |
| 2847 |
|
if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET; |
| 2848 |
|
|
| 2849 |
/* We need to find the pointer to any study data before we test for byte |
/* We need to find the pointer to any study data before we test for byte |
| 2850 |
flipping, so we scan the extra_data block first. This may set two fields in the |
flipping, so we scan the extra_data block first. This may set two fields in the |
| 2901 |
re->name_table_offset + re->name_count * re->name_entry_size; |
re->name_table_offset + re->name_count * re->name_entry_size; |
| 2902 |
md->start_subject = (const unsigned char *)subject; |
md->start_subject = (const unsigned char *)subject; |
| 2903 |
md->end_subject = end_subject; |
md->end_subject = end_subject; |
| 2904 |
|
md->start_offset = start_offset; |
| 2905 |
md->moptions = options; |
md->moptions = options; |
| 2906 |
md->poptions = re->options; |
md->poptions = re->options; |
| 2907 |
|
|
| 2908 |
|
/* If the BSR option is not set at match time, copy what was set |
| 2909 |
|
at compile time. */ |
| 2910 |
|
|
| 2911 |
|
if ((md->moptions & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) == 0) |
| 2912 |
|
{ |
| 2913 |
|
if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0) |
| 2914 |
|
md->moptions |= re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE); |
| 2915 |
|
#ifdef BSR_ANYCRLF |
| 2916 |
|
else md->moptions |= PCRE_BSR_ANYCRLF; |
| 2917 |
|
#endif |
| 2918 |
|
} |
| 2919 |
|
|
| 2920 |
/* Handle different types of newline. The three bits give eight cases. If |
/* Handle different types of newline. The three bits give eight cases. If |
| 2921 |
nothing is set at run time, whatever was used at compile time applies. */ |
nothing is set at run time, whatever was used at compile time applies. */ |
| 2922 |
|
|
| 2924 |
PCRE_NEWLINE_BITS) |
PCRE_NEWLINE_BITS) |
| 2925 |
{ |
{ |
| 2926 |
case 0: newline = NEWLINE; break; /* Compile-time default */ |
case 0: newline = NEWLINE; break; /* Compile-time default */ |
| 2927 |
case PCRE_NEWLINE_CR: newline = '\r'; break; |
case PCRE_NEWLINE_CR: newline = CHAR_CR; break; |
| 2928 |
case PCRE_NEWLINE_LF: newline = '\n'; break; |
case PCRE_NEWLINE_LF: newline = CHAR_NL; break; |
| 2929 |
case PCRE_NEWLINE_CR+ |
case PCRE_NEWLINE_CR+ |
| 2930 |
PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break; |
PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break; |
| 2931 |
case PCRE_NEWLINE_ANY: newline = -1; break; |
case PCRE_NEWLINE_ANY: newline = -1; break; |
| 2932 |
case PCRE_NEWLINE_ANYCRLF: newline = -2; break; |
case PCRE_NEWLINE_ANYCRLF: newline = -2; break; |
| 2933 |
default: return PCRE_ERROR_BADNEWLINE; |
default: return PCRE_ERROR_BADNEWLINE; |
| 2963 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 2964 |
if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) |
if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) |
| 2965 |
{ |
{ |
| 2966 |
if (_pcre_valid_utf8((uschar *)subject, length) >= 0) |
int tb; |
| 2967 |
return PCRE_ERROR_BADUTF8; |
if ((tb = _pcre_valid_utf8((uschar *)subject, length)) >= 0) |
| 2968 |
|
return (tb == length && (options & PCRE_PARTIAL_HARD) != 0)? |
| 2969 |
|
PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8; |
| 2970 |
if (start_offset > 0 && start_offset < length) |
if (start_offset > 0 && start_offset < length) |
| 2971 |
{ |
{ |
| 2972 |
int tb = ((uschar *)subject)[start_offset]; |
tb = ((USPTR)subject)[start_offset] & 0xc0; |
| 2973 |
if (tb > 127) |
if (tb == 0x80) return PCRE_ERROR_BADUTF8_OFFSET; |
|
{ |
|
|
tb &= 0xc0; |
|
|
if (tb != 0 && tb != 0xc0) return PCRE_ERROR_BADUTF8_OFFSET; |
|
|
} |
|
| 2974 |
} |
} |
| 2975 |
} |
} |
| 2976 |
#endif |
#endif |
| 2985 |
used in a loop when finding where to start. */ |
used in a loop when finding where to start. */ |
| 2986 |
|
|
| 2987 |
lcc = md->tables + lcc_offset; |
lcc = md->tables + lcc_offset; |
| 2988 |
startline = (re->options & PCRE_STARTLINE) != 0; |
startline = (re->flags & PCRE_STARTLINE) != 0; |
| 2989 |
firstline = (re->options & PCRE_FIRSTLINE) != 0; |
firstline = (re->options & PCRE_FIRSTLINE) != 0; |
| 2990 |
|
|
| 2991 |
/* Set up the first character to match, if available. The first_byte value is |
/* Set up the first character to match, if available. The first_byte value is |
| 2996 |
|
|
| 2997 |
if (!anchored) |
if (!anchored) |
| 2998 |
{ |
{ |
| 2999 |
if ((re->options & PCRE_FIRSTSET) != 0) |
if ((re->flags & PCRE_FIRSTSET) != 0) |
| 3000 |
{ |
{ |
| 3001 |
first_byte = re->first_byte & 255; |
first_byte = re->first_byte & 255; |
| 3002 |
if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) |
if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) |
| 3004 |
} |
} |
| 3005 |
else |
else |
| 3006 |
{ |
{ |
| 3007 |
if (startline && study != NULL && |
if (!startline && study != NULL && |
| 3008 |
(study->options & PCRE_STUDY_MAPPED) != 0) |
(study->flags & PCRE_STUDY_MAPPED) != 0) |
| 3009 |
start_bits = study->start_bits; |
start_bits = study->start_bits; |
| 3010 |
} |
} |
| 3011 |
} |
} |
| 3013 |
/* For anchored or unanchored matches, there may be a "last known required |
/* For anchored or unanchored matches, there may be a "last known required |
| 3014 |
character" set. */ |
character" set. */ |
| 3015 |
|
|
| 3016 |
if ((re->options & PCRE_REQCHSET) != 0) |
if ((re->flags & PCRE_REQCHSET) != 0) |
| 3017 |
{ |
{ |
| 3018 |
req_byte = re->req_byte & 255; |
req_byte = re->req_byte & 255; |
| 3019 |
req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; |
req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; |
| 3021 |
} |
} |
| 3022 |
|
|
| 3023 |
/* Call the main matching function, looping for a non-anchored regex after a |
/* Call the main matching function, looping for a non-anchored regex after a |
| 3024 |
failed match. Unless restarting, optimize by moving to the first match |
failed match. If not restarting, perform certain optimizations at the start of |
| 3025 |
character if possible, when not anchored. Then unless wanting a partial match, |
a match. */ |
|
check for a required later character. */ |
|
| 3026 |
|
|
| 3027 |
for (;;) |
for (;;) |
| 3028 |
{ |
{ |
| 3032 |
{ |
{ |
| 3033 |
const uschar *save_end_subject = end_subject; |
const uschar *save_end_subject = end_subject; |
| 3034 |
|
|
| 3035 |
/* 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 |
| 3036 |
start of the match is constrained to the first line of a multiline string. |
line of a multiline string. Implement this by temporarily adjusting |
| 3037 |
Implement this by temporarily adjusting end_subject so that we stop |
end_subject so that we stop scanning at a newline. If the match fails at |
| 3038 |
scanning at a newline. If the match fails at the newline, later code breaks |
the newline, later code breaks this loop. */ |
|
this loop. */ |
|
| 3039 |
|
|
| 3040 |
if (firstline) |
if (firstline) |
| 3041 |
{ |
{ |
| 3042 |
const uschar *t = current_subject; |
USPTR t = current_subject; |
| 3043 |
|
#ifdef SUPPORT_UTF8 |
| 3044 |
|
if (utf8) |
| 3045 |
|
{ |
| 3046 |
|
while (t < md->end_subject && !IS_NEWLINE(t)) |
| 3047 |
|
{ |
| 3048 |
|
t++; |
| 3049 |
|
while (t < end_subject && (*t & 0xc0) == 0x80) t++; |
| 3050 |
|
} |
| 3051 |
|
} |
| 3052 |
|
else |
| 3053 |
|
#endif |
| 3054 |
while (t < md->end_subject && !IS_NEWLINE(t)) t++; |
while (t < md->end_subject && !IS_NEWLINE(t)) t++; |
| 3055 |
end_subject = t; |
end_subject = t; |
| 3056 |
} |
} |
| 3057 |
|
|
| 3058 |
if (first_byte >= 0) |
/* There are some optimizations that avoid running the match if a known |
| 3059 |
|
starting point is not found. However, there is an option that disables |
| 3060 |
|
these, for testing and for ensuring that all callouts do actually occur. |
| 3061 |
|
The option can be set in the regex by (*NO_START_OPT) or passed in |
| 3062 |
|
match-time options. */ |
| 3063 |
|
|
| 3064 |
|
if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0) |
| 3065 |
{ |
{ |
| 3066 |
if (first_byte_caseless) |
/* Advance to a known first byte. */ |
| 3067 |
while (current_subject < end_subject && |
|
| 3068 |
lcc[*current_subject] != first_byte) |
if (first_byte >= 0) |
| 3069 |
current_subject++; |
{ |
| 3070 |
else |
if (first_byte_caseless) |
| 3071 |
while (current_subject < end_subject && *current_subject != first_byte) |
while (current_subject < end_subject && |
| 3072 |
current_subject++; |
lcc[*current_subject] != first_byte) |
| 3073 |
} |
current_subject++; |
| 3074 |
|
else |
| 3075 |
|
while (current_subject < end_subject && |
| 3076 |
|
*current_subject != first_byte) |
| 3077 |
|
current_subject++; |
| 3078 |
|
} |
| 3079 |
|
|
| 3080 |
/* Or to just after a linebreak for a multiline match if possible */ |
/* Or to just after a linebreak for a multiline match if possible */ |
| 3081 |
|
|
| 3082 |
else if (startline) |
else if (startline) |
|
{ |
|
|
if (current_subject > md->start_subject + start_offset) |
|
| 3083 |
{ |
{ |
| 3084 |
while (current_subject <= end_subject && !WAS_NEWLINE(current_subject)) |
if (current_subject > md->start_subject + start_offset) |
| 3085 |
current_subject++; |
{ |
| 3086 |
|
#ifdef SUPPORT_UTF8 |
| 3087 |
|
if (utf8) |
| 3088 |
|
{ |
| 3089 |
|
while (current_subject < end_subject && |
| 3090 |
|
!WAS_NEWLINE(current_subject)) |
| 3091 |
|
{ |
| 3092 |
|
current_subject++; |
| 3093 |
|
while(current_subject < end_subject && |
| 3094 |
|
(*current_subject & 0xc0) == 0x80) |
| 3095 |
|
current_subject++; |
| 3096 |
|
} |
| 3097 |
|
} |
| 3098 |
|
else |
| 3099 |
|
#endif |
| 3100 |
|
while (current_subject < end_subject && !WAS_NEWLINE(current_subject)) |
| 3101 |
|
current_subject++; |
| 3102 |
|
|
| 3103 |
/* If we have just passed a CR and the newline option is ANY or |
/* If we have just passed a CR and the newline option is ANY or |
| 3104 |
ANYCRLF, and we are now at a LF, advance the match position by one more |
ANYCRLF, and we are now at a LF, advance the match position by one |
| 3105 |
character. */ |
more character. */ |
| 3106 |
|
|
| 3107 |
if (current_subject[-1] == '\r' && |
if (current_subject[-1] == CHAR_CR && |
| 3108 |
(md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) && |
(md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) && |
| 3109 |
current_subject < end_subject && |
current_subject < end_subject && |
| 3110 |
*current_subject == '\n') |
*current_subject == CHAR_NL) |
| 3111 |
current_subject++; |
current_subject++; |
| 3112 |
|
} |
| 3113 |
} |
} |
|
} |
|
| 3114 |
|
|
| 3115 |
/* Or to a non-unique first char after study */ |
/* Or to a non-unique first char after study */ |
| 3116 |
|
|
| 3117 |
else if (start_bits != NULL) |
else if (start_bits != NULL) |
|
{ |
|
|
while (current_subject < end_subject) |
|
| 3118 |
{ |
{ |
| 3119 |
register unsigned int c = *current_subject; |
while (current_subject < end_subject) |
| 3120 |
if ((start_bits[c/8] & (1 << (c&7))) == 0) current_subject++; |
{ |
| 3121 |
|
register unsigned int c = *current_subject; |
| 3122 |
|
if ((start_bits[c/8] & (1 << (c&7))) == 0) |
| 3123 |
|
{ |
| 3124 |
|
current_subject++; |
| 3125 |
|
#ifdef SUPPORT_UTF8 |
| 3126 |
|
if (utf8) |
| 3127 |
|
while(current_subject < end_subject && |
| 3128 |
|
(*current_subject & 0xc0) == 0x80) current_subject++; |
| 3129 |
|
#endif |
| 3130 |
|
} |
| 3131 |
else break; |
else break; |
| 3132 |
|
} |
| 3133 |
} |
} |
| 3134 |
} |
} |
| 3135 |
|
|
| 3136 |
/* Restore fudged end_subject */ |
/* Restore fudged end_subject */ |
| 3137 |
|
|
| 3138 |
end_subject = save_end_subject; |
end_subject = save_end_subject; |
|
} |
|
|
|
|
|
/* If req_byte is set, we know that that character must appear in the subject |
|
|
for the match to succeed. If the first character is set, req_byte must be |
|
|
later in the subject; otherwise the test starts at the match point. This |
|
|
optimization can save a huge amount of work in patterns with nested unlimited |
|
|
repeats that aren't going to match. Writing separate code for cased/caseless |
|
|
versions makes it go faster, as does using an autoincrement and backing off |
|
|
on a match. |
|
|
|
|
|
HOWEVER: when the subject string is very, very long, searching to its end can |
|
|
take a long time, and give bad performance on quite ordinary patterns. This |
|
|
showed up when somebody was matching /^C/ on a 32-megabyte string... so we |
|
|
don't do this when the string is sufficiently long. |
|
|
|
|
|
ALSO: this processing is disabled when partial matching is requested. |
|
|
*/ |
|
|
|
|
|
if (req_byte >= 0 && |
|
|
end_subject - current_subject < REQ_BYTE_MAX && |
|
|
(options & PCRE_PARTIAL) == 0) |
|
|
{ |
|
|
register const uschar *p = current_subject + ((first_byte >= 0)? 1 : 0); |
|
| 3139 |
|
|
| 3140 |
/* We don't need to repeat the search if we haven't yet reached the |
/* The following two optimizations are disabled for partial matching or if |
| 3141 |
place we found it at last time. */ |
disabling is explicitly requested (and of course, by the test above, this |
| 3142 |
|
code is not obeyed when restarting after a partial match). */ |
| 3143 |
|
|
| 3144 |
if (p > req_byte_ptr) |
if ((options & PCRE_NO_START_OPTIMIZE) == 0 && |
| 3145 |
|
(options & (PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT)) == 0) |
| 3146 |
{ |
{ |
| 3147 |
if (req_byte_caseless) |
/* If the pattern was studied, a minimum subject length may be set. This |
| 3148 |
{ |
is a lower bound; no actual string of that length may actually match the |
| 3149 |
while (p < end_subject) |
pattern. Although the value is, strictly, in characters, we treat it as |
| 3150 |
{ |
bytes to avoid spending too much time in this optimization. */ |
| 3151 |
register int pp = *p++; |
|
| 3152 |
if (pp == req_byte || pp == req_byte2) { p--; break; } |
if (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0 && |
| 3153 |
} |
(pcre_uint32)(end_subject - current_subject) < study->minlength) |
| 3154 |
} |
return PCRE_ERROR_NOMATCH; |
| 3155 |
else |
|
| 3156 |
|
/* If req_byte is set, we know that that character must appear in the |
| 3157 |
|
subject for the match to succeed. If the first character is set, req_byte |
| 3158 |
|
must be later in the subject; otherwise the test starts at the match |
| 3159 |
|
point. This optimization can save a huge amount of work in patterns with |
| 3160 |
|
nested unlimited repeats that aren't going to match. Writing separate |
| 3161 |
|
code for cased/caseless versions makes it go faster, as does using an |
| 3162 |
|
autoincrement and backing off on a match. |
| 3163 |
|
|
| 3164 |
|
HOWEVER: when the subject string is very, very long, searching to its end |
| 3165 |
|
can take a long time, and give bad performance on quite ordinary |
| 3166 |
|
patterns. This showed up when somebody was matching /^C/ on a 32-megabyte |
| 3167 |
|
string... so we don't do this when the string is sufficiently long. */ |
| 3168 |
|
|
| 3169 |
|
if (req_byte >= 0 && end_subject - current_subject < REQ_BYTE_MAX) |
| 3170 |
{ |
{ |
| 3171 |
while (p < end_subject) |
register const uschar *p = current_subject + ((first_byte >= 0)? 1 : 0); |
| 3172 |
|
|
| 3173 |
|
/* We don't need to repeat the search if we haven't yet reached the |
| 3174 |
|
place we found it at last time. */ |
| 3175 |
|
|
| 3176 |
|
if (p > req_byte_ptr) |
| 3177 |
{ |
{ |
| 3178 |
if (*p++ == req_byte) { p--; break; } |
if (req_byte_caseless) |
| 3179 |
} |
{ |
| 3180 |
} |
while (p < end_subject) |
| 3181 |
|
{ |
| 3182 |
|
register int pp = *p++; |
| 3183 |
|
if (pp == req_byte || pp == req_byte2) { p--; break; } |
| 3184 |
|
} |
| 3185 |
|
} |
| 3186 |
|
else |
| 3187 |
|
{ |
| 3188 |
|
while (p < end_subject) |
| 3189 |
|
{ |
| 3190 |
|
if (*p++ == req_byte) { p--; break; } |
| 3191 |
|
} |
| 3192 |
|
} |
| 3193 |
|
|
| 3194 |
/* If we can't find the required character, break the matching loop, |
/* If we can't find the required character, break the matching loop, |
| 3195 |
which will cause a return or PCRE_ERROR_NOMATCH. */ |
which will cause a return or PCRE_ERROR_NOMATCH. */ |
| 3196 |
|
|
| 3197 |
if (p >= end_subject) break; |
if (p >= end_subject) break; |
| 3198 |
|
|
| 3199 |
/* If we have found the required character, save the point where we |
/* If we have found the required character, save the point where we |
| 3200 |
found it, so that we don't search again next time round the loop if |
found it, so that we don't search again next time round the loop if |
| 3201 |
the start hasn't passed this character yet. */ |
the start hasn't passed this character yet. */ |
| 3202 |
|
|
| 3203 |
req_byte_ptr = p; |
req_byte_ptr = p; |
| 3204 |
|
} |
| 3205 |
|
} |
| 3206 |
} |
} |
| 3207 |
} |
} /* End of optimizations that are done when not restarting */ |
| 3208 |
|
|
| 3209 |
/* OK, now we can do the business */ |
/* OK, now we can do the business */ |
| 3210 |
|
|
| 3211 |
|
md->start_used_ptr = current_subject; |
| 3212 |
|
|
| 3213 |
rc = internal_dfa_exec( |
rc = internal_dfa_exec( |
| 3214 |
md, /* fixed match data */ |
md, /* fixed match data */ |
| 3215 |
md->start_code, /* this subexpression's code */ |
md->start_code, /* this subexpression's code */ |
| 3240 |
} |
} |
| 3241 |
if (current_subject > end_subject) break; |
if (current_subject > end_subject) break; |
| 3242 |
|
|
| 3243 |
/* If we have just passed a CR and the newline option is CRLF or ANY or |
/* If we have just passed a CR and we are now at a LF, and the pattern does |
| 3244 |
ANYCRLF, and we are now at a LF, advance the match position by one more |
not contain any explicit matches for \r or \n, and the newline option is CRLF |
| 3245 |
character. */ |
or ANY or ANYCRLF, advance the match position by one more character. */ |
| 3246 |
|
|
| 3247 |
if (current_subject[-1] == '\r' && |
if (current_subject[-1] == CHAR_CR && |
| 3248 |
(md->nltype == NLTYPE_ANY || |
current_subject < end_subject && |
| 3249 |
md->nltype == NLTYPE_ANYCRLF || |
*current_subject == CHAR_NL && |
| 3250 |
md->nllen == 2) && |
(re->flags & PCRE_HASCRORLF) == 0 && |
| 3251 |
current_subject < end_subject && |
(md->nltype == NLTYPE_ANY || |
| 3252 |
*current_subject == '\n') |
md->nltype == NLTYPE_ANYCRLF || |
| 3253 |
|
md->nllen == 2)) |
| 3254 |
current_subject++; |
current_subject++; |
| 3255 |
|
|
| 3256 |
} /* "Bumpalong" loop */ |
} /* "Bumpalong" loop */ |