basic.pass.cpp 50 KB

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