basic.pass.cpp 51 KB

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