basic.pass.cpp 59 KB

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