pcre_jit_test.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  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.
  6. Main Library written by Philip Hazel
  7. Copyright (c) 1997-2012 University of Cambridge
  8. This JIT compiler regression test program was written by Zoltan Herczeg
  9. Copyright (c) 2010-2012
  10. -----------------------------------------------------------------------------
  11. Redistribution and use in source and binary forms, with or without
  12. modification, are permitted provided that the following conditions are met:
  13. * Redistributions of source code must retain the above copyright notice,
  14. this list of conditions and the following disclaimer.
  15. * Redistributions in binary form must reproduce the above copyright
  16. notice, this list of conditions and the following disclaimer in the
  17. documentation and/or other materials provided with the distribution.
  18. * Neither the name of the University of Cambridge nor the names of its
  19. contributors may be used to endorse or promote products derived from
  20. this software without specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. POSSIBILITY OF SUCH DAMAGE.
  32. -----------------------------------------------------------------------------
  33. */
  34. #ifdef HAVE_CONFIG_H
  35. #include "config.h"
  36. #endif
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include "pcre.h"
  40. #include "pcre_internal.h"
  41. /*
  42. Letter characters:
  43. \xe6\x92\xad = 0x64ad = 25773 (kanji)
  44. Non-letter characters:
  45. \xc2\xa1 = 0xa1 = (Inverted Exclamation Mark)
  46. \xf3\xa9\xb7\x80 = 0xe9dc0 = 957888
  47. \xed\xa0\x80 = 55296 = 0xd800 (Invalid UTF character)
  48. \xed\xb0\x80 = 56320 = 0xdc00 (Invalid UTF character)
  49. Newlines:
  50. \xc2\x85 = 0x85 = 133 (NExt Line = NEL)
  51. \xe2\x80\xa8 = 0x2028 = 8232 (Line Separator)
  52. Othercase pairs:
  53. \xc3\xa9 = 0xe9 = 233 (e')
  54. \xc3\x89 = 0xc9 = 201 (E')
  55. \xc3\xa1 = 0xe1 = 225 (a')
  56. \xc3\x81 = 0xc1 = 193 (A')
  57. \x53 = 0x53 = S
  58. \x73 = 0x73 = s
  59. \xc5\xbf = 0x17f = 383 (long S)
  60. \xc8\xba = 0x23a = 570
  61. \xe2\xb1\xa5 = 0x2c65 = 11365
  62. \xe1\xbd\xb8 = 0x1f78 = 8056
  63. \xe1\xbf\xb8 = 0x1ff8 = 8184
  64. \xf0\x90\x90\x80 = 0x10400 = 66560
  65. \xf0\x90\x90\xa8 = 0x10428 = 66600
  66. \xc7\x84 = 0x1c4 = 452
  67. \xc7\x85 = 0x1c5 = 453
  68. \xc7\x86 = 0x1c6 = 454
  69. Caseless sets:
  70. ucp_Armenian - \x{531}-\x{556} -> \x{561}-\x{586}
  71. ucp_Coptic - \x{2c80}-\x{2ce3} -> caseless: XOR 0x1
  72. ucp_Latin - \x{ff21}-\x{ff3a} -> \x{ff41]-\x{ff5a}
  73. Mark property:
  74. \xcc\x8d = 0x30d = 781
  75. Special:
  76. \xc2\x80 = 0x80 = 128 (lowest 2 byte character)
  77. \xdf\xbf = 0x7ff = 2047 (highest 2 byte character)
  78. \xe0\xa0\x80 = 0x800 = 2048 (lowest 2 byte character)
  79. \xef\xbf\xbf = 0xffff = 65535 (highest 3 byte character)
  80. \xf0\x90\x80\x80 = 0x10000 = 65536 (lowest 4 byte character)
  81. \xf4\x8f\xbf\xbf = 0x10ffff = 1114111 (highest allowed utf character)
  82. */
  83. static int regression_tests(void);
  84. int main(void)
  85. {
  86. int jit = 0;
  87. #if defined SUPPORT_PCRE8
  88. pcre_config(PCRE_CONFIG_JIT, &jit);
  89. #elif defined SUPPORT_PCRE16
  90. pcre16_config(PCRE_CONFIG_JIT, &jit);
  91. #elif defined SUPPORT_PCRE32
  92. pcre32_config(PCRE_CONFIG_JIT, &jit);
  93. #endif
  94. if (!jit) {
  95. printf("JIT must be enabled to run pcre_jit_test\n");
  96. return 1;
  97. }
  98. return regression_tests();
  99. }
  100. /* --------------------------------------------------------------------------------------- */
  101. #if !(defined SUPPORT_PCRE8) && !(defined SUPPORT_PCRE16) && !(defined SUPPORT_PCRE32)
  102. #error SUPPORT_PCRE8 or SUPPORT_PCRE16 or SUPPORT_PCRE32 must be defined
  103. #endif
  104. #define MUA (PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF)
  105. #define MUAP (PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF | PCRE_UCP)
  106. #define CMUA (PCRE_CASELESS | PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF)
  107. #define CMUAP (PCRE_CASELESS | PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF | PCRE_UCP)
  108. #define MA (PCRE_MULTILINE | PCRE_NEWLINE_ANYCRLF)
  109. #define MAP (PCRE_MULTILINE | PCRE_NEWLINE_ANYCRLF | PCRE_UCP)
  110. #define CMA (PCRE_CASELESS | PCRE_MULTILINE | PCRE_NEWLINE_ANYCRLF)
  111. #define OFFSET_MASK 0x00ffff
  112. #define F_NO8 0x010000
  113. #define F_NO16 0x020000
  114. #define F_NO32 0x020000
  115. #define F_NOMATCH 0x040000
  116. #define F_DIFF 0x080000
  117. #define F_FORCECONV 0x100000
  118. #define F_PROPERTY 0x200000
  119. #define F_STUDY 0x400000
  120. struct regression_test_case {
  121. int flags;
  122. int start_offset;
  123. const char *pattern;
  124. const char *input;
  125. };
  126. static struct regression_test_case regression_test_cases[] = {
  127. /* Constant strings. */
  128. { MUA, 0, "AbC", "AbAbC" },
  129. { MUA, 0, "ACCEPT", "AACACCACCEACCEPACCEPTACCEPTT" },
  130. { CMUA, 0, "aA#\xc3\xa9\xc3\x81", "aA#Aa#\xc3\x89\xc3\xa1" },
  131. { MA, 0, "[^a]", "aAbB" },
  132. { CMA, 0, "[^m]", "mMnN" },
  133. { MA, 0, "a[^b][^#]", "abacd" },
  134. { CMA, 0, "A[^B][^E]", "abacd" },
  135. { CMUA, 0, "[^x][^#]", "XxBll" },
  136. { MUA, 0, "[^a]", "aaa\xc3\xa1#Ab" },
  137. { CMUA, 0, "[^A]", "aA\xe6\x92\xad" },
  138. { MUA, 0, "\\W(\\W)?\\w", "\r\n+bc" },
  139. { MUA, 0, "\\W(\\W)?\\w", "\n\r+bc" },
  140. { MUA, 0, "\\W(\\W)?\\w", "\r\r+bc" },
  141. { MUA, 0, "\\W(\\W)?\\w", "\n\n+bc" },
  142. { MUA, 0, "[axd]", "sAXd" },
  143. { CMUA, 0, "[axd]", "sAXd" },
  144. { CMUA, 0 | F_NOMATCH, "[^axd]", "DxA" },
  145. { MUA, 0, "[a-dA-C]", "\xe6\x92\xad\xc3\xa9.B" },
  146. { MUA, 0, "[^a-dA-C]", "\xe6\x92\xad\xc3\xa9" },
  147. { CMUA, 0, "[^\xc3\xa9]", "\xc3\xa9\xc3\x89." },
  148. { MUA, 0, "[^\xc3\xa9]", "\xc3\xa9\xc3\x89." },
  149. { MUA, 0, "[^a]", "\xc2\x80[]" },
  150. { CMUA, 0, "\xf0\x90\x90\xa7", "\xf0\x90\x91\x8f" },
  151. { CMA, 0, "1a2b3c4", "1a2B3c51A2B3C4" },
  152. { PCRE_CASELESS, 0, "\xff#a", "\xff#\xff\xfe##\xff#A" },
  153. { PCRE_CASELESS, 0, "\xfe", "\xff\xfc#\xfe\xfe" },
  154. { PCRE_CASELESS, 0, "a1", "Aa1" },
  155. { MA, 0, "\\Ca", "cda" },
  156. { CMA, 0, "\\Ca", "CDA" },
  157. { MA, 0 | F_NOMATCH, "\\Cx", "cda" },
  158. { CMA, 0 | F_NOMATCH, "\\Cx", "CDA" },
  159. { CMUAP, 0, "\xf0\x90\x90\x80\xf0\x90\x90\xa8", "\xf0\x90\x90\xa8\xf0\x90\x90\x80" },
  160. { CMUAP, 0, "\xf0\x90\x90\x80{2}", "\xf0\x90\x90\x80#\xf0\x90\x90\xa8\xf0\x90\x90\x80" },
  161. { CMUAP, 0, "\xf0\x90\x90\xa8{2}", "\xf0\x90\x90\x80#\xf0\x90\x90\xa8\xf0\x90\x90\x80" },
  162. { CMUAP, 0, "\xe1\xbd\xb8\xe1\xbf\xb8", "\xe1\xbf\xb8\xe1\xbd\xb8" },
  163. { MA, 0, "[3-57-9]", "5" },
  164. /* Assertions. */
  165. { MUA, 0, "\\b[^A]", "A_B#" },
  166. { MA, 0 | F_NOMATCH, "\\b\\W", "\n*" },
  167. { MUA, 0, "\\B[^,]\\b[^s]\\b", "#X" },
  168. { MAP, 0, "\\B", "_\xa1" },
  169. { MAP, 0, "\\b_\\b[,A]\\B", "_," },
  170. { MUAP, 0, "\\b", "\xe6\x92\xad!" },
  171. { MUAP, 0, "\\B", "_\xc2\xa1\xc3\xa1\xc2\x85" },
  172. { MUAP, 0, "\\b[^A]\\B[^c]\\b[^_]\\B", "_\xc3\xa1\xe2\x80\xa8" },
  173. { MUAP, 0, "\\b\\w+\\B", "\xc3\x89\xc2\xa1\xe6\x92\xad\xc3\x81\xc3\xa1" },
  174. { MUA, 0 | F_NOMATCH, "\\b.", "\xcd\xbe" },
  175. { CMUAP, 0, "\\By", "\xf0\x90\x90\xa8y" },
  176. { MA, 0 | F_NOMATCH, "\\R^", "\n" },
  177. { MA, 1 | F_NOMATCH, "^", "\n" },
  178. { 0, 0, "^ab", "ab" },
  179. { 0, 0 | F_NOMATCH, "^ab", "aab" },
  180. { PCRE_MULTILINE | PCRE_NEWLINE_CRLF, 0, "^a", "\r\raa\n\naa\r\naa" },
  181. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF, 0, "^-", "\xe2\x80\xa8--\xc2\x85-\r\n-" },
  182. { PCRE_MULTILINE | PCRE_NEWLINE_ANY, 0, "^-", "a--b--\x85--" },
  183. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANY, 0, "^-", "a--\xe2\x80\xa8--" },
  184. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANY, 0, "^-", "a--\xc2\x85--" },
  185. { 0, 0, "ab$", "ab" },
  186. { 0, 0 | F_NOMATCH, "ab$", "abab\n\n" },
  187. { PCRE_DOLLAR_ENDONLY, 0 | F_NOMATCH, "ab$", "abab\r\n" },
  188. { PCRE_MULTILINE | PCRE_NEWLINE_CRLF, 0, "a$", "\r\raa\n\naa\r\naa" },
  189. { PCRE_MULTILINE | PCRE_NEWLINE_ANY, 0, "a$", "aaa" },
  190. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF, 0, "#$", "#\xc2\x85###\r#" },
  191. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANY, 0, "#$", "#\xe2\x80\xa9" },
  192. { PCRE_NOTBOL | PCRE_NEWLINE_ANY, 0 | F_NOMATCH, "^a", "aa\naa" },
  193. { PCRE_NOTBOL | PCRE_MULTILINE | PCRE_NEWLINE_ANY, 0, "^a", "aa\naa" },
  194. { PCRE_NOTEOL | PCRE_NEWLINE_ANY, 0 | F_NOMATCH, "a$", "aa\naa" },
  195. { PCRE_NOTEOL | PCRE_NEWLINE_ANY, 0 | F_NOMATCH, "a$", "aa\r\n" },
  196. { PCRE_UTF8 | PCRE_DOLLAR_ENDONLY | PCRE_NEWLINE_ANY, 0 | F_PROPERTY, "\\p{Any}{2,}$", "aa\r\n" },
  197. { PCRE_NOTEOL | PCRE_MULTILINE | PCRE_NEWLINE_ANY, 0, "a$", "aa\naa" },
  198. { PCRE_NEWLINE_CR, 0, ".\\Z", "aaa" },
  199. { PCRE_NEWLINE_CR | PCRE_UTF8, 0, "a\\Z", "aaa\r" },
  200. { PCRE_NEWLINE_CR, 0, ".\\Z", "aaa\n" },
  201. { PCRE_NEWLINE_CRLF, 0, ".\\Z", "aaa\r" },
  202. { PCRE_NEWLINE_CRLF | PCRE_UTF8, 0, ".\\Z", "aaa\n" },
  203. { PCRE_NEWLINE_CRLF, 0, ".\\Z", "aaa\r\n" },
  204. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa" },
  205. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\r" },
  206. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\n" },
  207. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\r\n" },
  208. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\xe2\x80\xa8" },
  209. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa" },
  210. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\r" },
  211. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\n" },
  212. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\r\n" },
  213. { PCRE_NEWLINE_ANY | PCRE_UTF8, 0, ".\\Z", "aaa\xc2\x85" },
  214. { PCRE_NEWLINE_ANY | PCRE_UTF8, 0, ".\\Z", "aaa\xe2\x80\xa8" },
  215. { MA, 0, "\\Aa", "aaa" },
  216. { MA, 1 | F_NOMATCH, "\\Aa", "aaa" },
  217. { MA, 1, "\\Ga", "aaa" },
  218. { MA, 1 | F_NOMATCH, "\\Ga", "aba" },
  219. { MA, 0, "a\\z", "aaa" },
  220. { MA, 0 | F_NOMATCH, "a\\z", "aab" },
  221. /* Brackets and alternatives. */
  222. { MUA, 0, "(ab|bb|cd)", "bacde" },
  223. { MUA, 0, "(?:ab|a)(bc|c)", "ababc" },
  224. { MUA, 0, "((ab|(cc))|(bb)|(?:cd|efg))", "abac" },
  225. { CMUA, 0, "((aB|(Cc))|(bB)|(?:cd|EFg))", "AcCe" },
  226. { MUA, 0, "((ab|(cc))|(bb)|(?:cd|ebg))", "acebebg" },
  227. { MUA, 0, "(?:(a)|(?:b))(cc|(?:d|e))(a|b)k", "accabdbbccbk" },
  228. { MUA, 0, "\xc7\x82|\xc6\x82", "\xf1\x83\x82\x82\xc7\x82\xc7\x83" },
  229. { MUA, 0, "=\xc7\x82|#\xc6\x82", "\xf1\x83\x82\x82=\xc7\x82\xc7\x83" },
  230. { MUA, 0, "\xc7\x82\xc7\x83|\xc6\x82\xc6\x82", "\xf1\x83\x82\x82\xc7\x82\xc7\x83" },
  231. { MUA, 0, "\xc6\x82\xc6\x82|\xc7\x83\xc7\x83|\xc8\x84\xc8\x84", "\xf1\x83\x82\x82\xc8\x84\xc8\x84" },
  232. /* Greedy and non-greedy ? operators. */
  233. { MUA, 0, "(?:a)?a", "laab" },
  234. { CMUA, 0, "(A)?A", "llaab" },
  235. { MUA, 0, "(a)?\?a", "aab" }, /* ?? is the prefix of trygraphs in GCC. */
  236. { MUA, 0, "(a)?a", "manm" },
  237. { CMUA, 0, "(a|b)?\?d((?:e)?)", "ABABdx" },
  238. { MUA, 0, "(a|b)?\?d((?:e)?)", "abcde" },
  239. { MUA, 0, "((?:ab)?\?g|b(?:g(nn|d)?\?)?)?\?(?:n)?m", "abgnbgnnbgdnmm" },
  240. /* Greedy and non-greedy + operators */
  241. { MUA, 0, "(aa)+aa", "aaaaaaa" },
  242. { MUA, 0, "(aa)+?aa", "aaaaaaa" },
  243. { MUA, 0, "(?:aba|ab|a)+l", "ababamababal" },
  244. { MUA, 0, "(?:aba|ab|a)+?l", "ababamababal" },
  245. { MUA, 0, "(a(?:bc|cb|b|c)+?|ss)+e", "accssabccbcacbccbbXaccssabccbcacbccbbe" },
  246. { MUA, 0, "(a(?:bc|cb|b|c)+|ss)+?e", "accssabccbcacbccbbXaccssabccbcacbccbbe" },
  247. { MUA, 0, "(?:(b(c)+?)+)?\?(?:(bc)+|(cb)+)+(?:m)+", "bccbcccbcbccbcbPbccbcccbcbccbcbmmn" },
  248. /* Greedy and non-greedy * operators */
  249. { CMUA, 0, "(?:AA)*AB", "aaaaaaamaaaaaaab" },
  250. { MUA, 0, "(?:aa)*?ab", "aaaaaaamaaaaaaab" },
  251. { MUA, 0, "(aa|ab)*ab", "aaabaaab" },
  252. { CMUA, 0, "(aa|Ab)*?aB", "aaabaaab" },
  253. { MUA, 0, "(a|b)*(?:a)*(?:b)*m", "abbbaaababanabbbaaababamm" },
  254. { MUA, 0, "(a|b)*?(?:a)*?(?:b)*?m", "abbbaaababanabbbaaababamm" },
  255. { MA, 0, "a(a(\\1*)a|(b)b+){0}a", "aa" },
  256. { MA, 0, "((?:a|)*){0}a", "a" },
  257. /* Combining ? + * operators */
  258. { MUA, 0, "((bm)+)?\?(?:a)*(bm)+n|((am)+?)?(?:a)+(am)*n", "bmbmabmamaaamambmaman" },
  259. { MUA, 0, "(((ab)?cd)*ef)+g", "abcdcdefcdefefmabcdcdefcdefefgg" },
  260. { MUA, 0, "(((ab)?\?cd)*?ef)+?g", "abcdcdefcdefefmabcdcdefcdefefgg" },
  261. { MUA, 0, "(?:(ab)?c|(?:ab)+?d)*g", "ababcdccababddg" },
  262. { MUA, 0, "(?:(?:ab)?\?c|(ab)+d)*?g", "ababcdccababddg" },
  263. /* Single character iterators. */
  264. { MUA, 0, "(a+aab)+aaaab", "aaaabcaaaabaabcaabcaaabaaaab" },
  265. { MUA, 0, "(a*a*aab)+x", "aaaaabaabaaabmaabx" },
  266. { MUA, 0, "(a*?(b|ab)a*?)+x", "aaaabcxbbaabaacbaaabaabax" },
  267. { MUA, 0, "(a+(ab|ad)a+)+x", "aaabaaaadaabaaabaaaadaaax" },
  268. { MUA, 0, "(a?(a)a?)+(aaa)", "abaaabaaaaaaaa" },
  269. { MUA, 0, "(a?\?(a)a?\?)+(b)", "aaaacaaacaacacbaaab" },
  270. { MUA, 0, "(a{0,4}(b))+d", "aaaaaabaabcaaaaabaaaaabd" },
  271. { MUA, 0, "(a{0,4}?[^b])+d+(a{0,4}[^b])d+", "aaaaadaaaacaadddaaddd" },
  272. { MUA, 0, "(ba{2})+c", "baabaaabacbaabaac" },
  273. { MUA, 0, "(a*+bc++)+", "aaabbcaaabcccab" },
  274. { MUA, 0, "(a?+[^b])+", "babaacacb" },
  275. { MUA, 0, "(a{0,3}+b)(a{0,3}+b)(a{0,3}+)[^c]", "abaabaaacbaabaaaac" },
  276. { CMUA, 0, "([a-c]+[d-f]+?)+?g", "aBdacdehAbDaFgA" },
  277. { CMUA, 0, "[c-f]+k", "DemmFke" },
  278. { MUA, 0, "([DGH]{0,4}M)+", "GGDGHDGMMHMDHHGHM" },
  279. { MUA, 0, "([a-c]{4,}s)+", "abasabbasbbaabsbba" },
  280. { CMUA, 0, "[ace]{3,7}", "AcbDAcEEcEd" },
  281. { CMUA, 0, "[ace]{3,7}?", "AcbDAcEEcEd" },
  282. { CMUA, 0, "[ace]{3,}", "AcbDAcEEcEd" },
  283. { CMUA, 0, "[ace]{3,}?", "AcbDAcEEcEd" },
  284. { MUA, 0, "[ckl]{2,}?g", "cdkkmlglglkcg" },
  285. { CMUA, 0, "[ace]{5}?", "AcCebDAcEEcEd" },
  286. { MUA, 0, "([AbC]{3,5}?d)+", "BACaAbbAEAACCbdCCbdCCAAbb" },
  287. { MUA, 0, "([^ab]{0,}s){2}", "abaabcdsABamsDDs" },
  288. { MUA, 0, "\\b\\w+\\B", "x,a_cd" },
  289. { MUAP, 0, "\\b[^\xc2\xa1]+\\B", "\xc3\x89\xc2\xa1\xe6\x92\xad\xc3\x81\xc3\xa1" },
  290. { CMUA, 0, "[^b]+(a*)([^c]?d{3})", "aaaaddd" },
  291. { CMUAP, 0, "\xe1\xbd\xb8{2}", "\xe1\xbf\xb8#\xe1\xbf\xb8\xe1\xbd\xb8" },
  292. { CMUA, 0, "[^\xf0\x90\x90\x80]{2,4}@", "\xf0\x90\x90\xa8\xf0\x90\x90\x80###\xf0\x90\x90\x80@@@" },
  293. { CMUA, 0, "[^\xe1\xbd\xb8][^\xc3\xa9]", "\xe1\xbd\xb8\xe1\xbf\xb8\xc3\xa9\xc3\x89#" },
  294. { MUA, 0, "[^\xe1\xbd\xb8][^\xc3\xa9]", "\xe1\xbd\xb8\xe1\xbf\xb8\xc3\xa9\xc3\x89#" },
  295. { MUA, 0, "[^\xe1\xbd\xb8]{3,}?", "##\xe1\xbd\xb8#\xe1\xbd\xb8#\xc3\x89#\xe1\xbd\xb8" },
  296. { MUA, 0, "\\d+123", "987654321,01234" },
  297. { MUA, 0, "abcd*|\\w+xy", "aaaaa,abxyz" },
  298. { MUA, 0, "(?:abc|((?:amc|\\b\\w*xy)))", "aaaaa,abxyz" },
  299. { MUA, 0, "a(?R)|([a-z]++)#", ".abcd.abcd#."},
  300. { MUA, 0, "a(?R)|([a-z]++)#", ".abcd.mbcd#."},
  301. { MUA, 0, ".[ab]*.", "xx" },
  302. { MUA, 0, ".[ab]*a", "xxa" },
  303. { MUA, 0, ".[ab]?.", "xx" },
  304. /* Bracket repeats with limit. */
  305. { MUA, 0, "(?:(ab){2}){5}M", "abababababababababababM" },
  306. { MUA, 0, "(?:ab|abab){1,5}M", "abababababababababababM" },
  307. { MUA, 0, "(?>ab|abab){1,5}M", "abababababababababababM" },
  308. { MUA, 0, "(?:ab|abab){1,5}?M", "abababababababababababM" },
  309. { MUA, 0, "(?>ab|abab){1,5}?M", "abababababababababababM" },
  310. { MUA, 0, "(?:(ab){1,4}?){1,3}?M", "abababababababababababababM" },
  311. { MUA, 0, "(?:(ab){1,4}){1,3}abababababababababababM", "ababababababababababababM" },
  312. { MUA, 0 | F_NOMATCH, "(?:(ab){1,4}){1,3}abababababababababababM", "abababababababababababM" },
  313. { MUA, 0, "(ab){4,6}?M", "abababababababM" },
  314. /* Basic character sets. */
  315. { MUA, 0, "(?:\\s)+(?:\\S)+", "ab \t\xc3\xa9\xe6\x92\xad " },
  316. { MUA, 0, "(\\w)*(k)(\\W)?\?", "abcdef abck11" },
  317. { MUA, 0, "\\((\\d)+\\)\\D", "a() (83 (8)2 (9)ab" },
  318. { MUA, 0, "\\w(\\s|(?:\\d)*,)+\\w\\wb", "a 5, 4,, bb 5, 4,, aab" },
  319. { MUA, 0, "(\\v+)(\\V+)", "\x0e\xc2\x85\xe2\x80\xa8\x0b\x09\xe2\x80\xa9" },
  320. { MUA, 0, "(\\h+)(\\H+)", "\xe2\x80\xa8\xe2\x80\x80\x20\xe2\x80\x8a\xe2\x81\x9f\xe3\x80\x80\x09\x20\xc2\xa0\x0a" },
  321. { MUA, 0, "x[bcef]+", "xaxdxecbfg" },
  322. { MUA, 0, "x[bcdghij]+", "xaxexfxdgbjk" },
  323. { MUA, 0, "x[^befg]+", "xbxexacdhg" },
  324. { MUA, 0, "x[^bcdl]+", "xlxbxaekmd" },
  325. { MUA, 0, "x[^bcdghi]+", "xbxdxgxaefji" },
  326. { MUA, 0, "x[B-Fb-f]+", "xaxAxgxbfBFG" },
  327. { CMUA, 0, "\\x{e9}+", "#\xf0\x90\x90\xa8\xc3\xa8\xc3\xa9\xc3\x89\xc3\x88" },
  328. { CMUA, 0, "[^\\x{e9}]+", "\xc3\xa9#\xf0\x90\x90\xa8\xc3\xa8\xc3\x88\xc3\x89" },
  329. { MUA, 0, "[\\x02\\x7e]+", "\xc3\x81\xe1\xbf\xb8\xf0\x90\x90\xa8\x01\x02\x7e\x7f" },
  330. { MUA, 0, "[^\\x02\\x7e]+", "\x02\xc3\x81\xe1\xbf\xb8\xf0\x90\x90\xa8\x01\x7f\x7e" },
  331. { MUA, 0, "[\\x{81}-\\x{7fe}]+", "#\xe1\xbf\xb8\xf0\x90\x90\xa8\xc2\x80\xc2\x81\xdf\xbe\xdf\xbf" },
  332. { MUA, 0, "[^\\x{81}-\\x{7fe}]+", "\xc2\x81#\xe1\xbf\xb8\xf0\x90\x90\xa8\xc2\x80\xdf\xbf\xdf\xbe" },
  333. { MUA, 0, "[\\x{801}-\\x{fffe}]+", "#\xc3\xa9\xf0\x90\x90\x80\xe0\xa0\x80\xe0\xa0\x81\xef\xbf\xbe\xef\xbf\xbf" },
  334. { MUA, 0, "[^\\x{801}-\\x{fffe}]+", "\xe0\xa0\x81#\xc3\xa9\xf0\x90\x90\x80\xe0\xa0\x80\xef\xbf\xbf\xef\xbf\xbe" },
  335. { MUA, 0, "[\\x{10001}-\\x{10fffe}]+", "#\xc3\xa9\xe2\xb1\xa5\xf0\x90\x80\x80\xf0\x90\x80\x81\xf4\x8f\xbf\xbe\xf4\x8f\xbf\xbf" },
  336. { MUA, 0, "[^\\x{10001}-\\x{10fffe}]+", "\xf0\x90\x80\x81#\xc3\xa9\xe2\xb1\xa5\xf0\x90\x80\x80\xf4\x8f\xbf\xbf\xf4\x8f\xbf\xbe" },
  337. /* Unicode properties. */
  338. { MUAP, 0, "[1-5\xc3\xa9\\w]", "\xc3\xa1_" },
  339. { MUAP, 0 | F_PROPERTY, "[\xc3\x81\\p{Ll}]", "A_\xc3\x89\xc3\xa1" },
  340. { MUAP, 0, "[\\Wd-h_x-z]+", "a\xc2\xa1#_yhzdxi" },
  341. { MUAP, 0 | F_NOMATCH | F_PROPERTY, "[\\P{Any}]", "abc" },
  342. { MUAP, 0 | F_NOMATCH | F_PROPERTY, "[^\\p{Any}]", "abc" },
  343. { MUAP, 0 | F_NOMATCH | F_PROPERTY, "[\\P{Any}\xc3\xa1-\xc3\xa8]", "abc" },
  344. { MUAP, 0 | F_NOMATCH | F_PROPERTY, "[^\\p{Any}\xc3\xa1-\xc3\xa8]", "abc" },
  345. { MUAP, 0 | F_NOMATCH | F_PROPERTY, "[\xc3\xa1-\xc3\xa8\\P{Any}]", "abc" },
  346. { MUAP, 0 | F_NOMATCH | F_PROPERTY, "[^\xc3\xa1-\xc3\xa8\\p{Any}]", "abc" },
  347. { MUAP, 0 | F_PROPERTY, "[\xc3\xa1-\xc3\xa8\\p{Any}]", "abc" },
  348. { MUAP, 0 | F_PROPERTY, "[^\xc3\xa1-\xc3\xa8\\P{Any}]", "abc" },
  349. { MUAP, 0, "[b-\xc3\xa9\\s]", "a\xc\xe6\x92\xad" },
  350. { CMUAP, 0, "[\xc2\x85-\xc2\x89\xc3\x89]", "\xc2\x84\xc3\xa9" },
  351. { MUAP, 0, "[^b-d^&\\s]{3,}", "db^ !a\xe2\x80\xa8_ae" },
  352. { MUAP, 0 | F_PROPERTY, "[^\\S\\P{Any}][\\sN]{1,3}[\\P{N}]{4}", "\xe2\x80\xaa\xa N\x9\xc3\xa9_0" },
  353. { MUA, 0 | F_PROPERTY, "[^\\P{L}\x9!D-F\xa]{2,3}", "\x9,.DF\xa.CG\xc3\x81" },
  354. { CMUAP, 0, "[\xc3\xa1-\xc3\xa9_\xe2\x80\xa0-\xe2\x80\xaf]{1,5}[^\xe2\x80\xa0-\xe2\x80\xaf]", "\xc2\xa1\xc3\x89\xc3\x89\xe2\x80\xaf_\xe2\x80\xa0" },
  355. { MUAP, 0 | F_PROPERTY, "[\xc3\xa2-\xc3\xa6\xc3\x81-\xc3\x84\xe2\x80\xa8-\xe2\x80\xa9\xe6\x92\xad\\p{Zs}]{2,}", "\xe2\x80\xa7\xe2\x80\xa9\xe6\x92\xad \xe6\x92\xae" },
  356. { MUAP, 0 | F_PROPERTY, "[\\P{L&}]{2}[^\xc2\x85-\xc2\x89\\p{Ll}\\p{Lu}]{2}", "\xc3\xa9\xe6\x92\xad.a\xe6\x92\xad|\xc2\x8a#" },
  357. { PCRE_UCP, 0, "[a-b\\s]{2,5}[^a]", "AB baaa" },
  358. /* Possible empty brackets. */
  359. { MUA, 0, "(?:|ab||bc|a)+d", "abcxabcabd" },
  360. { MUA, 0, "(|ab||bc|a)+d", "abcxabcabd" },
  361. { MUA, 0, "(?:|ab||bc|a)*d", "abcxabcabd" },
  362. { MUA, 0, "(|ab||bc|a)*d", "abcxabcabd" },
  363. { MUA, 0, "(?:|ab||bc|a)+?d", "abcxabcabd" },
  364. { MUA, 0, "(|ab||bc|a)+?d", "abcxabcabd" },
  365. { MUA, 0, "(?:|ab||bc|a)*?d", "abcxabcabd" },
  366. { MUA, 0, "(|ab||bc|a)*?d", "abcxabcabd" },
  367. { MUA, 0, "(((a)*?|(?:ba)+)+?|(?:|c|ca)*)*m", "abaacaccabacabalabaacaccabacabamm" },
  368. { MUA, 0, "(?:((?:a)*|(ba)+?)+|(|c|ca)*?)*?m", "abaacaccabacabalabaacaccabacabamm" },
  369. /* Start offset. */
  370. { MUA, 3, "(\\d|(?:\\w)*\\w)+", "0ac01Hb" },
  371. { MUA, 4 | F_NOMATCH, "(\\w\\W\\w)+", "ab#d" },
  372. { MUA, 2 | F_NOMATCH, "(\\w\\W\\w)+", "ab#d" },
  373. { MUA, 1, "(\\w\\W\\w)+", "ab#d" },
  374. /* Newline. */
  375. { PCRE_MULTILINE | PCRE_NEWLINE_CRLF, 0, "\\W{0,2}[^#]{3}", "\r\n#....." },
  376. { PCRE_MULTILINE | PCRE_NEWLINE_CR, 0, "\\W{0,2}[^#]{3}", "\r\n#....." },
  377. { PCRE_MULTILINE | PCRE_NEWLINE_CRLF, 0, "\\W{1,3}[^#]", "\r\n##...." },
  378. { MUA | PCRE_NO_UTF8_CHECK, 1, "^.a", "\n\x80\nxa" },
  379. { MUA, 1, "^", "\r\n" },
  380. { PCRE_MULTILINE | PCRE_NEWLINE_CRLF, 1 | F_NOMATCH, "^", "\r\n" },
  381. { PCRE_MULTILINE | PCRE_NEWLINE_CRLF, 1, "^", "\r\na" },
  382. /* Any character except newline or any newline. */
  383. { PCRE_NEWLINE_CRLF, 0, ".", "\r" },
  384. { PCRE_NEWLINE_CRLF | PCRE_UTF8, 0, ".(.).", "a\xc3\xa1\r\n\n\r\r" },
  385. { PCRE_NEWLINE_ANYCRLF, 0, ".(.)", "a\rb\nc\r\n\xc2\x85\xe2\x80\xa8" },
  386. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".(.)", "a\rb\nc\r\n\xc2\x85\xe2\x80\xa8" },
  387. { PCRE_NEWLINE_ANY | PCRE_UTF8, 0, "(.).", "a\rb\nc\r\n\xc2\x85\xe2\x80\xa9$de" },
  388. { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0 | F_NOMATCH, ".(.).", "\xe2\x80\xa8\nb\r" },
  389. { PCRE_NEWLINE_ANY, 0, "(.)(.)", "#\x85#\r#\n#\r\n#\x84" },
  390. { PCRE_NEWLINE_ANY | PCRE_UTF8, 0, "(.+)#", "#\rMn\xc2\x85#\n###" },
  391. { PCRE_BSR_ANYCRLF, 0, "\\R", "\r" },
  392. { PCRE_BSR_ANYCRLF, 0, "\\R", "\x85#\r\n#" },
  393. { PCRE_BSR_UNICODE | PCRE_UTF8, 0, "\\R", "ab\xe2\x80\xa8#c" },
  394. { PCRE_BSR_UNICODE | PCRE_UTF8, 0, "\\R", "ab\r\nc" },
  395. { PCRE_NEWLINE_CRLF | PCRE_BSR_UNICODE | PCRE_UTF8, 0, "(\\R.)+", "\xc2\x85\r\n#\xe2\x80\xa8\n\r\n\r" },
  396. { MUA, 0 | F_NOMATCH, "\\R+", "ab" },
  397. { MUA, 0, "\\R+", "ab\r\n\r" },
  398. { MUA, 0, "\\R*", "ab\r\n\r" },
  399. { MUA, 0, "\\R*", "\r\n\r" },
  400. { MUA, 0, "\\R{2,4}", "\r\nab\r\r" },
  401. { MUA, 0, "\\R{2,4}", "\r\nab\n\n\n\r\r\r" },
  402. { MUA, 0, "\\R{2,}", "\r\nab\n\n\n\r\r\r" },
  403. { MUA, 0, "\\R{0,3}", "\r\n\r\n\r\n\r\n\r\n" },
  404. { MUA, 0 | F_NOMATCH, "\\R+\\R\\R", "\r\n\r\n" },
  405. { MUA, 0, "\\R+\\R\\R", "\r\r\r" },
  406. { MUA, 0, "\\R*\\R\\R", "\n\r" },
  407. { MUA, 0 | F_NOMATCH, "\\R{2,4}\\R\\R", "\r\r\r" },
  408. { MUA, 0, "\\R{2,4}\\R\\R", "\r\r\r\r" },
  409. /* Atomic groups (no fallback from "next" direction). */
  410. { MUA, 0 | F_NOMATCH, "(?>ab)ab", "bab" },
  411. { MUA, 0 | F_NOMATCH, "(?>(ab))ab", "bab" },
  412. { MUA, 0, "(?>ab)+abc(?>de)*def(?>gh)?ghe(?>ij)+?k(?>lm)*?n(?>op)?\?op",
  413. "bababcdedefgheijijklmlmnop" },
  414. { MUA, 0, "(?>a(b)+a|(ab)?\?(b))an", "abban" },
  415. { MUA, 0, "(?>ab+a|(?:ab)?\?b)an", "abban" },
  416. { MUA, 0, "((?>ab|ad|)*?)(?>|c)*abad", "abababcababad" },
  417. { MUA, 0, "(?>(aa|b|)*+(?>(##)|###)*d|(aa)(?>(baa)?)m)", "aabaa#####da" },
  418. { MUA, 0, "((?>a|)+?)b", "aaacaaab" },
  419. { MUA, 0, "(?>x|)*$", "aaa" },
  420. { MUA, 0, "(?>(x)|)*$", "aaa" },
  421. { MUA, 0, "(?>x|())*$", "aaa" },
  422. { MUA, 0, "((?>[cxy]a|[a-d])*?)b", "aaa+ aaab" },
  423. { MUA, 0, "((?>[cxy](a)|[a-d])*?)b", "aaa+ aaab" },
  424. { MUA, 0, "(?>((?>(a+))))bab|(?>((?>(a+))))bb", "aaaabaaabaabab" },
  425. { MUA, 0, "(?>(?>a+))bab|(?>(?>a+))bb", "aaaabaaabaabab" },
  426. { MUA, 0, "(?>(a)c|(?>(c)|(a))a)b*?bab", "aaaabaaabaabab" },
  427. { MUA, 0, "(?>ac|(?>c|a)a)b*?bab", "aaaabaaabaabab" },
  428. { MUA, 0, "(?>(b)b|(a))*b(?>(c)|d)?x", "ababcaaabdbx" },
  429. { MUA, 0, "(?>bb|a)*b(?>c|d)?x", "ababcaaabdbx" },
  430. { MUA, 0, "(?>(bb)|a)*b(?>c|(d))?x", "ababcaaabdbx" },
  431. { MUA, 0, "(?>(a))*?(?>(a))+?(?>(a))??x", "aaaaaacccaaaaabax" },
  432. { MUA, 0, "(?>a)*?(?>a)+?(?>a)??x", "aaaaaacccaaaaabax" },
  433. { MUA, 0, "(?>(a)|)*?(?>(a)|)+?(?>(a)|)??x", "aaaaaacccaaaaabax" },
  434. { MUA, 0, "(?>a|)*?(?>a|)+?(?>a|)??x", "aaaaaacccaaaaabax" },
  435. { MUA, 0, "(?>a(?>(a{0,2}))*?b|aac)+b", "aaaaaaacaaaabaaaaacaaaabaacaaabb" },
  436. { CMA, 0, "(?>((?>a{32}|b+|(a*))?(?>c+|d*)?\?)+e)+?f", "aaccebbdde bbdaaaccebbdee bbdaaaccebbdeef" },
  437. { MUA, 0, "(?>(?:(?>aa|a||x)+?b|(?>aa|a||(x))+?c)?(?>[ad]{0,2})*?d)+d", "aaacdbaabdcabdbaaacd aacaabdbdcdcaaaadaabcbaadd" },
  438. { MUA, 0, "(?>(?:(?>aa|a||(x))+?b|(?>aa|a||x)+?c)?(?>[ad]{0,2})*?d)+d", "aaacdbaabdcabdbaaacd aacaabdbdcdcaaaadaabcbaadd" },
  439. { MUA, 0 | F_PROPERTY, "\\X", "\xcc\x8d\xcc\x8d" },
  440. { MUA, 0 | F_PROPERTY, "\\X", "\xcc\x8d\xcc\x8d#\xcc\x8d\xcc\x8d" },
  441. { MUA, 0 | F_PROPERTY, "\\X+..", "\xcc\x8d#\xcc\x8d#\xcc\x8d\xcc\x8d" },
  442. { MUA, 0 | F_PROPERTY, "\\X{2,4}", "abcdef" },
  443. { MUA, 0 | F_PROPERTY, "\\X{2,4}?", "abcdef" },
  444. { MUA, 0 | F_NOMATCH | F_PROPERTY, "\\X{2,4}..", "#\xcc\x8d##" },
  445. { MUA, 0 | F_PROPERTY, "\\X{2,4}..", "#\xcc\x8d#\xcc\x8d##" },
  446. { MUA, 0, "(c(ab)?+ab)+", "cabcababcab" },
  447. { MUA, 0, "(?>(a+)b)+aabab", "aaaabaaabaabab" },
  448. /* Possessive quantifiers. */
  449. { MUA, 0, "(?:a|b)++m", "mababbaaxababbaam" },
  450. { MUA, 0, "(?:a|b)*+m", "mababbaaxababbaam" },
  451. { MUA, 0, "(?:a|b)*+m", "ababbaaxababbaam" },
  452. { MUA, 0, "(a|b)++m", "mababbaaxababbaam" },
  453. { MUA, 0, "(a|b)*+m", "mababbaaxababbaam" },
  454. { MUA, 0, "(a|b)*+m", "ababbaaxababbaam" },
  455. { MUA, 0, "(a|b(*ACCEPT))++m", "maaxab" },
  456. { MUA, 0, "(?:b*)++m", "bxbbxbbbxm" },
  457. { MUA, 0, "(?:b*)++m", "bxbbxbbbxbbm" },
  458. { MUA, 0, "(?:b*)*+m", "bxbbxbbbxm" },
  459. { MUA, 0, "(?:b*)*+m", "bxbbxbbbxbbm" },
  460. { MUA, 0, "(b*)++m", "bxbbxbbbxm" },
  461. { MUA, 0, "(b*)++m", "bxbbxbbbxbbm" },
  462. { MUA, 0, "(b*)*+m", "bxbbxbbbxm" },
  463. { MUA, 0, "(b*)*+m", "bxbbxbbbxbbm" },
  464. { MUA, 0, "(?:a|(b))++m", "mababbaaxababbaam" },
  465. { MUA, 0, "(?:(a)|b)*+m", "mababbaaxababbaam" },
  466. { MUA, 0, "(?:(a)|(b))*+m", "ababbaaxababbaam" },
  467. { MUA, 0, "(a|(b))++m", "mababbaaxababbaam" },
  468. { MUA, 0, "((a)|b)*+m", "mababbaaxababbaam" },
  469. { MUA, 0, "((a)|(b))*+m", "ababbaaxababbaam" },
  470. { MUA, 0, "(a|(b)(*ACCEPT))++m", "maaxab" },
  471. { MUA, 0, "(?:(b*))++m", "bxbbxbbbxm" },
  472. { MUA, 0, "(?:(b*))++m", "bxbbxbbbxbbm" },
  473. { MUA, 0, "(?:(b*))*+m", "bxbbxbbbxm" },
  474. { MUA, 0, "(?:(b*))*+m", "bxbbxbbbxbbm" },
  475. { MUA, 0, "((b*))++m", "bxbbxbbbxm" },
  476. { MUA, 0, "((b*))++m", "bxbbxbbbxbbm" },
  477. { MUA, 0, "((b*))*+m", "bxbbxbbbxm" },
  478. { MUA, 0, "((b*))*+m", "bxbbxbbbxbbm" },
  479. { MUA, 0 | F_NOMATCH, "(?>(b{2,4}))(?:(?:(aa|c))++m|(?:(aa|c))+n)", "bbaacaaccaaaacxbbbmbn" },
  480. { MUA, 0, "((?:b)++a)+(cd)*+m", "bbababbacdcdnbbababbacdcdm" },
  481. { MUA, 0, "((?:(b))++a)+((c)d)*+m", "bbababbacdcdnbbababbacdcdm" },
  482. { MUA, 0, "(?:(?:(?:ab)*+k)++(?:n(?:cd)++)*+)*+m", "ababkkXababkkabkncXababkkabkncdcdncdXababkkabkncdcdncdkkabkncdXababkkabkncdcdncdkkabkncdm" },
  483. { MUA, 0, "(?:((ab)*+(k))++(n(?:c(d))++)*+)*+m", "ababkkXababkkabkncXababkkabkncdcdncdXababkkabkncdcdncdkkabkncdXababkkabkncdcdncdkkabkncdm" },
  484. /* Back references. */
  485. { MUA, 0, "(aa|bb)(\\1*)(ll|)(\\3*)bbbbbbc", "aaaaaabbbbbbbbc" },
  486. { CMUA, 0, "(aa|bb)(\\1+)(ll|)(\\3+)bbbbbbc", "bBbbBbCbBbbbBbbcbbBbbbBBbbC" },
  487. { CMA, 0, "(a{2,4})\\1", "AaAaaAaA" },
  488. { MUA, 0, "(aa|bb)(\\1?)aa(\\1?)(ll|)(\\4+)bbc", "aaaaaaaabbaabbbbaabbbbc" },
  489. { MUA, 0, "(aa|bb)(\\1{0,5})(ll|)(\\3{0,5})cc", "bbxxbbbbxxaaaaaaaaaaaaaaaacc" },
  490. { MUA, 0, "(aa|bb)(\\1{3,5})(ll|)(\\3{3,5})cc", "bbbbbbbbbbbbaaaaaaccbbbbbbbbbbbbbbcc" },
  491. { MUA, 0, "(aa|bb)(\\1{3,})(ll|)(\\3{3,})cc", "bbbbbbbbbbbbaaaaaaccbbbbbbbbbbbbbbcc" },
  492. { MUA, 0, "(\\w+)b(\\1+)c", "GabGaGaDbGaDGaDc" },
  493. { MUA, 0, "(?:(aa)|b)\\1?b", "bb" },
  494. { CMUA, 0, "(aa|bb)(\\1*?)aa(\\1+?)", "bBBbaaAAaaAAaa" },
  495. { MUA, 0, "(aa|bb)(\\1*?)(dd|)cc(\\3+?)", "aaaaaccdd" },
  496. { CMUA, 0, "(?:(aa|bb)(\\1?\?)cc){2}(\\1?\?)", "aAaABBbbAAaAcCaAcCaA" },
  497. { MUA, 0, "(?:(aa|bb)(\\1{3,5}?)){2}(dd|)(\\3{3,5}?)", "aaaaaabbbbbbbbbbaaaaaaaaaaaaaa" },
  498. { CMA, 0, "(?:(aa|bb)(\\1{3,}?)){2}(dd|)(\\3{3,}?)", "aaaaaabbbbbbbbbbaaaaaaaaaaaaaa" },
  499. { MUA, 0, "(?:(aa|bb)(\\1{0,3}?)){2}(dd|)(\\3{0,3}?)b(\\1{0,3}?)(\\1{0,3})", "aaaaaaaaaaaaaaabaaaaa" },
  500. { MUA, 0, "(a(?:\\1|)a){3}b", "aaaaaaaaaaab" },
  501. { MA, 0, "(a?)b(\\1\\1*\\1+\\1?\\1*?\\1+?\\1??\\1*+\\1++\\1?+\\1{4}\\1{3,5}\\1{4,}\\1{0,5}\\1{3,5}?\\1{4,}?\\1{0,5}?\\1{3,5}+\\1{4,}+\\1{0,5}+#){2}d", "bb#b##d" },
  502. { MUAP, 0 | F_PROPERTY, "(\\P{N})\\1{2,}", ".www." },
  503. { MUAP, 0 | F_PROPERTY, "(\\P{N})\\1{0,2}", "wwwww." },
  504. { MUAP, 0 | F_PROPERTY, "(\\P{N})\\1{1,2}ww", "wwww" },
  505. { MUAP, 0 | F_PROPERTY, "(\\P{N})\\1{1,2}ww", "wwwww" },
  506. { PCRE_UCP, 0 | F_PROPERTY, "(\\P{N})\\1{2,}", ".www." },
  507. { CMUAP, 0, "(\xf0\x90\x90\x80)\\1", "\xf0\x90\x90\xa8\xf0\x90\x90\xa8" },
  508. { MUA | PCRE_DUPNAMES, 0 | F_NOMATCH, "\\k<A>{1,3}(?<A>aa)(?<A>bb)", "aabb" },
  509. { MUA | PCRE_DUPNAMES | PCRE_JAVASCRIPT_COMPAT, 0, "\\k<A>{1,3}(?<A>aa)(?<A>bb)", "aabb" },
  510. { MUA | PCRE_DUPNAMES | PCRE_JAVASCRIPT_COMPAT, 0, "\\k<A>*(?<A>aa)(?<A>bb)", "aabb" },
  511. { MUA | PCRE_DUPNAMES, 0, "(?<A>aa)(?<A>bb)\\k<A>{0,3}aaaaaa", "aabbaaaaaa" },
  512. { MUA | PCRE_DUPNAMES, 0, "(?<A>aa)(?<A>bb)\\k<A>{2,5}bb", "aabbaaaabb" },
  513. { MUA | PCRE_DUPNAMES, 0, "(?:(?<A>aa)|(?<A>bb))\\k<A>{0,3}m", "aaaaaaaabbbbaabbbbm" },
  514. { MUA | PCRE_DUPNAMES, 0 | F_NOMATCH, "\\k<A>{1,3}?(?<A>aa)(?<A>bb)", "aabb" },
  515. { MUA | PCRE_DUPNAMES | PCRE_JAVASCRIPT_COMPAT, 0, "\\k<A>{1,3}?(?<A>aa)(?<A>bb)", "aabb" },
  516. { MUA | PCRE_DUPNAMES, 0, "\\k<A>*?(?<A>aa)(?<A>bb)", "aabb" },
  517. { MUA | PCRE_DUPNAMES, 0, "(?:(?<A>aa)|(?<A>bb))\\k<A>{0,3}?m", "aaaaaabbbbbbaabbbbbbbbbbm" },
  518. { MUA | PCRE_DUPNAMES, 0, "(?:(?<A>aa)|(?<A>bb))\\k<A>*?m", "aaaaaabbbbbbaabbbbbbbbbbm" },
  519. { MUA | PCRE_DUPNAMES, 0, "(?:(?<A>aa)|(?<A>bb))\\k<A>{2,3}?", "aaaabbbbaaaabbbbbbbbbb" },
  520. { CMUA | PCRE_DUPNAMES, 0, "(?:(?<A>AA)|(?<A>BB))\\k<A>{0,3}M", "aaaaaaaabbbbaabbbbm" },
  521. { CMUA | PCRE_DUPNAMES, 0, "(?:(?<A>AA)|(?<A>BB))\\k<A>{1,3}M", "aaaaaaaabbbbaabbbbm" },
  522. { CMUA | PCRE_DUPNAMES, 0, "(?:(?<A>AA)|(?<A>BB))\\k<A>{0,3}?M", "aaaaaabbbbbbaabbbbbbbbbbm" },
  523. { CMUA | PCRE_DUPNAMES, 0, "(?:(?<A>AA)|(?<A>BB))\\k<A>{2,3}?", "aaaabbbbaaaabbbbbbbbbb" },
  524. /* Assertions. */
  525. { MUA, 0, "(?=xx|yy|zz)\\w{4}", "abczzdefg" },
  526. { MUA, 0, "(?=((\\w+)b){3}|ab)", "dbbbb ab" },
  527. { MUA, 0, "(?!ab|bc|cd)[a-z]{2}", "Xabcdef" },
  528. { MUA, 0, "(?<=aaa|aa|a)a", "aaa" },
  529. { MUA, 2, "(?<=aaa|aa|a)a", "aaa" },
  530. { MA, 0, "(?<=aaa|aa|a)a", "aaa" },
  531. { MA, 2, "(?<=aaa|aa|a)a", "aaa" },
  532. { MUA, 0, "(\\d{2})(?!\\w+c|(((\\w?)m){2}n)+|\\1)", "x5656" },
  533. { MUA, 0, "((?=((\\d{2,6}\\w){2,}))\\w{5,20}K){2,}", "567v09708K12l00M00 567v09708K12l00M00K45K" },
  534. { MUA, 0, "(?=(?:(?=\\S+a)\\w*(b)){3})\\w+\\d", "bba bbab nbbkba nbbkba0kl" },
  535. { MUA, 0, "(?>a(?>(b+))a(?=(..)))*?k", "acabbcabbaabacabaabbakk" },
  536. { MUA, 0, "((?(?=(a))a)+k)", "bbak" },
  537. { MUA, 0, "((?(?=a)a)+k)", "bbak" },
  538. { MUA, 0 | F_NOMATCH, "(?=(?>(a))m)amk", "a k" },
  539. { MUA, 0 | F_NOMATCH, "(?!(?>(a))m)amk", "a k" },
  540. { MUA, 0 | F_NOMATCH, "(?>(?=(a))am)amk", "a k" },
  541. { MUA, 0, "(?=(?>a|(?=(?>(b+))a|c)[a-c]+)*?m)[a-cm]+k", "aaam bbam baaambaam abbabba baaambaamk" },
  542. { MUA, 0, "(?> ?\?\\b(?(?=\\w{1,4}(a))m)\\w{0,8}bc){2,}?", "bca ssbc mabd ssbc mabc" },
  543. { MUA, 0, "(?:(?=ab)?[^n][^n])+m", "ababcdabcdcdabnababcdabcdcdabm" },
  544. { MUA, 0, "(?:(?=a(b))?[^n][^n])+m", "ababcdabcdcdabnababcdabcdcdabm" },
  545. { MUA, 0, "(?:(?=.(.))??\\1.)+m", "aabbbcbacccanaabbbcbacccam" },
  546. { MUA, 0, "(?:(?=.)??[a-c])+m", "abacdcbacacdcaccam" },
  547. { MUA, 0, "((?!a)?(?!([^a]))?)+$", "acbab" },
  548. { MUA, 0, "((?!a)?\?(?!([^a]))?\?)+$", "acbab" },
  549. { MUA, 0, "a(?=(?C)\\B)b", "ab" },
  550. { MUA, 0, "a(?!(?C)\\B)bb|ab", "abb" },
  551. { MUA, 0, "a(?=\\b|(?C)\\B)b", "ab" },
  552. { MUA, 0, "a(?!\\b|(?C)\\B)bb|ab", "abb" },
  553. { MUA, 0, "c(?(?=(?C)\\B)ab|a)", "cab" },
  554. { MUA, 0, "c(?(?!(?C)\\B)ab|a)", "cab" },
  555. { MUA, 0, "c(?(?=\\b|(?C)\\B)ab|a)", "cab" },
  556. { MUA, 0, "c(?(?!\\b|(?C)\\B)ab|a)", "cab" },
  557. { MUA, 0, "a(?=)b", "ab" },
  558. { MUA, 0 | F_NOMATCH, "a(?!)b", "ab" },
  559. /* Not empty, ACCEPT, FAIL */
  560. { MUA | PCRE_NOTEMPTY, 0 | F_NOMATCH, "a*", "bcx" },
  561. { MUA | PCRE_NOTEMPTY, 0, "a*", "bcaad" },
  562. { MUA | PCRE_NOTEMPTY, 0, "a*?", "bcaad" },
  563. { MUA | PCRE_NOTEMPTY_ATSTART, 0, "a*", "bcaad" },
  564. { MUA, 0, "a(*ACCEPT)b", "ab" },
  565. { MUA | PCRE_NOTEMPTY, 0 | F_NOMATCH, "a*(*ACCEPT)b", "bcx" },
  566. { MUA | PCRE_NOTEMPTY, 0, "a*(*ACCEPT)b", "bcaad" },
  567. { MUA | PCRE_NOTEMPTY, 0, "a*?(*ACCEPT)b", "bcaad" },
  568. { MUA | PCRE_NOTEMPTY, 0 | F_NOMATCH, "(?:z|a*(*ACCEPT)b)", "bcx" },
  569. { MUA | PCRE_NOTEMPTY, 0, "(?:z|a*(*ACCEPT)b)", "bcaad" },
  570. { MUA | PCRE_NOTEMPTY, 0, "(?:z|a*?(*ACCEPT)b)", "bcaad" },
  571. { MUA | PCRE_NOTEMPTY_ATSTART, 0, "a*(*ACCEPT)b", "bcx" },
  572. { MUA | PCRE_NOTEMPTY_ATSTART, 0 | F_NOMATCH, "a*(*ACCEPT)b", "" },
  573. { MUA, 0, "((a(*ACCEPT)b))", "ab" },
  574. { MUA, 0, "(a(*FAIL)a|a)", "aaa" },
  575. { MUA, 0, "(?=ab(*ACCEPT)b)a", "ab" },
  576. { MUA, 0, "(?=(?:x|ab(*ACCEPT)b))", "ab" },
  577. { MUA, 0, "(?=(a(b(*ACCEPT)b)))a", "ab" },
  578. { MUA | PCRE_NOTEMPTY, 0, "(?=a*(*ACCEPT))c", "c" },
  579. /* Conditional blocks. */
  580. { MUA, 0, "(?(?=(a))a|b)+k", "ababbalbbadabak" },
  581. { MUA, 0, "(?(?!(b))a|b)+k", "ababbalbbadabak" },
  582. { MUA, 0, "(?(?=a)a|b)+k", "ababbalbbadabak" },
  583. { MUA, 0, "(?(?!b)a|b)+k", "ababbalbbadabak" },
  584. { MUA, 0, "(?(?=(a))a*|b*)+k", "ababbalbbadabak" },
  585. { MUA, 0, "(?(?!(b))a*|b*)+k", "ababbalbbadabak" },
  586. { MUA, 0, "(?(?!(b))(?:aaaaaa|a)|(?:bbbbbb|b))+aaaak", "aaaaaaaaaaaaaa bbbbbbbbbbbbbbb aaaaaaak" },
  587. { MUA, 0, "(?(?!b)(?:aaaaaa|a)|(?:bbbbbb|b))+aaaak", "aaaaaaaaaaaaaa bbbbbbbbbbbbbbb aaaaaaak" },
  588. { MUA, 0 | F_DIFF, "(?(?!(b))(?:aaaaaa|a)|(?:bbbbbb|b))+bbbbk", "aaaaaaaaaaaaaa bbbbbbbbbbbbbbb bbbbbbbk" },
  589. { MUA, 0, "(?(?!b)(?:aaaaaa|a)|(?:bbbbbb|b))+bbbbk", "aaaaaaaaaaaaaa bbbbbbbbbbbbbbb bbbbbbbk" },
  590. { MUA, 0, "(?(?=a)a*|b*)+k", "ababbalbbadabak" },
  591. { MUA, 0, "(?(?!b)a*|b*)+k", "ababbalbbadabak" },
  592. { MUA, 0, "(?(?=a)ab)", "a" },
  593. { MUA, 0, "(?(?<!b)c)", "b" },
  594. { MUA, 0, "(?(DEFINE)a(b))", "a" },
  595. { MUA, 0, "a(?(DEFINE)(?:b|(?:c?)+)*)", "a" },
  596. { MUA, 0, "(?(?=.[a-c])[k-l]|[A-D])", "kdB" },
  597. { MUA, 0, "(?(?!.{0,4}[cd])(aa|bb)|(cc|dd))+", "aabbccddaa" },
  598. { MUA, 0, "(?(?=[^#@]*@)(aaab|aa|aba)|(aba|aab)){3,}", "aaabaaaba#aaabaaaba#aaabaaaba@" },
  599. { MUA, 0, "((?=\\w{5})\\w(?(?=\\w*k)\\d|[a-f_])*\\w\\s)+", "mol m10kk m088k _f_a_ mbkkl" },
  600. { MUA, 0, "(c)?\?(?(1)a|b)", "cdcaa" },
  601. { MUA, 0, "(c)?\?(?(1)a|b)", "cbb" },
  602. { MUA, 0 | F_DIFF, "(?(?=(a))(aaaa|a?))+aak", "aaaaab aaaaak" },
  603. { MUA, 0, "(?(?=a)(aaaa|a?))+aak", "aaaaab aaaaak" },
  604. { MUA, 0, "(?(?!(b))(aaaa|a?))+aak", "aaaaab aaaaak" },
  605. { MUA, 0, "(?(?!b)(aaaa|a?))+aak", "aaaaab aaaaak" },
  606. { MUA, 0 | F_DIFF, "(?(?=(a))a*)+aak", "aaaaab aaaaak" },
  607. { MUA, 0, "(?(?=a)a*)+aak", "aaaaab aaaaak" },
  608. { MUA, 0, "(?(?!(b))a*)+aak", "aaaaab aaaaak" },
  609. { MUA, 0, "(?(?!b)a*)+aak", "aaaaab aaaaak" },
  610. { MUA, 0, "(?(?=(?=(?!(x))a)aa)aaa|(?(?=(?!y)bb)bbb))*k", "abaabbaaabbbaaabbb abaabbaaabbbaaabbbk" },
  611. { MUA, 0, "(?P<Name>a)?(?P<Name2>b)?(?(Name)c|d)*l", "bc ddd abccabccl" },
  612. { MUA, 0, "(?P<Name>a)?(?P<Name2>b)?(?(Name)c|d)+?dd", "bcabcacdb bdddd" },
  613. { MUA, 0, "(?P<Name>a)?(?P<Name2>b)?(?(Name)c|d)+l", "ababccddabdbccd abcccl" },
  614. { MUA, 0, "((?:a|aa)(?(1)aaa))x", "aax" },
  615. { MUA, 0, "(?(?!)a|b)", "ab" },
  616. { MUA, 0, "(?(?!)a)", "ab" },
  617. { MUA, 0 | F_NOMATCH, "(?(?!)a|b)", "ac" },
  618. /* Set start of match. */
  619. { MUA, 0, "(?:\\Ka)*aaaab", "aaaaaaaa aaaaaaabb" },
  620. { MUA, 0, "(?>\\Ka\\Ka)*aaaab", "aaaaaaaa aaaaaaaaaabb" },
  621. { MUA, 0, "a+\\K(?<=\\Gaa)a", "aaaaaa" },
  622. { MUA | PCRE_NOTEMPTY, 0 | F_NOMATCH, "a\\K(*ACCEPT)b", "aa" },
  623. { MUA | PCRE_NOTEMPTY_ATSTART, 0, "a\\K(*ACCEPT)b", "aa" },
  624. /* First line. */
  625. { MUA | PCRE_FIRSTLINE, 0 | F_PROPERTY, "\\p{Any}a", "bb\naaa" },
  626. { MUA | PCRE_FIRSTLINE, 0 | F_NOMATCH | F_PROPERTY, "\\p{Any}a", "bb\r\naaa" },
  627. { MUA | PCRE_FIRSTLINE, 0, "(?<=a)", "a" },
  628. { MUA | PCRE_FIRSTLINE, 0 | F_NOMATCH, "[^a][^b]", "ab" },
  629. { MUA | PCRE_FIRSTLINE, 0 | F_NOMATCH, "a", "\na" },
  630. { MUA | PCRE_FIRSTLINE, 0 | F_NOMATCH, "[abc]", "\na" },
  631. { MUA | PCRE_FIRSTLINE, 0 | F_NOMATCH, "^a", "\na" },
  632. { MUA | PCRE_FIRSTLINE, 0 | F_NOMATCH, "^(?<=\n)", "\na" },
  633. { MUA | PCRE_FIRSTLINE, 0, "\xf0\x90\x90\x80", "\xf0\x90\x90\x80" },
  634. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANY | PCRE_FIRSTLINE, 0 | F_NOMATCH, "#", "\xc2\x85#" },
  635. { PCRE_MULTILINE | PCRE_NEWLINE_ANY | PCRE_FIRSTLINE, 0 | F_NOMATCH, "#", "\x85#" },
  636. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANY | PCRE_FIRSTLINE, 0 | F_NOMATCH, "^#", "\xe2\x80\xa8#" },
  637. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 0 | F_PROPERTY, "\\p{Any}", "\r\na" },
  638. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 0, ".", "\r" },
  639. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 0, "a", "\ra" },
  640. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 0 | F_NOMATCH, "ba", "bbb\r\nba" },
  641. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 0 | F_NOMATCH | F_PROPERTY, "\\p{Any}{4}|a", "\r\na" },
  642. { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 1, ".", "\r\n" },
  643. { PCRE_FIRSTLINE | PCRE_NEWLINE_LF | PCRE_DOTALL, 0 | F_NOMATCH, "ab.", "ab" },
  644. { MUA | PCRE_FIRSTLINE, 1 | F_NOMATCH, "^[a-d0-9]", "\nxx\nd" },
  645. { PCRE_NEWLINE_ANY | PCRE_FIRSTLINE | PCRE_DOTALL, 0, "....a", "012\n0a" },
  646. { MUA | PCRE_FIRSTLINE, 0, "[aC]", "a" },
  647. /* Recurse. */
  648. { MUA, 0, "(a)(?1)", "aa" },
  649. { MUA, 0, "((a))(?1)", "aa" },
  650. { MUA, 0, "(b|a)(?1)", "aa" },
  651. { MUA, 0, "(b|(a))(?1)", "aa" },
  652. { MUA, 0 | F_NOMATCH, "((a)(b)(?:a*))(?1)", "aba" },
  653. { MUA, 0, "((a)(b)(?:a*))(?1)", "abab" },
  654. { MUA, 0, "((a+)c(?2))b(?1)", "aacaabaca" },
  655. { MUA, 0, "((?2)b|(a)){2}(?1)", "aabab" },
  656. { MUA, 0, "(?1)(a)*+(?2)(b(?1))", "aababa" },
  657. { MUA, 0, "(?1)(((a(*ACCEPT)))b)", "axaa" },
  658. { MUA, 0, "(?1)(?(DEFINE) (((ac(*ACCEPT)))b) )", "akaac" },
  659. { MUA, 0, "(a+)b(?1)b\\1", "abaaabaaaaa" },
  660. { MUA, 0 | F_NOMATCH, "(?(DEFINE)(aa|a))(?1)ab", "aab" },
  661. { MUA, 0, "(?(DEFINE)(a\\Kb))(?1)+ababc", "abababxabababc" },
  662. { MUA, 0, "(a\\Kb)(?1)+ababc", "abababxababababc" },
  663. { MUA, 0 | F_NOMATCH, "(a\\Kb)(?1)+ababc", "abababxababababxc" },
  664. { MUA, 0, "b|<(?R)*>", "<<b>" },
  665. { MUA, 0, "(a\\K){0}(?:(?1)b|ac)", "ac" },
  666. { MUA, 0, "(?(DEFINE)(a(?2)|b)(b(?1)|(a)))(?:(?1)|(?2))m", "ababababnababababaam" },
  667. { MUA, 0, "(a)((?(R)a|b))(?2)", "aabbabaa" },
  668. { MUA, 0, "(a)((?(R2)a|b))(?2)", "aabbabaa" },
  669. { MUA, 0, "(a)((?(R1)a|b))(?2)", "ababba" },
  670. { MUA, 0, "(?(R0)aa|bb(?R))", "abba aabb bbaa" },
  671. { MUA, 0, "((?(R)(?:aaaa|a)|(?:(aaaa)|(a)))+)(?1)$", "aaaaaaaaaa aaaa" },
  672. { MUA, 0, "(?P<Name>a(?(R&Name)a|b))(?1)", "aab abb abaa" },
  673. { MUA, 0, "((?(R)a|(?1)){3})", "XaaaaaaaaaX" },
  674. { MUA, 0, "((?:(?(R)a|(?1))){3})", "XaaaaaaaaaX" },
  675. { MUA, 0, "((?(R)a|(?1)){1,3})aaaaaa", "aaaaaaaaXaaaaaaaaa" },
  676. { MUA, 0, "((?(R)a|(?1)){1,3}?)M", "aaaM" },
  677. /* 16 bit specific tests. */
  678. { CMA, 0 | F_FORCECONV, "\xc3\xa1", "\xc3\x81\xc3\xa1" },
  679. { CMA, 0 | F_FORCECONV, "\xe1\xbd\xb8", "\xe1\xbf\xb8\xe1\xbd\xb8" },
  680. { CMA, 0 | F_FORCECONV, "[\xc3\xa1]", "\xc3\x81\xc3\xa1" },
  681. { CMA, 0 | F_FORCECONV, "[\xe1\xbd\xb8]", "\xe1\xbf\xb8\xe1\xbd\xb8" },
  682. { CMA, 0 | F_FORCECONV, "[a-\xed\xb0\x80]", "A" },
  683. { CMA, 0 | F_NO8 | F_FORCECONV, "[a-\\x{dc00}]", "B" },
  684. { CMA, 0 | F_NO8 | F_NOMATCH | F_FORCECONV, "[b-\\x{dc00}]", "a" },
  685. { CMA, 0 | F_NO8 | F_FORCECONV, "\xed\xa0\x80\\x{d800}\xed\xb0\x80\\x{dc00}", "\xed\xa0\x80\xed\xa0\x80\xed\xb0\x80\xed\xb0\x80" },
  686. { CMA, 0 | F_NO8 | F_FORCECONV, "[\xed\xa0\x80\\x{d800}]{1,2}?[\xed\xb0\x80\\x{dc00}]{1,2}?#", "\xed\xa0\x80\xed\xa0\x80\xed\xb0\x80\xed\xb0\x80#" },
  687. { CMA, 0 | F_FORCECONV, "[\xed\xa0\x80\xed\xb0\x80#]{0,3}(?<=\xed\xb0\x80.)", "\xed\xa0\x80#\xed\xa0\x80##\xed\xb0\x80\xed\xa0\x80" },
  688. { CMA, 0 | F_FORCECONV, "[\xed\xa0\x80-\xed\xb3\xbf]", "\xed\x9f\xbf\xed\xa0\x83" },
  689. { CMA, 0 | F_FORCECONV, "[\xed\xa0\x80-\xed\xb3\xbf]", "\xed\xb4\x80\xed\xb3\xb0" },
  690. { CMA, 0 | F_NO8 | F_FORCECONV, "[\\x{d800}-\\x{dcff}]", "\xed\x9f\xbf\xed\xa0\x83" },
  691. { CMA, 0 | F_NO8 | F_FORCECONV, "[\\x{d800}-\\x{dcff}]", "\xed\xb4\x80\xed\xb3\xb0" },
  692. { CMA, 0 | F_FORCECONV, "[\xed\xa0\x80-\xef\xbf\xbf]+[\x1-\xed\xb0\x80]+#", "\xed\xa0\x85\xc3\x81\xed\xa0\x85\xef\xbf\xb0\xc2\x85\xed\xa9\x89#" },
  693. { CMA, 0 | F_FORCECONV, "[\xed\xa0\x80][\xed\xb0\x80]{2,}", "\xed\xa0\x80\xed\xb0\x80\xed\xa0\x80\xed\xb0\x80\xed\xb0\x80\xed\xb0\x80" },
  694. { MA, 0 | F_FORCECONV, "[^\xed\xb0\x80]{3,}?", "##\xed\xb0\x80#\xed\xb0\x80#\xc3\x89#\xed\xb0\x80" },
  695. { MA, 0 | F_NO8 | F_FORCECONV, "[^\\x{dc00}]{3,}?", "##\xed\xb0\x80#\xed\xb0\x80#\xc3\x89#\xed\xb0\x80" },
  696. { CMA, 0 | F_FORCECONV, ".\\B.", "\xed\xa0\x80\xed\xb0\x80" },
  697. { CMA, 0 | F_FORCECONV, "\\D+(?:\\d+|.)\\S+(?:\\s+|.)\\W+(?:\\w+|.)\xed\xa0\x80\xed\xa0\x80", "\xed\xa0\x80\xed\xa0\x80\xed\xa0\x80\xed\xa0\x80\xed\xa0\x80\xed\xa0\x80\xed\xa0\x80\xed\xa0\x80" },
  698. { CMA, 0 | F_FORCECONV, "\\d*\\s*\\w*\xed\xa0\x80\xed\xa0\x80", "\xed\xa0\x80\xed\xa0\x80" },
  699. { CMA, 0 | F_FORCECONV | F_NOMATCH, "\\d*?\\D*?\\s*?\\S*?\\w*?\\W*?##", "\xed\xa0\x80\xed\xa0\x80\xed\xa0\x80\xed\xa0\x80#" },
  700. { CMA | PCRE_EXTENDED, 0 | F_FORCECONV, "\xed\xa0\x80 \xed\xb0\x80 !", "\xed\xa0\x80\xed\xb0\x80!" },
  701. { CMA, 0 | F_FORCECONV, "\xed\xa0\x80+#[^#]+\xed\xa0\x80", "\xed\xa0\x80#a\xed\xa0\x80" },
  702. { CMA, 0 | F_FORCECONV, "(\xed\xa0\x80+)#\\1", "\xed\xa0\x80\xed\xa0\x80#\xed\xa0\x80\xed\xa0\x80" },
  703. { PCRE_MULTILINE | PCRE_NEWLINE_ANY, 0 | F_NO8 | F_FORCECONV, "^-", "a--\xe2\x80\xa8--" },
  704. { PCRE_BSR_UNICODE, 0 | F_NO8 | F_FORCECONV, "\\R", "ab\xe2\x80\xa8" },
  705. { 0, 0 | F_NO8 | F_FORCECONV, "\\v", "ab\xe2\x80\xa9" },
  706. { 0, 0 | F_NO8 | F_FORCECONV, "\\h", "ab\xe1\xa0\x8e" },
  707. { 0, 0 | F_NO8 | F_FORCECONV, "\\v+?\\V+?#", "\xe2\x80\xa9\xe2\x80\xa9\xef\xbf\xbf\xef\xbf\xbf#" },
  708. { 0, 0 | F_NO8 | F_FORCECONV, "\\h+?\\H+?#", "\xe1\xa0\x8e\xe1\xa0\x8e\xef\xbf\xbf\xef\xbf\xbf#" },
  709. /* Partial matching. */
  710. { MUA | PCRE_PARTIAL_SOFT, 0, "ab", "a" },
  711. { MUA | PCRE_PARTIAL_SOFT, 0, "ab|a", "a" },
  712. { MUA | PCRE_PARTIAL_HARD, 0, "ab|a", "a" },
  713. { MUA | PCRE_PARTIAL_SOFT, 0, "\\b#", "a" },
  714. { MUA | PCRE_PARTIAL_SOFT, 0, "(?<=a)b", "a" },
  715. { MUA | PCRE_PARTIAL_SOFT, 0, "abc|(?<=xxa)bc", "xxab" },
  716. { MUA | PCRE_PARTIAL_SOFT, 0, "a\\B", "a" },
  717. { MUA | PCRE_PARTIAL_HARD, 0, "a\\b", "a" },
  718. /* (*MARK) verb. */
  719. { MUA, 0, "a(*MARK:aa)a", "ababaa" },
  720. { MUA, 0 | F_NOMATCH, "a(*:aa)a", "abab" },
  721. { MUA, 0, "a(*:aa)(b(*:bb)b|bc)", "abc" },
  722. { MUA, 0 | F_NOMATCH, "a(*:1)x|b(*:2)y", "abc" },
  723. { MUA, 0, "(?>a(*:aa))b|ac", "ac" },
  724. { MUA, 0, "(?(DEFINE)(a(*:aa)))(?1)", "a" },
  725. { MUA, 0 | F_NOMATCH, "(?(DEFINE)((a)(*:aa)))(?1)b", "aa" },
  726. { MUA, 0, "(?(DEFINE)(a(*:aa)))a(?1)b|aac", "aac" },
  727. { MUA, 0, "(a(*:aa)){0}(?:b(?1)b|c)+c", "babbab cc" },
  728. { MUA, 0, "(a(*:aa)){0}(?:b(?1)b)+", "babba" },
  729. { MUA, 0 | F_NOMATCH | F_STUDY, "(a(*:aa)){0}(?:b(?1)b)+", "ba" },
  730. { MUA, 0, "(a\\K(*:aa)){0}(?:b(?1)b|c)+c", "babbab cc" },
  731. { MUA, 0, "(a\\K(*:aa)){0}(?:b(?1)b)+", "babba" },
  732. { MUA, 0 | F_NOMATCH | F_STUDY, "(a\\K(*:aa)){0}(?:b(?1)b)+", "ba" },
  733. { MUA, 0 | F_NOMATCH | F_STUDY, "(*:mark)m", "a" },
  734. /* (*COMMIT) verb. */
  735. { MUA, 0 | F_NOMATCH, "a(*COMMIT)b", "ac" },
  736. { MUA, 0, "aa(*COMMIT)b", "xaxaab" },
  737. { MUA, 0 | F_NOMATCH, "a(*COMMIT)(*:msg)b|ac", "ac" },
  738. { MUA, 0 | F_NOMATCH, "(a(*COMMIT)b)++", "abac" },
  739. { MUA, 0 | F_NOMATCH, "((a)(*COMMIT)b)++", "abac" },
  740. { MUA, 0 | F_NOMATCH, "(?=a(*COMMIT)b)ab|ad", "ad" },
  741. /* (*PRUNE) verb. */
  742. { MUA, 0, "aa\\K(*PRUNE)b", "aaab" },
  743. { MUA, 0, "aa(*PRUNE:bb)b|a", "aa" },
  744. { MUA, 0, "(a)(a)(*PRUNE)b|(a)", "aa" },
  745. { MUA, 0, "(a)(a)(a)(a)(a)(a)(a)(a)(*PRUNE)b|(a)", "aaaaaaaa" },
  746. { MUA | PCRE_PARTIAL_SOFT, 0, "a(*PRUNE)a|", "a" },
  747. { MUA | PCRE_PARTIAL_SOFT, 0, "a(*PRUNE)a|m", "a" },
  748. { MUA, 0 | F_NOMATCH, "(?=a(*PRUNE)b)ab|ad", "ad" },
  749. { MUA, 0, "a(*COMMIT)(*PRUNE)d|bc", "abc" },
  750. { MUA, 0, "(?=a(*COMMIT)b)a(*PRUNE)c|bc", "abc" },
  751. { MUA, 0 | F_NOMATCH, "(*COMMIT)(?=a(*COMMIT)b)a(*PRUNE)c|bc", "abc" },
  752. { MUA, 0, "(?=(a)(*COMMIT)b)a(*PRUNE)c|bc", "abc" },
  753. { MUA, 0 | F_NOMATCH, "(*COMMIT)(?=(a)(*COMMIT)b)a(*PRUNE)c|bc", "abc" },
  754. { MUA, 0, "(a(*COMMIT)b){0}a(?1)(*PRUNE)c|bc", "abc" },
  755. { MUA, 0 | F_NOMATCH, "(a(*COMMIT)b){0}a(*COMMIT)(?1)(*PRUNE)c|bc", "abc" },
  756. { MUA, 0, "(a(*COMMIT)b)++(*PRUNE)d|c", "ababc" },
  757. { MUA, 0 | F_NOMATCH, "(*COMMIT)(a(*COMMIT)b)++(*PRUNE)d|c", "ababc" },
  758. { MUA, 0, "((a)(*COMMIT)b)++(*PRUNE)d|c", "ababc" },
  759. { MUA, 0 | F_NOMATCH, "(*COMMIT)((a)(*COMMIT)b)++(*PRUNE)d|c", "ababc" },
  760. { MUA, 0, "(?>a(*COMMIT)b)*abab(*PRUNE)d|ba", "ababab" },
  761. { MUA, 0 | F_NOMATCH, "(*COMMIT)(?>a(*COMMIT)b)*abab(*PRUNE)d|ba", "ababab" },
  762. { MUA, 0, "(?>a(*COMMIT)b)+abab(*PRUNE)d|ba", "ababab" },
  763. { MUA, 0 | F_NOMATCH, "(*COMMIT)(?>a(*COMMIT)b)+abab(*PRUNE)d|ba", "ababab" },
  764. { MUA, 0, "(?>a(*COMMIT)b)?ab(*PRUNE)d|ba", "aba" },
  765. { MUA, 0 | F_NOMATCH, "(*COMMIT)(?>a(*COMMIT)b)?ab(*PRUNE)d|ba", "aba" },
  766. { MUA, 0, "(?>a(*COMMIT)b)*?n(*PRUNE)d|ba", "abababn" },
  767. { MUA, 0 | F_NOMATCH, "(*COMMIT)(?>a(*COMMIT)b)*?n(*PRUNE)d|ba", "abababn" },
  768. { MUA, 0, "(?>a(*COMMIT)b)+?n(*PRUNE)d|ba", "abababn" },
  769. { MUA, 0 | F_NOMATCH, "(*COMMIT)(?>a(*COMMIT)b)+?n(*PRUNE)d|ba", "abababn" },
  770. { MUA, 0, "(?>a(*COMMIT)b)??n(*PRUNE)d|bn", "abn" },
  771. { MUA, 0 | F_NOMATCH, "(*COMMIT)(?>a(*COMMIT)b)??n(*PRUNE)d|bn", "abn" },
  772. /* (*SKIP) verb. */
  773. { MUA, 0 | F_NOMATCH, "(?=a(*SKIP)b)ab|ad", "ad" },
  774. { MUA, 0, "(\\w+(*SKIP)#)", "abcd,xyz#," },
  775. { MUA, 0, "\\w+(*SKIP)#|mm", "abcd,xyz#," },
  776. { MUA, 0 | F_NOMATCH, "b+(?<=(*SKIP)#c)|b+", "#bbb" },
  777. /* (*THEN) verb. */
  778. { MUA, 0, "((?:a(*THEN)|aab)(*THEN)c|a+)+m", "aabcaabcaabcaabcnacm" },
  779. { MUA, 0 | F_NOMATCH, "((?:a(*THEN)|aab)(*THEN)c|a+)+m", "aabcm" },
  780. { MUA, 0, "((?:a(*THEN)|aab)c|a+)+m", "aabcaabcnmaabcaabcm" },
  781. { MUA, 0, "((?:a|aab)(*THEN)c|a+)+m", "aam" },
  782. { MUA, 0, "((?:a(*COMMIT)|aab)(*THEN)c|a+)+m", "aam" },
  783. { MUA, 0, "(?(?=a(*THEN)b)ab|ad)", "ad" },
  784. { MUA, 0, "(?(?!a(*THEN)b)ad|add)", "add" },
  785. { MUA, 0 | F_NOMATCH, "(?(?=a)a(*THEN)b|ad)", "ad" },
  786. { MUA, 0, "(?!(?(?=a)ab|b(*THEN)d))bn|bnn", "bnn" },
  787. /* Deep recursion. */
  788. { MUA, 0, "((((?:(?:(?:\\w)+)?)*|(?>\\w)+?)+|(?>\\w)?\?)*)?\\s", "aaaaa+ " },
  789. { MUA, 0, "(?:((?:(?:(?:\\w*?)+)??|(?>\\w)?|\\w*+)*)+)+?\\s", "aa+ " },
  790. { MUA, 0, "((a?)+)+b", "aaaaaaaaaaaa b" },
  791. /* Deep recursion: Stack limit reached. */
  792. { MA, 0 | F_NOMATCH, "a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaa" },
  793. { MA, 0 | F_NOMATCH, "(?:a+)+b", "aaaaaaaaaaaaaaaaaaaaaaaa b" },
  794. { MA, 0 | F_NOMATCH, "(?:a+?)+?b", "aaaaaaaaaaaaaaaaaaaaaaaa b" },
  795. { MA, 0 | F_NOMATCH, "(?:a*)*b", "aaaaaaaaaaaaaaaaaaaaaaaa b" },
  796. { MA, 0 | F_NOMATCH, "(?:a*?)*?b", "aaaaaaaaaaaaaaaaaaaaaaaa b" },
  797. { 0, 0, NULL, NULL }
  798. };
  799. static const unsigned char *tables(int mode)
  800. {
  801. /* The purpose of this function to allow valgrind
  802. for reporting invalid reads and writes. */
  803. static unsigned char *tables_copy;
  804. const char *errorptr;
  805. int erroroffset;
  806. unsigned char *default_tables;
  807. #if defined SUPPORT_PCRE8
  808. pcre *regex;
  809. char null_str[1] = { 0 };
  810. #elif defined SUPPORT_PCRE16
  811. pcre16 *regex;
  812. PCRE_UCHAR16 null_str[1] = { 0 };
  813. #elif defined SUPPORT_PCRE32
  814. pcre32 *regex;
  815. PCRE_UCHAR32 null_str[1] = { 0 };
  816. #endif
  817. if (mode) {
  818. if (tables_copy)
  819. free(tables_copy);
  820. tables_copy = NULL;
  821. return NULL;
  822. }
  823. if (tables_copy)
  824. return tables_copy;
  825. default_tables = NULL;
  826. #if defined SUPPORT_PCRE8
  827. regex = pcre_compile(null_str, 0, &errorptr, &erroroffset, NULL);
  828. if (regex) {
  829. pcre_fullinfo(regex, NULL, PCRE_INFO_DEFAULT_TABLES, &default_tables);
  830. pcre_free(regex);
  831. }
  832. #elif defined SUPPORT_PCRE16
  833. regex = pcre16_compile(null_str, 0, &errorptr, &erroroffset, NULL);
  834. if (regex) {
  835. pcre16_fullinfo(regex, NULL, PCRE_INFO_DEFAULT_TABLES, &default_tables);
  836. pcre16_free(regex);
  837. }
  838. #elif defined SUPPORT_PCRE32
  839. regex = pcre32_compile(null_str, 0, &errorptr, &erroroffset, NULL);
  840. if (regex) {
  841. pcre32_fullinfo(regex, NULL, PCRE_INFO_DEFAULT_TABLES, &default_tables);
  842. pcre32_free(regex);
  843. }
  844. #endif
  845. /* Shouldn't ever happen. */
  846. if (!default_tables)
  847. return NULL;
  848. /* Unfortunately this value cannot get from pcre_fullinfo.
  849. Since this is a test program, this is acceptable at the moment. */
  850. tables_copy = (unsigned char *)malloc(1088);
  851. if (!tables_copy)
  852. return NULL;
  853. memcpy(tables_copy, default_tables, 1088);
  854. return tables_copy;
  855. }
  856. #ifdef SUPPORT_PCRE8
  857. static pcre_jit_stack* callback8(void *arg)
  858. {
  859. return (pcre_jit_stack *)arg;
  860. }
  861. #endif
  862. #ifdef SUPPORT_PCRE16
  863. static pcre16_jit_stack* callback16(void *arg)
  864. {
  865. return (pcre16_jit_stack *)arg;
  866. }
  867. #endif
  868. #ifdef SUPPORT_PCRE32
  869. static pcre32_jit_stack* callback32(void *arg)
  870. {
  871. return (pcre32_jit_stack *)arg;
  872. }
  873. #endif
  874. #ifdef SUPPORT_PCRE8
  875. static pcre_jit_stack *stack8;
  876. static pcre_jit_stack *getstack8(void)
  877. {
  878. if (!stack8)
  879. stack8 = pcre_jit_stack_alloc(1, 1024 * 1024);
  880. return stack8;
  881. }
  882. static void setstack8(pcre_extra *extra)
  883. {
  884. if (!extra) {
  885. if (stack8)
  886. pcre_jit_stack_free(stack8);
  887. stack8 = NULL;
  888. return;
  889. }
  890. pcre_assign_jit_stack(extra, callback8, getstack8());
  891. }
  892. #endif /* SUPPORT_PCRE8 */
  893. #ifdef SUPPORT_PCRE16
  894. static pcre16_jit_stack *stack16;
  895. static pcre16_jit_stack *getstack16(void)
  896. {
  897. if (!stack16)
  898. stack16 = pcre16_jit_stack_alloc(1, 1024 * 1024);
  899. return stack16;
  900. }
  901. static void setstack16(pcre16_extra *extra)
  902. {
  903. if (!extra) {
  904. if (stack16)
  905. pcre16_jit_stack_free(stack16);
  906. stack16 = NULL;
  907. return;
  908. }
  909. pcre16_assign_jit_stack(extra, callback16, getstack16());
  910. }
  911. #endif /* SUPPORT_PCRE16 */
  912. #ifdef SUPPORT_PCRE32
  913. static pcre32_jit_stack *stack32;
  914. static pcre32_jit_stack *getstack32(void)
  915. {
  916. if (!stack32)
  917. stack32 = pcre32_jit_stack_alloc(1, 1024 * 1024);
  918. return stack32;
  919. }
  920. static void setstack32(pcre32_extra *extra)
  921. {
  922. if (!extra) {
  923. if (stack32)
  924. pcre32_jit_stack_free(stack32);
  925. stack32 = NULL;
  926. return;
  927. }
  928. pcre32_assign_jit_stack(extra, callback32, getstack32());
  929. }
  930. #endif /* SUPPORT_PCRE32 */
  931. #ifdef SUPPORT_PCRE16
  932. static int convert_utf8_to_utf16(const char *input, PCRE_UCHAR16 *output, int *offsetmap, int max_length)
  933. {
  934. unsigned char *iptr = (unsigned char*)input;
  935. PCRE_UCHAR16 *optr = output;
  936. unsigned int c;
  937. if (max_length == 0)
  938. return 0;
  939. while (*iptr && max_length > 1) {
  940. c = 0;
  941. if (offsetmap)
  942. *offsetmap++ = (int)(iptr - (unsigned char*)input);
  943. if (*iptr < 0xc0)
  944. c = *iptr++;
  945. else if (!(*iptr & 0x20)) {
  946. c = ((iptr[0] & 0x1f) << 6) | (iptr[1] & 0x3f);
  947. iptr += 2;
  948. } else if (!(*iptr & 0x10)) {
  949. c = ((iptr[0] & 0x0f) << 12) | ((iptr[1] & 0x3f) << 6) | (iptr[2] & 0x3f);
  950. iptr += 3;
  951. } else if (!(*iptr & 0x08)) {
  952. c = ((iptr[0] & 0x07) << 18) | ((iptr[1] & 0x3f) << 12) | ((iptr[2] & 0x3f) << 6) | (iptr[3] & 0x3f);
  953. iptr += 4;
  954. }
  955. if (c < 65536) {
  956. *optr++ = c;
  957. max_length--;
  958. } else if (max_length <= 2) {
  959. *optr = '\0';
  960. return (int)(optr - output);
  961. } else {
  962. c -= 0x10000;
  963. *optr++ = 0xd800 | ((c >> 10) & 0x3ff);
  964. *optr++ = 0xdc00 | (c & 0x3ff);
  965. max_length -= 2;
  966. if (offsetmap)
  967. offsetmap++;
  968. }
  969. }
  970. if (offsetmap)
  971. *offsetmap = (int)(iptr - (unsigned char*)input);
  972. *optr = '\0';
  973. return (int)(optr - output);
  974. }
  975. static int copy_char8_to_char16(const char *input, PCRE_UCHAR16 *output, int max_length)
  976. {
  977. unsigned char *iptr = (unsigned char*)input;
  978. PCRE_UCHAR16 *optr = output;
  979. if (max_length == 0)
  980. return 0;
  981. while (*iptr && max_length > 1) {
  982. *optr++ = *iptr++;
  983. max_length--;
  984. }
  985. *optr = '\0';
  986. return (int)(optr - output);
  987. }
  988. #define REGTEST_MAX_LENGTH16 4096
  989. static PCRE_UCHAR16 regtest_buf16[REGTEST_MAX_LENGTH16];
  990. static int regtest_offsetmap16[REGTEST_MAX_LENGTH16];
  991. #endif /* SUPPORT_PCRE16 */
  992. #ifdef SUPPORT_PCRE32
  993. static int convert_utf8_to_utf32(const char *input, PCRE_UCHAR32 *output, int *offsetmap, int max_length)
  994. {
  995. unsigned char *iptr = (unsigned char*)input;
  996. PCRE_UCHAR32 *optr = output;
  997. unsigned int c;
  998. if (max_length == 0)
  999. return 0;
  1000. while (*iptr && max_length > 1) {
  1001. c = 0;
  1002. if (offsetmap)
  1003. *offsetmap++ = (int)(iptr - (unsigned char*)input);
  1004. if (*iptr < 0xc0)
  1005. c = *iptr++;
  1006. else if (!(*iptr & 0x20)) {
  1007. c = ((iptr[0] & 0x1f) << 6) | (iptr[1] & 0x3f);
  1008. iptr += 2;
  1009. } else if (!(*iptr & 0x10)) {
  1010. c = ((iptr[0] & 0x0f) << 12) | ((iptr[1] & 0x3f) << 6) | (iptr[2] & 0x3f);
  1011. iptr += 3;
  1012. } else if (!(*iptr & 0x08)) {
  1013. c = ((iptr[0] & 0x07) << 18) | ((iptr[1] & 0x3f) << 12) | ((iptr[2] & 0x3f) << 6) | (iptr[3] & 0x3f);
  1014. iptr += 4;
  1015. }
  1016. *optr++ = c;
  1017. max_length--;
  1018. }
  1019. if (offsetmap)
  1020. *offsetmap = (int)(iptr - (unsigned char*)input);
  1021. *optr = 0;
  1022. return (int)(optr - output);
  1023. }
  1024. static int copy_char8_to_char32(const char *input, PCRE_UCHAR32 *output, int max_length)
  1025. {
  1026. unsigned char *iptr = (unsigned char*)input;
  1027. PCRE_UCHAR32 *optr = output;
  1028. if (max_length == 0)
  1029. return 0;
  1030. while (*iptr && max_length > 1) {
  1031. *optr++ = *iptr++;
  1032. max_length--;
  1033. }
  1034. *optr = '\0';
  1035. return (int)(optr - output);
  1036. }
  1037. #define REGTEST_MAX_LENGTH32 4096
  1038. static PCRE_UCHAR32 regtest_buf32[REGTEST_MAX_LENGTH32];
  1039. static int regtest_offsetmap32[REGTEST_MAX_LENGTH32];
  1040. #endif /* SUPPORT_PCRE32 */
  1041. static int check_ascii(const char *input)
  1042. {
  1043. const unsigned char *ptr = (unsigned char *)input;
  1044. while (*ptr) {
  1045. if (*ptr > 127)
  1046. return 0;
  1047. ptr++;
  1048. }
  1049. return 1;
  1050. }
  1051. static int regression_tests(void)
  1052. {
  1053. struct regression_test_case *current = regression_test_cases;
  1054. const char *error;
  1055. char *cpu_info;
  1056. int i, err_offs;
  1057. int is_successful, is_ascii;
  1058. int total = 0;
  1059. int successful = 0;
  1060. int successful_row = 0;
  1061. int counter = 0;
  1062. int study_mode;
  1063. int utf = 0, ucp = 0;
  1064. int disabled_flags = 0;
  1065. #ifdef SUPPORT_PCRE8
  1066. pcre *re8;
  1067. pcre_extra *extra8;
  1068. pcre_extra dummy_extra8;
  1069. int ovector8_1[32];
  1070. int ovector8_2[32];
  1071. int return_value8[2];
  1072. unsigned char *mark8_1, *mark8_2;
  1073. #endif
  1074. #ifdef SUPPORT_PCRE16
  1075. pcre16 *re16;
  1076. pcre16_extra *extra16;
  1077. pcre16_extra dummy_extra16;
  1078. int ovector16_1[32];
  1079. int ovector16_2[32];
  1080. int return_value16[2];
  1081. PCRE_UCHAR16 *mark16_1, *mark16_2;
  1082. int length16;
  1083. #endif
  1084. #ifdef SUPPORT_PCRE32
  1085. pcre32 *re32;
  1086. pcre32_extra *extra32;
  1087. pcre32_extra dummy_extra32;
  1088. int ovector32_1[32];
  1089. int ovector32_2[32];
  1090. int return_value32[2];
  1091. PCRE_UCHAR32 *mark32_1, *mark32_2;
  1092. int length32;
  1093. #endif
  1094. /* This test compares the behaviour of interpreter and JIT. Although disabling
  1095. utf or ucp may make tests fail, if the pcre_exec result is the SAME, it is
  1096. still considered successful from pcre_jit_test point of view. */
  1097. #if defined SUPPORT_PCRE8
  1098. pcre_config(PCRE_CONFIG_JITTARGET, &cpu_info);
  1099. #elif defined SUPPORT_PCRE16
  1100. pcre16_config(PCRE_CONFIG_JITTARGET, &cpu_info);
  1101. #elif defined SUPPORT_PCRE32
  1102. pcre32_config(PCRE_CONFIG_JITTARGET, &cpu_info);
  1103. #endif
  1104. printf("Running JIT regression tests\n");
  1105. printf(" target CPU of SLJIT compiler: %s\n", cpu_info);
  1106. #if defined SUPPORT_PCRE8
  1107. pcre_config(PCRE_CONFIG_UTF8, &utf);
  1108. pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &ucp);
  1109. #elif defined SUPPORT_PCRE16
  1110. pcre16_config(PCRE_CONFIG_UTF16, &utf);
  1111. pcre16_config(PCRE_CONFIG_UNICODE_PROPERTIES, &ucp);
  1112. #elif defined SUPPORT_PCRE32
  1113. pcre32_config(PCRE_CONFIG_UTF32, &utf);
  1114. pcre32_config(PCRE_CONFIG_UNICODE_PROPERTIES, &ucp);
  1115. #endif
  1116. if (!utf)
  1117. disabled_flags |= PCRE_UTF8 | PCRE_UTF16 | PCRE_UTF32;
  1118. if (!ucp)
  1119. disabled_flags |= PCRE_UCP;
  1120. #ifdef SUPPORT_PCRE8
  1121. printf(" in 8 bit mode with UTF-8 %s and ucp %s:\n", utf ? "enabled" : "disabled", ucp ? "enabled" : "disabled");
  1122. #endif
  1123. #ifdef SUPPORT_PCRE16
  1124. printf(" in 16 bit mode with UTF-16 %s and ucp %s:\n", utf ? "enabled" : "disabled", ucp ? "enabled" : "disabled");
  1125. #endif
  1126. #ifdef SUPPORT_PCRE32
  1127. printf(" in 32 bit mode with UTF-32 %s and ucp %s:\n", utf ? "enabled" : "disabled", ucp ? "enabled" : "disabled");
  1128. #endif
  1129. while (current->pattern) {
  1130. /* printf("\nPattern: %s :\n", current->pattern); */
  1131. total++;
  1132. is_ascii = 0;
  1133. if (!(current->start_offset & F_PROPERTY))
  1134. is_ascii = check_ascii(current->pattern) && check_ascii(current->input);
  1135. if (current->flags & PCRE_PARTIAL_SOFT)
  1136. study_mode = PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE;
  1137. else if (current->flags & PCRE_PARTIAL_HARD)
  1138. study_mode = PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE;
  1139. else
  1140. study_mode = PCRE_STUDY_JIT_COMPILE;
  1141. error = NULL;
  1142. #ifdef SUPPORT_PCRE8
  1143. re8 = NULL;
  1144. if (!(current->start_offset & F_NO8))
  1145. re8 = pcre_compile(current->pattern,
  1146. current->flags & ~(PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | disabled_flags),
  1147. &error, &err_offs, tables(0));
  1148. extra8 = NULL;
  1149. if (re8) {
  1150. error = NULL;
  1151. extra8 = pcre_study(re8, study_mode, &error);
  1152. if (!extra8) {
  1153. printf("\n8 bit: Cannot study pattern: %s\n", current->pattern);
  1154. pcre_free(re8);
  1155. re8 = NULL;
  1156. }
  1157. else if (!(extra8->flags & PCRE_EXTRA_EXECUTABLE_JIT)) {
  1158. printf("\n8 bit: JIT compiler does not support: %s\n", current->pattern);
  1159. pcre_free_study(extra8);
  1160. pcre_free(re8);
  1161. re8 = NULL;
  1162. }
  1163. extra8->flags |= PCRE_EXTRA_MARK;
  1164. } else if (((utf && ucp) || is_ascii) && !(current->start_offset & F_NO8))
  1165. printf("\n8 bit: Cannot compile pattern \"%s\": %s\n", current->pattern, error);
  1166. #endif
  1167. #ifdef SUPPORT_PCRE16
  1168. if ((current->flags & PCRE_UTF16) || (current->start_offset & F_FORCECONV))
  1169. convert_utf8_to_utf16(current->pattern, regtest_buf16, NULL, REGTEST_MAX_LENGTH16);
  1170. else
  1171. copy_char8_to_char16(current->pattern, regtest_buf16, REGTEST_MAX_LENGTH16);
  1172. re16 = NULL;
  1173. if (!(current->start_offset & F_NO16))
  1174. re16 = pcre16_compile(regtest_buf16,
  1175. current->flags & ~(PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | disabled_flags),
  1176. &error, &err_offs, tables(0));
  1177. extra16 = NULL;
  1178. if (re16) {
  1179. error = NULL;
  1180. extra16 = pcre16_study(re16, study_mode, &error);
  1181. if (!extra16) {
  1182. printf("\n16 bit: Cannot study pattern: %s\n", current->pattern);
  1183. pcre16_free(re16);
  1184. re16 = NULL;
  1185. }
  1186. else if (!(extra16->flags & PCRE_EXTRA_EXECUTABLE_JIT)) {
  1187. printf("\n16 bit: JIT compiler does not support: %s\n", current->pattern);
  1188. pcre16_free_study(extra16);
  1189. pcre16_free(re16);
  1190. re16 = NULL;
  1191. }
  1192. extra16->flags |= PCRE_EXTRA_MARK;
  1193. } else if (((utf && ucp) || is_ascii) && !(current->start_offset & F_NO16))
  1194. printf("\n16 bit: Cannot compile pattern \"%s\": %s\n", current->pattern, error);
  1195. #endif
  1196. #ifdef SUPPORT_PCRE32
  1197. if ((current->flags & PCRE_UTF32) || (current->start_offset & F_FORCECONV))
  1198. convert_utf8_to_utf32(current->pattern, regtest_buf32, NULL, REGTEST_MAX_LENGTH32);
  1199. else
  1200. copy_char8_to_char32(current->pattern, regtest_buf32, REGTEST_MAX_LENGTH32);
  1201. re32 = NULL;
  1202. if (!(current->start_offset & F_NO32))
  1203. re32 = pcre32_compile(regtest_buf32,
  1204. current->flags & ~(PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | disabled_flags),
  1205. &error, &err_offs, tables(0));
  1206. extra32 = NULL;
  1207. if (re32) {
  1208. error = NULL;
  1209. extra32 = pcre32_study(re32, study_mode, &error);
  1210. if (!extra32) {
  1211. printf("\n32 bit: Cannot study pattern: %s\n", current->pattern);
  1212. pcre32_free(re32);
  1213. re32 = NULL;
  1214. }
  1215. if (!(extra32->flags & PCRE_EXTRA_EXECUTABLE_JIT)) {
  1216. printf("\n32 bit: JIT compiler does not support: %s\n", current->pattern);
  1217. pcre32_free_study(extra32);
  1218. pcre32_free(re32);
  1219. re32 = NULL;
  1220. }
  1221. extra32->flags |= PCRE_EXTRA_MARK;
  1222. } else if (((utf && ucp) || is_ascii) && !(current->start_offset & F_NO32))
  1223. printf("\n32 bit: Cannot compile pattern \"%s\": %s\n", current->pattern, error);
  1224. #endif
  1225. counter++;
  1226. if ((counter & 0x3) != 0) {
  1227. #ifdef SUPPORT_PCRE8
  1228. setstack8(NULL);
  1229. #endif
  1230. #ifdef SUPPORT_PCRE16
  1231. setstack16(NULL);
  1232. #endif
  1233. #ifdef SUPPORT_PCRE32
  1234. setstack32(NULL);
  1235. #endif
  1236. }
  1237. #ifdef SUPPORT_PCRE8
  1238. return_value8[0] = -1000;
  1239. return_value8[1] = -1000;
  1240. for (i = 0; i < 32; ++i)
  1241. ovector8_1[i] = -2;
  1242. for (i = 0; i < 32; ++i)
  1243. ovector8_2[i] = -2;
  1244. if (re8) {
  1245. mark8_1 = NULL;
  1246. mark8_2 = NULL;
  1247. extra8->mark = &mark8_1;
  1248. if ((counter & 0x1) != 0) {
  1249. setstack8(extra8);
  1250. return_value8[0] = pcre_exec(re8, extra8, current->input, strlen(current->input), current->start_offset & OFFSET_MASK,
  1251. current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | PCRE_NO_UTF8_CHECK), ovector8_1, 32);
  1252. } else
  1253. return_value8[0] = pcre_jit_exec(re8, extra8, current->input, strlen(current->input), current->start_offset & OFFSET_MASK,
  1254. current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | PCRE_NO_UTF8_CHECK), ovector8_1, 32, getstack8());
  1255. memset(&dummy_extra8, 0, sizeof(pcre_extra));
  1256. dummy_extra8.flags = PCRE_EXTRA_MARK;
  1257. if (current->start_offset & F_STUDY) {
  1258. dummy_extra8.flags |= PCRE_EXTRA_STUDY_DATA;
  1259. dummy_extra8.study_data = extra8->study_data;
  1260. }
  1261. dummy_extra8.mark = &mark8_2;
  1262. return_value8[1] = pcre_exec(re8, &dummy_extra8, current->input, strlen(current->input), current->start_offset & OFFSET_MASK,
  1263. current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | PCRE_NO_UTF8_CHECK), ovector8_2, 32);
  1264. }
  1265. #endif
  1266. #ifdef SUPPORT_PCRE16
  1267. return_value16[0] = -1000;
  1268. return_value16[1] = -1000;
  1269. for (i = 0; i < 32; ++i)
  1270. ovector16_1[i] = -2;
  1271. for (i = 0; i < 32; ++i)
  1272. ovector16_2[i] = -2;
  1273. if (re16) {
  1274. mark16_1 = NULL;
  1275. mark16_2 = NULL;
  1276. if ((current->flags & PCRE_UTF16) || (current->start_offset & F_FORCECONV))
  1277. length16 = convert_utf8_to_utf16(current->input, regtest_buf16, regtest_offsetmap16, REGTEST_MAX_LENGTH16);
  1278. else
  1279. length16 = copy_char8_to_char16(current->input, regtest_buf16, REGTEST_MAX_LENGTH16);
  1280. extra16->mark = &mark16_1;
  1281. if ((counter & 0x1) != 0) {
  1282. setstack16(extra16);
  1283. return_value16[0] = pcre16_exec(re16, extra16, regtest_buf16, length16, current->start_offset & OFFSET_MASK,
  1284. current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | PCRE_NO_UTF8_CHECK), ovector16_1, 32);
  1285. } else
  1286. return_value16[0] = pcre16_jit_exec(re16, extra16, regtest_buf16, length16, current->start_offset & OFFSET_MASK,
  1287. current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | PCRE_NO_UTF8_CHECK), ovector16_1, 32, getstack16());
  1288. memset(&dummy_extra16, 0, sizeof(pcre16_extra));
  1289. dummy_extra16.flags = PCRE_EXTRA_MARK;
  1290. if (current->start_offset & F_STUDY) {
  1291. dummy_extra16.flags |= PCRE_EXTRA_STUDY_DATA;
  1292. dummy_extra16.study_data = extra16->study_data;
  1293. }
  1294. dummy_extra16.mark = &mark16_2;
  1295. return_value16[1] = pcre16_exec(re16, &dummy_extra16, regtest_buf16, length16, current->start_offset & OFFSET_MASK,
  1296. current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | PCRE_NO_UTF8_CHECK), ovector16_2, 32);
  1297. }
  1298. #endif
  1299. #ifdef SUPPORT_PCRE32
  1300. return_value32[0] = -1000;
  1301. return_value32[1] = -1000;
  1302. for (i = 0; i < 32; ++i)
  1303. ovector32_1[i] = -2;
  1304. for (i = 0; i < 32; ++i)
  1305. ovector32_2[i] = -2;
  1306. if (re32) {
  1307. mark32_1 = NULL;
  1308. mark32_2 = NULL;
  1309. if ((current->flags & PCRE_UTF32) || (current->start_offset & F_FORCECONV))
  1310. length32 = convert_utf8_to_utf32(current->input, regtest_buf32, regtest_offsetmap32, REGTEST_MAX_LENGTH32);
  1311. else
  1312. length32 = copy_char8_to_char32(current->input, regtest_buf32, REGTEST_MAX_LENGTH32);
  1313. extra32->mark = &mark32_1;
  1314. if ((counter & 0x1) != 0) {
  1315. setstack32(extra32);
  1316. return_value32[0] = pcre32_exec(re32, extra32, regtest_buf32, length32, current->start_offset & OFFSET_MASK,
  1317. current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | PCRE_NO_UTF8_CHECK), ovector32_1, 32);
  1318. } else
  1319. return_value32[0] = pcre32_jit_exec(re32, extra32, regtest_buf32, length32, current->start_offset & OFFSET_MASK,
  1320. current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | PCRE_NO_UTF8_CHECK), ovector32_1, 32, getstack32());
  1321. memset(&dummy_extra32, 0, sizeof(pcre32_extra));
  1322. dummy_extra32.flags = PCRE_EXTRA_MARK;
  1323. if (current->start_offset & F_STUDY) {
  1324. dummy_extra32.flags |= PCRE_EXTRA_STUDY_DATA;
  1325. dummy_extra32.study_data = extra32->study_data;
  1326. }
  1327. dummy_extra32.mark = &mark32_2;
  1328. return_value32[1] = pcre32_exec(re32, &dummy_extra32, regtest_buf32, length32, current->start_offset & OFFSET_MASK,
  1329. current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD | PCRE_NO_UTF8_CHECK), ovector32_2, 32);
  1330. }
  1331. #endif
  1332. /* printf("[%d-%d-%d|%d-%d|%d-%d|%d-%d]%s",
  1333. return_value8[0], return_value16[0], return_value32[0],
  1334. ovector8_1[0], ovector8_1[1],
  1335. ovector16_1[0], ovector16_1[1],
  1336. ovector32_1[0], ovector32_1[1],
  1337. (current->flags & PCRE_CASELESS) ? "C" : ""); */
  1338. /* If F_DIFF is set, just run the test, but do not compare the results.
  1339. Segfaults can still be captured. */
  1340. is_successful = 1;
  1341. if (!(current->start_offset & F_DIFF)) {
  1342. #if defined SUPPORT_UTF && ((defined(SUPPORT_PCRE8) + defined(SUPPORT_PCRE16) + defined(SUPPORT_PCRE32)) >= 2)
  1343. if (!(current->start_offset & F_FORCECONV)) {
  1344. int return_value;
  1345. /* All results must be the same. */
  1346. #ifdef SUPPORT_PCRE8
  1347. if ((return_value = return_value8[0]) != return_value8[1]) {
  1348. printf("\n8 bit: Return value differs(J8:%d,I8:%d): [%d] '%s' @ '%s'\n",
  1349. return_value8[0], return_value8[1], total, current->pattern, current->input);
  1350. is_successful = 0;
  1351. } else
  1352. #endif
  1353. #ifdef SUPPORT_PCRE16
  1354. if ((return_value = return_value16[0]) != return_value16[1]) {
  1355. printf("\n16 bit: Return value differs(J16:%d,I16:%d): [%d] '%s' @ '%s'\n",
  1356. return_value16[0], return_value16[1], total, current->pattern, current->input);
  1357. is_successful = 0;
  1358. } else
  1359. #endif
  1360. #ifdef SUPPORT_PCRE32
  1361. if ((return_value = return_value32[0]) != return_value32[1]) {
  1362. printf("\n32 bit: Return value differs(J32:%d,I32:%d): [%d] '%s' @ '%s'\n",
  1363. return_value32[0], return_value32[1], total, current->pattern, current->input);
  1364. is_successful = 0;
  1365. } else
  1366. #endif
  1367. #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16
  1368. if (return_value8[0] != return_value16[0]) {
  1369. printf("\n8 and 16 bit: Return value differs(J8:%d,J16:%d): [%d] '%s' @ '%s'\n",
  1370. return_value8[0], return_value16[0],
  1371. total, current->pattern, current->input);
  1372. is_successful = 0;
  1373. } else
  1374. #endif
  1375. #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE32
  1376. if (return_value8[0] != return_value32[0]) {
  1377. printf("\n8 and 32 bit: Return value differs(J8:%d,J32:%d): [%d] '%s' @ '%s'\n",
  1378. return_value8[0], return_value32[0],
  1379. total, current->pattern, current->input);
  1380. is_successful = 0;
  1381. } else
  1382. #endif
  1383. #if defined SUPPORT_PCRE16 && defined SUPPORT_PCRE32
  1384. if (return_value16[0] != return_value32[0]) {
  1385. printf("\n16 and 32 bit: Return value differs(J16:%d,J32:%d): [%d] '%s' @ '%s'\n",
  1386. return_value16[0], return_value32[0],
  1387. total, current->pattern, current->input);
  1388. is_successful = 0;
  1389. } else
  1390. #endif
  1391. if (return_value >= 0 || return_value == PCRE_ERROR_PARTIAL) {
  1392. if (return_value == PCRE_ERROR_PARTIAL) {
  1393. return_value = 2;
  1394. } else {
  1395. return_value *= 2;
  1396. }
  1397. #ifdef SUPPORT_PCRE8
  1398. return_value8[0] = return_value;
  1399. #endif
  1400. #ifdef SUPPORT_PCRE16
  1401. return_value16[0] = return_value;
  1402. #endif
  1403. #ifdef SUPPORT_PCRE32
  1404. return_value32[0] = return_value;
  1405. #endif
  1406. /* Transform back the results. */
  1407. if (current->flags & PCRE_UTF8) {
  1408. #ifdef SUPPORT_PCRE16
  1409. for (i = 0; i < return_value; ++i) {
  1410. if (ovector16_1[i] >= 0)
  1411. ovector16_1[i] = regtest_offsetmap16[ovector16_1[i]];
  1412. if (ovector16_2[i] >= 0)
  1413. ovector16_2[i] = regtest_offsetmap16[ovector16_2[i]];
  1414. }
  1415. #endif
  1416. #ifdef SUPPORT_PCRE32
  1417. for (i = 0; i < return_value; ++i) {
  1418. if (ovector32_1[i] >= 0)
  1419. ovector32_1[i] = regtest_offsetmap32[ovector32_1[i]];
  1420. if (ovector32_2[i] >= 0)
  1421. ovector32_2[i] = regtest_offsetmap32[ovector32_2[i]];
  1422. }
  1423. #endif
  1424. }
  1425. for (i = 0; i < return_value; ++i) {
  1426. #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE16
  1427. if (ovector8_1[i] != ovector8_2[i] || ovector8_1[i] != ovector16_1[i] || ovector8_1[i] != ovector16_2[i]) {
  1428. printf("\n8 and 16 bit: Ovector[%d] value differs(J8:%d,I8:%d,J16:%d,I16:%d): [%d] '%s' @ '%s' \n",
  1429. i, ovector8_1[i], ovector8_2[i], ovector16_1[i], ovector16_2[i],
  1430. total, current->pattern, current->input);
  1431. is_successful = 0;
  1432. }
  1433. #endif
  1434. #if defined SUPPORT_PCRE8 && defined SUPPORT_PCRE32
  1435. if (ovector8_1[i] != ovector8_2[i] || ovector8_1[i] != ovector32_1[i] || ovector8_1[i] != ovector32_2[i]) {
  1436. printf("\n8 and 32 bit: Ovector[%d] value differs(J8:%d,I8:%d,J32:%d,I32:%d): [%d] '%s' @ '%s' \n",
  1437. i, ovector8_1[i], ovector8_2[i], ovector32_1[i], ovector32_2[i],
  1438. total, current->pattern, current->input);
  1439. is_successful = 0;
  1440. }
  1441. #endif
  1442. #if defined SUPPORT_PCRE16 && defined SUPPORT_PCRE32
  1443. if (ovector16_1[i] != ovector16_2[i] || ovector16_1[i] != ovector32_1[i] || ovector16_1[i] != ovector32_2[i]) {
  1444. printf("\n16 and 32 bit: Ovector[%d] value differs(J16:%d,I16:%d,J32:%d,I32:%d): [%d] '%s' @ '%s' \n",
  1445. i, ovector16_1[i], ovector16_2[i], ovector32_1[i], ovector32_2[i],
  1446. total, current->pattern, current->input);
  1447. is_successful = 0;
  1448. }
  1449. #endif
  1450. }
  1451. }
  1452. } else
  1453. #endif /* more than one of SUPPORT_PCRE8, SUPPORT_PCRE16 and SUPPORT_PCRE32 */
  1454. {
  1455. /* Only the 8 bit and 16 bit results must be equal. */
  1456. #ifdef SUPPORT_PCRE8
  1457. if (return_value8[0] != return_value8[1]) {
  1458. printf("\n8 bit: Return value differs(%d:%d): [%d] '%s' @ '%s'\n",
  1459. return_value8[0], return_value8[1], total, current->pattern, current->input);
  1460. is_successful = 0;
  1461. } else if (return_value8[0] >= 0 || return_value8[0] == PCRE_ERROR_PARTIAL) {
  1462. if (return_value8[0] == PCRE_ERROR_PARTIAL)
  1463. return_value8[0] = 2;
  1464. else
  1465. return_value8[0] *= 2;
  1466. for (i = 0; i < return_value8[0]; ++i)
  1467. if (ovector8_1[i] != ovector8_2[i]) {
  1468. printf("\n8 bit: Ovector[%d] value differs(%d:%d): [%d] '%s' @ '%s'\n",
  1469. i, ovector8_1[i], ovector8_2[i], total, current->pattern, current->input);
  1470. is_successful = 0;
  1471. }
  1472. }
  1473. #endif
  1474. #ifdef SUPPORT_PCRE16
  1475. if (return_value16[0] != return_value16[1]) {
  1476. printf("\n16 bit: Return value differs(%d:%d): [%d] '%s' @ '%s'\n",
  1477. return_value16[0], return_value16[1], total, current->pattern, current->input);
  1478. is_successful = 0;
  1479. } else if (return_value16[0] >= 0 || return_value16[0] == PCRE_ERROR_PARTIAL) {
  1480. if (return_value16[0] == PCRE_ERROR_PARTIAL)
  1481. return_value16[0] = 2;
  1482. else
  1483. return_value16[0] *= 2;
  1484. for (i = 0; i < return_value16[0]; ++i)
  1485. if (ovector16_1[i] != ovector16_2[i]) {
  1486. printf("\n16 bit: Ovector[%d] value differs(%d:%d): [%d] '%s' @ '%s'\n",
  1487. i, ovector16_1[i], ovector16_2[i], total, current->pattern, current->input);
  1488. is_successful = 0;
  1489. }
  1490. }
  1491. #endif
  1492. #ifdef SUPPORT_PCRE32
  1493. if (return_value32[0] != return_value32[1]) {
  1494. printf("\n32 bit: Return value differs(%d:%d): [%d] '%s' @ '%s'\n",
  1495. return_value32[0], return_value32[1], total, current->pattern, current->input);
  1496. is_successful = 0;
  1497. } else if (return_value32[0] >= 0 || return_value32[0] == PCRE_ERROR_PARTIAL) {
  1498. if (return_value32[0] == PCRE_ERROR_PARTIAL)
  1499. return_value32[0] = 2;
  1500. else
  1501. return_value32[0] *= 2;
  1502. for (i = 0; i < return_value32[0]; ++i)
  1503. if (ovector32_1[i] != ovector32_2[i]) {
  1504. printf("\n32 bit: Ovector[%d] value differs(%d:%d): [%d] '%s' @ '%s'\n",
  1505. i, ovector32_1[i], ovector32_2[i], total, current->pattern, current->input);
  1506. is_successful = 0;
  1507. }
  1508. }
  1509. #endif
  1510. }
  1511. }
  1512. if (is_successful) {
  1513. #ifdef SUPPORT_PCRE8
  1514. if (!(current->start_offset & F_NO8) && ((utf && ucp) || is_ascii)) {
  1515. if (return_value8[0] < 0 && !(current->start_offset & F_NOMATCH)) {
  1516. printf("8 bit: Test should match: [%d] '%s' @ '%s'\n",
  1517. total, current->pattern, current->input);
  1518. is_successful = 0;
  1519. }
  1520. if (return_value8[0] >= 0 && (current->start_offset & F_NOMATCH)) {
  1521. printf("8 bit: Test should not match: [%d] '%s' @ '%s'\n",
  1522. total, current->pattern, current->input);
  1523. is_successful = 0;
  1524. }
  1525. }
  1526. #endif
  1527. #ifdef SUPPORT_PCRE16
  1528. if (!(current->start_offset & F_NO16) && ((utf && ucp) || is_ascii)) {
  1529. if (return_value16[0] < 0 && !(current->start_offset & F_NOMATCH)) {
  1530. printf("16 bit: Test should match: [%d] '%s' @ '%s'\n",
  1531. total, current->pattern, current->input);
  1532. is_successful = 0;
  1533. }
  1534. if (return_value16[0] >= 0 && (current->start_offset & F_NOMATCH)) {
  1535. printf("16 bit: Test should not match: [%d] '%s' @ '%s'\n",
  1536. total, current->pattern, current->input);
  1537. is_successful = 0;
  1538. }
  1539. }
  1540. #endif
  1541. #ifdef SUPPORT_PCRE32
  1542. if (!(current->start_offset & F_NO32) && ((utf && ucp) || is_ascii)) {
  1543. if (return_value32[0] < 0 && !(current->start_offset & F_NOMATCH)) {
  1544. printf("32 bit: Test should match: [%d] '%s' @ '%s'\n",
  1545. total, current->pattern, current->input);
  1546. is_successful = 0;
  1547. }
  1548. if (return_value32[0] >= 0 && (current->start_offset & F_NOMATCH)) {
  1549. printf("32 bit: Test should not match: [%d] '%s' @ '%s'\n",
  1550. total, current->pattern, current->input);
  1551. is_successful = 0;
  1552. }
  1553. }
  1554. #endif
  1555. }
  1556. if (is_successful) {
  1557. #ifdef SUPPORT_PCRE8
  1558. if (mark8_1 != mark8_2) {
  1559. printf("8 bit: Mark value mismatch: [%d] '%s' @ '%s'\n",
  1560. total, current->pattern, current->input);
  1561. is_successful = 0;
  1562. }
  1563. #endif
  1564. #ifdef SUPPORT_PCRE16
  1565. if (mark16_1 != mark16_2) {
  1566. printf("16 bit: Mark value mismatch: [%d] '%s' @ '%s'\n",
  1567. total, current->pattern, current->input);
  1568. is_successful = 0;
  1569. }
  1570. #endif
  1571. #ifdef SUPPORT_PCRE32
  1572. if (mark32_1 != mark32_2) {
  1573. printf("32 bit: Mark value mismatch: [%d] '%s' @ '%s'\n",
  1574. total, current->pattern, current->input);
  1575. is_successful = 0;
  1576. }
  1577. #endif
  1578. }
  1579. #ifdef SUPPORT_PCRE8
  1580. if (re8) {
  1581. pcre_free_study(extra8);
  1582. pcre_free(re8);
  1583. }
  1584. #endif
  1585. #ifdef SUPPORT_PCRE16
  1586. if (re16) {
  1587. pcre16_free_study(extra16);
  1588. pcre16_free(re16);
  1589. }
  1590. #endif
  1591. #ifdef SUPPORT_PCRE32
  1592. if (re32) {
  1593. pcre32_free_study(extra32);
  1594. pcre32_free(re32);
  1595. }
  1596. #endif
  1597. if (is_successful) {
  1598. successful++;
  1599. successful_row++;
  1600. printf(".");
  1601. if (successful_row >= 60) {
  1602. successful_row = 0;
  1603. printf("\n");
  1604. }
  1605. } else
  1606. successful_row = 0;
  1607. fflush(stdout);
  1608. current++;
  1609. }
  1610. tables(1);
  1611. #ifdef SUPPORT_PCRE8
  1612. setstack8(NULL);
  1613. #endif
  1614. #ifdef SUPPORT_PCRE16
  1615. setstack16(NULL);
  1616. #endif
  1617. #ifdef SUPPORT_PCRE32
  1618. setstack32(NULL);
  1619. #endif
  1620. if (total == successful) {
  1621. printf("\nAll JIT regression tests are successfully passed.\n");
  1622. return 0;
  1623. } else {
  1624. printf("\nSuccessful test ratio: %d%% (%d failed)\n", successful * 100 / total, total - successful);
  1625. return 1;
  1626. }
  1627. }
  1628. /* End of pcre_jit_test.c */