PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/tags/harbour-3.0.0/src/3rd/pcre/pcredfa.c

#
C | 1903 lines | 1391 code | 236 blank | 276 comment | 498 complexity | 61a5650836fc7eb7ca0397bb06f5a3ee MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause, CC-BY-SA-3.0, LGPL-3.0, GPL-2.0, LGPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. /*************************************************
  2. * Perl-Compatible Regular Expressions *
  3. *************************************************/
  4. /* PCRE is a library of functions to support regular expressions whose syntax
  5. and semantics are as close as possible to those of the Perl 5 language (but see
  6. below for why this module is different).
  7. Written by Philip Hazel
  8. Copyright (c) 1997-2010 University of Cambridge
  9. -----------------------------------------------------------------------------
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. * Neither the name of the University of Cambridge nor the names of its
  18. contributors may be used to endorse or promote products derived from
  19. this software without specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  24. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. POSSIBILITY OF SUCH DAMAGE.
  31. -----------------------------------------------------------------------------
  32. */
  33. /* This module contains the external function pcre_dfa_exec(), which is an
  34. alternative matching function that uses a sort of DFA algorithm (not a true
  35. FSM). This is NOT Perl- compatible, but it has advantages in certain
  36. applications. */
  37. /* NOTE ABOUT PERFORMANCE: A user of this function sent some code that improved
  38. the performance of his patterns greatly. I could not use it as it stood, as it
  39. was not thread safe, and made assumptions about pattern sizes. Also, it caused
  40. test 7 to loop, and test 9 to crash with a segfault.
  41. The issue is the check for duplicate states, which is done by a simple linear
  42. search up the state list. (Grep for "duplicate" below to find the code.) For
  43. many patterns, there will never be many states active at one time, so a simple
  44. linear search is fine. In patterns that have many active states, it might be a
  45. bottleneck. The suggested code used an indexing scheme to remember which states
  46. had previously been used for each character, and avoided the linear search when
  47. it knew there was no chance of a duplicate. This was implemented when adding
  48. states to the state lists.
  49. I wrote some thread-safe, not-limited code to try something similar at the time
  50. of checking for duplicates (instead of when adding states), using index vectors
  51. on the stack. It did give a 13% improvement with one specially constructed
  52. pattern for certain subject strings, but on other strings and on many of the
  53. simpler patterns in the test suite it did worse. The major problem, I think,
  54. was the extra time to initialize the index. This had to be done for each call
  55. of internal_dfa_exec(). (The supplied patch used a static vector, initialized
  56. only once - I suspect this was the cause of the problems with the tests.)
  57. Overall, I concluded that the gains in some cases did not outweigh the losses
  58. in others, so I abandoned this code. */
  59. #ifdef HAVE_CONFIG_H
  60. #include "config.h"
  61. #endif
  62. #define NLBLOCK md /* Block containing newline information */
  63. #define PSSTART start_subject /* Field containing processed string start */
  64. #define PSEND end_subject /* Field containing processed string end */
  65. #include "pcreinal.h"
  66. /* For use to indent debugging output */
  67. #define SP " "
  68. /*************************************************
  69. * Code parameters and static tables *
  70. *************************************************/
  71. /* These are offsets that are used to turn the OP_TYPESTAR and friends opcodes
  72. into others, under special conditions. A gap of 20 between the blocks should be
  73. enough. The resulting opcodes don't have to be less than 256 because they are
  74. never stored, so we push them well clear of the normal opcodes. */
  75. #define OP_PROP_EXTRA 300
  76. #define OP_EXTUNI_EXTRA 320
  77. #define OP_ANYNL_EXTRA 340
  78. #define OP_HSPACE_EXTRA 360
  79. #define OP_VSPACE_EXTRA 380
  80. /* This table identifies those opcodes that are followed immediately by a
  81. character that is to be tested in some way. This makes it possible to
  82. centralize the loading of these characters. In the case of Type * etc, the
  83. "character" is the opcode for \D, \d, \S, \s, \W, or \w, which will always be a
  84. small value. Non-zero values in the table are the offsets from the opcode where
  85. the character is to be found. ***NOTE*** If the start of this table is
  86. modified, the three tables that follow must also be modified. */
  87. static const uschar coptable[] = {
  88. 0, /* End */
  89. 0, 0, 0, 0, 0, /* \A, \G, \K, \B, \b */
  90. 0, 0, 0, 0, 0, 0, /* \D, \d, \S, \s, \W, \w */
  91. 0, 0, 0, /* Any, AllAny, Anybyte */
  92. 0, 0, /* \P, \p */
  93. 0, 0, 0, 0, 0, /* \R, \H, \h, \V, \v */
  94. 0, /* \X */
  95. 0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */
  96. 1, /* Char */
  97. 1, /* Charnc */
  98. 1, /* not */
  99. /* Positive single-char repeats */
  100. 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */
  101. 3, 3, 3, /* upto, minupto, exact */
  102. 1, 1, 1, 3, /* *+, ++, ?+, upto+ */
  103. /* Negative single-char repeats - only for chars < 256 */
  104. 1, 1, 1, 1, 1, 1, /* NOT *, *?, +, +?, ?, ?? */
  105. 3, 3, 3, /* NOT upto, minupto, exact */
  106. 1, 1, 1, 3, /* NOT *+, ++, ?+, updo+ */
  107. /* Positive type repeats */
  108. 1, 1, 1, 1, 1, 1, /* Type *, *?, +, +?, ?, ?? */
  109. 3, 3, 3, /* Type upto, minupto, exact */
  110. 1, 1, 1, 3, /* Type *+, ++, ?+, upto+ */
  111. /* Character class & ref repeats */
  112. 0, 0, 0, 0, 0, 0, /* *, *?, +, +?, ?, ?? */
  113. 0, 0, /* CRRANGE, CRMINRANGE */
  114. 0, /* CLASS */
  115. 0, /* NCLASS */
  116. 0, /* XCLASS - variable length */
  117. 0, /* REF */
  118. 0, /* RECURSE */
  119. 0, /* CALLOUT */
  120. 0, /* Alt */
  121. 0, /* Ket */
  122. 0, /* KetRmax */
  123. 0, /* KetRmin */
  124. 0, /* Assert */
  125. 0, /* Assert not */
  126. 0, /* Assert behind */
  127. 0, /* Assert behind not */
  128. 0, /* Reverse */
  129. 0, 0, 0, 0, /* ONCE, BRA, CBRA, COND */
  130. 0, 0, 0, /* SBRA, SCBRA, SCOND */
  131. 0, 0, /* CREF, NCREF */
  132. 0, 0, /* RREF, NRREF */
  133. 0, /* DEF */
  134. 0, 0, /* BRAZERO, BRAMINZERO */
  135. 0, 0, 0, /* MARK, PRUNE, PRUNE_ARG, */
  136. 0, 0, 0, 0, /* SKIP, SKIP_ARG, THEN, THEN_ARG, */
  137. 0, 0, 0, 0, 0 /* COMMIT, FAIL, ACCEPT, CLOSE, SKIPZERO */
  138. };
  139. /* This table identifies those opcodes that inspect a character. It is used to
  140. remember the fact that a character could have been inspected when the end of
  141. the subject is reached. ***NOTE*** If the start of this table is modified, the
  142. two tables that follow must also be modified. */
  143. static const uschar poptable[] = {
  144. 0, /* End */
  145. 0, 0, 0, 1, 1, /* \A, \G, \K, \B, \b */
  146. 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */
  147. 1, 1, 1, /* Any, AllAny, Anybyte */
  148. 1, 1, /* \P, \p */
  149. 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */
  150. 1, /* \X */
  151. 0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */
  152. 1, /* Char */
  153. 1, /* Charnc */
  154. 1, /* not */
  155. /* Positive single-char repeats */
  156. 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */
  157. 1, 1, 1, /* upto, minupto, exact */
  158. 1, 1, 1, 1, /* *+, ++, ?+, upto+ */
  159. /* Negative single-char repeats - only for chars < 256 */
  160. 1, 1, 1, 1, 1, 1, /* NOT *, *?, +, +?, ?, ?? */
  161. 1, 1, 1, /* NOT upto, minupto, exact */
  162. 1, 1, 1, 1, /* NOT *+, ++, ?+, upto+ */
  163. /* Positive type repeats */
  164. 1, 1, 1, 1, 1, 1, /* Type *, *?, +, +?, ?, ?? */
  165. 1, 1, 1, /* Type upto, minupto, exact */
  166. 1, 1, 1, 1, /* Type *+, ++, ?+, upto+ */
  167. /* Character class & ref repeats */
  168. 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */
  169. 1, 1, /* CRRANGE, CRMINRANGE */
  170. 1, /* CLASS */
  171. 1, /* NCLASS */
  172. 1, /* XCLASS - variable length */
  173. 0, /* REF */
  174. 0, /* RECURSE */
  175. 0, /* CALLOUT */
  176. 0, /* Alt */
  177. 0, /* Ket */
  178. 0, /* KetRmax */
  179. 0, /* KetRmin */
  180. 0, /* Assert */
  181. 0, /* Assert not */
  182. 0, /* Assert behind */
  183. 0, /* Assert behind not */
  184. 0, /* Reverse */
  185. 0, 0, 0, 0, /* ONCE, BRA, CBRA, COND */
  186. 0, 0, 0, /* SBRA, SCBRA, SCOND */
  187. 0, 0, /* CREF, NCREF */
  188. 0, 0, /* RREF, NRREF */
  189. 0, /* DEF */
  190. 0, 0, /* BRAZERO, BRAMINZERO */
  191. 0, 0, 0, /* MARK, PRUNE, PRUNE_ARG, */
  192. 0, 0, 0, 0, /* SKIP, SKIP_ARG, THEN, THEN_ARG, */
  193. 0, 0, 0, 0, 0 /* COMMIT, FAIL, ACCEPT, CLOSE, SKIPZERO */
  194. };
  195. /* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W,
  196. and \w */
  197. static const uschar toptable1[] = {
  198. 0, 0, 0, 0, 0, 0,
  199. ctype_digit, ctype_digit,
  200. ctype_space, ctype_space,
  201. ctype_word, ctype_word,
  202. 0, 0 /* OP_ANY, OP_ALLANY */
  203. };
  204. static const uschar toptable2[] = {
  205. 0, 0, 0, 0, 0, 0,
  206. ctype_digit, 0,
  207. ctype_space, 0,
  208. ctype_word, 0,
  209. 1, 1 /* OP_ANY, OP_ALLANY */
  210. };
  211. /* Structure for holding data about a particular state, which is in effect the
  212. current data for an active path through the match tree. It must consist
  213. entirely of ints because the working vector we are passed, and which we put
  214. these structures in, is a vector of ints. */
  215. typedef struct stateblock {
  216. int offset; /* Offset to opcode */
  217. int count; /* Count for repeats */
  218. int ims; /* ims flag bits */
  219. int data; /* Some use extra data */
  220. } stateblock;
  221. #define INTS_PER_STATEBLOCK (sizeof(stateblock)/sizeof(int))
  222. #ifdef PCRE_DEBUG
  223. /*************************************************
  224. * Print character string *
  225. *************************************************/
  226. /* Character string printing function for debugging.
  227. Arguments:
  228. p points to string
  229. length number of bytes
  230. f where to print
  231. Returns: nothing
  232. */
  233. static void
  234. pchars(unsigned char *p, int length, FILE *f)
  235. {
  236. int c;
  237. while (length-- > 0)
  238. {
  239. if (isprint(c = *(p++)))
  240. fprintf(f, "%c", c);
  241. else
  242. fprintf(f, "\\x%02x", c);
  243. }
  244. }
  245. #endif
  246. /*************************************************
  247. * Execute a Regular Expression - DFA engine *
  248. *************************************************/
  249. /* This internal function applies a compiled pattern to a subject string,
  250. starting at a given point, using a DFA engine. This function is called from the
  251. external one, possibly multiple times if the pattern is not anchored. The
  252. function calls itself recursively for some kinds of subpattern.
  253. Arguments:
  254. md the match_data block with fixed information
  255. this_start_code the opening bracket of this subexpression's code
  256. current_subject where we currently are in the subject string
  257. start_offset start offset in the subject string
  258. offsets vector to contain the matching string offsets
  259. offsetcount size of same
  260. workspace vector of workspace
  261. wscount size of same
  262. ims the current ims flags
  263. rlevel function call recursion level
  264. recursing regex recursive call level
  265. Returns: > 0 => number of match offset pairs placed in offsets
  266. = 0 => offsets overflowed; longest matches are present
  267. -1 => failed to match
  268. < -1 => some kind of unexpected problem
  269. The following macros are used for adding states to the two state vectors (one
  270. for the current character, one for the following character). */
  271. #define ADD_ACTIVE(x,y) \
  272. if (active_count++ < wscount) \
  273. { \
  274. next_active_state->offset = (x); \
  275. next_active_state->count = (y); \
  276. next_active_state->ims = ims; \
  277. next_active_state++; \
  278. DPRINTF(("%.*sADD_ACTIVE(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \
  279. } \
  280. else return PCRE_ERROR_DFA_WSSIZE
  281. #define ADD_ACTIVE_DATA(x,y,z) \
  282. if (active_count++ < wscount) \
  283. { \
  284. next_active_state->offset = (x); \
  285. next_active_state->count = (y); \
  286. next_active_state->ims = ims; \
  287. next_active_state->data = (z); \
  288. next_active_state++; \
  289. DPRINTF(("%.*sADD_ACTIVE_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \
  290. } \
  291. else return PCRE_ERROR_DFA_WSSIZE
  292. #define ADD_NEW(x,y) \
  293. if (new_count++ < wscount) \
  294. { \
  295. next_new_state->offset = (x); \
  296. next_new_state->count = (y); \
  297. next_new_state->ims = ims; \
  298. next_new_state++; \
  299. DPRINTF(("%.*sADD_NEW(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \
  300. } \
  301. else return PCRE_ERROR_DFA_WSSIZE
  302. #define ADD_NEW_DATA(x,y,z) \
  303. if (new_count++ < wscount) \
  304. { \
  305. next_new_state->offset = (x); \
  306. next_new_state->count = (y); \
  307. next_new_state->ims = ims; \
  308. next_new_state->data = (z); \
  309. next_new_state++; \
  310. DPRINTF(("%.*sADD_NEW_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \
  311. } \
  312. else return PCRE_ERROR_DFA_WSSIZE
  313. /* And now, here is the code */
  314. static int
  315. internal_dfa_exec(
  316. dfa_match_data *md,
  317. const uschar *this_start_code,
  318. const uschar *current_subject,
  319. int start_offset,
  320. int *offsets,
  321. int offsetcount,
  322. int *workspace,
  323. int wscount,
  324. int ims,
  325. int rlevel,
  326. int recursing)
  327. {
  328. stateblock *active_states, *new_states, *temp_states;
  329. stateblock *next_active_state, *next_new_state;
  330. const uschar *ctypes, *lcc, *fcc;
  331. const uschar *ptr;
  332. const uschar *end_code, *first_op;
  333. int active_count, new_count, match_count;
  334. /* Some fields in the md block are frequently referenced, so we load them into
  335. independent variables in the hope that this will perform better. */
  336. const uschar *start_subject = md->start_subject;
  337. const uschar *end_subject = md->end_subject;
  338. const uschar *start_code = md->start_code;
  339. #ifdef SUPPORT_UTF8
  340. BOOL utf8 = (md->poptions & PCRE_UTF8) != 0;
  341. #else
  342. BOOL utf8 = FALSE;
  343. #endif
  344. rlevel++;
  345. offsetcount &= (-2);
  346. wscount -= 2;
  347. wscount = (wscount - (wscount % (INTS_PER_STATEBLOCK * 2))) /
  348. (2 * INTS_PER_STATEBLOCK);
  349. DPRINTF(("\n%.*s---------------------\n"
  350. "%.*sCall to internal_dfa_exec f=%d r=%d\n",
  351. rlevel*2-2, SP, rlevel*2-2, SP, rlevel, recursing));
  352. ctypes = md->tables + ctypes_offset;
  353. lcc = md->tables + lcc_offset;
  354. fcc = md->tables + fcc_offset;
  355. match_count = PCRE_ERROR_NOMATCH; /* A negative number */
  356. active_states = (stateblock *)(workspace + 2);
  357. next_new_state = new_states = active_states + wscount;
  358. new_count = 0;
  359. first_op = this_start_code + 1 + LINK_SIZE +
  360. ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0);
  361. /* The first thing in any (sub) pattern is a bracket of some sort. Push all
  362. the alternative states onto the list, and find out where the end is. This
  363. makes is possible to use this function recursively, when we want to stop at a
  364. matching internal ket rather than at the end.
  365. If the first opcode in the first alternative is OP_REVERSE, we are dealing with
  366. a backward assertion. In that case, we have to find out the maximum amount to
  367. move back, and set up each alternative appropriately. */
  368. if (*first_op == OP_REVERSE)
  369. {
  370. int max_back = 0;
  371. int gone_back;
  372. end_code = this_start_code;
  373. do
  374. {
  375. int back = GET(end_code, 2+LINK_SIZE);
  376. if (back > max_back) max_back = back;
  377. end_code += GET(end_code, 1);
  378. }
  379. while (*end_code == OP_ALT);
  380. /* If we can't go back the amount required for the longest lookbehind
  381. pattern, go back as far as we can; some alternatives may still be viable. */
  382. #ifdef SUPPORT_UTF8
  383. /* In character mode we have to step back character by character */
  384. if (utf8)
  385. {
  386. for (gone_back = 0; gone_back < max_back; gone_back++)
  387. {
  388. if (current_subject <= start_subject) break;
  389. current_subject--;
  390. while (current_subject > start_subject &&
  391. (*current_subject & 0xc0) == 0x80)
  392. current_subject--;
  393. }
  394. }
  395. else
  396. #endif
  397. /* In byte-mode we can do this quickly. */
  398. {
  399. gone_back = (current_subject - max_back < start_subject)?
  400. (int)(current_subject - start_subject) : max_back;
  401. current_subject -= gone_back;
  402. }
  403. /* Save the earliest consulted character */
  404. if (current_subject < md->start_used_ptr)
  405. md->start_used_ptr = current_subject;
  406. /* Now we can process the individual branches. */
  407. end_code = this_start_code;
  408. do
  409. {
  410. int back = GET(end_code, 2+LINK_SIZE);
  411. if (back <= gone_back)
  412. {
  413. int bstate = (int)(end_code - start_code + 2 + 2*LINK_SIZE);
  414. ADD_NEW_DATA(-bstate, 0, gone_back - back);
  415. }
  416. end_code += GET(end_code, 1);
  417. }
  418. while (*end_code == OP_ALT);
  419. }
  420. /* This is the code for a "normal" subpattern (not a backward assertion). The
  421. start of a whole pattern is always one of these. If we are at the top level,
  422. we may be asked to restart matching from the same point that we reached for a
  423. previous partial match. We still have to scan through the top-level branches to
  424. find the end state. */
  425. else
  426. {
  427. end_code = this_start_code;
  428. /* Restarting */
  429. if (rlevel == 1 && (md->moptions & PCRE_DFA_RESTART) != 0)
  430. {
  431. do { end_code += GET(end_code, 1); } while (*end_code == OP_ALT);
  432. new_count = workspace[1];
  433. if (!workspace[0])
  434. memcpy(new_states, active_states, new_count * sizeof(stateblock));
  435. }
  436. /* Not restarting */
  437. else
  438. {
  439. int length = 1 + LINK_SIZE +
  440. ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0);
  441. do
  442. {
  443. ADD_NEW((int)(end_code - start_code + length), 0);
  444. end_code += GET(end_code, 1);
  445. length = 1 + LINK_SIZE;
  446. }
  447. while (*end_code == OP_ALT);
  448. }
  449. }
  450. workspace[0] = 0; /* Bit indicating which vector is current */
  451. DPRINTF(("%.*sEnd state = %d\n", rlevel*2-2, SP, end_code - start_code));
  452. /* Loop for scanning the subject */
  453. ptr = current_subject;
  454. for (;;)
  455. {
  456. int i, j;
  457. int clen, dlen;
  458. unsigned int c, d;
  459. int forced_fail = 0;
  460. BOOL could_continue = FALSE;
  461. /* Make the new state list into the active state list and empty the
  462. new state list. */
  463. temp_states = active_states;
  464. active_states = new_states;
  465. new_states = temp_states;
  466. active_count = new_count;
  467. new_count = 0;
  468. workspace[0] ^= 1; /* Remember for the restarting feature */
  469. workspace[1] = active_count;
  470. #ifdef PCRE_DEBUG
  471. printf("%.*sNext character: rest of subject = \"", rlevel*2-2, SP);
  472. pchars((uschar *)ptr, strlen((char *)ptr), stdout);
  473. printf("\"\n");
  474. printf("%.*sActive states: ", rlevel*2-2, SP);
  475. for (i = 0; i < active_count; i++)
  476. printf("%d/%d ", active_states[i].offset, active_states[i].count);
  477. printf("\n");
  478. #endif
  479. /* Set the pointers for adding new states */
  480. next_active_state = active_states + active_count;
  481. next_new_state = new_states;
  482. /* Load the current character from the subject outside the loop, as many
  483. different states may want to look at it, and we assume that at least one
  484. will. */
  485. if (ptr < end_subject)
  486. {
  487. clen = 1; /* Number of bytes in the character */
  488. #ifdef SUPPORT_UTF8
  489. if (utf8) { GETCHARLEN(c, ptr, clen); } else
  490. #endif /* SUPPORT_UTF8 */
  491. c = *ptr;
  492. }
  493. else
  494. {
  495. clen = 0; /* This indicates the end of the subject */
  496. c = NOTACHAR; /* This value should never actually be used */
  497. }
  498. /* Scan up the active states and act on each one. The result of an action
  499. may be to add more states to the currently active list (e.g. on hitting a
  500. parenthesis) or it may be to put states on the new list, for considering
  501. when we move the character pointer on. */
  502. for (i = 0; i < active_count; i++)
  503. {
  504. stateblock *current_state = active_states + i;
  505. const uschar *code;
  506. int state_offset = current_state->offset;
  507. int count, codevalue, rrc;
  508. #ifdef PCRE_DEBUG
  509. printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset);
  510. if (clen == 0) printf("EOL\n");
  511. else if (c > 32 && c < 127) printf("'%c'\n", c);
  512. else printf("0x%02x\n", c);
  513. #endif
  514. /* This variable is referred to implicity in the ADD_xxx macros. */
  515. ims = current_state->ims;
  516. /* A negative offset is a special case meaning "hold off going to this
  517. (negated) state until the number of characters in the data field have
  518. been skipped". */
  519. if (state_offset < 0)
  520. {
  521. if (current_state->data > 0)
  522. {
  523. DPRINTF(("%.*sSkipping this character\n", rlevel*2-2, SP));
  524. ADD_NEW_DATA(state_offset, current_state->count,
  525. current_state->data - 1);
  526. continue;
  527. }
  528. else
  529. {
  530. current_state->offset = state_offset = -state_offset;
  531. }
  532. }
  533. /* Check for a duplicate state with the same count, and skip if found.
  534. See the note at the head of this module about the possibility of improving
  535. performance here. */
  536. for (j = 0; j < i; j++)
  537. {
  538. if (active_states[j].offset == state_offset &&
  539. active_states[j].count == current_state->count)
  540. {
  541. DPRINTF(("%.*sDuplicate state: skipped\n", rlevel*2-2, SP));
  542. goto NEXT_ACTIVE_STATE;
  543. }
  544. }
  545. /* The state offset is the offset to the opcode */
  546. code = start_code + state_offset;
  547. codevalue = *code;
  548. /* If this opcode inspects a character, but we are at the end of the
  549. subject, remember the fact for use when testing for a partial match. */
  550. if (clen == 0 && poptable[codevalue] != 0)
  551. could_continue = TRUE;
  552. /* If this opcode is followed by an inline character, load it. It is
  553. tempting to test for the presence of a subject character here, but that
  554. is wrong, because sometimes zero repetitions of the subject are
  555. permitted.
  556. We also use this mechanism for opcodes such as OP_TYPEPLUS that take an
  557. argument that is not a data character - but is always one byte long. We
  558. have to take special action to deal with \P, \p, \H, \h, \V, \v and \X in
  559. this case. To keep the other cases fast, convert these ones to new opcodes.
  560. */
  561. if (coptable[codevalue] > 0)
  562. {
  563. dlen = 1;
  564. #ifdef SUPPORT_UTF8
  565. if (utf8) { GETCHARLEN(d, (code + coptable[codevalue]), dlen); } else
  566. #endif /* SUPPORT_UTF8 */
  567. d = code[coptable[codevalue]];
  568. if (codevalue >= OP_TYPESTAR)
  569. {
  570. switch(d)
  571. {
  572. case OP_ANYBYTE: return PCRE_ERROR_DFA_UITEM;
  573. case OP_NOTPROP:
  574. case OP_PROP: codevalue += OP_PROP_EXTRA; break;
  575. case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break;
  576. case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break;
  577. case OP_NOT_HSPACE:
  578. case OP_HSPACE: codevalue += OP_HSPACE_EXTRA; break;
  579. case OP_NOT_VSPACE:
  580. case OP_VSPACE: codevalue += OP_VSPACE_EXTRA; break;
  581. default: break;
  582. }
  583. }
  584. }
  585. else
  586. {
  587. dlen = 0; /* Not strictly necessary, but compilers moan */
  588. d = NOTACHAR; /* if these variables are not set. */
  589. }
  590. /* Now process the individual opcodes */
  591. switch (codevalue)
  592. {
  593. /* ========================================================================== */
  594. /* These cases are never obeyed. This is a fudge that causes a compile-
  595. time error if the vectors coptable or poptable, which are indexed by
  596. opcode, are not the correct length. It seems to be the only way to do
  597. such a check at compile time, as the sizeof() operator does not work
  598. in the C preprocessor. */
  599. case OP_TABLE_LENGTH:
  600. case OP_TABLE_LENGTH +
  601. ((sizeof(coptable) == OP_TABLE_LENGTH) &&
  602. (sizeof(poptable) == OP_TABLE_LENGTH)):
  603. break;
  604. /* ========================================================================== */
  605. /* Reached a closing bracket. If not at the end of the pattern, carry
  606. on with the next opcode. Otherwise, unless we have an empty string and
  607. PCRE_NOTEMPTY is set, or PCRE_NOTEMPTY_ATSTART is set and we are at the
  608. start of the subject, save the match data, shifting up all previous
  609. matches so we always have the longest first. */
  610. case OP_KET:
  611. case OP_KETRMIN:
  612. case OP_KETRMAX:
  613. if (code != end_code)
  614. {
  615. ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0);
  616. if (codevalue != OP_KET)
  617. {
  618. ADD_ACTIVE(state_offset - GET(code, 1), 0);
  619. }
  620. }
  621. else
  622. {
  623. if (ptr > current_subject ||
  624. ((md->moptions & PCRE_NOTEMPTY) == 0 &&
  625. ((md->moptions & PCRE_NOTEMPTY_ATSTART) == 0 ||
  626. current_subject > start_subject + md->start_offset)))
  627. {
  628. if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0;
  629. else if (match_count > 0 && ++match_count * 2 >= offsetcount)
  630. match_count = 0;
  631. count = ((match_count == 0)? offsetcount : match_count * 2) - 2;
  632. if (count > 0) memmove(offsets + 2, offsets, count * sizeof(int));
  633. if (offsetcount >= 2)
  634. {
  635. offsets[0] = (int)(current_subject - start_subject);
  636. offsets[1] = (int)(ptr - start_subject);
  637. DPRINTF(("%.*sSet matched string = \"%.*s\"\n", rlevel*2-2, SP,
  638. offsets[1] - offsets[0], current_subject));
  639. }
  640. if ((md->moptions & PCRE_DFA_SHORTEST) != 0)
  641. {
  642. DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n"
  643. "%.*s---------------------\n\n", rlevel*2-2, SP, rlevel,
  644. match_count, rlevel*2-2, SP));
  645. return match_count;
  646. }
  647. }
  648. }
  649. break;
  650. /* ========================================================================== */
  651. /* These opcodes add to the current list of states without looking
  652. at the current character. */
  653. /*-----------------------------------------------------------------*/
  654. case OP_ALT:
  655. do { code += GET(code, 1); } while (*code == OP_ALT);
  656. ADD_ACTIVE((int)(code - start_code), 0);
  657. break;
  658. /*-----------------------------------------------------------------*/
  659. case OP_BRA:
  660. case OP_SBRA:
  661. do
  662. {
  663. ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
  664. code += GET(code, 1);
  665. }
  666. while (*code == OP_ALT);
  667. break;
  668. /*-----------------------------------------------------------------*/
  669. case OP_CBRA:
  670. case OP_SCBRA:
  671. ADD_ACTIVE((int)(code - start_code + 3 + LINK_SIZE), 0);
  672. code += GET(code, 1);
  673. while (*code == OP_ALT)
  674. {
  675. ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
  676. code += GET(code, 1);
  677. }
  678. break;
  679. /*-----------------------------------------------------------------*/
  680. case OP_BRAZERO:
  681. case OP_BRAMINZERO:
  682. ADD_ACTIVE(state_offset + 1, 0);
  683. code += 1 + GET(code, 2);
  684. while (*code == OP_ALT) code += GET(code, 1);
  685. ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
  686. break;
  687. /*-----------------------------------------------------------------*/
  688. case OP_SKIPZERO:
  689. code += 1 + GET(code, 2);
  690. while (*code == OP_ALT) code += GET(code, 1);
  691. ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
  692. break;
  693. /*-----------------------------------------------------------------*/
  694. case OP_CIRC:
  695. if ((ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0) ||
  696. ((ims & PCRE_MULTILINE) != 0 &&
  697. ptr != end_subject &&
  698. WAS_NEWLINE(ptr)))
  699. { ADD_ACTIVE(state_offset + 1, 0); }
  700. break;
  701. /*-----------------------------------------------------------------*/
  702. case OP_EOD:
  703. if (ptr >= end_subject)
  704. {
  705. if ((md->moptions & PCRE_PARTIAL_HARD) != 0)
  706. could_continue = TRUE;
  707. else { ADD_ACTIVE(state_offset + 1, 0); }
  708. }
  709. break;
  710. /*-----------------------------------------------------------------*/
  711. case OP_OPT:
  712. ims = code[1];
  713. ADD_ACTIVE(state_offset + 2, 0);
  714. break;
  715. /*-----------------------------------------------------------------*/
  716. case OP_SOD:
  717. if (ptr == start_subject) { ADD_ACTIVE(state_offset + 1, 0); }
  718. break;
  719. /*-----------------------------------------------------------------*/
  720. case OP_SOM:
  721. if (ptr == start_subject + start_offset) { ADD_ACTIVE(state_offset + 1, 0); }
  722. break;
  723. /* ========================================================================== */
  724. /* These opcodes inspect the next subject character, and sometimes
  725. the previous one as well, but do not have an argument. The variable
  726. clen contains the length of the current character and is zero if we are
  727. at the end of the subject. */
  728. /*-----------------------------------------------------------------*/
  729. case OP_ANY:
  730. if (clen > 0 && !IS_NEWLINE(ptr))
  731. { ADD_NEW(state_offset + 1, 0); }
  732. break;
  733. /*-----------------------------------------------------------------*/
  734. case OP_ALLANY:
  735. if (clen > 0)
  736. { ADD_NEW(state_offset + 1, 0); }
  737. break;
  738. /*-----------------------------------------------------------------*/
  739. case OP_EODN:
  740. if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0)
  741. could_continue = TRUE;
  742. else if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - md->nllen))
  743. { ADD_ACTIVE(state_offset + 1, 0); }
  744. break;
  745. /*-----------------------------------------------------------------*/
  746. case OP_DOLL:
  747. if ((md->moptions & PCRE_NOTEOL) == 0)
  748. {
  749. if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0)
  750. could_continue = TRUE;
  751. else if (clen == 0 ||
  752. ((md->poptions & PCRE_DOLLAR_ENDONLY) == 0 && IS_NEWLINE(ptr) &&
  753. ((ims & PCRE_MULTILINE) != 0 || ptr == end_subject - md->nllen)
  754. ))
  755. { ADD_ACTIVE(state_offset + 1, 0); }
  756. }
  757. else if ((ims & PCRE_MULTILINE) != 0 && IS_NEWLINE(ptr))
  758. { ADD_ACTIVE(state_offset + 1, 0); }
  759. break;
  760. /*-----------------------------------------------------------------*/
  761. case OP_DIGIT:
  762. case OP_WHITESPACE:
  763. case OP_WORDCHAR:
  764. if (clen > 0 && c < 256 &&
  765. ((ctypes[c] & toptable1[codevalue]) ^ toptable2[codevalue]) != 0)
  766. { ADD_NEW(state_offset + 1, 0); }
  767. break;
  768. /*-----------------------------------------------------------------*/
  769. case OP_NOT_DIGIT:
  770. case OP_NOT_WHITESPACE:
  771. case OP_NOT_WORDCHAR:
  772. if (clen > 0 && (c >= 256 ||
  773. ((ctypes[c] & toptable1[codevalue]) ^ toptable2[codevalue]) != 0))
  774. { ADD_NEW(state_offset + 1, 0); }
  775. break;
  776. /*-----------------------------------------------------------------*/
  777. case OP_WORD_BOUNDARY:
  778. case OP_NOT_WORD_BOUNDARY:
  779. {
  780. int left_word, right_word;
  781. if (ptr > start_subject)
  782. {
  783. const uschar *temp = ptr - 1;
  784. if (temp < md->start_used_ptr) md->start_used_ptr = temp;
  785. #ifdef SUPPORT_UTF8
  786. if (utf8) BACKCHAR(temp);
  787. #endif
  788. GETCHARTEST(d, temp);
  789. #ifdef SUPPORT_UCP
  790. if ((md->poptions & PCRE_UCP) != 0)
  791. {
  792. if (d == '_') left_word = TRUE; else
  793. {
  794. int cat = UCD_CATEGORY(d);
  795. left_word = (cat == ucp_L || cat == ucp_N);
  796. }
  797. }
  798. else
  799. #endif
  800. left_word = d < 256 && (ctypes[d] & ctype_word) != 0;
  801. }
  802. else left_word = FALSE;
  803. if (clen > 0)
  804. {
  805. #ifdef SUPPORT_UCP
  806. if ((md->poptions & PCRE_UCP) != 0)
  807. {
  808. if (c == '_') right_word = TRUE; else
  809. {
  810. int cat = UCD_CATEGORY(c);
  811. right_word = (cat == ucp_L || cat == ucp_N);
  812. }
  813. }
  814. else
  815. #endif
  816. right_word = c < 256 && (ctypes[c] & ctype_word) != 0;
  817. }
  818. else right_word = FALSE;
  819. if ((left_word == right_word) == (codevalue == OP_NOT_WORD_BOUNDARY))
  820. { ADD_ACTIVE(state_offset + 1, 0); }
  821. }
  822. break;
  823. /*-----------------------------------------------------------------*/
  824. /* Check the next character by Unicode property. We will get here only
  825. if the support is in the binary; otherwise a compile-time error occurs.
  826. */
  827. #ifdef SUPPORT_UCP
  828. case OP_PROP:
  829. case OP_NOTPROP:
  830. if (clen > 0)
  831. {
  832. BOOL OK;
  833. const ucd_record * prop = GET_UCD(c);
  834. switch(code[1])
  835. {
  836. case PT_ANY:
  837. OK = TRUE;
  838. break;
  839. case PT_LAMP:
  840. OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
  841. prop->chartype == ucp_Lt;
  842. break;
  843. case PT_GC:
  844. OK = _pcre_ucp_gentype[prop->chartype] == code[2];
  845. break;
  846. case PT_PC:
  847. OK = prop->chartype == code[2];
  848. break;
  849. case PT_SC:
  850. OK = prop->script == code[2];
  851. break;
  852. /* These are specials for combination cases. */
  853. case PT_ALNUM:
  854. OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
  855. _pcre_ucp_gentype[prop->chartype] == ucp_N;
  856. break;
  857. case PT_SPACE: /* Perl space */
  858. OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
  859. c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
  860. break;
  861. case PT_PXSPACE: /* POSIX space */
  862. OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
  863. c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
  864. c == CHAR_FF || c == CHAR_CR;
  865. break;
  866. case PT_WORD:
  867. OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
  868. _pcre_ucp_gentype[prop->chartype] == ucp_N ||
  869. c == CHAR_UNDERSCORE;
  870. break;
  871. /* Should never occur, but keep compilers from grumbling. */
  872. default:
  873. OK = codevalue != OP_PROP;
  874. break;
  875. }
  876. if (OK == (codevalue == OP_PROP)) { ADD_NEW(state_offset + 3, 0); }
  877. }
  878. break;
  879. #endif
  880. /* ========================================================================== */
  881. /* These opcodes likewise inspect the subject character, but have an
  882. argument that is not a data character. It is one of these opcodes:
  883. OP_ANY, OP_ALLANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE,
  884. OP_WORDCHAR, OP_NOT_WORDCHAR. The value is loaded into d. */
  885. case OP_TYPEPLUS:
  886. case OP_TYPEMINPLUS:
  887. case OP_TYPEPOSPLUS:
  888. count = current_state->count; /* Already matched */
  889. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  890. if (clen > 0)
  891. {
  892. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  893. (c < 256 &&
  894. (d != OP_ANY || !IS_NEWLINE(ptr)) &&
  895. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  896. {
  897. if (count > 0 && codevalue == OP_TYPEPOSPLUS)
  898. {
  899. active_count--; /* Remove non-match possibility */
  900. next_active_state--;
  901. }
  902. count++;
  903. ADD_NEW(state_offset, count);
  904. }
  905. }
  906. break;
  907. /*-----------------------------------------------------------------*/
  908. case OP_TYPEQUERY:
  909. case OP_TYPEMINQUERY:
  910. case OP_TYPEPOSQUERY:
  911. ADD_ACTIVE(state_offset + 2, 0);
  912. if (clen > 0)
  913. {
  914. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  915. (c < 256 &&
  916. (d != OP_ANY || !IS_NEWLINE(ptr)) &&
  917. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  918. {
  919. if (codevalue == OP_TYPEPOSQUERY)
  920. {
  921. active_count--; /* Remove non-match possibility */
  922. next_active_state--;
  923. }
  924. ADD_NEW(state_offset + 2, 0);
  925. }
  926. }
  927. break;
  928. /*-----------------------------------------------------------------*/
  929. case OP_TYPESTAR:
  930. case OP_TYPEMINSTAR:
  931. case OP_TYPEPOSSTAR:
  932. ADD_ACTIVE(state_offset + 2, 0);
  933. if (clen > 0)
  934. {
  935. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  936. (c < 256 &&
  937. (d != OP_ANY || !IS_NEWLINE(ptr)) &&
  938. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  939. {
  940. if (codevalue == OP_TYPEPOSSTAR)
  941. {
  942. active_count--; /* Remove non-match possibility */
  943. next_active_state--;
  944. }
  945. ADD_NEW(state_offset, 0);
  946. }
  947. }
  948. break;
  949. /*-----------------------------------------------------------------*/
  950. case OP_TYPEEXACT:
  951. count = current_state->count; /* Number already matched */
  952. if (clen > 0)
  953. {
  954. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  955. (c < 256 &&
  956. (d != OP_ANY || !IS_NEWLINE(ptr)) &&
  957. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  958. {
  959. if (++count >= GET2(code, 1))
  960. { ADD_NEW(state_offset + 4, 0); }
  961. else
  962. { ADD_NEW(state_offset, count); }
  963. }
  964. }
  965. break;
  966. /*-----------------------------------------------------------------*/
  967. case OP_TYPEUPTO:
  968. case OP_TYPEMINUPTO:
  969. case OP_TYPEPOSUPTO:
  970. ADD_ACTIVE(state_offset + 4, 0);
  971. count = current_state->count; /* Number already matched */
  972. if (clen > 0)
  973. {
  974. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  975. (c < 256 &&
  976. (d != OP_ANY || !IS_NEWLINE(ptr)) &&
  977. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  978. {
  979. if (codevalue == OP_TYPEPOSUPTO)
  980. {
  981. active_count--; /* Remove non-match possibility */
  982. next_active_state--;
  983. }
  984. if (++count >= GET2(code, 1))
  985. { ADD_NEW(state_offset + 4, 0); }
  986. else
  987. { ADD_NEW(state_offset, count); }
  988. }
  989. }
  990. break;
  991. /* ========================================================================== */
  992. /* These are virtual opcodes that are used when something like
  993. OP_TYPEPLUS has OP_PROP, OP_NOTPROP, OP_ANYNL, or OP_EXTUNI as its
  994. argument. It keeps the code above fast for the other cases. The argument
  995. is in the d variable. */
  996. #ifdef SUPPORT_UCP
  997. case OP_PROP_EXTRA + OP_TYPEPLUS:
  998. case OP_PROP_EXTRA + OP_TYPEMINPLUS:
  999. case OP_PROP_EXTRA + OP_TYPEPOSPLUS:
  1000. count = current_state->count; /* Already matched */
  1001. if (count > 0) { ADD_ACTIVE(state_offset + 4, 0); }
  1002. if (clen > 0)
  1003. {
  1004. BOOL OK;
  1005. const ucd_record * prop = GET_UCD(c);
  1006. switch(code[2])
  1007. {
  1008. case PT_ANY:
  1009. OK = TRUE;
  1010. break;
  1011. case PT_LAMP:
  1012. OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
  1013. prop->chartype == ucp_Lt;
  1014. break;
  1015. case PT_GC:
  1016. OK = _pcre_ucp_gentype[prop->chartype] == code[3];
  1017. break;
  1018. case PT_PC:
  1019. OK = prop->chartype == code[3];
  1020. break;
  1021. case PT_SC:
  1022. OK = prop->script == code[3];
  1023. break;
  1024. /* These are specials for combination cases. */
  1025. case PT_ALNUM:
  1026. OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
  1027. _pcre_ucp_gentype[prop->chartype] == ucp_N;
  1028. break;
  1029. case PT_SPACE: /* Perl space */
  1030. OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
  1031. c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
  1032. break;
  1033. case PT_PXSPACE: /* POSIX space */
  1034. OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
  1035. c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
  1036. c == CHAR_FF || c == CHAR_CR;
  1037. break;
  1038. case PT_WORD:
  1039. OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
  1040. _pcre_ucp_gentype[prop->chartype] == ucp_N ||
  1041. c == CHAR_UNDERSCORE;
  1042. break;
  1043. /* Should never occur, but keep compilers from grumbling. */
  1044. default:
  1045. OK = codevalue != OP_PROP;
  1046. break;
  1047. }
  1048. if (OK == (d == OP_PROP))
  1049. {
  1050. if (count > 0 && codevalue == OP_PROP_EXTRA + OP_TYPEPOSPLUS)
  1051. {
  1052. active_count--; /* Remove non-match possibility */
  1053. next_active_state--;
  1054. }
  1055. count++;
  1056. ADD_NEW(state_offset, count);
  1057. }
  1058. }
  1059. break;
  1060. /*-----------------------------------------------------------------*/
  1061. case OP_EXTUNI_EXTRA + OP_TYPEPLUS:
  1062. case OP_EXTUNI_EXTRA + OP_TYPEMINPLUS:
  1063. case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS:
  1064. count = current_state->count; /* Already matched */
  1065. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  1066. if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
  1067. {
  1068. const uschar *nptr = ptr + clen;
  1069. int ncount = 0;
  1070. if (count > 0 && codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS)
  1071. {
  1072. active_count--; /* Remove non-match possibility */
  1073. next_active_state--;
  1074. }
  1075. while (nptr < end_subject)
  1076. {
  1077. int nd;
  1078. int ndlen = 1;
  1079. GETCHARLEN(nd, nptr, ndlen);
  1080. if (UCD_CATEGORY(nd) != ucp_M) break;
  1081. ncount++;
  1082. nptr += ndlen;
  1083. }
  1084. count++;
  1085. ADD_NEW_DATA(-state_offset, count, ncount);
  1086. }
  1087. break;
  1088. #endif
  1089. /*-----------------------------------------------------------------*/
  1090. case OP_ANYNL_EXTRA + OP_TYPEPLUS:
  1091. case OP_ANYNL_EXTRA + OP_TYPEMINPLUS:
  1092. case OP_ANYNL_EXTRA + OP_TYPEPOSPLUS:
  1093. count = current_state->count; /* Already matched */
  1094. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  1095. if (clen > 0)
  1096. {
  1097. int ncount = 0;
  1098. switch (c)
  1099. {
  1100. case 0x000b:
  1101. case 0x000c:
  1102. case 0x0085:
  1103. case 0x2028:
  1104. case 0x2029:
  1105. if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
  1106. goto ANYNL01;
  1107. case 0x000d:
  1108. if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
  1109. /* Fall through */
  1110. ANYNL01:
  1111. case 0x000a:
  1112. if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS)
  1113. {
  1114. active_count--; /* Remove non-match possibility */
  1115. next_active_state--;
  1116. }
  1117. count++;
  1118. ADD_NEW_DATA(-state_offset, count, ncount);
  1119. break;
  1120. default:
  1121. break;
  1122. }
  1123. }
  1124. break;
  1125. /*-----------------------------------------------------------------*/
  1126. case OP_VSPACE_EXTRA + OP_TYPEPLUS:
  1127. case OP_VSPACE_EXTRA + OP_TYPEMINPLUS:
  1128. case OP_VSPACE_EXTRA + OP_TYPEPOSPLUS:
  1129. count = current_state->count; /* Already matched */
  1130. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  1131. if (clen > 0)
  1132. {
  1133. BOOL OK;
  1134. switch (c)
  1135. {
  1136. case 0x000a:
  1137. case 0x000b:
  1138. case 0x000c:
  1139. case 0x000d:
  1140. case 0x0085:
  1141. case 0x2028:
  1142. case 0x2029:
  1143. OK = TRUE;
  1144. break;
  1145. default:
  1146. OK = FALSE;
  1147. break;
  1148. }
  1149. if (OK == (d == OP_VSPACE))
  1150. {
  1151. if (count > 0 && codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSPLUS)
  1152. {
  1153. active_count--; /* Remove non-match possibility */
  1154. next_active_state--;
  1155. }
  1156. count++;
  1157. ADD_NEW_DATA(-state_offset, count, 0);
  1158. }
  1159. }
  1160. break;
  1161. /*-----------------------------------------------------------------*/
  1162. case OP_HSPACE_EXTRA + OP_TYPEPLUS:
  1163. case OP_HSPACE_EXTRA + OP_TYPEMINPLUS:
  1164. case OP_HSPACE_EXTRA + OP_TYPEPOSPLUS:
  1165. count = current_state->count; /* Already matched */
  1166. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  1167. if (clen > 0)
  1168. {
  1169. BOOL OK;
  1170. switch (c)
  1171. {
  1172. case 0x09: /* HT */
  1173. case 0x20: /* SPACE */
  1174. case 0xa0: /* NBSP */
  1175. case 0x1680: /* OGHAM SPACE MARK */
  1176. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
  1177. case 0x2000: /* EN QUAD */
  1178. case 0x2001: /* EM QUAD */
  1179. case 0x2002: /* EN SPACE */
  1180. case 0x2003: /* EM SPACE */
  1181. case 0x2004: /* THREE-PER-EM SPACE */
  1182. case 0x2005: /* FOUR-PER-EM SPACE */
  1183. case 0x2006: /* SIX-PER-EM SPACE */
  1184. case 0x2007: /* FIGURE SPACE */
  1185. case 0x2008: /* PUNCTUATION SPACE */

Large files files are truncated, but you can click here to view the full file