basic.pass.cpp 57 KB

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