extended.pass.cpp 59 KB

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