ecma.pass.cpp 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // NetBSD does not support LC_COLLATE at the moment
  10. // XFAIL: netbsd
  11. // REQUIRES: locale.cs_CZ.ISO8859-2
  12. // <regex>
  13. // template <class BidirectionalIterator, class Allocator, class charT, class traits>
  14. // bool
  15. // regex_search(BidirectionalIterator first, BidirectionalIterator last,
  16. // match_results<BidirectionalIterator, Allocator>& m,
  17. // const basic_regex<charT, traits>& e,
  18. // regex_constants::match_flag_type flags = regex_constants::match_default);
  19. // TODO: investigation needed
  20. // XFAIL: linux-gnu
  21. #include <regex>
  22. #include <cassert>
  23. #include "test_macros.h"
  24. #include "test_iterators.h"
  25. #include "platform_support.h" // locale name macros
  26. int main(int, char**)
  27. {
  28. {
  29. std::cmatch m;
  30. const char s[] = "a";
  31. assert(std::regex_search(s, m, std::regex("a")));
  32. assert(m.size() == 1);
  33. assert(!m.empty());
  34. assert(!m.prefix().matched);
  35. assert(m.prefix().first == s);
  36. assert(m.prefix().second == m[0].first);
  37. assert(!m.suffix().matched);
  38. assert(m.suffix().first == m[0].second);
  39. assert(m.suffix().second == s+1);
  40. assert(m.length(0) == 1);
  41. assert(m.position(0) == 0);
  42. assert(m.str(0) == "a");
  43. }
  44. {
  45. std::cmatch m;
  46. const char s[] = "ab";
  47. assert(std::regex_search(s, m, std::regex("ab")));
  48. assert(m.size() == 1);
  49. assert(!m.prefix().matched);
  50. assert(m.prefix().first == s);
  51. assert(m.prefix().second == m[0].first);
  52. assert(!m.suffix().matched);
  53. assert(m.suffix().first == m[0].second);
  54. assert(m.suffix().second == s+2);
  55. assert(m.length(0) == 2);
  56. assert(m.position(0) == 0);
  57. assert(m.str(0) == "ab");
  58. }
  59. {
  60. std::cmatch m;
  61. const char s[] = "ab";
  62. assert(!std::regex_search(s, m, std::regex("ba")));
  63. assert(m.size() == 0);
  64. assert(m.empty());
  65. }
  66. {
  67. std::cmatch m;
  68. const char s[] = "aab";
  69. assert(std::regex_search(s, m, std::regex("ab")));
  70. assert(m.size() == 1);
  71. assert(m.prefix().matched);
  72. assert(m.prefix().first == s);
  73. assert(m.prefix().second == m[0].first);
  74. assert(!m.suffix().matched);
  75. assert(m.suffix().first == m[0].second);
  76. assert(m.suffix().second == s+3);
  77. assert(m.length(0) == 2);
  78. assert(m.position(0) == 1);
  79. assert(m.str(0) == "ab");
  80. }
  81. {
  82. std::cmatch m;
  83. const char s[] = "aab";
  84. assert(!std::regex_search(s, m, std::regex("ab"),
  85. std::regex_constants::match_continuous));
  86. assert(m.size() == 0);
  87. }
  88. {
  89. std::cmatch m;
  90. const char s[] = "abcd";
  91. assert(std::regex_search(s, m, std::regex("bc")));
  92. assert(m.size() == 1);
  93. assert(m.prefix().matched);
  94. assert(m.prefix().first == s);
  95. assert(m.prefix().second == m[0].first);
  96. assert(m.suffix().matched);
  97. assert(m.suffix().first == m[0].second);
  98. assert(m.suffix().second == s+4);
  99. assert(m.length(0) == 2);
  100. assert(m.position(0) == 1);
  101. assert(m.str(0) == "bc");
  102. }
  103. {
  104. std::cmatch m;
  105. const char s[] = "abbc";
  106. assert(std::regex_search(s, m, std::regex("ab*c")));
  107. assert(m.size() == 1);
  108. assert(!m.prefix().matched);
  109. assert(m.prefix().first == s);
  110. assert(m.prefix().second == m[0].first);
  111. assert(!m.suffix().matched);
  112. assert(m.suffix().first == m[0].second);
  113. assert(m.suffix().second == s+4);
  114. assert(m.length(0) == 4);
  115. assert(m.position(0) == 0);
  116. assert(m.str(0) == s);
  117. }
  118. {
  119. std::cmatch m;
  120. const char s[] = "ababc";
  121. assert(std::regex_search(s, m, std::regex("(ab)*c")));
  122. assert(m.size() == 2);
  123. assert(!m.prefix().matched);
  124. assert(m.prefix().first == s);
  125. assert(m.prefix().second == m[0].first);
  126. assert(!m.suffix().matched);
  127. assert(m.suffix().first == m[0].second);
  128. assert(m.suffix().second == s+5);
  129. assert(m.length(0) == 5);
  130. assert(m.position(0) == 0);
  131. assert(m.str(0) == s);
  132. assert(m.length(1) == 2);
  133. assert(m.position(1) == 2);
  134. assert(m.str(1) == "ab");
  135. }
  136. {
  137. std::cmatch m;
  138. const char s[] = "abcdefghijk";
  139. assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
  140. assert(m.size() == 3);
  141. assert(m.prefix().matched);
  142. assert(m.prefix().first == s);
  143. assert(m.prefix().second == m[0].first);
  144. assert(m.suffix().matched);
  145. assert(m.suffix().first == m[0].second);
  146. assert(m.suffix().second == s+std::regex_traits<char>::length(s));
  147. assert(m.length(0) == 7);
  148. assert(m.position(0) == 2);
  149. assert(m.str(0) == "cdefghi");
  150. assert(m.length(1) == 3);
  151. assert(m.position(1) == 4);
  152. assert(m.str(1) == "efg");
  153. assert(m.length(2) == 1);
  154. assert(m.position(2) == 4);
  155. assert(m.str(2) == "e");
  156. }
  157. {
  158. std::cmatch m;
  159. const char s[] = "abc";
  160. assert(std::regex_search(s, m, std::regex("^abc")));
  161. assert(m.size() == 1);
  162. assert(!m.prefix().matched);
  163. assert(m.prefix().first == s);
  164. assert(m.prefix().second == m[0].first);
  165. assert(!m.suffix().matched);
  166. assert(m.suffix().first == m[0].second);
  167. assert(m.suffix().second == s+3);
  168. assert(m.length(0) == 3);
  169. assert(m.position(0) == 0);
  170. assert(m.str(0) == s);
  171. }
  172. {
  173. std::cmatch m;
  174. const char s[] = "abcd";
  175. assert(std::regex_search(s, m, std::regex("^abc")));
  176. assert(m.size() == 1);
  177. assert(!m.prefix().matched);
  178. assert(m.prefix().first == s);
  179. assert(m.prefix().second == m[0].first);
  180. assert(m.suffix().matched);
  181. assert(m.suffix().first == m[0].second);
  182. assert(m.suffix().second == s+4);
  183. assert(m.length(0) == 3);
  184. assert(m.position(0) == 0);
  185. assert(m.str(0) == "abc");
  186. }
  187. {
  188. std::cmatch m;
  189. const char s[] = "aabc";
  190. assert(!std::regex_search(s, m, std::regex("^abc")));
  191. assert(m.size() == 0);
  192. }
  193. {
  194. std::cmatch m;
  195. const char s[] = "abc";
  196. assert(std::regex_search(s, m, std::regex("abc$")));
  197. assert(m.size() == 1);
  198. assert(!m.prefix().matched);
  199. assert(m.prefix().first == s);
  200. assert(m.prefix().second == m[0].first);
  201. assert(!m.suffix().matched);
  202. assert(m.suffix().first == m[0].second);
  203. assert(m.suffix().second == s+3);
  204. assert(m.length(0) == 3);
  205. assert(m.position(0) == 0);
  206. assert(m.str(0) == s);
  207. }
  208. {
  209. std::cmatch m;
  210. const char s[] = "efabc";
  211. assert(std::regex_search(s, m, std::regex("abc$")));
  212. assert(m.size() == 1);
  213. assert(m.prefix().matched);
  214. assert(m.prefix().first == s);
  215. assert(m.prefix().second == m[0].first);
  216. assert(!m.suffix().matched);
  217. assert(m.suffix().first == m[0].second);
  218. assert(m.suffix().second == s+5);
  219. assert(m.length(0) == 3);
  220. assert(m.position(0) == 2);
  221. assert(m.str(0) == s+2);
  222. }
  223. {
  224. std::cmatch m;
  225. const char s[] = "efabcg";
  226. assert(!std::regex_search(s, m, std::regex("abc$")));
  227. assert(m.size() == 0);
  228. }
  229. {
  230. std::cmatch m;
  231. const char s[] = "abc";
  232. assert(std::regex_search(s, m, std::regex("a.c")));
  233. assert(m.size() == 1);
  234. assert(!m.prefix().matched);
  235. assert(m.prefix().first == s);
  236. assert(m.prefix().second == m[0].first);
  237. assert(!m.suffix().matched);
  238. assert(m.suffix().first == m[0].second);
  239. assert(m.suffix().second == s+3);
  240. assert(m.length(0) == 3);
  241. assert(m.position(0) == 0);
  242. assert(m.str(0) == s);
  243. }
  244. {
  245. std::cmatch m;
  246. const char s[] = "acc";
  247. assert(std::regex_search(s, m, std::regex("a.c")));
  248. assert(m.size() == 1);
  249. assert(!m.prefix().matched);
  250. assert(m.prefix().first == s);
  251. assert(m.prefix().second == m[0].first);
  252. assert(!m.suffix().matched);
  253. assert(m.suffix().first == m[0].second);
  254. assert(m.suffix().second == s+3);
  255. assert(m.length(0) == 3);
  256. assert(m.position(0) == 0);
  257. assert(m.str(0) == s);
  258. }
  259. {
  260. std::cmatch m;
  261. const char s[] = "acc";
  262. assert(std::regex_search(s, m, std::regex("a.c")));
  263. assert(m.size() == 1);
  264. assert(!m.prefix().matched);
  265. assert(m.prefix().first == s);
  266. assert(m.prefix().second == m[0].first);
  267. assert(!m.suffix().matched);
  268. assert(m.suffix().first == m[0].second);
  269. assert(m.suffix().second == s+3);
  270. assert(m.length(0) == 3);
  271. assert(m.position(0) == 0);
  272. assert(m.str(0) == s);
  273. }
  274. {
  275. std::cmatch m;
  276. const char s[] = "abcdef";
  277. assert(std::regex_search(s, m, std::regex("(.*).*")));
  278. assert(m.size() == 2);
  279. assert(!m.prefix().matched);
  280. assert(m.prefix().first == s);
  281. assert(m.prefix().second == m[0].first);
  282. assert(!m.suffix().matched);
  283. assert(m.suffix().first == m[0].second);
  284. assert(m.suffix().second == s+6);
  285. assert(m.length(0) == 6);
  286. assert(m.position(0) == 0);
  287. assert(m.str(0) == s);
  288. assert(m.length(1) == 6);
  289. assert(m.position(1) == 0);
  290. assert(m.str(1) == s);
  291. }
  292. {
  293. std::cmatch m;
  294. const char s[] = "bc";
  295. assert(std::regex_search(s, m, std::regex("(a*)*")));
  296. assert(m.size() == 2);
  297. assert(!m.prefix().matched);
  298. assert(m.prefix().first == s);
  299. assert(m.prefix().second == m[0].first);
  300. assert(m.suffix().matched);
  301. assert(m.suffix().first == m[0].second);
  302. assert(m.suffix().second == s+2);
  303. assert(m.length(0) == 0);
  304. assert(m.position(0) == 0);
  305. assert(m.str(0) == "");
  306. assert(m.length(1) == 0);
  307. assert(m.position(1) == 0);
  308. assert(m.str(1) == "");
  309. }
  310. {
  311. std::cmatch m;
  312. const char s[] = "abbc";
  313. assert(!std::regex_search(s, m, std::regex("ab{3,5}c")));
  314. assert(m.size() == 0);
  315. }
  316. {
  317. std::cmatch m;
  318. const char s[] = "abbbc";
  319. assert(std::regex_search(s, m, std::regex("ab{3,5}c")));
  320. assert(m.size() == 1);
  321. assert(!m.prefix().matched);
  322. assert(m.prefix().first == s);
  323. assert(m.prefix().second == m[0].first);
  324. assert(!m.suffix().matched);
  325. assert(m.suffix().first == m[0].second);
  326. assert(m.suffix().second == m[0].second);
  327. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  328. assert(m.position(0) == 0);
  329. assert(m.str(0) == s);
  330. }
  331. {
  332. std::cmatch m;
  333. const char s[] = "abbbbc";
  334. assert(std::regex_search(s, m, std::regex("ab{3,5}c")));
  335. assert(m.size() == 1);
  336. assert(!m.prefix().matched);
  337. assert(m.prefix().first == s);
  338. assert(m.prefix().second == m[0].first);
  339. assert(!m.suffix().matched);
  340. assert(m.suffix().first == m[0].second);
  341. assert(m.suffix().second == m[0].second);
  342. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  343. assert(m.position(0) == 0);
  344. assert(m.str(0) == s);
  345. }
  346. {
  347. std::cmatch m;
  348. const char s[] = "abbbbbc";
  349. assert(std::regex_search(s, m, std::regex("ab{3,5}c")));
  350. assert(m.size() == 1);
  351. assert(!m.prefix().matched);
  352. assert(m.prefix().first == s);
  353. assert(m.prefix().second == m[0].first);
  354. assert(!m.suffix().matched);
  355. assert(m.suffix().first == m[0].second);
  356. assert(m.suffix().second == m[0].second);
  357. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  358. assert(m.position(0) == 0);
  359. assert(m.str(0) == s);
  360. }
  361. {
  362. std::cmatch m;
  363. const char s[] = "adefc";
  364. assert(!std::regex_search(s, m, std::regex("ab{3,5}c")));
  365. assert(m.size() == 0);
  366. }
  367. {
  368. std::cmatch m;
  369. const char s[] = "abbbbbbc";
  370. assert(!std::regex_search(s, m, std::regex("ab{3,5}c")));
  371. assert(m.size() == 0);
  372. }
  373. {
  374. std::cmatch m;
  375. const char s[] = "adec";
  376. assert(!std::regex_search(s, m, std::regex("a.{3,5}c")));
  377. assert(m.size() == 0);
  378. }
  379. {
  380. std::cmatch m;
  381. const char s[] = "adefc";
  382. assert(std::regex_search(s, m, std::regex("a.{3,5}c")));
  383. assert(m.size() == 1);
  384. assert(!m.prefix().matched);
  385. assert(m.prefix().first == s);
  386. assert(m.prefix().second == m[0].first);
  387. assert(!m.suffix().matched);
  388. assert(m.suffix().first == m[0].second);
  389. assert(m.suffix().second == m[0].second);
  390. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  391. assert(m.position(0) == 0);
  392. assert(m.str(0) == s);
  393. }
  394. {
  395. std::cmatch m;
  396. const char s[] = "adefgc";
  397. assert(std::regex_search(s, m, std::regex("a.{3,5}c")));
  398. assert(m.size() == 1);
  399. assert(!m.prefix().matched);
  400. assert(m.prefix().first == s);
  401. assert(m.prefix().second == m[0].first);
  402. assert(!m.suffix().matched);
  403. assert(m.suffix().first == m[0].second);
  404. assert(m.suffix().second == m[0].second);
  405. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  406. assert(m.position(0) == 0);
  407. assert(m.str(0) == s);
  408. }
  409. {
  410. std::cmatch m;
  411. const char s[] = "adefghc";
  412. assert(std::regex_search(s, m, std::regex("a.{3,5}c")));
  413. assert(m.size() == 1);
  414. assert(!m.prefix().matched);
  415. assert(m.prefix().first == s);
  416. assert(m.prefix().second == m[0].first);
  417. assert(!m.suffix().matched);
  418. assert(m.suffix().first == m[0].second);
  419. assert(m.suffix().second == m[0].second);
  420. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  421. assert(m.position(0) == 0);
  422. assert(m.str(0) == s);
  423. }
  424. {
  425. std::cmatch m;
  426. const char s[] = "adefghic";
  427. assert(!std::regex_search(s, m, std::regex("a.{3,5}c")));
  428. assert(m.size() == 0);
  429. }
  430. {
  431. std::cmatch m;
  432. const char s[] = "tournament";
  433. assert(std::regex_search(s, m, std::regex("tour|to|tournament")));
  434. assert(m.size() == 1);
  435. assert(!m.prefix().matched);
  436. assert(m.prefix().first == s);
  437. assert(m.prefix().second == m[0].first);
  438. assert(m.suffix().matched);
  439. assert(m.suffix().first == m[0].second);
  440. assert(m.suffix().second == s + std::char_traits<char>::length(s));
  441. assert(m.length(0) == 4);
  442. assert(m.position(0) == 0);
  443. assert(m.str(0) == "tour");
  444. }
  445. {
  446. std::cmatch m;
  447. const char s[] = "tournamenttotour";
  448. assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+",
  449. std::regex_constants::nosubs)));
  450. assert(m.size() == 1);
  451. assert(!m.prefix().matched);
  452. assert(m.prefix().first == s);
  453. assert(m.prefix().second == m[0].first);
  454. assert(m.suffix().matched);
  455. assert(m.suffix().first == m[0].second);
  456. assert(m.suffix().second == s + std::char_traits<char>::length(s));
  457. assert(m.length(0) == 4);
  458. assert(m.position(0) == 0);
  459. assert(m.str(0) == "tour");
  460. }
  461. {
  462. std::cmatch m;
  463. const char s[] = "ttotour";
  464. assert(std::regex_search(s, m, std::regex("(tour|to|t)+")));
  465. assert(m.size() == 2);
  466. assert(!m.prefix().matched);
  467. assert(m.prefix().first == s);
  468. assert(m.prefix().second == m[0].first);
  469. assert(!m.suffix().matched);
  470. assert(m.suffix().first == m[0].second);
  471. assert(m.suffix().second == m[0].second);
  472. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  473. assert(m.position(0) == 0);
  474. assert(m.str(0) == s);
  475. assert(m.length(1) == 4);
  476. assert(m.position(1) == 3);
  477. assert(m.str(1) == "tour");
  478. }
  479. {
  480. std::cmatch m;
  481. const char s[] = "-ab,ab-";
  482. assert(!std::regex_search(s, m, std::regex("-(.*),\1-")));
  483. assert(m.size() == 0);
  484. }
  485. {
  486. std::cmatch m;
  487. const char s[] = "-ab,ab-";
  488. assert(std::regex_search(s, m, std::regex("-.*,.*-")));
  489. assert(m.size() == 1);
  490. assert(!m.prefix().matched);
  491. assert(m.prefix().first == s);
  492. assert(m.prefix().second == m[0].first);
  493. assert(!m.suffix().matched);
  494. assert(m.suffix().first == m[0].second);
  495. assert(m.suffix().second == m[0].second);
  496. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  497. assert(m.position(0) == 0);
  498. assert(m.str(0) == s);
  499. }
  500. {
  501. std::cmatch m;
  502. const char s[] = "a";
  503. assert(std::regex_search(s, m, std::regex("^[a]$")));
  504. assert(m.size() == 1);
  505. assert(!m.prefix().matched);
  506. assert(m.prefix().first == s);
  507. assert(m.prefix().second == m[0].first);
  508. assert(!m.suffix().matched);
  509. assert(m.suffix().first == m[0].second);
  510. assert(m.suffix().second == m[0].second);
  511. assert(m.length(0) == 1);
  512. assert(m.position(0) == 0);
  513. assert(m.str(0) == "a");
  514. }
  515. {
  516. std::cmatch m;
  517. const char s[] = "a";
  518. assert(std::regex_search(s, m, std::regex("^[ab]$")));
  519. assert(m.size() == 1);
  520. assert(!m.prefix().matched);
  521. assert(m.prefix().first == s);
  522. assert(m.prefix().second == m[0].first);
  523. assert(!m.suffix().matched);
  524. assert(m.suffix().first == m[0].second);
  525. assert(m.suffix().second == m[0].second);
  526. assert(m.length(0) == 1);
  527. assert(m.position(0) == 0);
  528. assert(m.str(0) == "a");
  529. }
  530. {
  531. std::cmatch m;
  532. const char s[] = "c";
  533. assert(std::regex_search(s, m, std::regex("^[a-f]$")));
  534. assert(m.size() == 1);
  535. assert(!m.prefix().matched);
  536. assert(m.prefix().first == s);
  537. assert(m.prefix().second == m[0].first);
  538. assert(!m.suffix().matched);
  539. assert(m.suffix().first == m[0].second);
  540. assert(m.suffix().second == m[0].second);
  541. assert(m.length(0) == 1);
  542. assert(m.position(0) == 0);
  543. assert(m.str(0) == s);
  544. }
  545. {
  546. std::cmatch m;
  547. const char s[] = "g";
  548. assert(!std::regex_search(s, m, std::regex("^[a-f]$")));
  549. assert(m.size() == 0);
  550. }
  551. {
  552. std::cmatch m;
  553. const char s[] = "Iraqi";
  554. assert(std::regex_search(s, m, std::regex("q[^u]")));
  555. assert(m.size() == 1);
  556. assert(m.prefix().matched);
  557. assert(m.prefix().first == s);
  558. assert(m.prefix().second == m[0].first);
  559. assert(!m.suffix().matched);
  560. assert(m.suffix().first == m[0].second);
  561. assert(m.suffix().second == m[0].second);
  562. assert(m.length(0) == 2);
  563. assert(m.position(0) == 3);
  564. assert(m.str(0) == "qi");
  565. }
  566. {
  567. std::cmatch m;
  568. const char s[] = "Iraq";
  569. assert(!std::regex_search(s, m, std::regex("q[^u]")));
  570. assert(m.size() == 0);
  571. }
  572. {
  573. std::cmatch m;
  574. const char s[] = "AmB";
  575. assert(std::regex_search(s, m, std::regex("A[[:lower:]]B")));
  576. assert(m.size() == 1);
  577. assert(!m.prefix().matched);
  578. assert(m.prefix().first == s);
  579. assert(m.prefix().second == m[0].first);
  580. assert(!m.suffix().matched);
  581. assert(m.suffix().first == m[0].second);
  582. assert(m.suffix().second == m[0].second);
  583. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  584. assert(m.position(0) == 0);
  585. assert(m.str(0) == s);
  586. }
  587. {
  588. std::cmatch m;
  589. const char s[] = "AMB";
  590. assert(!std::regex_search(s, m, std::regex("A[[:lower:]]B")));
  591. assert(m.size() == 0);
  592. }
  593. {
  594. std::cmatch m;
  595. const char s[] = "AMB";
  596. assert(std::regex_search(s, m, std::regex("A[^[:lower:]]B")));
  597. assert(m.size() == 1);
  598. assert(!m.prefix().matched);
  599. assert(m.prefix().first == s);
  600. assert(m.prefix().second == m[0].first);
  601. assert(!m.suffix().matched);
  602. assert(m.suffix().first == m[0].second);
  603. assert(m.suffix().second == m[0].second);
  604. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  605. assert(m.position(0) == 0);
  606. assert(m.str(0) == s);
  607. }
  608. {
  609. std::cmatch m;
  610. const char s[] = "AmB";
  611. assert(!std::regex_search(s, m, std::regex("A[^[:lower:]]B")));
  612. assert(m.size() == 0);
  613. }
  614. {
  615. std::cmatch m;
  616. const char s[] = "A5B";
  617. assert(!std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B")));
  618. assert(m.size() == 0);
  619. }
  620. {
  621. std::cmatch m;
  622. const char s[] = "A?B";
  623. assert(std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B")));
  624. assert(m.size() == 1);
  625. assert(!m.prefix().matched);
  626. assert(m.prefix().first == s);
  627. assert(m.prefix().second == m[0].first);
  628. assert(!m.suffix().matched);
  629. assert(m.suffix().first == m[0].second);
  630. assert(m.suffix().second == m[0].second);
  631. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  632. assert(m.position(0) == 0);
  633. assert(m.str(0) == s);
  634. }
  635. {
  636. std::cmatch m;
  637. const char s[] = "-";
  638. assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]")));
  639. assert(m.size() == 1);
  640. assert(!m.prefix().matched);
  641. assert(m.prefix().first == s);
  642. assert(m.prefix().second == m[0].first);
  643. assert(!m.suffix().matched);
  644. assert(m.suffix().first == m[0].second);
  645. assert(m.suffix().second == m[0].second);
  646. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  647. assert(m.position(0) == 0);
  648. assert(m.str(0) == s);
  649. }
  650. {
  651. std::cmatch m;
  652. const char s[] = "z";
  653. assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]")));
  654. assert(m.size() == 1);
  655. assert(!m.prefix().matched);
  656. assert(m.prefix().first == s);
  657. assert(m.prefix().second == m[0].first);
  658. assert(!m.suffix().matched);
  659. assert(m.suffix().first == m[0].second);
  660. assert(m.suffix().second == m[0].second);
  661. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  662. assert(m.position(0) == 0);
  663. assert(m.str(0) == s);
  664. }
  665. {
  666. std::cmatch m;
  667. const char s[] = "m";
  668. assert(!std::regex_search(s, m, std::regex("[a[.hyphen.]z]")));
  669. assert(m.size() == 0);
  670. }
  671. std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
  672. {
  673. std::cmatch m;
  674. const char s[] = "m";
  675. assert(std::regex_search(s, m, std::regex("[a[=M=]z]")));
  676. assert(m.size() == 1);
  677. assert(!m.prefix().matched);
  678. assert(m.prefix().first == s);
  679. assert(m.prefix().second == m[0].first);
  680. assert(!m.suffix().matched);
  681. assert(m.suffix().first == m[0].second);
  682. assert(m.suffix().second == m[0].second);
  683. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  684. assert(m.position(0) == 0);
  685. assert(m.str(0) == s);
  686. }
  687. {
  688. std::cmatch m;
  689. const char s[] = "Ch";
  690. assert(std::regex_search(s, m, std::regex("[a[.ch.]z]",
  691. std::regex_constants::icase)));
  692. assert(m.size() == 1);
  693. assert(!m.prefix().matched);
  694. assert(m.prefix().first == s);
  695. assert(m.prefix().second == m[0].first);
  696. assert(!m.suffix().matched);
  697. assert(m.suffix().first == m[0].second);
  698. assert(m.suffix().second == m[0].second);
  699. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  700. assert(m.position(0) == 0);
  701. assert(m.str(0) == s);
  702. }
  703. std::locale::global(std::locale("C"));
  704. {
  705. std::cmatch m;
  706. const char s[] = "m";
  707. assert(!std::regex_search(s, m, std::regex("[a[=M=]z]")));
  708. assert(m.size() == 0);
  709. }
  710. {
  711. std::cmatch m;
  712. const char s[] = "01a45cef9";
  713. assert(std::regex_search(s, m, std::regex("[ace1-9]*")));
  714. assert(m.size() == 1);
  715. assert(!m.prefix().matched);
  716. assert(m.prefix().first == s);
  717. assert(m.prefix().second == m[0].first);
  718. assert(m.suffix().matched);
  719. assert(m.suffix().first == m[0].second);
  720. assert(m.suffix().second == s + std::char_traits<char>::length(s));
  721. assert(m.length(0) == 0);
  722. assert(m.position(0) == 0);
  723. assert(m.str(0) == "");
  724. }
  725. {
  726. std::cmatch m;
  727. const char s[] = "01a45cef9";
  728. assert(std::regex_search(s, m, std::regex("[ace1-9]+")));
  729. assert(m.size() == 1);
  730. assert(m.prefix().matched);
  731. assert(m.prefix().first == s);
  732. assert(m.prefix().second == m[0].first);
  733. assert(m.suffix().matched);
  734. assert(m.suffix().first == m[0].second);
  735. assert(m.suffix().second == s + std::char_traits<char>::length(s));
  736. assert(m.length(0) == 6);
  737. assert(m.position(0) == 1);
  738. assert(m.str(0) == "1a45ce");
  739. }
  740. {
  741. const char r[] = "^[-+]?[0-9]+[CF]$";
  742. std::ptrdiff_t sr = std::char_traits<char>::length(r);
  743. typedef forward_iterator<const char*> FI;
  744. typedef bidirectional_iterator<const char*> BI;
  745. std::regex regex(FI(r), FI(r+sr));
  746. std::match_results<BI> m;
  747. const char s[] = "-40C";
  748. std::ptrdiff_t ss = std::char_traits<char>::length(s);
  749. assert(std::regex_search(BI(s), BI(s+ss), m, regex));
  750. assert(m.size() == 1);
  751. assert(!m.prefix().matched);
  752. assert(m.prefix().first == BI(s));
  753. assert(m.prefix().second == m[0].first);
  754. assert(!m.suffix().matched);
  755. assert(m.suffix().first == m[0].second);
  756. assert(m.suffix().second == m[0].second);
  757. assert(m.length(0) == 4);
  758. assert(m.position(0) == 0);
  759. assert(m.str(0) == s);
  760. }
  761. {
  762. std::cmatch m;
  763. const char s[] = "Jeff Jeffs ";
  764. assert(std::regex_search(s, m, std::regex("Jeff(?=s\\b)")));
  765. assert(m.size() == 1);
  766. assert(m.prefix().matched);
  767. assert(m.prefix().first == s);
  768. assert(m.prefix().second == m[0].first);
  769. assert(m.suffix().matched);
  770. assert(m.suffix().first == m[0].second);
  771. assert(m.suffix().second == s + std::char_traits<char>::length(s));
  772. assert(m.length(0) == 4);
  773. assert(m.position(0) == 5);
  774. assert(m.str(0) == "Jeff");
  775. }
  776. {
  777. std::cmatch m;
  778. const char s[] = "Jeffs Jeff";
  779. assert(std::regex_search(s, m, std::regex("Jeff(?!s\\b)")));
  780. assert(m.size() == 1);
  781. assert(m.prefix().matched);
  782. assert(m.prefix().first == s);
  783. assert(m.prefix().second == m[0].first);
  784. assert(!m.suffix().matched);
  785. assert(m.suffix().first == m[0].second);
  786. assert(m.suffix().second == s + std::char_traits<char>::length(s));
  787. assert(m.length(0) == 4);
  788. assert(m.position(0) == 6);
  789. assert(m.str(0) == "Jeff");
  790. }
  791. {
  792. std::cmatch m;
  793. const char s[] = "5%k";
  794. assert(std::regex_search(s, m, std::regex("\\d[\\W]k")));
  795. assert(m.size() == 1);
  796. assert(!m.prefix().matched);
  797. assert(m.prefix().first == s);
  798. assert(m.prefix().second == m[0].first);
  799. assert(!m.suffix().matched);
  800. assert(m.suffix().first == m[0].second);
  801. assert(m.suffix().second == s + std::char_traits<char>::length(s));
  802. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  803. assert(m.position(0) == 0);
  804. assert(m.str(0) == s);
  805. }
  806. {
  807. std::wcmatch m;
  808. const wchar_t s[] = L"a";
  809. assert(std::regex_search(s, m, std::wregex(L"a")));
  810. assert(m.size() == 1);
  811. assert(!m.empty());
  812. assert(!m.prefix().matched);
  813. assert(m.prefix().first == s);
  814. assert(m.prefix().second == m[0].first);
  815. assert(!m.suffix().matched);
  816. assert(m.suffix().first == m[0].second);
  817. assert(m.suffix().second == s+1);
  818. assert(m.length(0) == 1);
  819. assert(m.position(0) == 0);
  820. assert(m.str(0) == L"a");
  821. }
  822. {
  823. std::wcmatch m;
  824. const wchar_t s[] = L"ab";
  825. assert(std::regex_search(s, m, std::wregex(L"ab")));
  826. assert(m.size() == 1);
  827. assert(!m.prefix().matched);
  828. assert(m.prefix().first == s);
  829. assert(m.prefix().second == m[0].first);
  830. assert(!m.suffix().matched);
  831. assert(m.suffix().first == m[0].second);
  832. assert(m.suffix().second == s+2);
  833. assert(m.length(0) == 2);
  834. assert(m.position(0) == 0);
  835. assert(m.str(0) == L"ab");
  836. }
  837. {
  838. std::wcmatch m;
  839. const wchar_t s[] = L"ab";
  840. assert(!std::regex_search(s, m, std::wregex(L"ba")));
  841. assert(m.size() == 0);
  842. assert(m.empty());
  843. }
  844. {
  845. std::wcmatch m;
  846. const wchar_t s[] = L"aab";
  847. assert(std::regex_search(s, m, std::wregex(L"ab")));
  848. assert(m.size() == 1);
  849. assert(m.prefix().matched);
  850. assert(m.prefix().first == s);
  851. assert(m.prefix().second == m[0].first);
  852. assert(!m.suffix().matched);
  853. assert(m.suffix().first == m[0].second);
  854. assert(m.suffix().second == s+3);
  855. assert(m.length(0) == 2);
  856. assert(m.position(0) == 1);
  857. assert(m.str(0) == L"ab");
  858. }
  859. {
  860. std::wcmatch m;
  861. const wchar_t s[] = L"aab";
  862. assert(!std::regex_search(s, m, std::wregex(L"ab"),
  863. std::regex_constants::match_continuous));
  864. assert(m.size() == 0);
  865. }
  866. {
  867. std::wcmatch m;
  868. const wchar_t s[] = L"abcd";
  869. assert(std::regex_search(s, m, std::wregex(L"bc")));
  870. assert(m.size() == 1);
  871. assert(m.prefix().matched);
  872. assert(m.prefix().first == s);
  873. assert(m.prefix().second == m[0].first);
  874. assert(m.suffix().matched);
  875. assert(m.suffix().first == m[0].second);
  876. assert(m.suffix().second == s+4);
  877. assert(m.length(0) == 2);
  878. assert(m.position(0) == 1);
  879. assert(m.str(0) == L"bc");
  880. }
  881. {
  882. std::wcmatch m;
  883. const wchar_t s[] = L"abbc";
  884. assert(std::regex_search(s, m, std::wregex(L"ab*c")));
  885. assert(m.size() == 1);
  886. assert(!m.prefix().matched);
  887. assert(m.prefix().first == s);
  888. assert(m.prefix().second == m[0].first);
  889. assert(!m.suffix().matched);
  890. assert(m.suffix().first == m[0].second);
  891. assert(m.suffix().second == s+4);
  892. assert(m.length(0) == 4);
  893. assert(m.position(0) == 0);
  894. assert(m.str(0) == s);
  895. }
  896. {
  897. std::wcmatch m;
  898. const wchar_t s[] = L"ababc";
  899. assert(std::regex_search(s, m, std::wregex(L"(ab)*c")));
  900. assert(m.size() == 2);
  901. assert(!m.prefix().matched);
  902. assert(m.prefix().first == s);
  903. assert(m.prefix().second == m[0].first);
  904. assert(!m.suffix().matched);
  905. assert(m.suffix().first == m[0].second);
  906. assert(m.suffix().second == s+5);
  907. assert(m.length(0) == 5);
  908. assert(m.position(0) == 0);
  909. assert(m.str(0) == s);
  910. assert(m.length(1) == 2);
  911. assert(m.position(1) == 2);
  912. assert(m.str(1) == L"ab");
  913. }
  914. {
  915. std::wcmatch m;
  916. const wchar_t s[] = L"abcdefghijk";
  917. assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
  918. assert(m.size() == 3);
  919. assert(m.prefix().matched);
  920. assert(m.prefix().first == s);
  921. assert(m.prefix().second == m[0].first);
  922. assert(m.suffix().matched);
  923. assert(m.suffix().first == m[0].second);
  924. assert(m.suffix().second == s+std::regex_traits<wchar_t>::length(s));
  925. assert(m.length(0) == 7);
  926. assert(m.position(0) == 2);
  927. assert(m.str(0) == L"cdefghi");
  928. assert(m.length(1) == 3);
  929. assert(m.position(1) == 4);
  930. assert(m.str(1) == L"efg");
  931. assert(m.length(2) == 1);
  932. assert(m.position(2) == 4);
  933. assert(m.str(2) == L"e");
  934. }
  935. {
  936. std::wcmatch m;
  937. const wchar_t s[] = L"abc";
  938. assert(std::regex_search(s, m, std::wregex(L"^abc")));
  939. assert(m.size() == 1);
  940. assert(!m.prefix().matched);
  941. assert(m.prefix().first == s);
  942. assert(m.prefix().second == m[0].first);
  943. assert(!m.suffix().matched);
  944. assert(m.suffix().first == m[0].second);
  945. assert(m.suffix().second == s+3);
  946. assert(m.length(0) == 3);
  947. assert(m.position(0) == 0);
  948. assert(m.str(0) == s);
  949. }
  950. {
  951. std::wcmatch m;
  952. const wchar_t s[] = L"abcd";
  953. assert(std::regex_search(s, m, std::wregex(L"^abc")));
  954. assert(m.size() == 1);
  955. assert(!m.prefix().matched);
  956. assert(m.prefix().first == s);
  957. assert(m.prefix().second == m[0].first);
  958. assert(m.suffix().matched);
  959. assert(m.suffix().first == m[0].second);
  960. assert(m.suffix().second == s+4);
  961. assert(m.length(0) == 3);
  962. assert(m.position(0) == 0);
  963. assert(m.str(0) == L"abc");
  964. }
  965. {
  966. std::wcmatch m;
  967. const wchar_t s[] = L"aabc";
  968. assert(!std::regex_search(s, m, std::wregex(L"^abc")));
  969. assert(m.size() == 0);
  970. }
  971. {
  972. std::wcmatch m;
  973. const wchar_t s[] = L"abc";
  974. assert(std::regex_search(s, m, std::wregex(L"abc$")));
  975. assert(m.size() == 1);
  976. assert(!m.prefix().matched);
  977. assert(m.prefix().first == s);
  978. assert(m.prefix().second == m[0].first);
  979. assert(!m.suffix().matched);
  980. assert(m.suffix().first == m[0].second);
  981. assert(m.suffix().second == s+3);
  982. assert(m.length(0) == 3);
  983. assert(m.position(0) == 0);
  984. assert(m.str(0) == s);
  985. }
  986. {
  987. std::wcmatch m;
  988. const wchar_t s[] = L"efabc";
  989. assert(std::regex_search(s, m, std::wregex(L"abc$")));
  990. assert(m.size() == 1);
  991. assert(m.prefix().matched);
  992. assert(m.prefix().first == s);
  993. assert(m.prefix().second == m[0].first);
  994. assert(!m.suffix().matched);
  995. assert(m.suffix().first == m[0].second);
  996. assert(m.suffix().second == s+5);
  997. assert(m.length(0) == 3);
  998. assert(m.position(0) == 2);
  999. assert(m.str(0) == s+2);
  1000. }
  1001. {
  1002. std::wcmatch m;
  1003. const wchar_t s[] = L"efabcg";
  1004. assert(!std::regex_search(s, m, std::wregex(L"abc$")));
  1005. assert(m.size() == 0);
  1006. }
  1007. {
  1008. std::wcmatch m;
  1009. const wchar_t s[] = L"abc";
  1010. assert(std::regex_search(s, m, std::wregex(L"a.c")));
  1011. assert(m.size() == 1);
  1012. assert(!m.prefix().matched);
  1013. assert(m.prefix().first == s);
  1014. assert(m.prefix().second == m[0].first);
  1015. assert(!m.suffix().matched);
  1016. assert(m.suffix().first == m[0].second);
  1017. assert(m.suffix().second == s+3);
  1018. assert(m.length(0) == 3);
  1019. assert(m.position(0) == 0);
  1020. assert(m.str(0) == s);
  1021. }
  1022. {
  1023. std::wcmatch m;
  1024. const wchar_t s[] = L"acc";
  1025. assert(std::regex_search(s, m, std::wregex(L"a.c")));
  1026. assert(m.size() == 1);
  1027. assert(!m.prefix().matched);
  1028. assert(m.prefix().first == s);
  1029. assert(m.prefix().second == m[0].first);
  1030. assert(!m.suffix().matched);
  1031. assert(m.suffix().first == m[0].second);
  1032. assert(m.suffix().second == s+3);
  1033. assert(m.length(0) == 3);
  1034. assert(m.position(0) == 0);
  1035. assert(m.str(0) == s);
  1036. }
  1037. {
  1038. std::wcmatch m;
  1039. const wchar_t s[] = L"acc";
  1040. assert(std::regex_search(s, m, std::wregex(L"a.c")));
  1041. assert(m.size() == 1);
  1042. assert(!m.prefix().matched);
  1043. assert(m.prefix().first == s);
  1044. assert(m.prefix().second == m[0].first);
  1045. assert(!m.suffix().matched);
  1046. assert(m.suffix().first == m[0].second);
  1047. assert(m.suffix().second == s+3);
  1048. assert(m.length(0) == 3);
  1049. assert(m.position(0) == 0);
  1050. assert(m.str(0) == s);
  1051. }
  1052. {
  1053. std::wcmatch m;
  1054. const wchar_t s[] = L"abcdef";
  1055. assert(std::regex_search(s, m, std::wregex(L"(.*).*")));
  1056. assert(m.size() == 2);
  1057. assert(!m.prefix().matched);
  1058. assert(m.prefix().first == s);
  1059. assert(m.prefix().second == m[0].first);
  1060. assert(!m.suffix().matched);
  1061. assert(m.suffix().first == m[0].second);
  1062. assert(m.suffix().second == s+6);
  1063. assert(m.length(0) == 6);
  1064. assert(m.position(0) == 0);
  1065. assert(m.str(0) == s);
  1066. assert(m.length(1) == 6);
  1067. assert(m.position(1) == 0);
  1068. assert(m.str(1) == s);
  1069. }
  1070. {
  1071. std::wcmatch m;
  1072. const wchar_t s[] = L"bc";
  1073. assert(std::regex_search(s, m, std::wregex(L"(a*)*")));
  1074. assert(m.size() == 2);
  1075. assert(!m.prefix().matched);
  1076. assert(m.prefix().first == s);
  1077. assert(m.prefix().second == m[0].first);
  1078. assert(m.suffix().matched);
  1079. assert(m.suffix().first == m[0].second);
  1080. assert(m.suffix().second == s+2);
  1081. assert(m.length(0) == 0);
  1082. assert(m.position(0) == 0);
  1083. assert(m.str(0) == L"");
  1084. assert(m.length(1) == 0);
  1085. assert(m.position(1) == 0);
  1086. assert(m.str(1) == L"");
  1087. }
  1088. {
  1089. std::wcmatch m;
  1090. const wchar_t s[] = L"abbc";
  1091. assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
  1092. assert(m.size() == 0);
  1093. }
  1094. {
  1095. std::wcmatch m;
  1096. const wchar_t s[] = L"abbbc";
  1097. assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
  1098. assert(m.size() == 1);
  1099. assert(!m.prefix().matched);
  1100. assert(m.prefix().first == s);
  1101. assert(m.prefix().second == m[0].first);
  1102. assert(!m.suffix().matched);
  1103. assert(m.suffix().first == m[0].second);
  1104. assert(m.suffix().second == m[0].second);
  1105. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1106. assert(m.position(0) == 0);
  1107. assert(m.str(0) == s);
  1108. }
  1109. {
  1110. std::wcmatch m;
  1111. const wchar_t s[] = L"abbbbc";
  1112. assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
  1113. assert(m.size() == 1);
  1114. assert(!m.prefix().matched);
  1115. assert(m.prefix().first == s);
  1116. assert(m.prefix().second == m[0].first);
  1117. assert(!m.suffix().matched);
  1118. assert(m.suffix().first == m[0].second);
  1119. assert(m.suffix().second == m[0].second);
  1120. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1121. assert(m.position(0) == 0);
  1122. assert(m.str(0) == s);
  1123. }
  1124. {
  1125. std::wcmatch m;
  1126. const wchar_t s[] = L"abbbbbc";
  1127. assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
  1128. assert(m.size() == 1);
  1129. assert(!m.prefix().matched);
  1130. assert(m.prefix().first == s);
  1131. assert(m.prefix().second == m[0].first);
  1132. assert(!m.suffix().matched);
  1133. assert(m.suffix().first == m[0].second);
  1134. assert(m.suffix().second == m[0].second);
  1135. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1136. assert(m.position(0) == 0);
  1137. assert(m.str(0) == s);
  1138. }
  1139. {
  1140. std::wcmatch m;
  1141. const wchar_t s[] = L"adefc";
  1142. assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
  1143. assert(m.size() == 0);
  1144. }
  1145. {
  1146. std::wcmatch m;
  1147. const wchar_t s[] = L"abbbbbbc";
  1148. assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
  1149. assert(m.size() == 0);
  1150. }
  1151. {
  1152. std::wcmatch m;
  1153. const wchar_t s[] = L"adec";
  1154. assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c")));
  1155. assert(m.size() == 0);
  1156. }
  1157. {
  1158. std::wcmatch m;
  1159. const wchar_t s[] = L"adefc";
  1160. assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c")));
  1161. assert(m.size() == 1);
  1162. assert(!m.prefix().matched);
  1163. assert(m.prefix().first == s);
  1164. assert(m.prefix().second == m[0].first);
  1165. assert(!m.suffix().matched);
  1166. assert(m.suffix().first == m[0].second);
  1167. assert(m.suffix().second == m[0].second);
  1168. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1169. assert(m.position(0) == 0);
  1170. assert(m.str(0) == s);
  1171. }
  1172. {
  1173. std::wcmatch m;
  1174. const wchar_t s[] = L"adefgc";
  1175. assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c")));
  1176. assert(m.size() == 1);
  1177. assert(!m.prefix().matched);
  1178. assert(m.prefix().first == s);
  1179. assert(m.prefix().second == m[0].first);
  1180. assert(!m.suffix().matched);
  1181. assert(m.suffix().first == m[0].second);
  1182. assert(m.suffix().second == m[0].second);
  1183. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1184. assert(m.position(0) == 0);
  1185. assert(m.str(0) == s);
  1186. }
  1187. {
  1188. std::wcmatch m;
  1189. const wchar_t s[] = L"adefghc";
  1190. assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c")));
  1191. assert(m.size() == 1);
  1192. assert(!m.prefix().matched);
  1193. assert(m.prefix().first == s);
  1194. assert(m.prefix().second == m[0].first);
  1195. assert(!m.suffix().matched);
  1196. assert(m.suffix().first == m[0].second);
  1197. assert(m.suffix().second == m[0].second);
  1198. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1199. assert(m.position(0) == 0);
  1200. assert(m.str(0) == s);
  1201. }
  1202. {
  1203. std::wcmatch m;
  1204. const wchar_t s[] = L"adefghic";
  1205. assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c")));
  1206. assert(m.size() == 0);
  1207. }
  1208. {
  1209. std::wcmatch m;
  1210. const wchar_t s[] = L"tournament";
  1211. assert(std::regex_search(s, m, std::wregex(L"tour|to|tournament")));
  1212. assert(m.size() == 1);
  1213. assert(!m.prefix().matched);
  1214. assert(m.prefix().first == s);
  1215. assert(m.prefix().second == m[0].first);
  1216. assert(m.suffix().matched);
  1217. assert(m.suffix().first == m[0].second);
  1218. assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
  1219. assert(m.length(0) == 4);
  1220. assert(m.position(0) == 0);
  1221. assert(m.str(0) == L"tour");
  1222. }
  1223. {
  1224. std::wcmatch m;
  1225. const wchar_t s[] = L"tournamenttotour";
  1226. assert(std::regex_search(s, m, std::wregex(L"(tour|to|tournament)+",
  1227. std::regex_constants::nosubs)));
  1228. assert(m.size() == 1);
  1229. assert(!m.prefix().matched);
  1230. assert(m.prefix().first == s);
  1231. assert(m.prefix().second == m[0].first);
  1232. assert(m.suffix().matched);
  1233. assert(m.suffix().first == m[0].second);
  1234. assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
  1235. assert(m.length(0) == 4);
  1236. assert(m.position(0) == 0);
  1237. assert(m.str(0) == L"tour");
  1238. }
  1239. {
  1240. std::wcmatch m;
  1241. const wchar_t s[] = L"ttotour";
  1242. assert(std::regex_search(s, m, std::wregex(L"(tour|to|t)+")));
  1243. assert(m.size() == 2);
  1244. assert(!m.prefix().matched);
  1245. assert(m.prefix().first == s);
  1246. assert(m.prefix().second == m[0].first);
  1247. assert(!m.suffix().matched);
  1248. assert(m.suffix().first == m[0].second);
  1249. assert(m.suffix().second == m[0].second);
  1250. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1251. assert(m.position(0) == 0);
  1252. assert(m.str(0) == s);
  1253. assert(m.length(1) == 4);
  1254. assert(m.position(1) == 3);
  1255. assert(m.str(1) == L"tour");
  1256. }
  1257. {
  1258. std::wcmatch m;
  1259. const wchar_t s[] = L"-ab,ab-";
  1260. assert(!std::regex_search(s, m, std::wregex(L"-(.*),\1-")));
  1261. assert(m.size() == 0);
  1262. }
  1263. {
  1264. std::wcmatch m;
  1265. const wchar_t s[] = L"-ab,ab-";
  1266. assert(std::regex_search(s, m, std::wregex(L"-.*,.*-")));
  1267. assert(m.size() == 1);
  1268. assert(!m.prefix().matched);
  1269. assert(m.prefix().first == s);
  1270. assert(m.prefix().second == m[0].first);
  1271. assert(!m.suffix().matched);
  1272. assert(m.suffix().first == m[0].second);
  1273. assert(m.suffix().second == m[0].second);
  1274. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1275. assert(m.position(0) == 0);
  1276. assert(m.str(0) == s);
  1277. }
  1278. {
  1279. std::wcmatch m;
  1280. const wchar_t s[] = L"a";
  1281. assert(std::regex_search(s, m, std::wregex(L"^[a]$")));
  1282. assert(m.size() == 1);
  1283. assert(!m.prefix().matched);
  1284. assert(m.prefix().first == s);
  1285. assert(m.prefix().second == m[0].first);
  1286. assert(!m.suffix().matched);
  1287. assert(m.suffix().first == m[0].second);
  1288. assert(m.suffix().second == m[0].second);
  1289. assert(m.length(0) == 1);
  1290. assert(m.position(0) == 0);
  1291. assert(m.str(0) == L"a");
  1292. }
  1293. {
  1294. std::wcmatch m;
  1295. const wchar_t s[] = L"a";
  1296. assert(std::regex_search(s, m, std::wregex(L"^[ab]$")));
  1297. assert(m.size() == 1);
  1298. assert(!m.prefix().matched);
  1299. assert(m.prefix().first == s);
  1300. assert(m.prefix().second == m[0].first);
  1301. assert(!m.suffix().matched);
  1302. assert(m.suffix().first == m[0].second);
  1303. assert(m.suffix().second == m[0].second);
  1304. assert(m.length(0) == 1);
  1305. assert(m.position(0) == 0);
  1306. assert(m.str(0) == L"a");
  1307. }
  1308. {
  1309. std::wcmatch m;
  1310. const wchar_t s[] = L"c";
  1311. assert(std::regex_search(s, m, std::wregex(L"^[a-f]$")));
  1312. assert(m.size() == 1);
  1313. assert(!m.prefix().matched);
  1314. assert(m.prefix().first == s);
  1315. assert(m.prefix().second == m[0].first);
  1316. assert(!m.suffix().matched);
  1317. assert(m.suffix().first == m[0].second);
  1318. assert(m.suffix().second == m[0].second);
  1319. assert(m.length(0) == 1);
  1320. assert(m.position(0) == 0);
  1321. assert(m.str(0) == s);
  1322. }
  1323. {
  1324. std::wcmatch m;
  1325. const wchar_t s[] = L"g";
  1326. assert(!std::regex_search(s, m, std::wregex(L"^[a-f]$")));
  1327. assert(m.size() == 0);
  1328. }
  1329. {
  1330. std::wcmatch m;
  1331. const wchar_t s[] = L"Iraqi";
  1332. assert(std::regex_search(s, m, std::wregex(L"q[^u]")));
  1333. assert(m.size() == 1);
  1334. assert(m.prefix().matched);
  1335. assert(m.prefix().first == s);
  1336. assert(m.prefix().second == m[0].first);
  1337. assert(!m.suffix().matched);
  1338. assert(m.suffix().first == m[0].second);
  1339. assert(m.suffix().second == m[0].second);
  1340. assert(m.length(0) == 2);
  1341. assert(m.position(0) == 3);
  1342. assert(m.str(0) == L"qi");
  1343. }
  1344. {
  1345. std::wcmatch m;
  1346. const wchar_t s[] = L"Iraq";
  1347. assert(!std::regex_search(s, m, std::wregex(L"q[^u]")));
  1348. assert(m.size() == 0);
  1349. }
  1350. {
  1351. std::wcmatch m;
  1352. const wchar_t s[] = L"AmB";
  1353. assert(std::regex_search(s, m, std::wregex(L"A[[:lower:]]B")));
  1354. assert(m.size() == 1);
  1355. assert(!m.prefix().matched);
  1356. assert(m.prefix().first == s);
  1357. assert(m.prefix().second == m[0].first);
  1358. assert(!m.suffix().matched);
  1359. assert(m.suffix().first == m[0].second);
  1360. assert(m.suffix().second == m[0].second);
  1361. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1362. assert(m.position(0) == 0);
  1363. assert(m.str(0) == s);
  1364. }
  1365. {
  1366. std::wcmatch m;
  1367. const wchar_t s[] = L"AMB";
  1368. assert(!std::regex_search(s, m, std::wregex(L"A[[:lower:]]B")));
  1369. assert(m.size() == 0);
  1370. }
  1371. {
  1372. std::wcmatch m;
  1373. const wchar_t s[] = L"AMB";
  1374. assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B")));
  1375. assert(m.size() == 1);
  1376. assert(!m.prefix().matched);
  1377. assert(m.prefix().first == s);
  1378. assert(m.prefix().second == m[0].first);
  1379. assert(!m.suffix().matched);
  1380. assert(m.suffix().first == m[0].second);
  1381. assert(m.suffix().second == m[0].second);
  1382. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1383. assert(m.position(0) == 0);
  1384. assert(m.str(0) == s);
  1385. }
  1386. {
  1387. std::wcmatch m;
  1388. const wchar_t s[] = L"AmB";
  1389. assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B")));
  1390. assert(m.size() == 0);
  1391. }
  1392. {
  1393. std::wcmatch m;
  1394. const wchar_t s[] = L"A5B";
  1395. assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
  1396. assert(m.size() == 0);
  1397. }
  1398. {
  1399. std::wcmatch m;
  1400. const wchar_t s[] = L"A?B";
  1401. assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
  1402. assert(m.size() == 1);
  1403. assert(!m.prefix().matched);
  1404. assert(m.prefix().first == s);
  1405. assert(m.prefix().second == m[0].first);
  1406. assert(!m.suffix().matched);
  1407. assert(m.suffix().first == m[0].second);
  1408. assert(m.suffix().second == m[0].second);
  1409. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1410. assert(m.position(0) == 0);
  1411. assert(m.str(0) == s);
  1412. }
  1413. {
  1414. std::wcmatch m;
  1415. const wchar_t s[] = L"-";
  1416. assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]")));
  1417. assert(m.size() == 1);
  1418. assert(!m.prefix().matched);
  1419. assert(m.prefix().first == s);
  1420. assert(m.prefix().second == m[0].first);
  1421. assert(!m.suffix().matched);
  1422. assert(m.suffix().first == m[0].second);
  1423. assert(m.suffix().second == m[0].second);
  1424. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1425. assert(m.position(0) == 0);
  1426. assert(m.str(0) == s);
  1427. }
  1428. {
  1429. std::wcmatch m;
  1430. const wchar_t s[] = L"z";
  1431. assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]")));
  1432. assert(m.size() == 1);
  1433. assert(!m.prefix().matched);
  1434. assert(m.prefix().first == s);
  1435. assert(m.prefix().second == m[0].first);
  1436. assert(!m.suffix().matched);
  1437. assert(m.suffix().first == m[0].second);
  1438. assert(m.suffix().second == m[0].second);
  1439. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1440. assert(m.position(0) == 0);
  1441. assert(m.str(0) == s);
  1442. }
  1443. {
  1444. std::wcmatch m;
  1445. const wchar_t s[] = L"m";
  1446. assert(!std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]")));
  1447. assert(m.size() == 0);
  1448. }
  1449. std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
  1450. {
  1451. std::wcmatch m;
  1452. const wchar_t s[] = L"m";
  1453. assert(std::regex_search(s, m, std::wregex(L"[a[=M=]z]")));
  1454. assert(m.size() == 1);
  1455. assert(!m.prefix().matched);
  1456. assert(m.prefix().first == s);
  1457. assert(m.prefix().second == m[0].first);
  1458. assert(!m.suffix().matched);
  1459. assert(m.suffix().first == m[0].second);
  1460. assert(m.suffix().second == m[0].second);
  1461. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1462. assert(m.position(0) == 0);
  1463. assert(m.str(0) == s);
  1464. }
  1465. {
  1466. std::wcmatch m;
  1467. const wchar_t s[] = L"Ch";
  1468. assert(std::regex_search(s, m, std::wregex(L"[a[.ch.]z]",
  1469. std::regex_constants::icase)));
  1470. assert(m.size() == 1);
  1471. assert(!m.prefix().matched);
  1472. assert(m.prefix().first == s);
  1473. assert(m.prefix().second == m[0].first);
  1474. assert(!m.suffix().matched);
  1475. assert(m.suffix().first == m[0].second);
  1476. assert(m.suffix().second == m[0].second);
  1477. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1478. assert(m.position(0) == 0);
  1479. assert(m.str(0) == s);
  1480. }
  1481. std::locale::global(std::locale("C"));
  1482. {
  1483. std::wcmatch m;
  1484. const wchar_t s[] = L"m";
  1485. assert(!std::regex_search(s, m, std::wregex(L"[a[=M=]z]")));
  1486. assert(m.size() == 0);
  1487. }
  1488. {
  1489. std::wcmatch m;
  1490. const wchar_t s[] = L"01a45cef9";
  1491. assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*")));
  1492. assert(m.size() == 1);
  1493. assert(!m.prefix().matched);
  1494. assert(m.prefix().first == s);
  1495. assert(m.prefix().second == m[0].first);
  1496. assert(m.suffix().matched);
  1497. assert(m.suffix().first == m[0].second);
  1498. assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
  1499. assert(m.length(0) == 0);
  1500. assert(m.position(0) == 0);
  1501. assert(m.str(0) == L"");
  1502. }
  1503. {
  1504. std::wcmatch m;
  1505. const wchar_t s[] = L"01a45cef9";
  1506. assert(std::regex_search(s, m, std::wregex(L"[ace1-9]+")));
  1507. assert(m.size() == 1);
  1508. assert(m.prefix().matched);
  1509. assert(m.prefix().first == s);
  1510. assert(m.prefix().second == m[0].first);
  1511. assert(m.suffix().matched);
  1512. assert(m.suffix().first == m[0].second);
  1513. assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
  1514. assert(m.length(0) == 6);
  1515. assert(m.position(0) == 1);
  1516. assert(m.str(0) == L"1a45ce");
  1517. }
  1518. {
  1519. const wchar_t r[] = L"^[-+]?[0-9]+[CF]$";
  1520. std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r);
  1521. typedef forward_iterator<const wchar_t*> FI;
  1522. typedef bidirectional_iterator<const wchar_t*> BI;
  1523. std::wregex regex(FI(r), FI(r+sr));
  1524. std::match_results<BI> m;
  1525. const wchar_t s[] = L"-40C";
  1526. std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s);
  1527. assert(std::regex_search(BI(s), BI(s+ss), m, regex));
  1528. assert(m.size() == 1);
  1529. assert(!m.prefix().matched);
  1530. assert(m.prefix().first == BI(s));
  1531. assert(m.prefix().second == m[0].first);
  1532. assert(!m.suffix().matched);
  1533. assert(m.suffix().first == m[0].second);
  1534. assert(m.suffix().second == m[0].second);
  1535. assert(m.length(0) == 4);
  1536. assert(m.position(0) == 0);
  1537. assert(m.str(0) == s);
  1538. }
  1539. {
  1540. std::wcmatch m;
  1541. const wchar_t s[] = L"Jeff Jeffs ";
  1542. assert(std::regex_search(s, m, std::wregex(L"Jeff(?=s\\b)")));
  1543. assert(m.size() == 1);
  1544. assert(m.prefix().matched);
  1545. assert(m.prefix().first == s);
  1546. assert(m.prefix().second == m[0].first);
  1547. assert(m.suffix().matched);
  1548. assert(m.suffix().first == m[0].second);
  1549. assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
  1550. assert(m.length(0) == 4);
  1551. assert(m.position(0) == 5);
  1552. assert(m.str(0) == L"Jeff");
  1553. }
  1554. {
  1555. std::wcmatch m;
  1556. const wchar_t s[] = L"Jeffs Jeff";
  1557. assert(std::regex_search(s, m, std::wregex(L"Jeff(?!s\\b)")));
  1558. assert(m.size() == 1);
  1559. assert(m.prefix().matched);
  1560. assert(m.prefix().first == s);
  1561. assert(m.prefix().second == m[0].first);
  1562. assert(!m.suffix().matched);
  1563. assert(m.suffix().first == m[0].second);
  1564. assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
  1565. assert(m.length(0) == 4);
  1566. assert(m.position(0) == 6);
  1567. assert(m.str(0) == L"Jeff");
  1568. }
  1569. {
  1570. std::wcmatch m;
  1571. const wchar_t s[] = L"5%k";
  1572. assert(std::regex_search(s, m, std::wregex(L"\\d[\\W]k")));
  1573. assert(m.size() == 1);
  1574. assert(!m.prefix().matched);
  1575. assert(m.prefix().first == s);
  1576. assert(m.prefix().second == m[0].first);
  1577. assert(!m.suffix().matched);
  1578. assert(m.suffix().first == m[0].second);
  1579. assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
  1580. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1581. assert(m.position(0) == 0);
  1582. assert(m.str(0) == s);
  1583. }
  1584. return 0;
  1585. }