regex 208 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_REGEX
  10. #define _LIBCPP_REGEX
  11. /*
  12. regex synopsis
  13. #include <compare>
  14. #include <initializer_list>
  15. namespace std
  16. {
  17. namespace regex_constants
  18. {
  19. enum syntax_option_type
  20. {
  21. icase = unspecified,
  22. nosubs = unspecified,
  23. optimize = unspecified,
  24. collate = unspecified,
  25. ECMAScript = unspecified,
  26. basic = unspecified,
  27. extended = unspecified,
  28. awk = unspecified,
  29. grep = unspecified,
  30. egrep = unspecified,
  31. multiline = unspecified
  32. };
  33. constexpr syntax_option_type operator~(syntax_option_type f);
  34. constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
  35. constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
  36. enum match_flag_type
  37. {
  38. match_default = 0,
  39. match_not_bol = unspecified,
  40. match_not_eol = unspecified,
  41. match_not_bow = unspecified,
  42. match_not_eow = unspecified,
  43. match_any = unspecified,
  44. match_not_null = unspecified,
  45. match_continuous = unspecified,
  46. match_prev_avail = unspecified,
  47. format_default = 0,
  48. format_sed = unspecified,
  49. format_no_copy = unspecified,
  50. format_first_only = unspecified
  51. };
  52. constexpr match_flag_type operator~(match_flag_type f);
  53. constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
  54. constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
  55. enum error_type
  56. {
  57. error_collate = unspecified,
  58. error_ctype = unspecified,
  59. error_escape = unspecified,
  60. error_backref = unspecified,
  61. error_brack = unspecified,
  62. error_paren = unspecified,
  63. error_brace = unspecified,
  64. error_badbrace = unspecified,
  65. error_range = unspecified,
  66. error_space = unspecified,
  67. error_badrepeat = unspecified,
  68. error_complexity = unspecified,
  69. error_stack = unspecified
  70. };
  71. } // regex_constants
  72. class regex_error
  73. : public runtime_error
  74. {
  75. public:
  76. explicit regex_error(regex_constants::error_type ecode);
  77. regex_constants::error_type code() const;
  78. };
  79. template <class charT>
  80. struct regex_traits
  81. {
  82. public:
  83. typedef charT char_type;
  84. typedef basic_string<char_type> string_type;
  85. typedef locale locale_type;
  86. typedef /bitmask_type/ char_class_type;
  87. regex_traits();
  88. static size_t length(const char_type* p);
  89. charT translate(charT c) const;
  90. charT translate_nocase(charT c) const;
  91. template <class ForwardIterator>
  92. string_type
  93. transform(ForwardIterator first, ForwardIterator last) const;
  94. template <class ForwardIterator>
  95. string_type
  96. transform_primary( ForwardIterator first, ForwardIterator last) const;
  97. template <class ForwardIterator>
  98. string_type
  99. lookup_collatename(ForwardIterator first, ForwardIterator last) const;
  100. template <class ForwardIterator>
  101. char_class_type
  102. lookup_classname(ForwardIterator first, ForwardIterator last,
  103. bool icase = false) const;
  104. bool isctype(charT c, char_class_type f) const;
  105. int value(charT ch, int radix) const;
  106. locale_type imbue(locale_type l);
  107. locale_type getloc()const;
  108. };
  109. template <class charT, class traits = regex_traits<charT>>
  110. class basic_regex
  111. {
  112. public:
  113. // types:
  114. typedef charT value_type;
  115. typedef traits traits_type;
  116. typedef typename traits::string_type string_type;
  117. typedef regex_constants::syntax_option_type flag_type;
  118. typedef typename traits::locale_type locale_type;
  119. // constants:
  120. static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
  121. static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
  122. static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
  123. static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
  124. static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
  125. static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
  126. static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
  127. static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
  128. static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
  129. static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
  130. static constexpr regex_constants::syntax_option_type multiline = regex_constants::multiline;
  131. // construct/copy/destroy:
  132. basic_regex();
  133. explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
  134. basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
  135. basic_regex(const basic_regex&);
  136. basic_regex(basic_regex&&) noexcept;
  137. template <class ST, class SA>
  138. explicit basic_regex(const basic_string<charT, ST, SA>& p,
  139. flag_type f = regex_constants::ECMAScript);
  140. template <class ForwardIterator>
  141. basic_regex(ForwardIterator first, ForwardIterator last,
  142. flag_type f = regex_constants::ECMAScript);
  143. basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
  144. ~basic_regex();
  145. basic_regex& operator=(const basic_regex&);
  146. basic_regex& operator=(basic_regex&&) noexcept;
  147. basic_regex& operator=(const charT* ptr);
  148. basic_regex& operator=(initializer_list<charT> il);
  149. template <class ST, class SA>
  150. basic_regex& operator=(const basic_string<charT, ST, SA>& p);
  151. // assign:
  152. basic_regex& assign(const basic_regex& that);
  153. basic_regex& assign(basic_regex&& that) noexcept;
  154. basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
  155. basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
  156. template <class string_traits, class A>
  157. basic_regex& assign(const basic_string<charT, string_traits, A>& s,
  158. flag_type f = regex_constants::ECMAScript);
  159. template <class InputIterator>
  160. basic_regex& assign(InputIterator first, InputIterator last,
  161. flag_type f = regex_constants::ECMAScript);
  162. basic_regex& assign(initializer_list<charT>, flag_type f = regex_constants::ECMAScript);
  163. // const operations:
  164. unsigned mark_count() const;
  165. flag_type flags() const;
  166. // locale:
  167. locale_type imbue(locale_type loc);
  168. locale_type getloc() const;
  169. // swap:
  170. void swap(basic_regex&);
  171. };
  172. template<class ForwardIterator>
  173. basic_regex(ForwardIterator, ForwardIterator,
  174. regex_constants::syntax_option_type = regex_constants::ECMAScript)
  175. -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; // C++17
  176. typedef basic_regex<char> regex;
  177. typedef basic_regex<wchar_t> wregex;
  178. template <class charT, class traits>
  179. void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
  180. template <class BidirectionalIterator>
  181. class sub_match
  182. : public pair<BidirectionalIterator, BidirectionalIterator>
  183. {
  184. public:
  185. typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
  186. typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
  187. typedef BidirectionalIterator iterator;
  188. typedef basic_string<value_type> string_type;
  189. bool matched;
  190. constexpr sub_match();
  191. difference_type length() const;
  192. operator string_type() const;
  193. string_type str() const;
  194. int compare(const sub_match& s) const;
  195. int compare(const string_type& s) const;
  196. int compare(const value_type* s) const;
  197. void swap(sub_match& s) noexcept(see below);
  198. };
  199. typedef sub_match<const char*> csub_match;
  200. typedef sub_match<const wchar_t*> wcsub_match;
  201. typedef sub_match<string::const_iterator> ssub_match;
  202. typedef sub_match<wstring::const_iterator> wssub_match;
  203. template <class BiIter>
  204. bool
  205. operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
  206. template <class BiIter>
  207. auto
  208. operator<=>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); // Since C++20
  209. template <class BiIter> // Removed in C++20
  210. bool
  211. operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
  212. template <class BiIter> // Removed in C++20
  213. bool
  214. operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
  215. template <class BiIter> // Removed in C++20
  216. bool
  217. operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
  218. template <class BiIter> // Removed in C++20
  219. bool
  220. operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
  221. template <class BiIter> // Removed in C++20
  222. bool
  223. operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
  224. template <class BiIter, class ST, class SA> // Removed in C++20
  225. bool
  226. operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
  227. const sub_match<BiIter>& rhs);
  228. template <class BiIter, class ST, class SA> // Removed in C++20
  229. bool
  230. operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
  231. const sub_match<BiIter>& rhs);
  232. template <class BiIter, class ST, class SA> // Removed in C++20
  233. bool
  234. operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
  235. const sub_match<BiIter>& rhs);
  236. template <class BiIter, class ST, class SA> // Removed in C++20
  237. bool
  238. operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
  239. const sub_match<BiIter>& rhs);
  240. template <class BiIter, class ST, class SA> // Removed in C++20
  241. bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
  242. const sub_match<BiIter>& rhs);
  243. template <class BiIter, class ST, class SA> // Removed in C++20
  244. bool
  245. operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
  246. const sub_match<BiIter>& rhs);
  247. template <class BiIter, class ST, class SA>
  248. bool
  249. operator==(const sub_match<BiIter>& lhs,
  250. const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
  251. template <class BiIter, class ST, class SA> // Since C++20
  252. auto
  253. operator<=>(const sub_match<BiIter>& lhs,
  254. const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
  255. template <class BiIter, class ST, class SA> // Removed in C++20
  256. bool
  257. operator!=(const sub_match<BiIter>& lhs,
  258. const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
  259. template <class BiIter, class ST, class SA> // Removed in C++20
  260. bool
  261. operator<(const sub_match<BiIter>& lhs,
  262. const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
  263. template <class BiIter, class ST, class SA> // Removed in C++20
  264. bool
  265. operator>(const sub_match<BiIter>& lhs,
  266. const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
  267. template <class BiIter, class ST, class SA> // Removed in C++20
  268. bool
  269. operator>=(const sub_match<BiIter>& lhs,
  270. const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
  271. template <class BiIter, class ST, class SA> // Removed in C++20
  272. bool
  273. operator<=(const sub_match<BiIter>& lhs,
  274. const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
  275. template <class BiIter> // Removed in C++20
  276. bool
  277. operator==(typename iterator_traits<BiIter>::value_type const* lhs,
  278. const sub_match<BiIter>& rhs);
  279. template <class BiIter> // Removed in C++20
  280. bool
  281. operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
  282. const sub_match<BiIter>& rhs);
  283. template <class BiIter> // Removed in C++20
  284. bool
  285. operator<(typename iterator_traits<BiIter>::value_type const* lhs,
  286. const sub_match<BiIter>& rhs);
  287. template <class BiIter> // Removed in C++20
  288. bool
  289. operator>(typename iterator_traits<BiIter>::value_type const* lhs,
  290. const sub_match<BiIter>& rhs);
  291. template <class BiIter> // Removed in C++20
  292. bool
  293. operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
  294. const sub_match<BiIter>& rhs);
  295. template <class BiIter> // Removed in C++20
  296. bool
  297. operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
  298. const sub_match<BiIter>& rhs);
  299. template <class BiIter>
  300. bool
  301. operator==(const sub_match<BiIter>& lhs,
  302. typename iterator_traits<BiIter>::value_type const* rhs);
  303. template <class BiIter> // Since C++20
  304. auto
  305. operator<=>(const sub_match<BiIter>& lhs,
  306. typename iterator_traits<BiIter>::value_type const* rhs);
  307. template <class BiIter, class ST, class SA> // Removed in C++20
  308. bool
  309. operator!=(const sub_match<BiIter>& lhs,
  310. typename iterator_traits<BiIter>::value_type const* rhs);
  311. template <class BiIter> // Removed in C++20
  312. bool
  313. operator<(const sub_match<BiIter>& lhs,
  314. typename iterator_traits<BiIter>::value_type const* rhs);
  315. template <class BiIter> // Removed in C++20
  316. bool
  317. operator>(const sub_match<BiIter>& lhs,
  318. typename iterator_traits<BiIter>::value_type const* rhs);
  319. template <class BiIter> // Removed in C++20
  320. bool
  321. operator>=(const sub_match<BiIter>& lhs,
  322. typename iterator_traits<BiIter>::value_type const* rhs);
  323. template <class BiIter> // Removed in C++20
  324. bool
  325. operator<=(const sub_match<BiIter>& lhs,
  326. typename iterator_traits<BiIter>::value_type const* rhs);
  327. template <class BiIter> // Removed in C++20
  328. bool
  329. operator==(typename iterator_traits<BiIter>::value_type const& lhs,
  330. const sub_match<BiIter>& rhs);
  331. template <class BiIter> // Removed in C++20
  332. bool
  333. operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
  334. const sub_match<BiIter>& rhs);
  335. template <class BiIter> // Removed in C++20
  336. bool
  337. operator<(typename iterator_traits<BiIter>::value_type const& lhs,
  338. const sub_match<BiIter>& rhs);
  339. template <class BiIter> // Removed in C++20
  340. bool
  341. operator>(typename iterator_traits<BiIter>::value_type const& lhs,
  342. const sub_match<BiIter>& rhs);
  343. template <class BiIter> // Removed in C++20
  344. bool
  345. operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
  346. const sub_match<BiIter>& rhs);
  347. template <class BiIter> // Removed in C++20
  348. bool
  349. operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
  350. const sub_match<BiIter>& rhs);
  351. template <class BiIter>
  352. bool
  353. operator==(const sub_match<BiIter>& lhs,
  354. typename iterator_traits<BiIter>::value_type const& rhs);
  355. template <class BiIter> // Since C++20
  356. auto
  357. operator<=>(const sub_match<BiIter>& lhs,
  358. typename iterator_traits<BiIter>::value_type const& rhs);
  359. template <class BiIter> // Removed in C++20
  360. bool
  361. operator!=(const sub_match<BiIter>& lhs,
  362. typename iterator_traits<BiIter>::value_type const& rhs);
  363. template <class BiIter> // Removed in C++20
  364. bool
  365. operator<(const sub_match<BiIter>& lhs,
  366. typename iterator_traits<BiIter>::value_type const& rhs);
  367. template <class BiIter> // Removed in C++20
  368. bool
  369. operator>(const sub_match<BiIter>& lhs,
  370. typename iterator_traits<BiIter>::value_type const& rhs);
  371. template <class BiIter> // Removed in C++20
  372. bool
  373. operator>=(const sub_match<BiIter>& lhs,
  374. typename iterator_traits<BiIter>::value_type const& rhs);
  375. template <class BiIter> // Removed in C++20
  376. bool
  377. operator<=(const sub_match<BiIter>& lhs,
  378. typename iterator_traits<BiIter>::value_type const& rhs);
  379. template <class charT, class ST, class BiIter>
  380. basic_ostream<charT, ST>&
  381. operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
  382. template <class BidirectionalIterator,
  383. class Allocator = allocator<sub_match<BidirectionalIterator>>>
  384. class match_results
  385. {
  386. public:
  387. typedef sub_match<BidirectionalIterator> value_type;
  388. typedef const value_type& const_reference;
  389. typedef value_type& reference;
  390. typedef /implementation-defined/ const_iterator;
  391. typedef const_iterator iterator;
  392. typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
  393. typedef typename allocator_traits<Allocator>::size_type size_type;
  394. typedef Allocator allocator_type;
  395. typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
  396. typedef basic_string<char_type> string_type;
  397. // construct/copy/destroy:
  398. explicit match_results(const Allocator& a = Allocator()); // before C++20
  399. match_results() : match_results(Allocator()) {} // C++20
  400. explicit match_results(const Allocator& a); // C++20
  401. match_results(const match_results& m);
  402. match_results(match_results&& m) noexcept;
  403. match_results& operator=(const match_results& m);
  404. match_results& operator=(match_results&& m);
  405. ~match_results();
  406. bool ready() const;
  407. // size:
  408. size_type size() const;
  409. size_type max_size() const;
  410. bool empty() const;
  411. // element access:
  412. difference_type length(size_type sub = 0) const;
  413. difference_type position(size_type sub = 0) const;
  414. string_type str(size_type sub = 0) const;
  415. const_reference operator[](size_type n) const;
  416. const_reference prefix() const;
  417. const_reference suffix() const;
  418. const_iterator begin() const;
  419. const_iterator end() const;
  420. const_iterator cbegin() const;
  421. const_iterator cend() const;
  422. // format:
  423. template <class OutputIter>
  424. OutputIter
  425. format(OutputIter out, const char_type* fmt_first,
  426. const char_type* fmt_last,
  427. regex_constants::match_flag_type flags = regex_constants::format_default) const;
  428. template <class OutputIter, class ST, class SA>
  429. OutputIter
  430. format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
  431. regex_constants::match_flag_type flags = regex_constants::format_default) const;
  432. template <class ST, class SA>
  433. basic_string<char_type, ST, SA>
  434. format(const basic_string<char_type, ST, SA>& fmt,
  435. regex_constants::match_flag_type flags = regex_constants::format_default) const;
  436. string_type
  437. format(const char_type* fmt,
  438. regex_constants::match_flag_type flags = regex_constants::format_default) const;
  439. // allocator:
  440. allocator_type get_allocator() const;
  441. // swap:
  442. void swap(match_results& that);
  443. };
  444. typedef match_results<const char*> cmatch;
  445. typedef match_results<const wchar_t*> wcmatch;
  446. typedef match_results<string::const_iterator> smatch;
  447. typedef match_results<wstring::const_iterator> wsmatch;
  448. template <class BidirectionalIterator, class Allocator>
  449. bool
  450. operator==(const match_results<BidirectionalIterator, Allocator>& m1,
  451. const match_results<BidirectionalIterator, Allocator>& m2);
  452. template <class BidirectionalIterator, class Allocator> // Removed in C++20
  453. bool
  454. operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
  455. const match_results<BidirectionalIterator, Allocator>& m2);
  456. template <class BidirectionalIterator, class Allocator>
  457. void
  458. swap(match_results<BidirectionalIterator, Allocator>& m1,
  459. match_results<BidirectionalIterator, Allocator>& m2);
  460. template <class BidirectionalIterator, class Allocator, class charT, class traits>
  461. bool
  462. regex_match(BidirectionalIterator first, BidirectionalIterator last,
  463. match_results<BidirectionalIterator, Allocator>& m,
  464. const basic_regex<charT, traits>& e,
  465. regex_constants::match_flag_type flags = regex_constants::match_default);
  466. template <class BidirectionalIterator, class charT, class traits>
  467. bool
  468. regex_match(BidirectionalIterator first, BidirectionalIterator last,
  469. const basic_regex<charT, traits>& e,
  470. regex_constants::match_flag_type flags = regex_constants::match_default);
  471. template <class charT, class Allocator, class traits>
  472. bool
  473. regex_match(const charT* str, match_results<const charT*, Allocator>& m,
  474. const basic_regex<charT, traits>& e,
  475. regex_constants::match_flag_type flags = regex_constants::match_default);
  476. template <class ST, class SA, class Allocator, class charT, class traits>
  477. bool
  478. regex_match(const basic_string<charT, ST, SA>& s,
  479. match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
  480. const basic_regex<charT, traits>& e,
  481. regex_constants::match_flag_type flags = regex_constants::match_default);
  482. template <class ST, class SA, class Allocator, class charT, class traits>
  483. bool
  484. regex_match(const basic_string<charT, ST, SA>&& s,
  485. match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
  486. const basic_regex<charT, traits>& e,
  487. regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
  488. template <class charT, class traits>
  489. bool
  490. regex_match(const charT* str, const basic_regex<charT, traits>& e,
  491. regex_constants::match_flag_type flags = regex_constants::match_default);
  492. template <class ST, class SA, class charT, class traits>
  493. bool
  494. regex_match(const basic_string<charT, ST, SA>& s,
  495. const basic_regex<charT, traits>& e,
  496. regex_constants::match_flag_type flags = regex_constants::match_default);
  497. template <class BidirectionalIterator, class Allocator, class charT, class traits>
  498. bool
  499. regex_search(BidirectionalIterator first, BidirectionalIterator last,
  500. match_results<BidirectionalIterator, Allocator>& m,
  501. const basic_regex<charT, traits>& e,
  502. regex_constants::match_flag_type flags = regex_constants::match_default);
  503. template <class BidirectionalIterator, class charT, class traits>
  504. bool
  505. regex_search(BidirectionalIterator first, BidirectionalIterator last,
  506. const basic_regex<charT, traits>& e,
  507. regex_constants::match_flag_type flags = regex_constants::match_default);
  508. template <class charT, class Allocator, class traits>
  509. bool
  510. regex_search(const charT* str, match_results<const charT*, Allocator>& m,
  511. const basic_regex<charT, traits>& e,
  512. regex_constants::match_flag_type flags = regex_constants::match_default);
  513. template <class charT, class traits>
  514. bool
  515. regex_search(const charT* str, const basic_regex<charT, traits>& e,
  516. regex_constants::match_flag_type flags = regex_constants::match_default);
  517. template <class ST, class SA, class charT, class traits>
  518. bool
  519. regex_search(const basic_string<charT, ST, SA>& s,
  520. const basic_regex<charT, traits>& e,
  521. regex_constants::match_flag_type flags = regex_constants::match_default);
  522. template <class ST, class SA, class Allocator, class charT, class traits>
  523. bool
  524. regex_search(const basic_string<charT, ST, SA>& s,
  525. match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
  526. const basic_regex<charT, traits>& e,
  527. regex_constants::match_flag_type flags = regex_constants::match_default);
  528. template <class ST, class SA, class Allocator, class charT, class traits>
  529. bool
  530. regex_search(const basic_string<charT, ST, SA>&& s,
  531. match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
  532. const basic_regex<charT, traits>& e,
  533. regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
  534. template <class OutputIterator, class BidirectionalIterator,
  535. class traits, class charT, class ST, class SA>
  536. OutputIterator
  537. regex_replace(OutputIterator out,
  538. BidirectionalIterator first, BidirectionalIterator last,
  539. const basic_regex<charT, traits>& e,
  540. const basic_string<charT, ST, SA>& fmt,
  541. regex_constants::match_flag_type flags = regex_constants::match_default);
  542. template <class OutputIterator, class BidirectionalIterator,
  543. class traits, class charT>
  544. OutputIterator
  545. regex_replace(OutputIterator out,
  546. BidirectionalIterator first, BidirectionalIterator last,
  547. const basic_regex<charT, traits>& e, const charT* fmt,
  548. regex_constants::match_flag_type flags = regex_constants::match_default);
  549. template <class traits, class charT, class ST, class SA, class FST, class FSA>
  550. basic_string<charT, ST, SA>
  551. regex_replace(const basic_string<charT, ST, SA>& s,
  552. const basic_regex<charT, traits>& e,
  553. const basic_string<charT, FST, FSA>& fmt,
  554. regex_constants::match_flag_type flags = regex_constants::match_default);
  555. template <class traits, class charT, class ST, class SA>
  556. basic_string<charT, ST, SA>
  557. regex_replace(const basic_string<charT, ST, SA>& s,
  558. const basic_regex<charT, traits>& e, const charT* fmt,
  559. regex_constants::match_flag_type flags = regex_constants::match_default);
  560. template <class traits, class charT, class ST, class SA>
  561. basic_string<charT>
  562. regex_replace(const charT* s,
  563. const basic_regex<charT, traits>& e,
  564. const basic_string<charT, ST, SA>& fmt,
  565. regex_constants::match_flag_type flags = regex_constants::match_default);
  566. template <class traits, class charT>
  567. basic_string<charT>
  568. regex_replace(const charT* s,
  569. const basic_regex<charT, traits>& e,
  570. const charT* fmt,
  571. regex_constants::match_flag_type flags = regex_constants::match_default);
  572. template <class BidirectionalIterator,
  573. class charT = typename iterator_traits< BidirectionalIterator>::value_type,
  574. class traits = regex_traits<charT>>
  575. class regex_iterator
  576. {
  577. public:
  578. typedef basic_regex<charT, traits> regex_type;
  579. typedef match_results<BidirectionalIterator> value_type;
  580. typedef ptrdiff_t difference_type;
  581. typedef const value_type* pointer;
  582. typedef const value_type& reference;
  583. typedef forward_iterator_tag iterator_category;
  584. typedef input_iterator_tag iterator_concept; // since C++20
  585. regex_iterator();
  586. regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
  587. const regex_type& re,
  588. regex_constants::match_flag_type m = regex_constants::match_default);
  589. regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
  590. const regex_type&& re,
  591. regex_constants::match_flag_type m
  592. = regex_constants::match_default) = delete; // C++14
  593. regex_iterator(const regex_iterator&);
  594. regex_iterator& operator=(const regex_iterator&);
  595. bool operator==(const regex_iterator&) const;
  596. bool operator==(default_sentinel_t) const { return *this == regex_iterator(); } // since C++20
  597. bool operator!=(const regex_iterator&) const; // Removed in C++20
  598. const value_type& operator*() const;
  599. const value_type* operator->() const;
  600. regex_iterator& operator++();
  601. regex_iterator operator++(int);
  602. };
  603. typedef regex_iterator<const char*> cregex_iterator;
  604. typedef regex_iterator<const wchar_t*> wcregex_iterator;
  605. typedef regex_iterator<string::const_iterator> sregex_iterator;
  606. typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
  607. template <class BidirectionalIterator,
  608. class charT = typename iterator_traits<BidirectionalIterator>::value_type,
  609. class traits = regex_traits<charT>>
  610. class regex_token_iterator
  611. {
  612. public:
  613. typedef basic_regex<charT, traits> regex_type;
  614. typedef sub_match<BidirectionalIterator> value_type;
  615. typedef ptrdiff_t difference_type;
  616. typedef const value_type* pointer;
  617. typedef const value_type& reference;
  618. typedef forward_iterator_tag iterator_category;
  619. typedef input_iterator_tag iterator_concept; // since C++20
  620. regex_token_iterator();
  621. regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
  622. const regex_type& re, int submatch = 0,
  623. regex_constants::match_flag_type m = regex_constants::match_default);
  624. regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
  625. const regex_type&& re, int submatch = 0,
  626. regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
  627. regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
  628. const regex_type& re, const vector<int>& submatches,
  629. regex_constants::match_flag_type m = regex_constants::match_default);
  630. regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
  631. const regex_type&& re, const vector<int>& submatches,
  632. regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
  633. regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
  634. const regex_type& re, initializer_list<int> submatches,
  635. regex_constants::match_flag_type m = regex_constants::match_default);
  636. regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
  637. const regex_type&& re, initializer_list<int> submatches,
  638. regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
  639. template <size_t N>
  640. regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
  641. const regex_type& re, const int (&submatches)[N],
  642. regex_constants::match_flag_type m = regex_constants::match_default);
  643. template <size_t N>
  644. regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
  645. const regex_type&& re, const int (&submatches)[N],
  646. regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
  647. regex_token_iterator(const regex_token_iterator&);
  648. regex_token_iterator& operator=(const regex_token_iterator&);
  649. bool operator==(const regex_token_iterator&) const;
  650. bool operator==(default_sentinel_t) const { return *this == regex_token_iterator(); } // since C++20
  651. bool operator!=(const regex_token_iterator&) const; // Removed in C++20
  652. const value_type& operator*() const;
  653. const value_type* operator->() const;
  654. regex_token_iterator& operator++();
  655. regex_token_iterator operator++(int);
  656. };
  657. typedef regex_token_iterator<const char*> cregex_token_iterator;
  658. typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
  659. typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
  660. typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
  661. } // std
  662. */
  663. #include <__algorithm/find.h>
  664. #include <__algorithm/search.h>
  665. #include <__assert>
  666. #include <__availability>
  667. #include <__config>
  668. #include <__iterator/back_insert_iterator.h>
  669. #include <__iterator/default_sentinel.h>
  670. #include <__iterator/wrap_iter.h>
  671. #include <__locale>
  672. #include <__memory/shared_ptr.h>
  673. #include <__memory_resource/polymorphic_allocator.h>
  674. #include <__type_traits/is_swappable.h>
  675. #include <__utility/move.h>
  676. #include <__utility/pair.h>
  677. #include <__utility/swap.h>
  678. #include <__verbose_abort>
  679. #include <deque>
  680. #include <stdexcept>
  681. #include <string>
  682. #include <vector>
  683. #include <version>
  684. // standard-mandated includes
  685. // [iterator.range]
  686. #include <__iterator/access.h>
  687. #include <__iterator/data.h>
  688. #include <__iterator/empty.h>
  689. #include <__iterator/reverse_access.h>
  690. #include <__iterator/size.h>
  691. // [re.syn]
  692. #include <compare>
  693. #include <initializer_list>
  694. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  695. # pragma GCC system_header
  696. #endif
  697. _LIBCPP_PUSH_MACROS
  698. #include <__undef_macros>
  699. #define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
  700. _LIBCPP_BEGIN_NAMESPACE_STD
  701. namespace regex_constants {
  702. // syntax_option_type
  703. enum syntax_option_type {
  704. icase = 1 << 0,
  705. nosubs = 1 << 1,
  706. optimize = 1 << 2,
  707. collate = 1 << 3,
  708. #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
  709. ECMAScript = 1 << 9,
  710. #else
  711. ECMAScript = 0,
  712. #endif
  713. basic = 1 << 4,
  714. extended = 1 << 5,
  715. awk = 1 << 6,
  716. grep = 1 << 7,
  717. egrep = 1 << 8,
  718. // 1 << 9 may be used by ECMAScript
  719. multiline = 1 << 10
  720. };
  721. _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR syntax_option_type __get_grammar(syntax_option_type __g) {
  722. #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
  723. return static_cast<syntax_option_type>(__g & 0x3F0);
  724. #else
  725. return static_cast<syntax_option_type>(__g & 0x1F0);
  726. #endif
  727. }
  728. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type operator~(syntax_option_type __x) {
  729. return syntax_option_type(~int(__x) & 0x1FF);
  730. }
  731. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type
  732. operator&(syntax_option_type __x, syntax_option_type __y) {
  733. return syntax_option_type(int(__x) & int(__y));
  734. }
  735. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type
  736. operator|(syntax_option_type __x, syntax_option_type __y) {
  737. return syntax_option_type(int(__x) | int(__y));
  738. }
  739. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type
  740. operator^(syntax_option_type __x, syntax_option_type __y) {
  741. return syntax_option_type(int(__x) ^ int(__y));
  742. }
  743. inline _LIBCPP_HIDE_FROM_ABI syntax_option_type& operator&=(syntax_option_type& __x, syntax_option_type __y) {
  744. __x = __x & __y;
  745. return __x;
  746. }
  747. inline _LIBCPP_HIDE_FROM_ABI syntax_option_type& operator|=(syntax_option_type& __x, syntax_option_type __y) {
  748. __x = __x | __y;
  749. return __x;
  750. }
  751. inline _LIBCPP_HIDE_FROM_ABI syntax_option_type& operator^=(syntax_option_type& __x, syntax_option_type __y) {
  752. __x = __x ^ __y;
  753. return __x;
  754. }
  755. // match_flag_type
  756. enum match_flag_type {
  757. match_default = 0,
  758. match_not_bol = 1 << 0,
  759. match_not_eol = 1 << 1,
  760. match_not_bow = 1 << 2,
  761. match_not_eow = 1 << 3,
  762. match_any = 1 << 4,
  763. match_not_null = 1 << 5,
  764. match_continuous = 1 << 6,
  765. match_prev_avail = 1 << 7,
  766. format_default = 0,
  767. format_sed = 1 << 8,
  768. format_no_copy = 1 << 9,
  769. format_first_only = 1 << 10,
  770. __no_update_pos = 1 << 11,
  771. __full_match = 1 << 12
  772. };
  773. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator~(match_flag_type __x) {
  774. return match_flag_type(~int(__x) & 0x0FFF);
  775. }
  776. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator&(match_flag_type __x, match_flag_type __y) {
  777. return match_flag_type(int(__x) & int(__y));
  778. }
  779. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator|(match_flag_type __x, match_flag_type __y) {
  780. return match_flag_type(int(__x) | int(__y));
  781. }
  782. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator^(match_flag_type __x, match_flag_type __y) {
  783. return match_flag_type(int(__x) ^ int(__y));
  784. }
  785. inline _LIBCPP_HIDE_FROM_ABI match_flag_type& operator&=(match_flag_type& __x, match_flag_type __y) {
  786. __x = __x & __y;
  787. return __x;
  788. }
  789. inline _LIBCPP_HIDE_FROM_ABI match_flag_type& operator|=(match_flag_type& __x, match_flag_type __y) {
  790. __x = __x | __y;
  791. return __x;
  792. }
  793. inline _LIBCPP_HIDE_FROM_ABI match_flag_type& operator^=(match_flag_type& __x, match_flag_type __y) {
  794. __x = __x ^ __y;
  795. return __x;
  796. }
  797. enum error_type {
  798. error_collate = 1,
  799. error_ctype,
  800. error_escape,
  801. error_backref,
  802. error_brack,
  803. error_paren,
  804. error_brace,
  805. error_badbrace,
  806. error_range,
  807. error_space,
  808. error_badrepeat,
  809. error_complexity,
  810. error_stack,
  811. __re_err_grammar,
  812. __re_err_empty,
  813. __re_err_unknown,
  814. __re_err_parse
  815. };
  816. } // namespace regex_constants
  817. class _LIBCPP_EXPORTED_FROM_ABI regex_error : public runtime_error {
  818. regex_constants::error_type __code_;
  819. public:
  820. explicit regex_error(regex_constants::error_type __ecode);
  821. _LIBCPP_HIDE_FROM_ABI regex_error(const regex_error&) _NOEXCEPT = default;
  822. ~regex_error() _NOEXCEPT override;
  823. _LIBCPP_HIDE_FROM_ABI regex_constants::error_type code() const { return __code_; }
  824. };
  825. template <regex_constants::error_type _Ev>
  826. _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_regex_error() {
  827. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  828. throw regex_error(_Ev);
  829. #else
  830. _LIBCPP_VERBOSE_ABORT("regex_error was thrown in -fno-exceptions mode");
  831. #endif
  832. }
  833. template <class _CharT>
  834. struct _LIBCPP_TEMPLATE_VIS regex_traits {
  835. public:
  836. typedef _CharT char_type;
  837. typedef basic_string<char_type> string_type;
  838. typedef locale locale_type;
  839. #if defined(__BIONIC__) || defined(_NEWLIB_VERSION)
  840. // Originally bionic's ctype_base used its own ctype masks because the
  841. // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask
  842. // was only 8 bits wide and already saturated, so it used a wider type here
  843. // to make room for __regex_word (then a part of this class rather than
  844. // ctype_base). Bionic has since moved to the builtin ctype_base
  845. // implementation, but this was not updated to match. Since then Android has
  846. // needed to maintain a stable libc++ ABI, and this can't be changed without
  847. // an ABI break.
  848. // We also need this workaround for newlib since _NEWLIB_VERSION is not
  849. // defined yet inside __config, so we can't set the
  850. // _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE macro. Additionally, newlib is
  851. // often used for space constrained environments, so it makes sense not to
  852. // duplicate the ctype table.
  853. typedef uint16_t char_class_type;
  854. #else
  855. typedef ctype_base::mask char_class_type;
  856. #endif
  857. static const char_class_type __regex_word = ctype_base::__regex_word;
  858. private:
  859. locale __loc_;
  860. const ctype<char_type>* __ct_;
  861. const collate<char_type>* __col_;
  862. public:
  863. regex_traits();
  864. _LIBCPP_HIDE_FROM_ABI static size_t length(const char_type* __p) { return char_traits<char_type>::length(__p); }
  865. _LIBCPP_HIDE_FROM_ABI char_type translate(char_type __c) const { return __c; }
  866. char_type translate_nocase(char_type __c) const;
  867. template <class _ForwardIterator>
  868. string_type transform(_ForwardIterator __f, _ForwardIterator __l) const;
  869. template <class _ForwardIterator>
  870. _LIBCPP_HIDE_FROM_ABI string_type transform_primary(_ForwardIterator __f, _ForwardIterator __l) const {
  871. return __transform_primary(__f, __l, char_type());
  872. }
  873. template <class _ForwardIterator>
  874. _LIBCPP_HIDE_FROM_ABI string_type lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const {
  875. return __lookup_collatename(__f, __l, char_type());
  876. }
  877. template <class _ForwardIterator>
  878. _LIBCPP_HIDE_FROM_ABI char_class_type
  879. lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase = false) const {
  880. return __lookup_classname(__f, __l, __icase, char_type());
  881. }
  882. bool isctype(char_type __c, char_class_type __m) const;
  883. _LIBCPP_HIDE_FROM_ABI int value(char_type __ch, int __radix) const { return __regex_traits_value(__ch, __radix); }
  884. locale_type imbue(locale_type __l);
  885. _LIBCPP_HIDE_FROM_ABI locale_type getloc() const { return __loc_; }
  886. private:
  887. void __init();
  888. template <class _ForwardIterator>
  889. string_type __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
  890. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  891. template <class _ForwardIterator>
  892. string_type __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
  893. #endif
  894. template <class _ForwardIterator>
  895. string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
  896. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  897. template <class _ForwardIterator>
  898. string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
  899. #endif
  900. template <class _ForwardIterator>
  901. char_class_type __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, char) const;
  902. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  903. template <class _ForwardIterator>
  904. char_class_type __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, wchar_t) const;
  905. #endif
  906. static int __regex_traits_value(unsigned char __ch, int __radix);
  907. _LIBCPP_HIDE_FROM_ABI int __regex_traits_value(char __ch, int __radix) const {
  908. return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);
  909. }
  910. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  911. _LIBCPP_HIDE_FROM_ABI int __regex_traits_value(wchar_t __ch, int __radix) const;
  912. #endif
  913. };
  914. template <class _CharT>
  915. const typename regex_traits<_CharT>::char_class_type regex_traits<_CharT>::__regex_word;
  916. template <class _CharT>
  917. regex_traits<_CharT>::regex_traits() {
  918. __init();
  919. }
  920. template <class _CharT>
  921. typename regex_traits<_CharT>::char_type regex_traits<_CharT>::translate_nocase(char_type __c) const {
  922. return __ct_->tolower(__c);
  923. }
  924. template <class _CharT>
  925. template <class _ForwardIterator>
  926. typename regex_traits<_CharT>::string_type
  927. regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const {
  928. string_type __s(__f, __l);
  929. return __col_->transform(__s.data(), __s.data() + __s.size());
  930. }
  931. template <class _CharT>
  932. void regex_traits<_CharT>::__init() {
  933. __ct_ = &std::use_facet<ctype<char_type> >(__loc_);
  934. __col_ = &std::use_facet<collate<char_type> >(__loc_);
  935. }
  936. template <class _CharT>
  937. typename regex_traits<_CharT>::locale_type regex_traits<_CharT>::imbue(locale_type __l) {
  938. locale __r = __loc_;
  939. __loc_ = __l;
  940. __init();
  941. return __r;
  942. }
  943. // transform_primary is very FreeBSD-specific
  944. template <class _CharT>
  945. template <class _ForwardIterator>
  946. typename regex_traits<_CharT>::string_type
  947. regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const {
  948. const string_type __s(__f, __l);
  949. string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
  950. switch (__d.size()) {
  951. case 1:
  952. break;
  953. case 12:
  954. __d[11] = __d[3];
  955. break;
  956. default:
  957. __d.clear();
  958. break;
  959. }
  960. return __d;
  961. }
  962. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  963. template <class _CharT>
  964. template <class _ForwardIterator>
  965. typename regex_traits<_CharT>::string_type
  966. regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const {
  967. const string_type __s(__f, __l);
  968. string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
  969. switch (__d.size()) {
  970. case 1:
  971. break;
  972. case 3:
  973. __d[2] = __d[0];
  974. break;
  975. default:
  976. __d.clear();
  977. break;
  978. }
  979. return __d;
  980. }
  981. #endif
  982. // lookup_collatename is very FreeBSD-specific
  983. _LIBCPP_EXPORTED_FROM_ABI string __get_collation_name(const char* __s);
  984. template <class _CharT>
  985. template <class _ForwardIterator>
  986. typename regex_traits<_CharT>::string_type
  987. regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const {
  988. string_type __s(__f, __l);
  989. string_type __r;
  990. if (!__s.empty()) {
  991. __r = std::__get_collation_name(__s.c_str());
  992. if (__r.empty() && __s.size() <= 2) {
  993. __r = __col_->transform(__s.data(), __s.data() + __s.size());
  994. if (__r.size() == 1 || __r.size() == 12)
  995. __r = __s;
  996. else
  997. __r.clear();
  998. }
  999. }
  1000. return __r;
  1001. }
  1002. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1003. template <class _CharT>
  1004. template <class _ForwardIterator>
  1005. typename regex_traits<_CharT>::string_type
  1006. regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const {
  1007. string_type __s(__f, __l);
  1008. string __n;
  1009. __n.reserve(__s.size());
  1010. for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); __i != __e; ++__i) {
  1011. if (static_cast<unsigned>(*__i) >= 127)
  1012. return string_type();
  1013. __n.push_back(char(*__i));
  1014. }
  1015. string_type __r;
  1016. if (!__s.empty()) {
  1017. __n = __get_collation_name(__n.c_str());
  1018. if (!__n.empty())
  1019. __r.assign(__n.begin(), __n.end());
  1020. else if (__s.size() <= 2) {
  1021. __r = __col_->transform(__s.data(), __s.data() + __s.size());
  1022. if (__r.size() == 1 || __r.size() == 3)
  1023. __r = __s;
  1024. else
  1025. __r.clear();
  1026. }
  1027. }
  1028. return __r;
  1029. }
  1030. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1031. // lookup_classname
  1032. regex_traits<char>::char_class_type _LIBCPP_EXPORTED_FROM_ABI __get_classname(const char* __s, bool __icase);
  1033. template <class _CharT>
  1034. template <class _ForwardIterator>
  1035. typename regex_traits<_CharT>::char_class_type
  1036. regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, char) const {
  1037. string_type __s(__f, __l);
  1038. __ct_->tolower(&__s[0], &__s[0] + __s.size());
  1039. return std::__get_classname(__s.c_str(), __icase);
  1040. }
  1041. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1042. template <class _CharT>
  1043. template <class _ForwardIterator>
  1044. typename regex_traits<_CharT>::char_class_type
  1045. regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, wchar_t) const {
  1046. string_type __s(__f, __l);
  1047. __ct_->tolower(&__s[0], &__s[0] + __s.size());
  1048. string __n;
  1049. __n.reserve(__s.size());
  1050. for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); __i != __e; ++__i) {
  1051. if (static_cast<unsigned>(*__i) >= 127)
  1052. return char_class_type();
  1053. __n.push_back(char(*__i));
  1054. }
  1055. return __get_classname(__n.c_str(), __icase);
  1056. }
  1057. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1058. template <class _CharT>
  1059. bool regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const {
  1060. if (__ct_->is(__m, __c))
  1061. return true;
  1062. return (__c == '_' && (__m & __regex_word));
  1063. }
  1064. inline _LIBCPP_HIDE_FROM_ABI bool __is_07(unsigned char __c) {
  1065. return (__c & 0xF8u) ==
  1066. #if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
  1067. 0xF0;
  1068. #else
  1069. 0x30;
  1070. #endif
  1071. }
  1072. inline _LIBCPP_HIDE_FROM_ABI bool __is_89(unsigned char __c) {
  1073. return (__c & 0xFEu) ==
  1074. #if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
  1075. 0xF8;
  1076. #else
  1077. 0x38;
  1078. #endif
  1079. }
  1080. inline _LIBCPP_HIDE_FROM_ABI unsigned char __to_lower(unsigned char __c) {
  1081. #if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
  1082. return __c & 0xBF;
  1083. #else
  1084. return __c | 0x20;
  1085. #endif
  1086. }
  1087. template <class _CharT>
  1088. int regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) {
  1089. if (__is_07(__ch)) // '0' <= __ch && __ch <= '7'
  1090. return __ch - '0';
  1091. if (__radix != 8) {
  1092. if (__is_89(__ch)) // '8' <= __ch && __ch <= '9'
  1093. return __ch - '0';
  1094. if (__radix == 16) {
  1095. __ch = __to_lower(__ch); // tolower
  1096. if ('a' <= __ch && __ch <= 'f')
  1097. return __ch - ('a' - 10);
  1098. }
  1099. }
  1100. return -1;
  1101. }
  1102. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1103. template <class _CharT>
  1104. inline int regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const {
  1105. return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
  1106. }
  1107. #endif
  1108. template <class _CharT>
  1109. class __node;
  1110. template <class _BidirectionalIterator>
  1111. class _LIBCPP_TEMPLATE_VIS sub_match;
  1112. template <class _BidirectionalIterator, class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
  1113. class _LIBCPP_TEMPLATE_VIS match_results;
  1114. template <class _CharT>
  1115. struct __state {
  1116. enum {
  1117. __end_state = -1000,
  1118. __consume_input, // -999
  1119. __begin_marked_expr, // -998
  1120. __end_marked_expr, // -997
  1121. __pop_state, // -996
  1122. __accept_and_consume, // -995
  1123. __accept_but_not_consume, // -994
  1124. __reject, // -993
  1125. __split,
  1126. __repeat
  1127. };
  1128. int __do_;
  1129. const _CharT* __first_;
  1130. const _CharT* __current_;
  1131. const _CharT* __last_;
  1132. vector<sub_match<const _CharT*> > __sub_matches_;
  1133. vector<pair<size_t, const _CharT*> > __loop_data_;
  1134. const __node<_CharT>* __node_;
  1135. regex_constants::match_flag_type __flags_;
  1136. bool __at_first_;
  1137. _LIBCPP_HIDE_FROM_ABI __state()
  1138. : __do_(0),
  1139. __first_(nullptr),
  1140. __current_(nullptr),
  1141. __last_(nullptr),
  1142. __node_(nullptr),
  1143. __flags_(),
  1144. __at_first_(false) {}
  1145. };
  1146. // __node
  1147. template <class _CharT>
  1148. class __node {
  1149. __node(const __node&);
  1150. __node& operator=(const __node&);
  1151. public:
  1152. typedef std::__state<_CharT> __state;
  1153. _LIBCPP_HIDE_FROM_ABI __node() {}
  1154. _LIBCPP_HIDE_FROM_ABI_VIRTUAL
  1155. virtual ~__node() {}
  1156. _LIBCPP_HIDE_FROM_ABI_VIRTUAL
  1157. virtual void __exec(__state&) const {}
  1158. _LIBCPP_HIDE_FROM_ABI_VIRTUAL
  1159. virtual void __exec_split(bool, __state&) const {}
  1160. };
  1161. // __end_state
  1162. template <class _CharT>
  1163. class __end_state : public __node<_CharT> {
  1164. public:
  1165. typedef std::__state<_CharT> __state;
  1166. _LIBCPP_HIDE_FROM_ABI __end_state() {}
  1167. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1168. };
  1169. template <class _CharT>
  1170. void __end_state<_CharT>::__exec(__state& __s) const {
  1171. __s.__do_ = __state::__end_state;
  1172. }
  1173. // __has_one_state
  1174. template <class _CharT>
  1175. class __has_one_state : public __node<_CharT> {
  1176. __node<_CharT>* __first_;
  1177. public:
  1178. _LIBCPP_HIDE_FROM_ABI explicit __has_one_state(__node<_CharT>* __s) : __first_(__s) {}
  1179. _LIBCPP_HIDE_FROM_ABI __node<_CharT>* first() const { return __first_; }
  1180. _LIBCPP_HIDE_FROM_ABI __node<_CharT>*& first() { return __first_; }
  1181. };
  1182. // __owns_one_state
  1183. template <class _CharT>
  1184. class __owns_one_state : public __has_one_state<_CharT> {
  1185. typedef __has_one_state<_CharT> base;
  1186. public:
  1187. _LIBCPP_HIDE_FROM_ABI explicit __owns_one_state(__node<_CharT>* __s) : base(__s) {}
  1188. ~__owns_one_state() override;
  1189. };
  1190. template <class _CharT>
  1191. __owns_one_state<_CharT>::~__owns_one_state() {
  1192. delete this->first();
  1193. }
  1194. // __empty_state
  1195. template <class _CharT>
  1196. class __empty_state : public __owns_one_state<_CharT> {
  1197. typedef __owns_one_state<_CharT> base;
  1198. public:
  1199. typedef std::__state<_CharT> __state;
  1200. _LIBCPP_HIDE_FROM_ABI explicit __empty_state(__node<_CharT>* __s) : base(__s) {}
  1201. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1202. };
  1203. template <class _CharT>
  1204. void __empty_state<_CharT>::__exec(__state& __s) const {
  1205. __s.__do_ = __state::__accept_but_not_consume;
  1206. __s.__node_ = this->first();
  1207. }
  1208. // __empty_non_own_state
  1209. template <class _CharT>
  1210. class __empty_non_own_state : public __has_one_state<_CharT> {
  1211. typedef __has_one_state<_CharT> base;
  1212. public:
  1213. typedef std::__state<_CharT> __state;
  1214. _LIBCPP_HIDE_FROM_ABI explicit __empty_non_own_state(__node<_CharT>* __s) : base(__s) {}
  1215. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1216. };
  1217. template <class _CharT>
  1218. void __empty_non_own_state<_CharT>::__exec(__state& __s) const {
  1219. __s.__do_ = __state::__accept_but_not_consume;
  1220. __s.__node_ = this->first();
  1221. }
  1222. // __repeat_one_loop
  1223. template <class _CharT>
  1224. class __repeat_one_loop : public __has_one_state<_CharT> {
  1225. typedef __has_one_state<_CharT> base;
  1226. public:
  1227. typedef std::__state<_CharT> __state;
  1228. _LIBCPP_HIDE_FROM_ABI explicit __repeat_one_loop(__node<_CharT>* __s) : base(__s) {}
  1229. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1230. };
  1231. template <class _CharT>
  1232. void __repeat_one_loop<_CharT>::__exec(__state& __s) const {
  1233. __s.__do_ = __state::__repeat;
  1234. __s.__node_ = this->first();
  1235. }
  1236. // __owns_two_states
  1237. template <class _CharT>
  1238. class __owns_two_states : public __owns_one_state<_CharT> {
  1239. typedef __owns_one_state<_CharT> base;
  1240. base* __second_;
  1241. public:
  1242. _LIBCPP_HIDE_FROM_ABI explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) : base(__s1), __second_(__s2) {}
  1243. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual ~__owns_two_states();
  1244. _LIBCPP_HIDE_FROM_ABI base* second() const { return __second_; }
  1245. _LIBCPP_HIDE_FROM_ABI base*& second() { return __second_; }
  1246. };
  1247. template <class _CharT>
  1248. __owns_two_states<_CharT>::~__owns_two_states() {
  1249. delete __second_;
  1250. }
  1251. // __loop
  1252. template <class _CharT>
  1253. class __loop : public __owns_two_states<_CharT> {
  1254. typedef __owns_two_states<_CharT> base;
  1255. size_t __min_;
  1256. size_t __max_;
  1257. unsigned __loop_id_;
  1258. unsigned __mexp_begin_;
  1259. unsigned __mexp_end_;
  1260. bool __greedy_;
  1261. public:
  1262. typedef std::__state<_CharT> __state;
  1263. _LIBCPP_HIDE_FROM_ABI explicit __loop(
  1264. unsigned __loop_id,
  1265. __node<_CharT>* __s1,
  1266. __owns_one_state<_CharT>* __s2,
  1267. unsigned __mexp_begin,
  1268. unsigned __mexp_end,
  1269. bool __greedy = true,
  1270. size_t __min = 0,
  1271. size_t __max = numeric_limits<size_t>::max())
  1272. : base(__s1, __s2),
  1273. __min_(__min),
  1274. __max_(__max),
  1275. __loop_id_(__loop_id),
  1276. __mexp_begin_(__mexp_begin),
  1277. __mexp_end_(__mexp_end),
  1278. __greedy_(__greedy) {}
  1279. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state& __s) const;
  1280. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec_split(bool __second, __state& __s) const;
  1281. private:
  1282. _LIBCPP_HIDE_FROM_ABI void __init_repeat(__state& __s) const {
  1283. __s.__loop_data_[__loop_id_].second = __s.__current_;
  1284. for (size_t __i = __mexp_begin_ - 1; __i != __mexp_end_ - 1; ++__i) {
  1285. __s.__sub_matches_[__i].first = __s.__last_;
  1286. __s.__sub_matches_[__i].second = __s.__last_;
  1287. __s.__sub_matches_[__i].matched = false;
  1288. }
  1289. }
  1290. };
  1291. template <class _CharT>
  1292. void __loop<_CharT>::__exec(__state& __s) const {
  1293. if (__s.__do_ == __state::__repeat) {
  1294. bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
  1295. bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
  1296. if (__do_repeat && __do_alt && __s.__loop_data_[__loop_id_].second == __s.__current_)
  1297. __do_repeat = false;
  1298. if (__do_repeat && __do_alt)
  1299. __s.__do_ = __state::__split;
  1300. else if (__do_repeat) {
  1301. __s.__do_ = __state::__accept_but_not_consume;
  1302. __s.__node_ = this->first();
  1303. __init_repeat(__s);
  1304. } else {
  1305. __s.__do_ = __state::__accept_but_not_consume;
  1306. __s.__node_ = this->second();
  1307. }
  1308. } else {
  1309. __s.__loop_data_[__loop_id_].first = 0;
  1310. bool __do_repeat = 0 < __max_;
  1311. bool __do_alt = 0 >= __min_;
  1312. if (__do_repeat && __do_alt)
  1313. __s.__do_ = __state::__split;
  1314. else if (__do_repeat) {
  1315. __s.__do_ = __state::__accept_but_not_consume;
  1316. __s.__node_ = this->first();
  1317. __init_repeat(__s);
  1318. } else {
  1319. __s.__do_ = __state::__accept_but_not_consume;
  1320. __s.__node_ = this->second();
  1321. }
  1322. }
  1323. }
  1324. template <class _CharT>
  1325. void __loop<_CharT>::__exec_split(bool __second, __state& __s) const {
  1326. __s.__do_ = __state::__accept_but_not_consume;
  1327. if (__greedy_ != __second) {
  1328. __s.__node_ = this->first();
  1329. __init_repeat(__s);
  1330. } else
  1331. __s.__node_ = this->second();
  1332. }
  1333. // __alternate
  1334. template <class _CharT>
  1335. class __alternate : public __owns_two_states<_CharT> {
  1336. typedef __owns_two_states<_CharT> base;
  1337. public:
  1338. typedef std::__state<_CharT> __state;
  1339. _LIBCPP_HIDE_FROM_ABI explicit __alternate(__owns_one_state<_CharT>* __s1, __owns_one_state<_CharT>* __s2)
  1340. : base(__s1, __s2) {}
  1341. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state& __s) const;
  1342. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec_split(bool __second, __state& __s) const;
  1343. };
  1344. template <class _CharT>
  1345. void __alternate<_CharT>::__exec(__state& __s) const {
  1346. __s.__do_ = __state::__split;
  1347. }
  1348. template <class _CharT>
  1349. void __alternate<_CharT>::__exec_split(bool __second, __state& __s) const {
  1350. __s.__do_ = __state::__accept_but_not_consume;
  1351. if (__second)
  1352. __s.__node_ = this->second();
  1353. else
  1354. __s.__node_ = this->first();
  1355. }
  1356. // __begin_marked_subexpression
  1357. template <class _CharT>
  1358. class __begin_marked_subexpression : public __owns_one_state<_CharT> {
  1359. typedef __owns_one_state<_CharT> base;
  1360. unsigned __mexp_;
  1361. public:
  1362. typedef std::__state<_CharT> __state;
  1363. _LIBCPP_HIDE_FROM_ABI explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
  1364. : base(__s), __mexp_(__mexp) {}
  1365. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1366. };
  1367. template <class _CharT>
  1368. void __begin_marked_subexpression<_CharT>::__exec(__state& __s) const {
  1369. __s.__do_ = __state::__accept_but_not_consume;
  1370. __s.__sub_matches_[__mexp_ - 1].first = __s.__current_;
  1371. __s.__node_ = this->first();
  1372. }
  1373. // __end_marked_subexpression
  1374. template <class _CharT>
  1375. class __end_marked_subexpression : public __owns_one_state<_CharT> {
  1376. typedef __owns_one_state<_CharT> base;
  1377. unsigned __mexp_;
  1378. public:
  1379. typedef std::__state<_CharT> __state;
  1380. _LIBCPP_HIDE_FROM_ABI explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
  1381. : base(__s), __mexp_(__mexp) {}
  1382. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1383. };
  1384. template <class _CharT>
  1385. void __end_marked_subexpression<_CharT>::__exec(__state& __s) const {
  1386. __s.__do_ = __state::__accept_but_not_consume;
  1387. __s.__sub_matches_[__mexp_ - 1].second = __s.__current_;
  1388. __s.__sub_matches_[__mexp_ - 1].matched = true;
  1389. __s.__node_ = this->first();
  1390. }
  1391. // __back_ref
  1392. template <class _CharT>
  1393. class __back_ref : public __owns_one_state<_CharT> {
  1394. typedef __owns_one_state<_CharT> base;
  1395. unsigned __mexp_;
  1396. public:
  1397. typedef std::__state<_CharT> __state;
  1398. _LIBCPP_HIDE_FROM_ABI explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) : base(__s), __mexp_(__mexp) {}
  1399. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1400. };
  1401. template <class _CharT>
  1402. void __back_ref<_CharT>::__exec(__state& __s) const {
  1403. if (__mexp_ > __s.__sub_matches_.size())
  1404. __throw_regex_error<regex_constants::error_backref>();
  1405. sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_ - 1];
  1406. if (__sm.matched) {
  1407. ptrdiff_t __len = __sm.second - __sm.first;
  1408. if (__s.__last_ - __s.__current_ >= __len && std::equal(__sm.first, __sm.second, __s.__current_)) {
  1409. __s.__do_ = __state::__accept_but_not_consume;
  1410. __s.__current_ += __len;
  1411. __s.__node_ = this->first();
  1412. } else {
  1413. __s.__do_ = __state::__reject;
  1414. __s.__node_ = nullptr;
  1415. }
  1416. } else {
  1417. __s.__do_ = __state::__reject;
  1418. __s.__node_ = nullptr;
  1419. }
  1420. }
  1421. // __back_ref_icase
  1422. template <class _CharT, class _Traits>
  1423. class __back_ref_icase : public __owns_one_state<_CharT> {
  1424. typedef __owns_one_state<_CharT> base;
  1425. _Traits __traits_;
  1426. unsigned __mexp_;
  1427. public:
  1428. typedef std::__state<_CharT> __state;
  1429. _LIBCPP_HIDE_FROM_ABI explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, __node<_CharT>* __s)
  1430. : base(__s), __traits_(__traits), __mexp_(__mexp) {}
  1431. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1432. };
  1433. template <class _CharT, class _Traits>
  1434. void __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const {
  1435. sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_ - 1];
  1436. if (__sm.matched) {
  1437. ptrdiff_t __len = __sm.second - __sm.first;
  1438. if (__s.__last_ - __s.__current_ >= __len) {
  1439. for (ptrdiff_t __i = 0; __i < __len; ++__i) {
  1440. if (__traits_.translate_nocase(__sm.first[__i]) != __traits_.translate_nocase(__s.__current_[__i]))
  1441. goto __not_equal;
  1442. }
  1443. __s.__do_ = __state::__accept_but_not_consume;
  1444. __s.__current_ += __len;
  1445. __s.__node_ = this->first();
  1446. } else {
  1447. __s.__do_ = __state::__reject;
  1448. __s.__node_ = nullptr;
  1449. }
  1450. } else {
  1451. __not_equal:
  1452. __s.__do_ = __state::__reject;
  1453. __s.__node_ = nullptr;
  1454. }
  1455. }
  1456. // __back_ref_collate
  1457. template <class _CharT, class _Traits>
  1458. class __back_ref_collate : public __owns_one_state<_CharT> {
  1459. typedef __owns_one_state<_CharT> base;
  1460. _Traits __traits_;
  1461. unsigned __mexp_;
  1462. public:
  1463. typedef std::__state<_CharT> __state;
  1464. _LIBCPP_HIDE_FROM_ABI explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, __node<_CharT>* __s)
  1465. : base(__s), __traits_(__traits), __mexp_(__mexp) {}
  1466. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1467. };
  1468. template <class _CharT, class _Traits>
  1469. void __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const {
  1470. sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_ - 1];
  1471. if (__sm.matched) {
  1472. ptrdiff_t __len = __sm.second - __sm.first;
  1473. if (__s.__last_ - __s.__current_ >= __len) {
  1474. for (ptrdiff_t __i = 0; __i < __len; ++__i) {
  1475. if (__traits_.translate(__sm.first[__i]) != __traits_.translate(__s.__current_[__i]))
  1476. goto __not_equal;
  1477. }
  1478. __s.__do_ = __state::__accept_but_not_consume;
  1479. __s.__current_ += __len;
  1480. __s.__node_ = this->first();
  1481. } else {
  1482. __s.__do_ = __state::__reject;
  1483. __s.__node_ = nullptr;
  1484. }
  1485. } else {
  1486. __not_equal:
  1487. __s.__do_ = __state::__reject;
  1488. __s.__node_ = nullptr;
  1489. }
  1490. }
  1491. // __word_boundary
  1492. template <class _CharT, class _Traits>
  1493. class __word_boundary : public __owns_one_state<_CharT> {
  1494. typedef __owns_one_state<_CharT> base;
  1495. _Traits __traits_;
  1496. bool __invert_;
  1497. public:
  1498. typedef std::__state<_CharT> __state;
  1499. _LIBCPP_HIDE_FROM_ABI explicit __word_boundary(const _Traits& __traits, bool __invert, __node<_CharT>* __s)
  1500. : base(__s), __traits_(__traits), __invert_(__invert) {}
  1501. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1502. };
  1503. template <class _CharT, class _Traits>
  1504. void __word_boundary<_CharT, _Traits>::__exec(__state& __s) const {
  1505. bool __is_word_b = false;
  1506. if (__s.__first_ != __s.__last_) {
  1507. if (__s.__current_ == __s.__last_) {
  1508. if (!(__s.__flags_ & regex_constants::match_not_eow)) {
  1509. _CharT __c = __s.__current_[-1];
  1510. __is_word_b = __c == '_' || __traits_.isctype(__c, ctype_base::alnum);
  1511. }
  1512. } else if (__s.__current_ == __s.__first_ && !(__s.__flags_ & regex_constants::match_prev_avail)) {
  1513. if (!(__s.__flags_ & regex_constants::match_not_bow)) {
  1514. _CharT __c = *__s.__current_;
  1515. __is_word_b = __c == '_' || __traits_.isctype(__c, ctype_base::alnum);
  1516. }
  1517. } else {
  1518. _CharT __c1 = __s.__current_[-1];
  1519. _CharT __c2 = *__s.__current_;
  1520. bool __is_c1_b = __c1 == '_' || __traits_.isctype(__c1, ctype_base::alnum);
  1521. bool __is_c2_b = __c2 == '_' || __traits_.isctype(__c2, ctype_base::alnum);
  1522. __is_word_b = __is_c1_b != __is_c2_b;
  1523. }
  1524. }
  1525. if (__is_word_b != __invert_) {
  1526. __s.__do_ = __state::__accept_but_not_consume;
  1527. __s.__node_ = this->first();
  1528. } else {
  1529. __s.__do_ = __state::__reject;
  1530. __s.__node_ = nullptr;
  1531. }
  1532. }
  1533. // __l_anchor
  1534. template <class _CharT>
  1535. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __is_eol(_CharT __c) {
  1536. return __c == '\r' || __c == '\n';
  1537. }
  1538. template <class _CharT>
  1539. class __l_anchor_multiline : public __owns_one_state<_CharT> {
  1540. typedef __owns_one_state<_CharT> base;
  1541. bool __multiline_;
  1542. public:
  1543. typedef std::__state<_CharT> __state;
  1544. _LIBCPP_HIDE_FROM_ABI __l_anchor_multiline(bool __multiline, __node<_CharT>* __s)
  1545. : base(__s), __multiline_(__multiline) {}
  1546. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1547. };
  1548. template <class _CharT>
  1549. void __l_anchor_multiline<_CharT>::__exec(__state& __s) const {
  1550. if (__s.__at_first_ && __s.__current_ == __s.__first_ && !(__s.__flags_ & regex_constants::match_not_bol)) {
  1551. __s.__do_ = __state::__accept_but_not_consume;
  1552. __s.__node_ = this->first();
  1553. } else if (__multiline_ && !__s.__at_first_ && std::__is_eol(*std::prev(__s.__current_))) {
  1554. __s.__do_ = __state::__accept_but_not_consume;
  1555. __s.__node_ = this->first();
  1556. } else {
  1557. __s.__do_ = __state::__reject;
  1558. __s.__node_ = nullptr;
  1559. }
  1560. }
  1561. // __r_anchor
  1562. template <class _CharT>
  1563. class __r_anchor_multiline : public __owns_one_state<_CharT> {
  1564. typedef __owns_one_state<_CharT> base;
  1565. bool __multiline_;
  1566. public:
  1567. typedef std::__state<_CharT> __state;
  1568. _LIBCPP_HIDE_FROM_ABI __r_anchor_multiline(bool __multiline, __node<_CharT>* __s)
  1569. : base(__s), __multiline_(__multiline) {}
  1570. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1571. };
  1572. template <class _CharT>
  1573. void __r_anchor_multiline<_CharT>::__exec(__state& __s) const {
  1574. if (__s.__current_ == __s.__last_ && !(__s.__flags_ & regex_constants::match_not_eol)) {
  1575. __s.__do_ = __state::__accept_but_not_consume;
  1576. __s.__node_ = this->first();
  1577. } else if (__multiline_ && std::__is_eol(*__s.__current_)) {
  1578. __s.__do_ = __state::__accept_but_not_consume;
  1579. __s.__node_ = this->first();
  1580. } else {
  1581. __s.__do_ = __state::__reject;
  1582. __s.__node_ = nullptr;
  1583. }
  1584. }
  1585. // __match_any
  1586. template <class _CharT>
  1587. class __match_any : public __owns_one_state<_CharT> {
  1588. typedef __owns_one_state<_CharT> base;
  1589. public:
  1590. typedef std::__state<_CharT> __state;
  1591. _LIBCPP_HIDE_FROM_ABI __match_any(__node<_CharT>* __s) : base(__s) {}
  1592. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1593. };
  1594. template <class _CharT>
  1595. void __match_any<_CharT>::__exec(__state& __s) const {
  1596. if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) {
  1597. __s.__do_ = __state::__accept_and_consume;
  1598. ++__s.__current_;
  1599. __s.__node_ = this->first();
  1600. } else {
  1601. __s.__do_ = __state::__reject;
  1602. __s.__node_ = nullptr;
  1603. }
  1604. }
  1605. // __match_any_but_newline
  1606. template <class _CharT>
  1607. class __match_any_but_newline : public __owns_one_state<_CharT> {
  1608. typedef __owns_one_state<_CharT> base;
  1609. public:
  1610. typedef std::__state<_CharT> __state;
  1611. _LIBCPP_HIDE_FROM_ABI __match_any_but_newline(__node<_CharT>* __s) : base(__s) {}
  1612. void __exec(__state&) const override;
  1613. };
  1614. template <>
  1615. _LIBCPP_EXPORTED_FROM_ABI void __match_any_but_newline<char>::__exec(__state&) const;
  1616. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1617. template <>
  1618. _LIBCPP_EXPORTED_FROM_ABI void __match_any_but_newline<wchar_t>::__exec(__state&) const;
  1619. #endif
  1620. // __match_char
  1621. template <class _CharT>
  1622. class __match_char : public __owns_one_state<_CharT> {
  1623. typedef __owns_one_state<_CharT> base;
  1624. _CharT __c_;
  1625. __match_char(const __match_char&);
  1626. __match_char& operator=(const __match_char&);
  1627. public:
  1628. typedef std::__state<_CharT> __state;
  1629. _LIBCPP_HIDE_FROM_ABI __match_char(_CharT __c, __node<_CharT>* __s) : base(__s), __c_(__c) {}
  1630. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1631. };
  1632. template <class _CharT>
  1633. void __match_char<_CharT>::__exec(__state& __s) const {
  1634. if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) {
  1635. __s.__do_ = __state::__accept_and_consume;
  1636. ++__s.__current_;
  1637. __s.__node_ = this->first();
  1638. } else {
  1639. __s.__do_ = __state::__reject;
  1640. __s.__node_ = nullptr;
  1641. }
  1642. }
  1643. // __match_char_icase
  1644. template <class _CharT, class _Traits>
  1645. class __match_char_icase : public __owns_one_state<_CharT> {
  1646. typedef __owns_one_state<_CharT> base;
  1647. _Traits __traits_;
  1648. _CharT __c_;
  1649. __match_char_icase(const __match_char_icase&);
  1650. __match_char_icase& operator=(const __match_char_icase&);
  1651. public:
  1652. typedef std::__state<_CharT> __state;
  1653. _LIBCPP_HIDE_FROM_ABI __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
  1654. : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
  1655. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1656. };
  1657. template <class _CharT, class _Traits>
  1658. void __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const {
  1659. if (__s.__current_ != __s.__last_ && __traits_.translate_nocase(*__s.__current_) == __c_) {
  1660. __s.__do_ = __state::__accept_and_consume;
  1661. ++__s.__current_;
  1662. __s.__node_ = this->first();
  1663. } else {
  1664. __s.__do_ = __state::__reject;
  1665. __s.__node_ = nullptr;
  1666. }
  1667. }
  1668. // __match_char_collate
  1669. template <class _CharT, class _Traits>
  1670. class __match_char_collate : public __owns_one_state<_CharT> {
  1671. typedef __owns_one_state<_CharT> base;
  1672. _Traits __traits_;
  1673. _CharT __c_;
  1674. __match_char_collate(const __match_char_collate&);
  1675. __match_char_collate& operator=(const __match_char_collate&);
  1676. public:
  1677. typedef std::__state<_CharT> __state;
  1678. _LIBCPP_HIDE_FROM_ABI __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
  1679. : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
  1680. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1681. };
  1682. template <class _CharT, class _Traits>
  1683. void __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const {
  1684. if (__s.__current_ != __s.__last_ && __traits_.translate(*__s.__current_) == __c_) {
  1685. __s.__do_ = __state::__accept_and_consume;
  1686. ++__s.__current_;
  1687. __s.__node_ = this->first();
  1688. } else {
  1689. __s.__do_ = __state::__reject;
  1690. __s.__node_ = nullptr;
  1691. }
  1692. }
  1693. // __bracket_expression
  1694. template <class _CharT, class _Traits>
  1695. class __bracket_expression : public __owns_one_state<_CharT> {
  1696. typedef __owns_one_state<_CharT> base;
  1697. typedef typename _Traits::string_type string_type;
  1698. _Traits __traits_;
  1699. vector<_CharT> __chars_;
  1700. vector<_CharT> __neg_chars_;
  1701. vector<pair<string_type, string_type> > __ranges_;
  1702. vector<pair<_CharT, _CharT> > __digraphs_;
  1703. vector<string_type> __equivalences_;
  1704. typename regex_traits<_CharT>::char_class_type __mask_;
  1705. typename regex_traits<_CharT>::char_class_type __neg_mask_;
  1706. bool __negate_;
  1707. bool __icase_;
  1708. bool __collate_;
  1709. bool __might_have_digraph_;
  1710. __bracket_expression(const __bracket_expression&);
  1711. __bracket_expression& operator=(const __bracket_expression&);
  1712. public:
  1713. typedef std::__state<_CharT> __state;
  1714. _LIBCPP_HIDE_FROM_ABI
  1715. __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, bool __negate, bool __icase, bool __collate)
  1716. : base(__s),
  1717. __traits_(__traits),
  1718. __mask_(),
  1719. __neg_mask_(),
  1720. __negate_(__negate),
  1721. __icase_(__icase),
  1722. __collate_(__collate),
  1723. __might_have_digraph_(__traits_.getloc().name() != "C") {}
  1724. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  1725. _LIBCPP_HIDE_FROM_ABI bool __negated() const { return __negate_; }
  1726. _LIBCPP_HIDE_FROM_ABI void __add_char(_CharT __c) {
  1727. if (__icase_)
  1728. __chars_.push_back(__traits_.translate_nocase(__c));
  1729. else if (__collate_)
  1730. __chars_.push_back(__traits_.translate(__c));
  1731. else
  1732. __chars_.push_back(__c);
  1733. }
  1734. _LIBCPP_HIDE_FROM_ABI void __add_neg_char(_CharT __c) {
  1735. if (__icase_)
  1736. __neg_chars_.push_back(__traits_.translate_nocase(__c));
  1737. else if (__collate_)
  1738. __neg_chars_.push_back(__traits_.translate(__c));
  1739. else
  1740. __neg_chars_.push_back(__c);
  1741. }
  1742. _LIBCPP_HIDE_FROM_ABI void __add_range(string_type __b, string_type __e) {
  1743. if (__collate_) {
  1744. if (__icase_) {
  1745. for (size_t __i = 0; __i < __b.size(); ++__i)
  1746. __b[__i] = __traits_.translate_nocase(__b[__i]);
  1747. for (size_t __i = 0; __i < __e.size(); ++__i)
  1748. __e[__i] = __traits_.translate_nocase(__e[__i]);
  1749. } else {
  1750. for (size_t __i = 0; __i < __b.size(); ++__i)
  1751. __b[__i] = __traits_.translate(__b[__i]);
  1752. for (size_t __i = 0; __i < __e.size(); ++__i)
  1753. __e[__i] = __traits_.translate(__e[__i]);
  1754. }
  1755. __ranges_.push_back(
  1756. std::make_pair(__traits_.transform(__b.begin(), __b.end()), __traits_.transform(__e.begin(), __e.end())));
  1757. } else {
  1758. if (__b.size() != 1 || __e.size() != 1)
  1759. __throw_regex_error<regex_constants::error_range>();
  1760. if (__icase_) {
  1761. __b[0] = __traits_.translate_nocase(__b[0]);
  1762. __e[0] = __traits_.translate_nocase(__e[0]);
  1763. }
  1764. __ranges_.push_back(std::make_pair(std::move(__b), std::move(__e)));
  1765. }
  1766. }
  1767. _LIBCPP_HIDE_FROM_ABI void __add_digraph(_CharT __c1, _CharT __c2) {
  1768. if (__icase_)
  1769. __digraphs_.push_back(std::make_pair(__traits_.translate_nocase(__c1), __traits_.translate_nocase(__c2)));
  1770. else if (__collate_)
  1771. __digraphs_.push_back(std::make_pair(__traits_.translate(__c1), __traits_.translate(__c2)));
  1772. else
  1773. __digraphs_.push_back(std::make_pair(__c1, __c2));
  1774. }
  1775. _LIBCPP_HIDE_FROM_ABI void __add_equivalence(const string_type& __s) { __equivalences_.push_back(__s); }
  1776. _LIBCPP_HIDE_FROM_ABI void __add_class(typename regex_traits<_CharT>::char_class_type __mask) { __mask_ |= __mask; }
  1777. _LIBCPP_HIDE_FROM_ABI void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) {
  1778. __neg_mask_ |= __mask;
  1779. }
  1780. };
  1781. template <class _CharT, class _Traits>
  1782. void __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const {
  1783. bool __found = false;
  1784. unsigned __consumed = 0;
  1785. if (__s.__current_ != __s.__last_) {
  1786. ++__consumed;
  1787. if (__might_have_digraph_) {
  1788. const _CharT* __next = std::next(__s.__current_);
  1789. if (__next != __s.__last_) {
  1790. pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
  1791. if (__icase_) {
  1792. __ch2.first = __traits_.translate_nocase(__ch2.first);
  1793. __ch2.second = __traits_.translate_nocase(__ch2.second);
  1794. } else if (__collate_) {
  1795. __ch2.first = __traits_.translate(__ch2.first);
  1796. __ch2.second = __traits_.translate(__ch2.second);
  1797. }
  1798. if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first + 2).empty()) {
  1799. // __ch2 is a digraph in this locale
  1800. ++__consumed;
  1801. for (size_t __i = 0; __i < __digraphs_.size(); ++__i) {
  1802. if (__ch2 == __digraphs_[__i]) {
  1803. __found = true;
  1804. goto __exit;
  1805. }
  1806. }
  1807. if (__collate_ && !__ranges_.empty()) {
  1808. string_type __s2 = __traits_.transform(&__ch2.first, &__ch2.first + 2);
  1809. for (size_t __i = 0; __i < __ranges_.size(); ++__i) {
  1810. if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) {
  1811. __found = true;
  1812. goto __exit;
  1813. }
  1814. }
  1815. }
  1816. if (!__equivalences_.empty()) {
  1817. string_type __s2 = __traits_.transform_primary(&__ch2.first, &__ch2.first + 2);
  1818. for (size_t __i = 0; __i < __equivalences_.size(); ++__i) {
  1819. if (__s2 == __equivalences_[__i]) {
  1820. __found = true;
  1821. goto __exit;
  1822. }
  1823. }
  1824. }
  1825. if (__traits_.isctype(__ch2.first, __mask_) && __traits_.isctype(__ch2.second, __mask_)) {
  1826. __found = true;
  1827. goto __exit;
  1828. }
  1829. if (!__traits_.isctype(__ch2.first, __neg_mask_) && !__traits_.isctype(__ch2.second, __neg_mask_)) {
  1830. __found = true;
  1831. goto __exit;
  1832. }
  1833. goto __exit;
  1834. }
  1835. }
  1836. }
  1837. // test *__s.__current_ as not a digraph
  1838. _CharT __ch = *__s.__current_;
  1839. if (__icase_)
  1840. __ch = __traits_.translate_nocase(__ch);
  1841. else if (__collate_)
  1842. __ch = __traits_.translate(__ch);
  1843. for (size_t __i = 0; __i < __chars_.size(); ++__i) {
  1844. if (__ch == __chars_[__i]) {
  1845. __found = true;
  1846. goto __exit;
  1847. }
  1848. }
  1849. // When there's at least one of __neg_chars_ and __neg_mask_, the set
  1850. // of "__found" chars is
  1851. // union(complement(union(__neg_chars_, __neg_mask_)),
  1852. // other cases...)
  1853. //
  1854. // It doesn't make sense to check this when there are no __neg_chars_
  1855. // and no __neg_mask_.
  1856. if (!(__neg_mask_ == 0 && __neg_chars_.empty())) {
  1857. const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_);
  1858. const bool __in_neg_chars = std::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != __neg_chars_.end();
  1859. if (!(__in_neg_mask || __in_neg_chars)) {
  1860. __found = true;
  1861. goto __exit;
  1862. }
  1863. }
  1864. if (!__ranges_.empty()) {
  1865. string_type __s2 = __collate_ ? __traits_.transform(&__ch, &__ch + 1) : string_type(1, __ch);
  1866. for (size_t __i = 0; __i < __ranges_.size(); ++__i) {
  1867. if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) {
  1868. __found = true;
  1869. goto __exit;
  1870. }
  1871. }
  1872. }
  1873. if (!__equivalences_.empty()) {
  1874. string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
  1875. for (size_t __i = 0; __i < __equivalences_.size(); ++__i) {
  1876. if (__s2 == __equivalences_[__i]) {
  1877. __found = true;
  1878. goto __exit;
  1879. }
  1880. }
  1881. }
  1882. if (__traits_.isctype(__ch, __mask_)) {
  1883. __found = true;
  1884. goto __exit;
  1885. }
  1886. } else
  1887. __found = __negate_; // force reject
  1888. __exit:
  1889. if (__found != __negate_) {
  1890. __s.__do_ = __state::__accept_and_consume;
  1891. __s.__current_ += __consumed;
  1892. __s.__node_ = this->first();
  1893. } else {
  1894. __s.__do_ = __state::__reject;
  1895. __s.__node_ = nullptr;
  1896. }
  1897. }
  1898. template <class _CharT, class _Traits>
  1899. class __lookahead;
  1900. template <class _CharT, class _Traits = regex_traits<_CharT> >
  1901. class _LIBCPP_TEMPLATE_VIS basic_regex;
  1902. typedef basic_regex<char> regex;
  1903. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1904. typedef basic_regex<wchar_t> wregex;
  1905. #endif
  1906. template <class _CharT, class _Traits>
  1907. class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(regex)
  1908. _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex)) basic_regex {
  1909. public:
  1910. // types:
  1911. typedef _CharT value_type;
  1912. typedef _Traits traits_type;
  1913. typedef typename _Traits::string_type string_type;
  1914. typedef regex_constants::syntax_option_type flag_type;
  1915. typedef typename _Traits::locale_type locale_type;
  1916. private:
  1917. _Traits __traits_;
  1918. flag_type __flags_;
  1919. unsigned __marked_count_;
  1920. unsigned __loop_count_;
  1921. int __open_count_;
  1922. shared_ptr<__empty_state<_CharT> > __start_;
  1923. __owns_one_state<_CharT>* __end_;
  1924. typedef std::__state<_CharT> __state;
  1925. typedef std::__node<_CharT> __node;
  1926. public:
  1927. // constants:
  1928. static const regex_constants::syntax_option_type icase = regex_constants::icase;
  1929. static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
  1930. static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
  1931. static const regex_constants::syntax_option_type collate = regex_constants::collate;
  1932. static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
  1933. static const regex_constants::syntax_option_type basic = regex_constants::basic;
  1934. static const regex_constants::syntax_option_type extended = regex_constants::extended;
  1935. static const regex_constants::syntax_option_type awk = regex_constants::awk;
  1936. static const regex_constants::syntax_option_type grep = regex_constants::grep;
  1937. static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
  1938. static const regex_constants::syntax_option_type multiline = regex_constants::multiline;
  1939. // construct/copy/destroy:
  1940. _LIBCPP_HIDE_FROM_ABI basic_regex()
  1941. : __flags_(regex_constants::ECMAScript),
  1942. __marked_count_(0),
  1943. __loop_count_(0),
  1944. __open_count_(0),
  1945. __end_(nullptr) {}
  1946. _LIBCPP_HIDE_FROM_ABI explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
  1947. : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
  1948. __init(__p, __p + __traits_.length(__p));
  1949. }
  1950. _LIBCPP_HIDE_FROM_ABI basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
  1951. : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
  1952. __init(__p, __p + __len);
  1953. }
  1954. // basic_regex(const basic_regex&) = default;
  1955. // basic_regex(basic_regex&&) = default;
  1956. template <class _ST, class _SA>
  1957. _LIBCPP_HIDE_FROM_ABI explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
  1958. flag_type __f = regex_constants::ECMAScript)
  1959. : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
  1960. __init(__p.begin(), __p.end());
  1961. }
  1962. template <class _ForwardIterator>
  1963. _LIBCPP_HIDE_FROM_ABI
  1964. basic_regex(_ForwardIterator __first, _ForwardIterator __last, flag_type __f = regex_constants::ECMAScript)
  1965. : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
  1966. __init(__first, __last);
  1967. }
  1968. #ifndef _LIBCPP_CXX03_LANG
  1969. _LIBCPP_HIDE_FROM_ABI basic_regex(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript)
  1970. : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
  1971. __init(__il.begin(), __il.end());
  1972. }
  1973. #endif // _LIBCPP_CXX03_LANG
  1974. // ~basic_regex() = default;
  1975. // basic_regex& operator=(const basic_regex&) = default;
  1976. // basic_regex& operator=(basic_regex&&) = default;
  1977. _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(const value_type* __p) { return assign(__p); }
  1978. #ifndef _LIBCPP_CXX03_LANG
  1979. _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(initializer_list<value_type> __il) { return assign(__il); }
  1980. #endif // _LIBCPP_CXX03_LANG
  1981. template <class _ST, class _SA>
  1982. _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) {
  1983. return assign(__p);
  1984. }
  1985. // assign:
  1986. _LIBCPP_HIDE_FROM_ABI basic_regex& assign(const basic_regex& __that) { return *this = __that; }
  1987. #ifndef _LIBCPP_CXX03_LANG
  1988. _LIBCPP_HIDE_FROM_ABI basic_regex& assign(basic_regex&& __that) _NOEXCEPT { return *this = std::move(__that); }
  1989. #endif
  1990. _LIBCPP_HIDE_FROM_ABI basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) {
  1991. return assign(__p, __p + __traits_.length(__p), __f);
  1992. }
  1993. _LIBCPP_HIDE_FROM_ABI basic_regex&
  1994. assign(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript) {
  1995. return assign(__p, __p + __len, __f);
  1996. }
  1997. template <class _ST, class _SA>
  1998. _LIBCPP_HIDE_FROM_ABI basic_regex&
  1999. assign(const basic_string<value_type, _ST, _SA>& __s, flag_type __f = regex_constants::ECMAScript) {
  2000. return assign(__s.begin(), __s.end(), __f);
  2001. }
  2002. template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
  2003. _LIBCPP_HIDE_FROM_ABI basic_regex&
  2004. assign(_InputIterator __first, _InputIterator __last, flag_type __f = regex_constants::ECMAScript) {
  2005. basic_string<_CharT> __t(__first, __last);
  2006. return assign(__t.begin(), __t.end(), __f);
  2007. }
  2008. private:
  2009. _LIBCPP_HIDE_FROM_ABI void __member_init(flag_type __f) {
  2010. __flags_ = __f;
  2011. __marked_count_ = 0;
  2012. __loop_count_ = 0;
  2013. __open_count_ = 0;
  2014. __end_ = nullptr;
  2015. }
  2016. public:
  2017. template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
  2018. _LIBCPP_HIDE_FROM_ABI basic_regex&
  2019. assign(_ForwardIterator __first, _ForwardIterator __last, flag_type __f = regex_constants::ECMAScript) {
  2020. return assign(basic_regex(__first, __last, __f));
  2021. }
  2022. #ifndef _LIBCPP_CXX03_LANG
  2023. _LIBCPP_HIDE_FROM_ABI basic_regex&
  2024. assign(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript) {
  2025. return assign(__il.begin(), __il.end(), __f);
  2026. }
  2027. #endif // _LIBCPP_CXX03_LANG
  2028. // const operations:
  2029. _LIBCPP_HIDE_FROM_ABI unsigned mark_count() const { return __marked_count_; }
  2030. _LIBCPP_HIDE_FROM_ABI flag_type flags() const { return __flags_; }
  2031. // locale:
  2032. _LIBCPP_HIDE_FROM_ABI locale_type imbue(locale_type __loc) {
  2033. __member_init(ECMAScript);
  2034. __start_.reset();
  2035. return __traits_.imbue(__loc);
  2036. }
  2037. _LIBCPP_HIDE_FROM_ABI locale_type getloc() const { return __traits_.getloc(); }
  2038. // swap:
  2039. void swap(basic_regex& __r);
  2040. private:
  2041. _LIBCPP_HIDE_FROM_ABI unsigned __loop_count() const { return __loop_count_; }
  2042. _LIBCPP_HIDE_FROM_ABI bool __use_multiline() const {
  2043. return __get_grammar(__flags_) == ECMAScript && (__flags_ & multiline);
  2044. }
  2045. template <class _ForwardIterator>
  2046. void __init(_ForwardIterator __first, _ForwardIterator __last);
  2047. template <class _ForwardIterator>
  2048. _ForwardIterator __parse(_ForwardIterator __first, _ForwardIterator __last);
  2049. template <class _ForwardIterator>
  2050. _ForwardIterator __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
  2051. template <class _ForwardIterator>
  2052. _ForwardIterator __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
  2053. template <class _ForwardIterator>
  2054. _ForwardIterator __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
  2055. template <class _ForwardIterator>
  2056. _ForwardIterator __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
  2057. template <class _ForwardIterator>
  2058. _ForwardIterator __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
  2059. template <class _ForwardIterator>
  2060. _ForwardIterator __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
  2061. template <class _ForwardIterator>
  2062. _ForwardIterator __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
  2063. template <class _ForwardIterator>
  2064. _ForwardIterator __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
  2065. template <class _ForwardIterator>
  2066. _ForwardIterator __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
  2067. template <class _ForwardIterator>
  2068. _ForwardIterator __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
  2069. template <class _ForwardIterator>
  2070. _ForwardIterator __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
  2071. template <class _ForwardIterator>
  2072. _ForwardIterator __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
  2073. template <class _ForwardIterator>
  2074. _ForwardIterator __parse_RE_dupl_symbol(
  2075. _ForwardIterator __first,
  2076. _ForwardIterator __last,
  2077. __owns_one_state<_CharT>* __s,
  2078. unsigned __mexp_begin,
  2079. unsigned __mexp_end);
  2080. template <class _ForwardIterator>
  2081. _ForwardIterator __parse_ERE_dupl_symbol(
  2082. _ForwardIterator __first,
  2083. _ForwardIterator __last,
  2084. __owns_one_state<_CharT>* __s,
  2085. unsigned __mexp_begin,
  2086. unsigned __mexp_end);
  2087. template <class _ForwardIterator>
  2088. _ForwardIterator __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
  2089. template <class _ForwardIterator>
  2090. _ForwardIterator
  2091. __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
  2092. template <class _ForwardIterator>
  2093. _ForwardIterator __parse_expression_term(
  2094. _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
  2095. template <class _ForwardIterator>
  2096. _ForwardIterator __parse_equivalence_class(
  2097. _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
  2098. template <class _ForwardIterator>
  2099. _ForwardIterator __parse_character_class(
  2100. _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
  2101. template <class _ForwardIterator>
  2102. _ForwardIterator
  2103. __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>& __col_sym);
  2104. template <class _ForwardIterator>
  2105. _ForwardIterator __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
  2106. template <class _ForwardIterator>
  2107. _ForwardIterator __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
  2108. template <class _ForwardIterator>
  2109. _ForwardIterator __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
  2110. template <class _ForwardIterator>
  2111. _ForwardIterator __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
  2112. template <class _ForwardIterator>
  2113. _ForwardIterator __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
  2114. template <class _ForwardIterator>
  2115. _ForwardIterator __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
  2116. template <class _ForwardIterator>
  2117. _ForwardIterator __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
  2118. template <class _ForwardIterator>
  2119. _ForwardIterator __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
  2120. template <class _ForwardIterator>
  2121. _ForwardIterator __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
  2122. template <class _ForwardIterator>
  2123. _ForwardIterator __parse_term(_ForwardIterator __first, _ForwardIterator __last);
  2124. template <class _ForwardIterator>
  2125. _ForwardIterator __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
  2126. template <class _ForwardIterator>
  2127. _ForwardIterator __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
  2128. template <class _ForwardIterator>
  2129. _ForwardIterator __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
  2130. template <class _ForwardIterator>
  2131. _ForwardIterator __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
  2132. template <class _ForwardIterator>
  2133. _ForwardIterator __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
  2134. template <class _ForwardIterator>
  2135. _ForwardIterator
  2136. __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str = nullptr);
  2137. template <class _ForwardIterator>
  2138. _ForwardIterator __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
  2139. template <class _ForwardIterator>
  2140. _ForwardIterator __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
  2141. template <class _ForwardIterator>
  2142. _ForwardIterator __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
  2143. template <class _ForwardIterator>
  2144. _ForwardIterator __parse_class_escape(
  2145. _ForwardIterator __first,
  2146. _ForwardIterator __last,
  2147. basic_string<_CharT>& __str,
  2148. __bracket_expression<_CharT, _Traits>* __ml);
  2149. template <class _ForwardIterator>
  2150. _ForwardIterator
  2151. __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str = nullptr);
  2152. bool __test_back_ref(_CharT);
  2153. _LIBCPP_HIDE_FROM_ABI void __push_l_anchor();
  2154. void __push_r_anchor();
  2155. void __push_match_any();
  2156. void __push_match_any_but_newline();
  2157. _LIBCPP_HIDE_FROM_ABI void __push_greedy_inf_repeat(
  2158. size_t __min, __owns_one_state<_CharT>* __s, unsigned __mexp_begin = 0, unsigned __mexp_end = 0) {
  2159. __push_loop(__min, numeric_limits<size_t>::max(), __s, __mexp_begin, __mexp_end);
  2160. }
  2161. _LIBCPP_HIDE_FROM_ABI void __push_nongreedy_inf_repeat(
  2162. size_t __min, __owns_one_state<_CharT>* __s, unsigned __mexp_begin = 0, unsigned __mexp_end = 0) {
  2163. __push_loop(__min, numeric_limits<size_t>::max(), __s, __mexp_begin, __mexp_end, false);
  2164. }
  2165. void __push_loop(size_t __min,
  2166. size_t __max,
  2167. __owns_one_state<_CharT>* __s,
  2168. size_t __mexp_begin = 0,
  2169. size_t __mexp_end = 0,
  2170. bool __greedy = true);
  2171. __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
  2172. void __push_char(value_type __c);
  2173. void __push_back_ref(int __i);
  2174. void __push_alternation(__owns_one_state<_CharT>* __sa, __owns_one_state<_CharT>* __sb);
  2175. void __push_begin_marked_subexpression();
  2176. void __push_end_marked_subexpression(unsigned);
  2177. void __push_empty();
  2178. void __push_word_boundary(bool);
  2179. void __push_lookahead(const basic_regex&, bool, unsigned);
  2180. template <class _Allocator>
  2181. bool __search(const _CharT* __first,
  2182. const _CharT* __last,
  2183. match_results<const _CharT*, _Allocator>& __m,
  2184. regex_constants::match_flag_type __flags) const;
  2185. template <class _Allocator>
  2186. bool __match_at_start(const _CharT* __first,
  2187. const _CharT* __last,
  2188. match_results<const _CharT*, _Allocator>& __m,
  2189. regex_constants::match_flag_type __flags,
  2190. bool) const;
  2191. template <class _Allocator>
  2192. bool __match_at_start_ecma(
  2193. const _CharT* __first,
  2194. const _CharT* __last,
  2195. match_results<const _CharT*, _Allocator>& __m,
  2196. regex_constants::match_flag_type __flags,
  2197. bool) const;
  2198. template <class _Allocator>
  2199. bool __match_at_start_posix_nosubs(
  2200. const _CharT* __first,
  2201. const _CharT* __last,
  2202. match_results<const _CharT*, _Allocator>& __m,
  2203. regex_constants::match_flag_type __flags,
  2204. bool) const;
  2205. template <class _Allocator>
  2206. bool __match_at_start_posix_subs(
  2207. const _CharT* __first,
  2208. const _CharT* __last,
  2209. match_results<const _CharT*, _Allocator>& __m,
  2210. regex_constants::match_flag_type __flags,
  2211. bool) const;
  2212. template <class _Bp, class _Ap, class _Cp, class _Tp>
  2213. friend bool
  2214. regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
  2215. template <class _Ap, class _Cp, class _Tp>
  2216. friend bool
  2217. regex_search(const _Cp*,
  2218. const _Cp*,
  2219. match_results<const _Cp*, _Ap>&,
  2220. const basic_regex<_Cp, _Tp>&,
  2221. regex_constants::match_flag_type);
  2222. template <class _Bp, class _Cp, class _Tp>
  2223. friend bool regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
  2224. template <class _Cp, class _Tp>
  2225. friend bool regex_search(const _Cp*, const _Cp*, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
  2226. template <class _Cp, class _Ap, class _Tp>
  2227. friend bool regex_search(
  2228. const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
  2229. template <class _ST, class _SA, class _Cp, class _Tp>
  2230. friend bool regex_search(const basic_string<_Cp, _ST, _SA>& __s,
  2231. const basic_regex<_Cp, _Tp>& __e,
  2232. regex_constants::match_flag_type __flags);
  2233. template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
  2234. friend bool regex_search(const basic_string<_Cp, _ST, _SA>& __s,
  2235. match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
  2236. const basic_regex<_Cp, _Tp>& __e,
  2237. regex_constants::match_flag_type __flags);
  2238. template <class _Iter, class _Ap, class _Cp, class _Tp>
  2239. friend bool
  2240. regex_search(__wrap_iter<_Iter> __first,
  2241. __wrap_iter<_Iter> __last,
  2242. match_results<__wrap_iter<_Iter>, _Ap>& __m,
  2243. const basic_regex<_Cp, _Tp>& __e,
  2244. regex_constants::match_flag_type __flags);
  2245. template <class, class>
  2246. friend class __lookahead;
  2247. };
  2248. #if _LIBCPP_STD_VER >= 17
  2249. template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
  2250. basic_regex(_ForwardIterator, _ForwardIterator, regex_constants::syntax_option_type = regex_constants::ECMAScript)
  2251. -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
  2252. #endif
  2253. template <class _CharT, class _Traits>
  2254. const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
  2255. template <class _CharT, class _Traits>
  2256. const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
  2257. template <class _CharT, class _Traits>
  2258. const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
  2259. template <class _CharT, class _Traits>
  2260. const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
  2261. template <class _CharT, class _Traits>
  2262. const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
  2263. template <class _CharT, class _Traits>
  2264. const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
  2265. template <class _CharT, class _Traits>
  2266. const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
  2267. template <class _CharT, class _Traits>
  2268. const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
  2269. template <class _CharT, class _Traits>
  2270. const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
  2271. template <class _CharT, class _Traits>
  2272. const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
  2273. template <class _CharT, class _Traits>
  2274. void basic_regex<_CharT, _Traits>::swap(basic_regex& __r) {
  2275. using std::swap;
  2276. swap(__traits_, __r.__traits_);
  2277. swap(__flags_, __r.__flags_);
  2278. swap(__marked_count_, __r.__marked_count_);
  2279. swap(__loop_count_, __r.__loop_count_);
  2280. swap(__open_count_, __r.__open_count_);
  2281. swap(__start_, __r.__start_);
  2282. swap(__end_, __r.__end_);
  2283. }
  2284. template <class _CharT, class _Traits>
  2285. inline _LIBCPP_HIDE_FROM_ABI void swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) {
  2286. return __x.swap(__y);
  2287. }
  2288. // __lookahead
  2289. template <class _CharT, class _Traits>
  2290. class __lookahead : public __owns_one_state<_CharT> {
  2291. typedef __owns_one_state<_CharT> base;
  2292. basic_regex<_CharT, _Traits> __exp_;
  2293. unsigned __mexp_;
  2294. bool __invert_;
  2295. __lookahead(const __lookahead&);
  2296. __lookahead& operator=(const __lookahead&);
  2297. public:
  2298. typedef std::__state<_CharT> __state;
  2299. _LIBCPP_HIDE_FROM_ABI
  2300. __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
  2301. : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
  2302. _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
  2303. };
  2304. template <class _CharT, class _Traits>
  2305. void __lookahead<_CharT, _Traits>::__exec(__state& __s) const {
  2306. match_results<const _CharT*> __m;
  2307. __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
  2308. bool __matched = __exp_.__match_at_start_ecma(
  2309. __s.__current_,
  2310. __s.__last_,
  2311. __m,
  2312. (__s.__flags_ | regex_constants::match_continuous) & ~regex_constants::__full_match,
  2313. __s.__at_first_ && __s.__current_ == __s.__first_);
  2314. if (__matched != __invert_) {
  2315. __s.__do_ = __state::__accept_but_not_consume;
  2316. __s.__node_ = this->first();
  2317. for (unsigned __i = 1; __i < __m.size(); ++__i) {
  2318. __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
  2319. }
  2320. } else {
  2321. __s.__do_ = __state::__reject;
  2322. __s.__node_ = nullptr;
  2323. }
  2324. }
  2325. template <class _CharT, class _Traits>
  2326. template <class _ForwardIterator>
  2327. void basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last) {
  2328. if (__get_grammar(__flags_) == 0)
  2329. __flags_ |= regex_constants::ECMAScript;
  2330. _ForwardIterator __temp = __parse(__first, __last);
  2331. if (__temp != __last)
  2332. __throw_regex_error<regex_constants::__re_err_parse>();
  2333. }
  2334. template <class _CharT, class _Traits>
  2335. template <class _ForwardIterator>
  2336. _ForwardIterator basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, _ForwardIterator __last) {
  2337. {
  2338. unique_ptr<__node> __h(new __end_state<_CharT>);
  2339. __start_.reset(new __empty_state<_CharT>(__h.get()));
  2340. __h.release();
  2341. __end_ = __start_.get();
  2342. }
  2343. switch (__get_grammar(__flags_)) {
  2344. case ECMAScript:
  2345. __first = __parse_ecma_exp(__first, __last);
  2346. break;
  2347. case basic:
  2348. __first = __parse_basic_reg_exp(__first, __last);
  2349. break;
  2350. case extended:
  2351. case awk:
  2352. __first = __parse_extended_reg_exp(__first, __last);
  2353. break;
  2354. case grep:
  2355. __first = __parse_grep(__first, __last);
  2356. break;
  2357. case egrep:
  2358. __first = __parse_egrep(__first, __last);
  2359. break;
  2360. default:
  2361. __throw_regex_error<regex_constants::__re_err_grammar>();
  2362. }
  2363. return __first;
  2364. }
  2365. template <class _CharT, class _Traits>
  2366. template <class _ForwardIterator>
  2367. _ForwardIterator
  2368. basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last) {
  2369. if (__first != __last) {
  2370. if (*__first == '^') {
  2371. __push_l_anchor();
  2372. ++__first;
  2373. }
  2374. if (__first != __last) {
  2375. __first = __parse_RE_expression(__first, __last);
  2376. if (__first != __last) {
  2377. _ForwardIterator __temp = std::next(__first);
  2378. if (__temp == __last && *__first == '$') {
  2379. __push_r_anchor();
  2380. ++__first;
  2381. }
  2382. }
  2383. }
  2384. if (__first != __last)
  2385. __throw_regex_error<regex_constants::__re_err_empty>();
  2386. }
  2387. return __first;
  2388. }
  2389. template <class _CharT, class _Traits>
  2390. template <class _ForwardIterator>
  2391. _ForwardIterator
  2392. basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last) {
  2393. __owns_one_state<_CharT>* __sa = __end_;
  2394. _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
  2395. if (__temp == __first)
  2396. __throw_regex_error<regex_constants::__re_err_empty>();
  2397. __first = __temp;
  2398. while (__first != __last && *__first == '|') {
  2399. __owns_one_state<_CharT>* __sb = __end_;
  2400. __temp = __parse_ERE_branch(++__first, __last);
  2401. if (__temp == __first)
  2402. __throw_regex_error<regex_constants::__re_err_empty>();
  2403. __push_alternation(__sa, __sb);
  2404. __first = __temp;
  2405. }
  2406. return __first;
  2407. }
  2408. template <class _CharT, class _Traits>
  2409. template <class _ForwardIterator>
  2410. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last) {
  2411. _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
  2412. if (__temp == __first)
  2413. __throw_regex_error<regex_constants::__re_err_empty>();
  2414. do {
  2415. __first = __temp;
  2416. __temp = __parse_ERE_expression(__first, __last);
  2417. } while (__temp != __first);
  2418. return __first;
  2419. }
  2420. template <class _CharT, class _Traits>
  2421. template <class _ForwardIterator>
  2422. _ForwardIterator
  2423. basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last) {
  2424. __owns_one_state<_CharT>* __e = __end_;
  2425. unsigned __mexp_begin = __marked_count_;
  2426. _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
  2427. if (__temp == __first && __temp != __last) {
  2428. switch (*__temp) {
  2429. case '^':
  2430. __push_l_anchor();
  2431. ++__temp;
  2432. break;
  2433. case '$':
  2434. __push_r_anchor();
  2435. ++__temp;
  2436. break;
  2437. case '(':
  2438. __push_begin_marked_subexpression();
  2439. unsigned __temp_count = __marked_count_;
  2440. ++__open_count_;
  2441. __temp = __parse_extended_reg_exp(++__temp, __last);
  2442. if (__temp == __last || *__temp != ')')
  2443. __throw_regex_error<regex_constants::error_paren>();
  2444. __push_end_marked_subexpression(__temp_count);
  2445. --__open_count_;
  2446. ++__temp;
  2447. break;
  2448. }
  2449. }
  2450. if (__temp != __first)
  2451. __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin + 1, __marked_count_ + 1);
  2452. __first = __temp;
  2453. return __first;
  2454. }
  2455. template <class _CharT, class _Traits>
  2456. template <class _ForwardIterator>
  2457. _ForwardIterator
  2458. basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last) {
  2459. while (true) {
  2460. _ForwardIterator __temp = __parse_simple_RE(__first, __last);
  2461. if (__temp == __first)
  2462. break;
  2463. __first = __temp;
  2464. }
  2465. return __first;
  2466. }
  2467. template <class _CharT, class _Traits>
  2468. template <class _ForwardIterator>
  2469. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last) {
  2470. if (__first != __last) {
  2471. __owns_one_state<_CharT>* __e = __end_;
  2472. unsigned __mexp_begin = __marked_count_;
  2473. _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
  2474. if (__temp != __first)
  2475. __first = __parse_RE_dupl_symbol(__temp, __last, __e, __mexp_begin + 1, __marked_count_ + 1);
  2476. }
  2477. return __first;
  2478. }
  2479. template <class _CharT, class _Traits>
  2480. template <class _ForwardIterator>
  2481. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last) {
  2482. _ForwardIterator __temp = __first;
  2483. __first = __parse_one_char_or_coll_elem_RE(__first, __last);
  2484. if (__temp == __first) {
  2485. __temp = __parse_Back_open_paren(__first, __last);
  2486. if (__temp != __first) {
  2487. __push_begin_marked_subexpression();
  2488. unsigned __temp_count = __marked_count_;
  2489. __first = __parse_RE_expression(__temp, __last);
  2490. __temp = __parse_Back_close_paren(__first, __last);
  2491. if (__temp == __first)
  2492. __throw_regex_error<regex_constants::error_paren>();
  2493. __push_end_marked_subexpression(__temp_count);
  2494. __first = __temp;
  2495. } else
  2496. __first = __parse_BACKREF(__first, __last);
  2497. }
  2498. return __first;
  2499. }
  2500. template <class _CharT, class _Traits>
  2501. template <class _ForwardIterator>
  2502. _ForwardIterator
  2503. basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last) {
  2504. _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
  2505. if (__temp == __first) {
  2506. __temp = __parse_QUOTED_CHAR(__first, __last);
  2507. if (__temp == __first) {
  2508. if (__temp != __last && *__temp == '.') {
  2509. __push_match_any();
  2510. ++__temp;
  2511. } else
  2512. __temp = __parse_bracket_expression(__first, __last);
  2513. }
  2514. }
  2515. __first = __temp;
  2516. return __first;
  2517. }
  2518. template <class _CharT, class _Traits>
  2519. template <class _ForwardIterator>
  2520. _ForwardIterator
  2521. basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last) {
  2522. _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
  2523. if (__temp == __first) {
  2524. __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
  2525. if (__temp == __first) {
  2526. if (__temp != __last && *__temp == '.') {
  2527. __push_match_any();
  2528. ++__temp;
  2529. } else
  2530. __temp = __parse_bracket_expression(__first, __last);
  2531. }
  2532. }
  2533. __first = __temp;
  2534. return __first;
  2535. }
  2536. template <class _CharT, class _Traits>
  2537. template <class _ForwardIterator>
  2538. _ForwardIterator
  2539. basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last) {
  2540. if (__first != __last) {
  2541. _ForwardIterator __temp = std::next(__first);
  2542. if (__temp != __last) {
  2543. if (*__first == '\\' && *__temp == '(')
  2544. __first = ++__temp;
  2545. }
  2546. }
  2547. return __first;
  2548. }
  2549. template <class _CharT, class _Traits>
  2550. template <class _ForwardIterator>
  2551. _ForwardIterator
  2552. basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last) {
  2553. if (__first != __last) {
  2554. _ForwardIterator __temp = std::next(__first);
  2555. if (__temp != __last) {
  2556. if (*__first == '\\' && *__temp == ')')
  2557. __first = ++__temp;
  2558. }
  2559. }
  2560. return __first;
  2561. }
  2562. template <class _CharT, class _Traits>
  2563. template <class _ForwardIterator>
  2564. _ForwardIterator
  2565. basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last) {
  2566. if (__first != __last) {
  2567. _ForwardIterator __temp = std::next(__first);
  2568. if (__temp != __last) {
  2569. if (*__first == '\\' && *__temp == '{')
  2570. __first = ++__temp;
  2571. }
  2572. }
  2573. return __first;
  2574. }
  2575. template <class _CharT, class _Traits>
  2576. template <class _ForwardIterator>
  2577. _ForwardIterator
  2578. basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last) {
  2579. if (__first != __last) {
  2580. _ForwardIterator __temp = std::next(__first);
  2581. if (__temp != __last) {
  2582. if (*__first == '\\' && *__temp == '}')
  2583. __first = ++__temp;
  2584. }
  2585. }
  2586. return __first;
  2587. }
  2588. template <class _CharT, class _Traits>
  2589. template <class _ForwardIterator>
  2590. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last) {
  2591. if (__first != __last) {
  2592. _ForwardIterator __temp = std::next(__first);
  2593. if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp))
  2594. __first = ++__temp;
  2595. }
  2596. return __first;
  2597. }
  2598. template <class _CharT, class _Traits>
  2599. template <class _ForwardIterator>
  2600. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last) {
  2601. if (__first != __last) {
  2602. _ForwardIterator __temp = std::next(__first);
  2603. if (__temp == __last && *__first == '$')
  2604. return __first;
  2605. // Not called inside a bracket
  2606. if (*__first == '.' || *__first == '\\' || *__first == '[')
  2607. return __first;
  2608. __push_char(*__first);
  2609. ++__first;
  2610. }
  2611. return __first;
  2612. }
  2613. template <class _CharT, class _Traits>
  2614. template <class _ForwardIterator>
  2615. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last) {
  2616. if (__first != __last) {
  2617. switch (*__first) {
  2618. case '^':
  2619. case '.':
  2620. case '[':
  2621. case '$':
  2622. case '(':
  2623. case '|':
  2624. case '*':
  2625. case '+':
  2626. case '?':
  2627. case '{':
  2628. case '\\':
  2629. break;
  2630. case ')':
  2631. if (__open_count_ == 0) {
  2632. __push_char(*__first);
  2633. ++__first;
  2634. }
  2635. break;
  2636. default:
  2637. __push_char(*__first);
  2638. ++__first;
  2639. break;
  2640. }
  2641. }
  2642. return __first;
  2643. }
  2644. template <class _CharT, class _Traits>
  2645. template <class _ForwardIterator>
  2646. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last) {
  2647. if (__first != __last) {
  2648. _ForwardIterator __temp = std::next(__first);
  2649. if (__temp != __last) {
  2650. if (*__first == '\\') {
  2651. switch (*__temp) {
  2652. case '^':
  2653. case '.':
  2654. case '*':
  2655. case '[':
  2656. case '$':
  2657. case '\\':
  2658. __push_char(*__temp);
  2659. __first = ++__temp;
  2660. break;
  2661. }
  2662. }
  2663. }
  2664. }
  2665. return __first;
  2666. }
  2667. template <class _CharT, class _Traits>
  2668. template <class _ForwardIterator>
  2669. _ForwardIterator
  2670. basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last) {
  2671. if (__first != __last) {
  2672. _ForwardIterator __temp = std::next(__first);
  2673. if (__temp != __last) {
  2674. if (*__first == '\\') {
  2675. switch (*__temp) {
  2676. case '^':
  2677. case '.':
  2678. case '*':
  2679. case '[':
  2680. case '$':
  2681. case '\\':
  2682. case '(':
  2683. case ')':
  2684. case '|':
  2685. case '+':
  2686. case '?':
  2687. case '{':
  2688. case '}':
  2689. __push_char(*__temp);
  2690. __first = ++__temp;
  2691. break;
  2692. default:
  2693. if (__get_grammar(__flags_) == awk)
  2694. __first = __parse_awk_escape(++__first, __last);
  2695. else if (__test_back_ref(*__temp))
  2696. __first = ++__temp;
  2697. break;
  2698. }
  2699. }
  2700. }
  2701. }
  2702. return __first;
  2703. }
  2704. template <class _CharT, class _Traits>
  2705. template <class _ForwardIterator>
  2706. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(
  2707. _ForwardIterator __first,
  2708. _ForwardIterator __last,
  2709. __owns_one_state<_CharT>* __s,
  2710. unsigned __mexp_begin,
  2711. unsigned __mexp_end) {
  2712. if (__first != __last) {
  2713. if (*__first == '*') {
  2714. __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
  2715. ++__first;
  2716. } else {
  2717. _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
  2718. if (__temp != __first) {
  2719. int __min = 0;
  2720. __first = __temp;
  2721. __temp = __parse_DUP_COUNT(__first, __last, __min);
  2722. if (__temp == __first)
  2723. __throw_regex_error<regex_constants::error_badbrace>();
  2724. __first = __temp;
  2725. if (__first == __last)
  2726. __throw_regex_error<regex_constants::error_brace>();
  2727. if (*__first != ',') {
  2728. __temp = __parse_Back_close_brace(__first, __last);
  2729. if (__temp == __first)
  2730. __throw_regex_error<regex_constants::error_brace>();
  2731. __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, true);
  2732. __first = __temp;
  2733. } else {
  2734. ++__first; // consume ','
  2735. int __max = -1;
  2736. __first = __parse_DUP_COUNT(__first, __last, __max);
  2737. __temp = __parse_Back_close_brace(__first, __last);
  2738. if (__temp == __first)
  2739. __throw_regex_error<regex_constants::error_brace>();
  2740. if (__max == -1)
  2741. __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
  2742. else {
  2743. if (__max < __min)
  2744. __throw_regex_error<regex_constants::error_badbrace>();
  2745. __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, true);
  2746. }
  2747. __first = __temp;
  2748. }
  2749. }
  2750. }
  2751. }
  2752. return __first;
  2753. }
  2754. template <class _CharT, class _Traits>
  2755. template <class _ForwardIterator>
  2756. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(
  2757. _ForwardIterator __first,
  2758. _ForwardIterator __last,
  2759. __owns_one_state<_CharT>* __s,
  2760. unsigned __mexp_begin,
  2761. unsigned __mexp_end) {
  2762. if (__first != __last) {
  2763. unsigned __grammar = __get_grammar(__flags_);
  2764. switch (*__first) {
  2765. case '*':
  2766. ++__first;
  2767. if (__grammar == ECMAScript && __first != __last && *__first == '?') {
  2768. ++__first;
  2769. __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
  2770. } else
  2771. __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
  2772. break;
  2773. case '+':
  2774. ++__first;
  2775. if (__grammar == ECMAScript && __first != __last && *__first == '?') {
  2776. ++__first;
  2777. __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
  2778. } else
  2779. __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
  2780. break;
  2781. case '?':
  2782. ++__first;
  2783. if (__grammar == ECMAScript && __first != __last && *__first == '?') {
  2784. ++__first;
  2785. __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
  2786. } else
  2787. __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
  2788. break;
  2789. case '{': {
  2790. int __min;
  2791. _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
  2792. if (__temp == __first)
  2793. __throw_regex_error<regex_constants::error_badbrace>();
  2794. __first = __temp;
  2795. if (__first == __last)
  2796. __throw_regex_error<regex_constants::error_brace>();
  2797. switch (*__first) {
  2798. case '}':
  2799. ++__first;
  2800. if (__grammar == ECMAScript && __first != __last && *__first == '?') {
  2801. ++__first;
  2802. __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
  2803. } else
  2804. __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
  2805. break;
  2806. case ',':
  2807. ++__first;
  2808. if (__first == __last)
  2809. __throw_regex_error<regex_constants::error_badbrace>();
  2810. if (*__first == '}') {
  2811. ++__first;
  2812. if (__grammar == ECMAScript && __first != __last && *__first == '?') {
  2813. ++__first;
  2814. __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
  2815. } else
  2816. __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
  2817. } else {
  2818. int __max = -1;
  2819. __temp = __parse_DUP_COUNT(__first, __last, __max);
  2820. if (__temp == __first)
  2821. __throw_regex_error<regex_constants::error_brace>();
  2822. __first = __temp;
  2823. if (__first == __last || *__first != '}')
  2824. __throw_regex_error<regex_constants::error_brace>();
  2825. ++__first;
  2826. if (__max < __min)
  2827. __throw_regex_error<regex_constants::error_badbrace>();
  2828. if (__grammar == ECMAScript && __first != __last && *__first == '?') {
  2829. ++__first;
  2830. __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
  2831. } else
  2832. __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
  2833. }
  2834. break;
  2835. default:
  2836. __throw_regex_error<regex_constants::error_badbrace>();
  2837. }
  2838. } break;
  2839. }
  2840. }
  2841. return __first;
  2842. }
  2843. template <class _CharT, class _Traits>
  2844. template <class _ForwardIterator>
  2845. _ForwardIterator
  2846. basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last) {
  2847. if (__first != __last && *__first == '[') {
  2848. ++__first;
  2849. if (__first == __last)
  2850. __throw_regex_error<regex_constants::error_brack>();
  2851. bool __negate = false;
  2852. if (*__first == '^') {
  2853. ++__first;
  2854. __negate = true;
  2855. }
  2856. __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
  2857. // __ml owned by *this
  2858. if (__first == __last)
  2859. __throw_regex_error<regex_constants::error_brack>();
  2860. if (__get_grammar(__flags_) != ECMAScript && *__first == ']') {
  2861. __ml->__add_char(']');
  2862. ++__first;
  2863. }
  2864. __first = __parse_follow_list(__first, __last, __ml);
  2865. if (__first == __last)
  2866. __throw_regex_error<regex_constants::error_brack>();
  2867. if (*__first == '-') {
  2868. __ml->__add_char('-');
  2869. ++__first;
  2870. }
  2871. if (__first == __last || *__first != ']')
  2872. __throw_regex_error<regex_constants::error_brack>();
  2873. ++__first;
  2874. }
  2875. return __first;
  2876. }
  2877. template <class _CharT, class _Traits>
  2878. template <class _ForwardIterator>
  2879. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_follow_list(
  2880. _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
  2881. if (__first != __last) {
  2882. while (true) {
  2883. _ForwardIterator __temp = __parse_expression_term(__first, __last, __ml);
  2884. if (__temp == __first)
  2885. break;
  2886. __first = __temp;
  2887. }
  2888. }
  2889. return __first;
  2890. }
  2891. template <class _CharT, class _Traits>
  2892. template <class _ForwardIterator>
  2893. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_expression_term(
  2894. _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
  2895. if (__first != __last && *__first != ']') {
  2896. _ForwardIterator __temp = std::next(__first);
  2897. basic_string<_CharT> __start_range;
  2898. if (__temp != __last && *__first == '[') {
  2899. if (*__temp == '=')
  2900. return __parse_equivalence_class(++__temp, __last, __ml);
  2901. else if (*__temp == ':')
  2902. return __parse_character_class(++__temp, __last, __ml);
  2903. else if (*__temp == '.')
  2904. __first = __parse_collating_symbol(++__temp, __last, __start_range);
  2905. }
  2906. unsigned __grammar = __get_grammar(__flags_);
  2907. if (__start_range.empty()) {
  2908. if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') {
  2909. if (__grammar == ECMAScript)
  2910. __first = __parse_class_escape(++__first, __last, __start_range, __ml);
  2911. else
  2912. __first = __parse_awk_escape(++__first, __last, &__start_range);
  2913. } else {
  2914. __start_range = *__first;
  2915. ++__first;
  2916. }
  2917. }
  2918. if (__first != __last && *__first != ']') {
  2919. __temp = std::next(__first);
  2920. if (__temp != __last && *__first == '-' && *__temp != ']') {
  2921. // parse a range
  2922. basic_string<_CharT> __end_range;
  2923. __first = __temp;
  2924. ++__temp;
  2925. if (__temp != __last && *__first == '[' && *__temp == '.')
  2926. __first = __parse_collating_symbol(++__temp, __last, __end_range);
  2927. else {
  2928. if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') {
  2929. if (__grammar == ECMAScript)
  2930. __first = __parse_class_escape(++__first, __last, __end_range, __ml);
  2931. else
  2932. __first = __parse_awk_escape(++__first, __last, &__end_range);
  2933. } else {
  2934. __end_range = *__first;
  2935. ++__first;
  2936. }
  2937. }
  2938. __ml->__add_range(std::move(__start_range), std::move(__end_range));
  2939. } else if (!__start_range.empty()) {
  2940. if (__start_range.size() == 1)
  2941. __ml->__add_char(__start_range[0]);
  2942. else
  2943. __ml->__add_digraph(__start_range[0], __start_range[1]);
  2944. }
  2945. } else if (!__start_range.empty()) {
  2946. if (__start_range.size() == 1)
  2947. __ml->__add_char(__start_range[0]);
  2948. else
  2949. __ml->__add_digraph(__start_range[0], __start_range[1]);
  2950. }
  2951. }
  2952. return __first;
  2953. }
  2954. template <class _CharT, class _Traits>
  2955. template <class _ForwardIterator>
  2956. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_class_escape(
  2957. _ForwardIterator __first,
  2958. _ForwardIterator __last,
  2959. basic_string<_CharT>& __str,
  2960. __bracket_expression<_CharT, _Traits>* __ml) {
  2961. if (__first == __last)
  2962. __throw_regex_error<regex_constants::error_escape>();
  2963. switch (*__first) {
  2964. case 0:
  2965. __str = *__first;
  2966. return ++__first;
  2967. case 'b':
  2968. __str = _CharT(8);
  2969. return ++__first;
  2970. case 'd':
  2971. __ml->__add_class(ctype_base::digit);
  2972. return ++__first;
  2973. case 'D':
  2974. __ml->__add_neg_class(ctype_base::digit);
  2975. return ++__first;
  2976. case 's':
  2977. __ml->__add_class(ctype_base::space);
  2978. return ++__first;
  2979. case 'S':
  2980. __ml->__add_neg_class(ctype_base::space);
  2981. return ++__first;
  2982. case 'w':
  2983. __ml->__add_class(ctype_base::alnum);
  2984. __ml->__add_char('_');
  2985. return ++__first;
  2986. case 'W':
  2987. __ml->__add_neg_class(ctype_base::alnum);
  2988. __ml->__add_neg_char('_');
  2989. return ++__first;
  2990. }
  2991. __first = __parse_character_escape(__first, __last, &__str);
  2992. return __first;
  2993. }
  2994. template <class _CharT, class _Traits>
  2995. template <class _ForwardIterator>
  2996. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_awk_escape(
  2997. _ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str) {
  2998. if (__first == __last)
  2999. __throw_regex_error<regex_constants::error_escape>();
  3000. switch (*__first) {
  3001. case '\\':
  3002. case '"':
  3003. case '/':
  3004. if (__str)
  3005. *__str = *__first;
  3006. else
  3007. __push_char(*__first);
  3008. return ++__first;
  3009. case 'a':
  3010. if (__str)
  3011. *__str = _CharT(7);
  3012. else
  3013. __push_char(_CharT(7));
  3014. return ++__first;
  3015. case 'b':
  3016. if (__str)
  3017. *__str = _CharT(8);
  3018. else
  3019. __push_char(_CharT(8));
  3020. return ++__first;
  3021. case 'f':
  3022. if (__str)
  3023. *__str = _CharT(0xC);
  3024. else
  3025. __push_char(_CharT(0xC));
  3026. return ++__first;
  3027. case 'n':
  3028. if (__str)
  3029. *__str = _CharT(0xA);
  3030. else
  3031. __push_char(_CharT(0xA));
  3032. return ++__first;
  3033. case 'r':
  3034. if (__str)
  3035. *__str = _CharT(0xD);
  3036. else
  3037. __push_char(_CharT(0xD));
  3038. return ++__first;
  3039. case 't':
  3040. if (__str)
  3041. *__str = _CharT(0x9);
  3042. else
  3043. __push_char(_CharT(0x9));
  3044. return ++__first;
  3045. case 'v':
  3046. if (__str)
  3047. *__str = _CharT(0xB);
  3048. else
  3049. __push_char(_CharT(0xB));
  3050. return ++__first;
  3051. }
  3052. if ('0' <= *__first && *__first <= '7') {
  3053. unsigned __val = *__first - '0';
  3054. if (++__first != __last && ('0' <= *__first && *__first <= '7')) {
  3055. __val = 8 * __val + *__first - '0';
  3056. if (++__first != __last && ('0' <= *__first && *__first <= '7'))
  3057. __val = 8 * __val + *__first++ - '0';
  3058. }
  3059. if (__str)
  3060. *__str = _CharT(__val);
  3061. else
  3062. __push_char(_CharT(__val));
  3063. } else
  3064. __throw_regex_error<regex_constants::error_escape>();
  3065. return __first;
  3066. }
  3067. template <class _CharT, class _Traits>
  3068. template <class _ForwardIterator>
  3069. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_equivalence_class(
  3070. _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
  3071. // Found [=
  3072. // This means =] must exist
  3073. value_type __equal_close[2] = {'=', ']'};
  3074. _ForwardIterator __temp = std::search(__first, __last, __equal_close, __equal_close + 2);
  3075. if (__temp == __last)
  3076. __throw_regex_error<regex_constants::error_brack>();
  3077. // [__first, __temp) contains all text in [= ... =]
  3078. string_type __collate_name = __traits_.lookup_collatename(__first, __temp);
  3079. if (__collate_name.empty())
  3080. __throw_regex_error<regex_constants::error_collate>();
  3081. string_type __equiv_name = __traits_.transform_primary(__collate_name.begin(), __collate_name.end());
  3082. if (!__equiv_name.empty())
  3083. __ml->__add_equivalence(__equiv_name);
  3084. else {
  3085. switch (__collate_name.size()) {
  3086. case 1:
  3087. __ml->__add_char(__collate_name[0]);
  3088. break;
  3089. case 2:
  3090. __ml->__add_digraph(__collate_name[0], __collate_name[1]);
  3091. break;
  3092. default:
  3093. __throw_regex_error<regex_constants::error_collate>();
  3094. }
  3095. }
  3096. __first = std::next(__temp, 2);
  3097. return __first;
  3098. }
  3099. template <class _CharT, class _Traits>
  3100. template <class _ForwardIterator>
  3101. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_class(
  3102. _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
  3103. // Found [:
  3104. // This means :] must exist
  3105. value_type __colon_close[2] = {':', ']'};
  3106. _ForwardIterator __temp = std::search(__first, __last, __colon_close, __colon_close + 2);
  3107. if (__temp == __last)
  3108. __throw_regex_error<regex_constants::error_brack>();
  3109. // [__first, __temp) contains all text in [: ... :]
  3110. typedef typename _Traits::char_class_type char_class_type;
  3111. char_class_type __class_type = __traits_.lookup_classname(__first, __temp, __flags_ & icase);
  3112. if (__class_type == 0)
  3113. __throw_regex_error<regex_constants::error_ctype>();
  3114. __ml->__add_class(__class_type);
  3115. __first = std::next(__temp, 2);
  3116. return __first;
  3117. }
  3118. template <class _CharT, class _Traits>
  3119. template <class _ForwardIterator>
  3120. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_collating_symbol(
  3121. _ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>& __col_sym) {
  3122. // Found [.
  3123. // This means .] must exist
  3124. value_type __dot_close[2] = {'.', ']'};
  3125. _ForwardIterator __temp = std::search(__first, __last, __dot_close, __dot_close + 2);
  3126. if (__temp == __last)
  3127. __throw_regex_error<regex_constants::error_brack>();
  3128. // [__first, __temp) contains all text in [. ... .]
  3129. __col_sym = __traits_.lookup_collatename(__first, __temp);
  3130. switch (__col_sym.size()) {
  3131. case 1:
  3132. case 2:
  3133. break;
  3134. default:
  3135. __throw_regex_error<regex_constants::error_collate>();
  3136. }
  3137. __first = std::next(__temp, 2);
  3138. return __first;
  3139. }
  3140. template <class _CharT, class _Traits>
  3141. template <class _ForwardIterator>
  3142. _ForwardIterator
  3143. basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c) {
  3144. if (__first != __last) {
  3145. int __val = __traits_.value(*__first, 10);
  3146. if (__val != -1) {
  3147. __c = __val;
  3148. for (++__first; __first != __last && (__val = __traits_.value(*__first, 10)) != -1; ++__first) {
  3149. if (__c >= numeric_limits<int>::max() / 10)
  3150. __throw_regex_error<regex_constants::error_badbrace>();
  3151. __c *= 10;
  3152. __c += __val;
  3153. }
  3154. }
  3155. }
  3156. return __first;
  3157. }
  3158. template <class _CharT, class _Traits>
  3159. template <class _ForwardIterator>
  3160. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last) {
  3161. __owns_one_state<_CharT>* __sa = __end_;
  3162. _ForwardIterator __temp = __parse_alternative(__first, __last);
  3163. if (__temp == __first)
  3164. __push_empty();
  3165. __first = __temp;
  3166. while (__first != __last && *__first == '|') {
  3167. __owns_one_state<_CharT>* __sb = __end_;
  3168. __temp = __parse_alternative(++__first, __last);
  3169. if (__temp == __first)
  3170. __push_empty();
  3171. __push_alternation(__sa, __sb);
  3172. __first = __temp;
  3173. }
  3174. return __first;
  3175. }
  3176. template <class _CharT, class _Traits>
  3177. template <class _ForwardIterator>
  3178. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, _ForwardIterator __last) {
  3179. while (true) {
  3180. _ForwardIterator __temp = __parse_term(__first, __last);
  3181. if (__temp == __first)
  3182. break;
  3183. __first = __temp;
  3184. }
  3185. return __first;
  3186. }
  3187. template <class _CharT, class _Traits>
  3188. template <class _ForwardIterator>
  3189. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, _ForwardIterator __last) {
  3190. _ForwardIterator __temp = __parse_assertion(__first, __last);
  3191. if (__temp == __first) {
  3192. __owns_one_state<_CharT>* __e = __end_;
  3193. unsigned __mexp_begin = __marked_count_;
  3194. __temp = __parse_atom(__first, __last);
  3195. if (__temp != __first)
  3196. __first = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin + 1, __marked_count_ + 1);
  3197. } else
  3198. __first = __temp;
  3199. return __first;
  3200. }
  3201. template <class _CharT, class _Traits>
  3202. template <class _ForwardIterator>
  3203. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, _ForwardIterator __last) {
  3204. if (__first != __last) {
  3205. switch (*__first) {
  3206. case '^':
  3207. __push_l_anchor();
  3208. ++__first;
  3209. break;
  3210. case '$':
  3211. __push_r_anchor();
  3212. ++__first;
  3213. break;
  3214. case '\\': {
  3215. _ForwardIterator __temp = std::next(__first);
  3216. if (__temp != __last) {
  3217. if (*__temp == 'b') {
  3218. __push_word_boundary(false);
  3219. __first = ++__temp;
  3220. } else if (*__temp == 'B') {
  3221. __push_word_boundary(true);
  3222. __first = ++__temp;
  3223. }
  3224. }
  3225. } break;
  3226. case '(': {
  3227. _ForwardIterator __temp = std::next(__first);
  3228. if (__temp != __last && *__temp == '?') {
  3229. if (++__temp != __last) {
  3230. switch (*__temp) {
  3231. case '=': {
  3232. basic_regex __exp;
  3233. __exp.__flags_ = __flags_;
  3234. __temp = __exp.__parse(++__temp, __last);
  3235. unsigned __mexp = __exp.__marked_count_;
  3236. __push_lookahead(std::move(__exp), false, __marked_count_);
  3237. __marked_count_ += __mexp;
  3238. if (__temp == __last || *__temp != ')')
  3239. __throw_regex_error<regex_constants::error_paren>();
  3240. __first = ++__temp;
  3241. } break;
  3242. case '!': {
  3243. basic_regex __exp;
  3244. __exp.__flags_ = __flags_;
  3245. __temp = __exp.__parse(++__temp, __last);
  3246. unsigned __mexp = __exp.__marked_count_;
  3247. __push_lookahead(std::move(__exp), true, __marked_count_);
  3248. __marked_count_ += __mexp;
  3249. if (__temp == __last || *__temp != ')')
  3250. __throw_regex_error<regex_constants::error_paren>();
  3251. __first = ++__temp;
  3252. } break;
  3253. }
  3254. }
  3255. }
  3256. } break;
  3257. }
  3258. }
  3259. return __first;
  3260. }
  3261. template <class _CharT, class _Traits>
  3262. template <class _ForwardIterator>
  3263. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, _ForwardIterator __last) {
  3264. if (__first != __last) {
  3265. switch (*__first) {
  3266. case '.':
  3267. __push_match_any_but_newline();
  3268. ++__first;
  3269. break;
  3270. case '\\':
  3271. __first = __parse_atom_escape(__first, __last);
  3272. break;
  3273. case '[':
  3274. __first = __parse_bracket_expression(__first, __last);
  3275. break;
  3276. case '(': {
  3277. ++__first;
  3278. if (__first == __last)
  3279. __throw_regex_error<regex_constants::error_paren>();
  3280. _ForwardIterator __temp = std::next(__first);
  3281. if (__temp != __last && *__first == '?' && *__temp == ':') {
  3282. ++__open_count_;
  3283. __first = __parse_ecma_exp(++__temp, __last);
  3284. if (__first == __last || *__first != ')')
  3285. __throw_regex_error<regex_constants::error_paren>();
  3286. --__open_count_;
  3287. ++__first;
  3288. } else {
  3289. __push_begin_marked_subexpression();
  3290. unsigned __temp_count = __marked_count_;
  3291. ++__open_count_;
  3292. __first = __parse_ecma_exp(__first, __last);
  3293. if (__first == __last || *__first != ')')
  3294. __throw_regex_error<regex_constants::error_paren>();
  3295. __push_end_marked_subexpression(__temp_count);
  3296. --__open_count_;
  3297. ++__first;
  3298. }
  3299. } break;
  3300. case '*':
  3301. case '+':
  3302. case '?':
  3303. case '{':
  3304. __throw_regex_error<regex_constants::error_badrepeat>();
  3305. break;
  3306. default:
  3307. __first = __parse_pattern_character(__first, __last);
  3308. break;
  3309. }
  3310. }
  3311. return __first;
  3312. }
  3313. template <class _CharT, class _Traits>
  3314. template <class _ForwardIterator>
  3315. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last) {
  3316. if (__first != __last && *__first == '\\') {
  3317. _ForwardIterator __t1 = std::next(__first);
  3318. if (__t1 == __last)
  3319. __throw_regex_error<regex_constants::error_escape>();
  3320. _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
  3321. if (__t2 != __t1)
  3322. __first = __t2;
  3323. else {
  3324. __t2 = __parse_character_class_escape(__t1, __last);
  3325. if (__t2 != __t1)
  3326. __first = __t2;
  3327. else {
  3328. __t2 = __parse_character_escape(__t1, __last);
  3329. if (__t2 != __t1)
  3330. __first = __t2;
  3331. }
  3332. }
  3333. }
  3334. return __first;
  3335. }
  3336. template <class _CharT, class _Traits>
  3337. template <class _ForwardIterator>
  3338. _ForwardIterator
  3339. basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last) {
  3340. if (__first != __last) {
  3341. if (*__first == '0') {
  3342. __push_char(_CharT());
  3343. ++__first;
  3344. } else if ('1' <= *__first && *__first <= '9') {
  3345. unsigned __v = *__first - '0';
  3346. for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; ++__first) {
  3347. if (__v >= numeric_limits<unsigned>::max() / 10)
  3348. __throw_regex_error<regex_constants::error_backref>();
  3349. __v = 10 * __v + *__first - '0';
  3350. }
  3351. if (__v == 0 || __v > mark_count())
  3352. __throw_regex_error<regex_constants::error_backref>();
  3353. __push_back_ref(__v);
  3354. }
  3355. }
  3356. return __first;
  3357. }
  3358. template <class _CharT, class _Traits>
  3359. template <class _ForwardIterator>
  3360. _ForwardIterator
  3361. basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last) {
  3362. if (__first != __last) {
  3363. __bracket_expression<_CharT, _Traits>* __ml;
  3364. switch (*__first) {
  3365. case 'd':
  3366. __ml = __start_matching_list(false);
  3367. __ml->__add_class(ctype_base::digit);
  3368. ++__first;
  3369. break;
  3370. case 'D':
  3371. __ml = __start_matching_list(true);
  3372. __ml->__add_class(ctype_base::digit);
  3373. ++__first;
  3374. break;
  3375. case 's':
  3376. __ml = __start_matching_list(false);
  3377. __ml->__add_class(ctype_base::space);
  3378. ++__first;
  3379. break;
  3380. case 'S':
  3381. __ml = __start_matching_list(true);
  3382. __ml->__add_class(ctype_base::space);
  3383. ++__first;
  3384. break;
  3385. case 'w':
  3386. __ml = __start_matching_list(false);
  3387. __ml->__add_class(ctype_base::alnum);
  3388. __ml->__add_char('_');
  3389. ++__first;
  3390. break;
  3391. case 'W':
  3392. __ml = __start_matching_list(true);
  3393. __ml->__add_class(ctype_base::alnum);
  3394. __ml->__add_char('_');
  3395. ++__first;
  3396. break;
  3397. }
  3398. }
  3399. return __first;
  3400. }
  3401. template <class _CharT, class _Traits>
  3402. template <class _ForwardIterator>
  3403. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
  3404. _ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str) {
  3405. if (__first != __last) {
  3406. _ForwardIterator __t;
  3407. unsigned __sum = 0;
  3408. int __hd;
  3409. switch (*__first) {
  3410. case 'f':
  3411. if (__str)
  3412. *__str = _CharT(0xC);
  3413. else
  3414. __push_char(_CharT(0xC));
  3415. ++__first;
  3416. break;
  3417. case 'n':
  3418. if (__str)
  3419. *__str = _CharT(0xA);
  3420. else
  3421. __push_char(_CharT(0xA));
  3422. ++__first;
  3423. break;
  3424. case 'r':
  3425. if (__str)
  3426. *__str = _CharT(0xD);
  3427. else
  3428. __push_char(_CharT(0xD));
  3429. ++__first;
  3430. break;
  3431. case 't':
  3432. if (__str)
  3433. *__str = _CharT(0x9);
  3434. else
  3435. __push_char(_CharT(0x9));
  3436. ++__first;
  3437. break;
  3438. case 'v':
  3439. if (__str)
  3440. *__str = _CharT(0xB);
  3441. else
  3442. __push_char(_CharT(0xB));
  3443. ++__first;
  3444. break;
  3445. case 'c':
  3446. if ((__t = std::next(__first)) != __last) {
  3447. if (('A' <= *__t && *__t <= 'Z') || ('a' <= *__t && *__t <= 'z')) {
  3448. if (__str)
  3449. *__str = _CharT(*__t % 32);
  3450. else
  3451. __push_char(_CharT(*__t % 32));
  3452. __first = ++__t;
  3453. } else
  3454. __throw_regex_error<regex_constants::error_escape>();
  3455. } else
  3456. __throw_regex_error<regex_constants::error_escape>();
  3457. break;
  3458. case 'u':
  3459. ++__first;
  3460. if (__first == __last)
  3461. __throw_regex_error<regex_constants::error_escape>();
  3462. __hd = __traits_.value(*__first, 16);
  3463. if (__hd == -1)
  3464. __throw_regex_error<regex_constants::error_escape>();
  3465. __sum = 16 * __sum + static_cast<unsigned>(__hd);
  3466. ++__first;
  3467. if (__first == __last)
  3468. __throw_regex_error<regex_constants::error_escape>();
  3469. __hd = __traits_.value(*__first, 16);
  3470. if (__hd == -1)
  3471. __throw_regex_error<regex_constants::error_escape>();
  3472. __sum = 16 * __sum + static_cast<unsigned>(__hd);
  3473. // fallthrough
  3474. case 'x':
  3475. ++__first;
  3476. if (__first == __last)
  3477. __throw_regex_error<regex_constants::error_escape>();
  3478. __hd = __traits_.value(*__first, 16);
  3479. if (__hd == -1)
  3480. __throw_regex_error<regex_constants::error_escape>();
  3481. __sum = 16 * __sum + static_cast<unsigned>(__hd);
  3482. ++__first;
  3483. if (__first == __last)
  3484. __throw_regex_error<regex_constants::error_escape>();
  3485. __hd = __traits_.value(*__first, 16);
  3486. if (__hd == -1)
  3487. __throw_regex_error<regex_constants::error_escape>();
  3488. __sum = 16 * __sum + static_cast<unsigned>(__hd);
  3489. if (__str)
  3490. *__str = _CharT(__sum);
  3491. else
  3492. __push_char(_CharT(__sum));
  3493. ++__first;
  3494. break;
  3495. case '0':
  3496. if (__str)
  3497. *__str = _CharT(0);
  3498. else
  3499. __push_char(_CharT(0));
  3500. ++__first;
  3501. break;
  3502. default:
  3503. if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) {
  3504. if (__str)
  3505. *__str = *__first;
  3506. else
  3507. __push_char(*__first);
  3508. ++__first;
  3509. } else
  3510. __throw_regex_error<regex_constants::error_escape>();
  3511. break;
  3512. }
  3513. }
  3514. return __first;
  3515. }
  3516. template <class _CharT, class _Traits>
  3517. template <class _ForwardIterator>
  3518. _ForwardIterator
  3519. basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last) {
  3520. if (__first != __last) {
  3521. switch (*__first) {
  3522. case '^':
  3523. case '$':
  3524. case '\\':
  3525. case '.':
  3526. case '*':
  3527. case '+':
  3528. case '?':
  3529. case '(':
  3530. case ')':
  3531. case '[':
  3532. case ']':
  3533. case '{':
  3534. case '}':
  3535. case '|':
  3536. break;
  3537. default:
  3538. __push_char(*__first);
  3539. ++__first;
  3540. break;
  3541. }
  3542. }
  3543. return __first;
  3544. }
  3545. template <class _CharT, class _Traits>
  3546. template <class _ForwardIterator>
  3547. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, _ForwardIterator __last) {
  3548. __owns_one_state<_CharT>* __sa = __end_;
  3549. _ForwardIterator __t1 = std::find(__first, __last, _CharT('\n'));
  3550. if (__t1 != __first)
  3551. __parse_basic_reg_exp(__first, __t1);
  3552. else
  3553. __push_empty();
  3554. __first = __t1;
  3555. if (__first != __last)
  3556. ++__first;
  3557. while (__first != __last) {
  3558. __t1 = std::find(__first, __last, _CharT('\n'));
  3559. __owns_one_state<_CharT>* __sb = __end_;
  3560. if (__t1 != __first)
  3561. __parse_basic_reg_exp(__first, __t1);
  3562. else
  3563. __push_empty();
  3564. __push_alternation(__sa, __sb);
  3565. __first = __t1;
  3566. if (__first != __last)
  3567. ++__first;
  3568. }
  3569. return __first;
  3570. }
  3571. template <class _CharT, class _Traits>
  3572. template <class _ForwardIterator>
  3573. _ForwardIterator basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, _ForwardIterator __last) {
  3574. __owns_one_state<_CharT>* __sa = __end_;
  3575. _ForwardIterator __t1 = std::find(__first, __last, _CharT('\n'));
  3576. if (__t1 != __first)
  3577. __parse_extended_reg_exp(__first, __t1);
  3578. else
  3579. __push_empty();
  3580. __first = __t1;
  3581. if (__first != __last)
  3582. ++__first;
  3583. while (__first != __last) {
  3584. __t1 = std::find(__first, __last, _CharT('\n'));
  3585. __owns_one_state<_CharT>* __sb = __end_;
  3586. if (__t1 != __first)
  3587. __parse_extended_reg_exp(__first, __t1);
  3588. else
  3589. __push_empty();
  3590. __push_alternation(__sa, __sb);
  3591. __first = __t1;
  3592. if (__first != __last)
  3593. ++__first;
  3594. }
  3595. return __first;
  3596. }
  3597. template <class _CharT, class _Traits>
  3598. bool basic_regex<_CharT, _Traits>::__test_back_ref(_CharT __c) {
  3599. unsigned __val = __traits_.value(__c, 10);
  3600. if (__val >= 1 && __val <= 9) {
  3601. if (__val > mark_count())
  3602. __throw_regex_error<regex_constants::error_backref>();
  3603. __push_back_ref(__val);
  3604. return true;
  3605. }
  3606. return false;
  3607. }
  3608. template <class _CharT, class _Traits>
  3609. void basic_regex<_CharT, _Traits>::__push_loop(
  3610. size_t __min, size_t __max, __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, bool __greedy) {
  3611. unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
  3612. __end_->first() = nullptr;
  3613. unique_ptr<__loop<_CharT> > __e2(
  3614. new __loop<_CharT>(__loop_count_, __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, __min, __max));
  3615. __s->first() = nullptr;
  3616. __e1.release();
  3617. __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
  3618. __end_ = __e2->second();
  3619. __s->first() = __e2.release();
  3620. ++__loop_count_;
  3621. }
  3622. template <class _CharT, class _Traits>
  3623. void basic_regex<_CharT, _Traits>::__push_char(value_type __c) {
  3624. if (flags() & icase)
  3625. __end_->first() = new __match_char_icase<_CharT, _Traits>(__traits_, __c, __end_->first());
  3626. else if (flags() & collate)
  3627. __end_->first() = new __match_char_collate<_CharT, _Traits>(__traits_, __c, __end_->first());
  3628. else
  3629. __end_->first() = new __match_char<_CharT>(__c, __end_->first());
  3630. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3631. }
  3632. template <class _CharT, class _Traits>
  3633. void basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() {
  3634. if (!(__flags_ & nosubs)) {
  3635. __end_->first() = new __begin_marked_subexpression<_CharT>(++__marked_count_, __end_->first());
  3636. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3637. }
  3638. }
  3639. template <class _CharT, class _Traits>
  3640. void basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) {
  3641. if (!(__flags_ & nosubs)) {
  3642. __end_->first() = new __end_marked_subexpression<_CharT>(__sub, __end_->first());
  3643. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3644. }
  3645. }
  3646. template <class _CharT, class _Traits>
  3647. void basic_regex<_CharT, _Traits>::__push_l_anchor() {
  3648. __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
  3649. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3650. }
  3651. template <class _CharT, class _Traits>
  3652. void basic_regex<_CharT, _Traits>::__push_r_anchor() {
  3653. __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
  3654. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3655. }
  3656. template <class _CharT, class _Traits>
  3657. void basic_regex<_CharT, _Traits>::__push_match_any() {
  3658. __end_->first() = new __match_any<_CharT>(__end_->first());
  3659. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3660. }
  3661. template <class _CharT, class _Traits>
  3662. void basic_regex<_CharT, _Traits>::__push_match_any_but_newline() {
  3663. __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
  3664. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3665. }
  3666. template <class _CharT, class _Traits>
  3667. void basic_regex<_CharT, _Traits>::__push_empty() {
  3668. __end_->first() = new __empty_state<_CharT>(__end_->first());
  3669. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3670. }
  3671. template <class _CharT, class _Traits>
  3672. void basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) {
  3673. __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, __end_->first());
  3674. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3675. }
  3676. template <class _CharT, class _Traits>
  3677. void basic_regex<_CharT, _Traits>::__push_back_ref(int __i) {
  3678. if (flags() & icase)
  3679. __end_->first() = new __back_ref_icase<_CharT, _Traits>(__traits_, __i, __end_->first());
  3680. else if (flags() & collate)
  3681. __end_->first() = new __back_ref_collate<_CharT, _Traits>(__traits_, __i, __end_->first());
  3682. else
  3683. __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
  3684. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3685. }
  3686. template <class _CharT, class _Traits>
  3687. void basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, __owns_one_state<_CharT>* __ea) {
  3688. __sa->first() = new __alternate<_CharT>(
  3689. static_cast<__owns_one_state<_CharT>*>(__sa->first()), static_cast<__owns_one_state<_CharT>*>(__ea->first()));
  3690. __ea->first() = nullptr;
  3691. __ea->first() = new __empty_state<_CharT>(__end_->first());
  3692. __end_->first() = nullptr;
  3693. __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
  3694. __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
  3695. }
  3696. template <class _CharT, class _Traits>
  3697. __bracket_expression<_CharT, _Traits>* basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) {
  3698. __bracket_expression<_CharT, _Traits>* __r = new __bracket_expression<_CharT, _Traits>(
  3699. __traits_, __end_->first(), __negate, __flags_ & icase, __flags_ & collate);
  3700. __end_->first() = __r;
  3701. __end_ = __r;
  3702. return __r;
  3703. }
  3704. template <class _CharT, class _Traits>
  3705. void basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, bool __invert, unsigned __mexp) {
  3706. __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, __end_->first(), __mexp);
  3707. __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
  3708. }
  3709. // sub_match
  3710. typedef sub_match<const char*> csub_match;
  3711. typedef sub_match<string::const_iterator> ssub_match;
  3712. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  3713. typedef sub_match<const wchar_t*> wcsub_match;
  3714. typedef sub_match<wstring::const_iterator> wssub_match;
  3715. #endif
  3716. template <class _BidirectionalIterator>
  3717. class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(csub_match)
  3718. _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match)) _LIBCPP_PREFERRED_NAME(ssub_match)
  3719. _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match)) sub_match
  3720. : public pair<_BidirectionalIterator, _BidirectionalIterator> {
  3721. public:
  3722. typedef _BidirectionalIterator iterator;
  3723. typedef typename iterator_traits<iterator>::value_type value_type;
  3724. typedef typename iterator_traits<iterator>::difference_type difference_type;
  3725. typedef basic_string<value_type> string_type;
  3726. bool matched;
  3727. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR sub_match() : matched() {}
  3728. _LIBCPP_HIDE_FROM_ABI difference_type length() const {
  3729. return matched ? std::distance(this->first, this->second) : 0;
  3730. }
  3731. _LIBCPP_HIDE_FROM_ABI string_type str() const {
  3732. return matched ? string_type(this->first, this->second) : string_type();
  3733. }
  3734. _LIBCPP_HIDE_FROM_ABI operator string_type() const { return str(); }
  3735. _LIBCPP_HIDE_FROM_ABI int compare(const sub_match& __s) const { return str().compare(__s.str()); }
  3736. _LIBCPP_HIDE_FROM_ABI int compare(const string_type& __s) const { return str().compare(__s); }
  3737. _LIBCPP_HIDE_FROM_ABI int compare(const value_type* __s) const { return str().compare(__s); }
  3738. _LIBCPP_HIDE_FROM_ABI void swap(sub_match& __s)
  3739. #ifndef _LIBCPP_CXX03_LANG
  3740. _NOEXCEPT(__is_nothrow_swappable<_BidirectionalIterator>::value)
  3741. #endif // _LIBCPP_CXX03_LANG
  3742. {
  3743. this->pair<_BidirectionalIterator, _BidirectionalIterator>::swap(__s);
  3744. std::swap(matched, __s.matched);
  3745. }
  3746. };
  3747. template <class _BiIter>
  3748. inline _LIBCPP_HIDE_FROM_ABI bool operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
  3749. return __x.compare(__y) == 0;
  3750. }
  3751. #if _LIBCPP_STD_VER >= 20
  3752. template <class _BiIter>
  3753. using __sub_match_cat = compare_three_way_result_t<basic_string<typename iterator_traits<_BiIter>::value_type>>;
  3754. template <class _BiIter>
  3755. _LIBCPP_HIDE_FROM_ABI auto operator<=>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
  3756. return static_cast<__sub_match_cat<_BiIter>>(__x.compare(__y) <=> 0);
  3757. }
  3758. #else // _LIBCPP_STD_VER >= 20
  3759. template <class _BiIter>
  3760. inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
  3761. return !(__x == __y);
  3762. }
  3763. template <class _BiIter>
  3764. inline _LIBCPP_HIDE_FROM_ABI bool operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
  3765. return __x.compare(__y) < 0;
  3766. }
  3767. template <class _BiIter>
  3768. inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
  3769. return !(__y < __x);
  3770. }
  3771. template <class _BiIter>
  3772. inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
  3773. return !(__x < __y);
  3774. }
  3775. template <class _BiIter>
  3776. inline _LIBCPP_HIDE_FROM_ABI bool operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
  3777. return __y < __x;
  3778. }
  3779. template <class _BiIter, class _ST, class _SA>
  3780. inline _LIBCPP_HIDE_FROM_ABI bool
  3781. operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
  3782. const sub_match<_BiIter>& __y) {
  3783. return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
  3784. }
  3785. template <class _BiIter, class _ST, class _SA>
  3786. inline _LIBCPP_HIDE_FROM_ABI bool
  3787. operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
  3788. const sub_match<_BiIter>& __y) {
  3789. return !(__x == __y);
  3790. }
  3791. template <class _BiIter, class _ST, class _SA>
  3792. inline _LIBCPP_HIDE_FROM_ABI bool
  3793. operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
  3794. const sub_match<_BiIter>& __y) {
  3795. return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
  3796. }
  3797. template <class _BiIter, class _ST, class _SA>
  3798. inline _LIBCPP_HIDE_FROM_ABI bool
  3799. operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
  3800. const sub_match<_BiIter>& __y) {
  3801. return __y < __x;
  3802. }
  3803. template <class _BiIter, class _ST, class _SA>
  3804. inline _LIBCPP_HIDE_FROM_ABI bool
  3805. operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
  3806. const sub_match<_BiIter>& __y) {
  3807. return !(__x < __y);
  3808. }
  3809. template <class _BiIter, class _ST, class _SA>
  3810. inline _LIBCPP_HIDE_FROM_ABI bool
  3811. operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
  3812. const sub_match<_BiIter>& __y) {
  3813. return !(__y < __x);
  3814. }
  3815. #endif // _LIBCPP_STD_VER >= 20
  3816. template <class _BiIter, class _ST, class _SA>
  3817. inline _LIBCPP_HIDE_FROM_ABI bool
  3818. operator==(const sub_match<_BiIter>& __x,
  3819. const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
  3820. return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
  3821. }
  3822. #if _LIBCPP_STD_VER >= 20
  3823. template <class _BiIter, class _ST, class _SA>
  3824. _LIBCPP_HIDE_FROM_ABI auto
  3825. operator<=>(const sub_match<_BiIter>& __x,
  3826. const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
  3827. return static_cast<__sub_match_cat<_BiIter>>(
  3828. __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) <=> 0);
  3829. }
  3830. #else // _LIBCPP_STD_VER >= 20
  3831. template <class _BiIter, class _ST, class _SA>
  3832. inline _LIBCPP_HIDE_FROM_ABI bool
  3833. operator!=(const sub_match<_BiIter>& __x,
  3834. const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
  3835. return !(__x == __y);
  3836. }
  3837. template <class _BiIter, class _ST, class _SA>
  3838. inline _LIBCPP_HIDE_FROM_ABI bool
  3839. operator<(const sub_match<_BiIter>& __x,
  3840. const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
  3841. return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
  3842. }
  3843. template <class _BiIter, class _ST, class _SA>
  3844. inline _LIBCPP_HIDE_FROM_ABI bool
  3845. operator>(const sub_match<_BiIter>& __x,
  3846. const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
  3847. return __y < __x;
  3848. }
  3849. template <class _BiIter, class _ST, class _SA>
  3850. inline _LIBCPP_HIDE_FROM_ABI bool
  3851. operator>=(const sub_match<_BiIter>& __x,
  3852. const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
  3853. return !(__x < __y);
  3854. }
  3855. template <class _BiIter, class _ST, class _SA>
  3856. inline _LIBCPP_HIDE_FROM_ABI bool
  3857. operator<=(const sub_match<_BiIter>& __x,
  3858. const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
  3859. return !(__y < __x);
  3860. }
  3861. template <class _BiIter>
  3862. inline _LIBCPP_HIDE_FROM_ABI bool
  3863. operator==(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
  3864. return __y.compare(__x) == 0;
  3865. }
  3866. template <class _BiIter>
  3867. inline _LIBCPP_HIDE_FROM_ABI bool
  3868. operator!=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
  3869. return !(__x == __y);
  3870. }
  3871. template <class _BiIter>
  3872. inline _LIBCPP_HIDE_FROM_ABI bool
  3873. operator<(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
  3874. return __y.compare(__x) > 0;
  3875. }
  3876. template <class _BiIter>
  3877. inline _LIBCPP_HIDE_FROM_ABI bool
  3878. operator>(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
  3879. return __y < __x;
  3880. }
  3881. template <class _BiIter>
  3882. inline _LIBCPP_HIDE_FROM_ABI bool
  3883. operator>=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
  3884. return !(__x < __y);
  3885. }
  3886. template <class _BiIter>
  3887. inline _LIBCPP_HIDE_FROM_ABI bool
  3888. operator<=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
  3889. return !(__y < __x);
  3890. }
  3891. #endif // _LIBCPP_STD_VER >= 20
  3892. template <class _BiIter>
  3893. inline _LIBCPP_HIDE_FROM_ABI bool
  3894. operator==(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
  3895. return __x.compare(__y) == 0;
  3896. }
  3897. #if _LIBCPP_STD_VER >= 20
  3898. template <class _BiIter>
  3899. _LIBCPP_HIDE_FROM_ABI auto
  3900. operator<=>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
  3901. return static_cast<__sub_match_cat<_BiIter>>(__x.compare(__y) <=> 0);
  3902. }
  3903. #else // _LIBCPP_STD_VER >= 20
  3904. template <class _BiIter>
  3905. inline _LIBCPP_HIDE_FROM_ABI bool
  3906. operator!=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
  3907. return !(__x == __y);
  3908. }
  3909. template <class _BiIter>
  3910. inline _LIBCPP_HIDE_FROM_ABI bool
  3911. operator<(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
  3912. return __x.compare(__y) < 0;
  3913. }
  3914. template <class _BiIter>
  3915. inline _LIBCPP_HIDE_FROM_ABI bool
  3916. operator>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
  3917. return __y < __x;
  3918. }
  3919. template <class _BiIter>
  3920. inline _LIBCPP_HIDE_FROM_ABI bool
  3921. operator>=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
  3922. return !(__x < __y);
  3923. }
  3924. template <class _BiIter>
  3925. inline _LIBCPP_HIDE_FROM_ABI bool
  3926. operator<=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
  3927. return !(__y < __x);
  3928. }
  3929. template <class _BiIter>
  3930. inline _LIBCPP_HIDE_FROM_ABI bool
  3931. operator==(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
  3932. typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
  3933. return __y.compare(string_type(1, __x)) == 0;
  3934. }
  3935. template <class _BiIter>
  3936. inline _LIBCPP_HIDE_FROM_ABI bool
  3937. operator!=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
  3938. return !(__x == __y);
  3939. }
  3940. template <class _BiIter>
  3941. inline _LIBCPP_HIDE_FROM_ABI bool
  3942. operator<(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
  3943. typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
  3944. return __y.compare(string_type(1, __x)) > 0;
  3945. }
  3946. template <class _BiIter>
  3947. inline _LIBCPP_HIDE_FROM_ABI bool
  3948. operator>(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
  3949. return __y < __x;
  3950. }
  3951. template <class _BiIter>
  3952. inline _LIBCPP_HIDE_FROM_ABI bool
  3953. operator>=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
  3954. return !(__x < __y);
  3955. }
  3956. template <class _BiIter>
  3957. inline _LIBCPP_HIDE_FROM_ABI bool
  3958. operator<=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
  3959. return !(__y < __x);
  3960. }
  3961. #endif // _LIBCPP_STD_VER >= 20
  3962. template <class _BiIter>
  3963. inline _LIBCPP_HIDE_FROM_ABI bool
  3964. operator==(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
  3965. typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
  3966. return __x.compare(string_type(1, __y)) == 0;
  3967. }
  3968. #if _LIBCPP_STD_VER >= 20
  3969. template <class _BiIter>
  3970. _LIBCPP_HIDE_FROM_ABI auto
  3971. operator<=>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
  3972. using string_type = basic_string<typename iterator_traits<_BiIter>::value_type>;
  3973. return static_cast<__sub_match_cat<_BiIter>>(__x.compare(string_type(1, __y)) <=> 0);
  3974. }
  3975. #else // _LIBCPP_STD_VER >= 20
  3976. template <class _BiIter>
  3977. inline _LIBCPP_HIDE_FROM_ABI bool
  3978. operator!=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
  3979. return !(__x == __y);
  3980. }
  3981. template <class _BiIter>
  3982. inline _LIBCPP_HIDE_FROM_ABI bool
  3983. operator<(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
  3984. typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
  3985. return __x.compare(string_type(1, __y)) < 0;
  3986. }
  3987. template <class _BiIter>
  3988. inline _LIBCPP_HIDE_FROM_ABI bool
  3989. operator>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
  3990. return __y < __x;
  3991. }
  3992. template <class _BiIter>
  3993. inline _LIBCPP_HIDE_FROM_ABI bool
  3994. operator>=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
  3995. return !(__x < __y);
  3996. }
  3997. template <class _BiIter>
  3998. inline _LIBCPP_HIDE_FROM_ABI bool
  3999. operator<=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
  4000. return !(__y < __x);
  4001. }
  4002. #endif // _LIBCPP_STD_VER >= 20
  4003. template <class _CharT, class _ST, class _BiIter>
  4004. inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _ST>&
  4005. operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) {
  4006. return __os << __m.str();
  4007. }
  4008. typedef match_results<const char*> cmatch;
  4009. typedef match_results<string::const_iterator> smatch;
  4010. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  4011. typedef match_results<const wchar_t*> wcmatch;
  4012. typedef match_results<wstring::const_iterator> wsmatch;
  4013. #endif
  4014. template <class _BidirectionalIterator, class _Allocator>
  4015. class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cmatch) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
  4016. _LIBCPP_PREFERRED_NAME(smatch) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch)) match_results {
  4017. public:
  4018. typedef _Allocator allocator_type;
  4019. typedef sub_match<_BidirectionalIterator> value_type;
  4020. private:
  4021. typedef vector<value_type, allocator_type> __container_type;
  4022. __container_type __matches_;
  4023. value_type __unmatched_;
  4024. value_type __prefix_;
  4025. value_type __suffix_;
  4026. bool __ready_;
  4027. public:
  4028. _BidirectionalIterator __position_start_;
  4029. typedef const value_type& const_reference;
  4030. typedef value_type& reference;
  4031. typedef typename __container_type::const_iterator const_iterator;
  4032. typedef const_iterator iterator;
  4033. typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
  4034. typedef typename allocator_traits<allocator_type>::size_type size_type;
  4035. typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
  4036. typedef basic_string<char_type> string_type;
  4037. // construct/copy/destroy:
  4038. #ifndef _LIBCPP_CXX03_LANG
  4039. match_results() : match_results(allocator_type()) {}
  4040. explicit match_results(const allocator_type& __a);
  4041. #else
  4042. explicit match_results(const allocator_type& __a = allocator_type());
  4043. #endif
  4044. // match_results(const match_results&) = default;
  4045. // match_results& operator=(const match_results&) = default;
  4046. // match_results(match_results&& __m) = default;
  4047. // match_results& operator=(match_results&& __m) = default;
  4048. // ~match_results() = default;
  4049. _LIBCPP_HIDE_FROM_ABI bool ready() const { return __ready_; }
  4050. // size:
  4051. _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __matches_.size(); }
  4052. _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __matches_.max_size(); }
  4053. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return size() == 0; }
  4054. // element access:
  4055. _LIBCPP_HIDE_FROM_ABI difference_type length(size_type __sub = 0) const {
  4056. // If the match results are not ready, this will return `0`.
  4057. _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::length() called when not ready");
  4058. return (*this)[__sub].length();
  4059. }
  4060. _LIBCPP_HIDE_FROM_ABI difference_type position(size_type __sub = 0) const {
  4061. // If the match results are not ready, this will return the result of subtracting two default-constructed iterators
  4062. // (which is typically a well-defined operation).
  4063. _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::position() called when not ready");
  4064. return std::distance(__position_start_, (*this)[__sub].first);
  4065. }
  4066. _LIBCPP_HIDE_FROM_ABI string_type str(size_type __sub = 0) const {
  4067. // If the match results are not ready, this will return an empty string.
  4068. _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::str() called when not ready");
  4069. return (*this)[__sub].str();
  4070. }
  4071. _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const {
  4072. // If the match results are not ready, this call will be equivalent to calling this function with `__n >= size()`,
  4073. // returning an empty subrange.
  4074. _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::operator[]() called when not ready");
  4075. return __n < __matches_.size() ? __matches_[__n] : __unmatched_;
  4076. }
  4077. _LIBCPP_HIDE_FROM_ABI const_reference prefix() const {
  4078. // If the match results are not ready, this will return a default-constructed empty `__suffix_`.
  4079. _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::prefix() called when not ready");
  4080. return __prefix_;
  4081. }
  4082. _LIBCPP_HIDE_FROM_ABI const_reference suffix() const {
  4083. // If the match results are not ready, this will return a default-constructed empty `__suffix_`.
  4084. _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::suffix() called when not ready");
  4085. return __suffix_;
  4086. }
  4087. _LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return empty() ? __matches_.end() : __matches_.begin(); }
  4088. _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __matches_.end(); }
  4089. _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const { return empty() ? __matches_.end() : __matches_.begin(); }
  4090. _LIBCPP_HIDE_FROM_ABI const_iterator cend() const { return __matches_.end(); }
  4091. // format:
  4092. template <class _OutputIter>
  4093. _OutputIter format(_OutputIter __output_iter,
  4094. const char_type* __fmt_first,
  4095. const char_type* __fmt_last,
  4096. regex_constants::match_flag_type __flags = regex_constants::format_default) const;
  4097. template <class _OutputIter, class _ST, class _SA>
  4098. _LIBCPP_HIDE_FROM_ABI _OutputIter
  4099. format(_OutputIter __output_iter,
  4100. const basic_string<char_type, _ST, _SA>& __fmt,
  4101. regex_constants::match_flag_type __flags = regex_constants::format_default) const {
  4102. return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);
  4103. }
  4104. template <class _ST, class _SA>
  4105. _LIBCPP_HIDE_FROM_ABI basic_string<char_type, _ST, _SA>
  4106. format(const basic_string<char_type, _ST, _SA>& __fmt,
  4107. regex_constants::match_flag_type __flags = regex_constants::format_default) const {
  4108. basic_string<char_type, _ST, _SA> __r;
  4109. format(std::back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), __flags);
  4110. return __r;
  4111. }
  4112. _LIBCPP_HIDE_FROM_ABI string_type
  4113. format(const char_type* __fmt, regex_constants::match_flag_type __flags = regex_constants::format_default) const {
  4114. string_type __r;
  4115. format(std::back_inserter(__r), __fmt, __fmt + char_traits<char_type>::length(__fmt), __flags);
  4116. return __r;
  4117. }
  4118. // allocator:
  4119. _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const { return __matches_.get_allocator(); }
  4120. // swap:
  4121. void swap(match_results& __m);
  4122. template <class _Bp, class _Ap>
  4123. _LIBCPP_HIDE_FROM_ABI void
  4124. __assign(_BidirectionalIterator __f,
  4125. _BidirectionalIterator __l,
  4126. const match_results<_Bp, _Ap>& __m,
  4127. bool __no_update_pos) {
  4128. _Bp __mf = __m.prefix().first;
  4129. __matches_.resize(__m.size());
  4130. for (size_type __i = 0; __i < __matches_.size(); ++__i) {
  4131. __matches_[__i].first = std::next(__f, std::distance(__mf, __m[__i].first));
  4132. __matches_[__i].second = std::next(__f, std::distance(__mf, __m[__i].second));
  4133. __matches_[__i].matched = __m[__i].matched;
  4134. }
  4135. __unmatched_.first = __l;
  4136. __unmatched_.second = __l;
  4137. __unmatched_.matched = false;
  4138. __prefix_.first = std::next(__f, std::distance(__mf, __m.prefix().first));
  4139. __prefix_.second = std::next(__f, std::distance(__mf, __m.prefix().second));
  4140. __prefix_.matched = __m.prefix().matched;
  4141. __suffix_.first = std::next(__f, std::distance(__mf, __m.suffix().first));
  4142. __suffix_.second = std::next(__f, std::distance(__mf, __m.suffix().second));
  4143. __suffix_.matched = __m.suffix().matched;
  4144. if (!__no_update_pos)
  4145. __position_start_ = __prefix_.first;
  4146. __ready_ = __m.ready();
  4147. }
  4148. private:
  4149. void __init(unsigned __s, _BidirectionalIterator __f, _BidirectionalIterator __l, bool __no_update_pos = false);
  4150. template <class, class>
  4151. friend class basic_regex;
  4152. template <class _Bp, class _Ap, class _Cp, class _Tp>
  4153. friend bool
  4154. regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
  4155. template <class _Bp, class _Ap>
  4156. friend bool operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
  4157. template <class, class>
  4158. friend class __lookahead;
  4159. };
  4160. template <class _BidirectionalIterator, class _Allocator>
  4161. match_results<_BidirectionalIterator, _Allocator>::match_results(const allocator_type& __a)
  4162. : __matches_(__a), __unmatched_(), __prefix_(), __suffix_(), __ready_(false), __position_start_() {}
  4163. template <class _BidirectionalIterator, class _Allocator>
  4164. void match_results<_BidirectionalIterator, _Allocator>::__init(
  4165. unsigned __s, _BidirectionalIterator __f, _BidirectionalIterator __l, bool __no_update_pos) {
  4166. __unmatched_.first = __l;
  4167. __unmatched_.second = __l;
  4168. __unmatched_.matched = false;
  4169. __matches_.assign(__s, __unmatched_);
  4170. __prefix_.first = __f;
  4171. __prefix_.second = __f;
  4172. __prefix_.matched = false;
  4173. __suffix_ = __unmatched_;
  4174. if (!__no_update_pos)
  4175. __position_start_ = __prefix_.first;
  4176. __ready_ = true;
  4177. }
  4178. template <class _BidirectionalIterator, class _Allocator>
  4179. template <class _OutputIter>
  4180. _OutputIter match_results<_BidirectionalIterator, _Allocator>::format(
  4181. _OutputIter __output_iter,
  4182. const char_type* __fmt_first,
  4183. const char_type* __fmt_last,
  4184. regex_constants::match_flag_type __flags) const {
  4185. // Note: this duplicates a check in `vector::operator[]` but provides a better error message.
  4186. _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(ready(), "match_results::format() called when not ready");
  4187. if (__flags & regex_constants::format_sed) {
  4188. for (; __fmt_first != __fmt_last; ++__fmt_first) {
  4189. if (*__fmt_first == '&')
  4190. __output_iter = std::copy(__matches_[0].first, __matches_[0].second, __output_iter);
  4191. else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) {
  4192. ++__fmt_first;
  4193. if ('0' <= *__fmt_first && *__fmt_first <= '9') {
  4194. size_t __i = *__fmt_first - '0';
  4195. __output_iter = std::copy((*this)[__i].first, (*this)[__i].second, __output_iter);
  4196. } else {
  4197. *__output_iter = *__fmt_first;
  4198. ++__output_iter;
  4199. }
  4200. } else {
  4201. *__output_iter = *__fmt_first;
  4202. ++__output_iter;
  4203. }
  4204. }
  4205. } else {
  4206. for (; __fmt_first != __fmt_last; ++__fmt_first) {
  4207. if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) {
  4208. switch (__fmt_first[1]) {
  4209. case '$':
  4210. *__output_iter = *++__fmt_first;
  4211. ++__output_iter;
  4212. break;
  4213. case '&':
  4214. ++__fmt_first;
  4215. __output_iter = std::copy(__matches_[0].first, __matches_[0].second, __output_iter);
  4216. break;
  4217. case '`':
  4218. ++__fmt_first;
  4219. __output_iter = std::copy(__prefix_.first, __prefix_.second, __output_iter);
  4220. break;
  4221. case '\'':
  4222. ++__fmt_first;
  4223. __output_iter = std::copy(__suffix_.first, __suffix_.second, __output_iter);
  4224. break;
  4225. default:
  4226. if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') {
  4227. ++__fmt_first;
  4228. size_t __idx = *__fmt_first - '0';
  4229. if (__fmt_first + 1 != __fmt_last && '0' <= __fmt_first[1] && __fmt_first[1] <= '9') {
  4230. ++__fmt_first;
  4231. if (__idx >= numeric_limits<size_t>::max() / 10)
  4232. __throw_regex_error<regex_constants::error_escape>();
  4233. __idx = 10 * __idx + *__fmt_first - '0';
  4234. }
  4235. __output_iter = std::copy((*this)[__idx].first, (*this)[__idx].second, __output_iter);
  4236. } else {
  4237. *__output_iter = *__fmt_first;
  4238. ++__output_iter;
  4239. }
  4240. break;
  4241. }
  4242. } else {
  4243. *__output_iter = *__fmt_first;
  4244. ++__output_iter;
  4245. }
  4246. }
  4247. }
  4248. return __output_iter;
  4249. }
  4250. template <class _BidirectionalIterator, class _Allocator>
  4251. void match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) {
  4252. using std::swap;
  4253. swap(__matches_, __m.__matches_);
  4254. swap(__unmatched_, __m.__unmatched_);
  4255. swap(__prefix_, __m.__prefix_);
  4256. swap(__suffix_, __m.__suffix_);
  4257. swap(__position_start_, __m.__position_start_);
  4258. swap(__ready_, __m.__ready_);
  4259. }
  4260. template <class _BidirectionalIterator, class _Allocator>
  4261. _LIBCPP_HIDE_FROM_ABI bool operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
  4262. const match_results<_BidirectionalIterator, _Allocator>& __y) {
  4263. if (__x.__ready_ != __y.__ready_)
  4264. return false;
  4265. if (!__x.__ready_)
  4266. return true;
  4267. return __x.__matches_ == __y.__matches_ && __x.__prefix_ == __y.__prefix_ && __x.__suffix_ == __y.__suffix_;
  4268. }
  4269. #if _LIBCPP_STD_VER < 20
  4270. template <class _BidirectionalIterator, class _Allocator>
  4271. inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
  4272. const match_results<_BidirectionalIterator, _Allocator>& __y) {
  4273. return !(__x == __y);
  4274. }
  4275. #endif
  4276. template <class _BidirectionalIterator, class _Allocator>
  4277. inline _LIBCPP_HIDE_FROM_ABI void
  4278. swap(match_results<_BidirectionalIterator, _Allocator>& __x, match_results<_BidirectionalIterator, _Allocator>& __y) {
  4279. __x.swap(__y);
  4280. }
  4281. // regex_search
  4282. template <class _CharT, class _Traits>
  4283. template <class _Allocator>
  4284. bool basic_regex<_CharT, _Traits>::__match_at_start_ecma(
  4285. const _CharT* __first,
  4286. const _CharT* __last,
  4287. match_results<const _CharT*, _Allocator>& __m,
  4288. regex_constants::match_flag_type __flags,
  4289. bool __at_first) const {
  4290. vector<__state> __states;
  4291. __node* __st = __start_.get();
  4292. if (__st) {
  4293. sub_match<const _CharT*> __unmatched;
  4294. __unmatched.first = __last;
  4295. __unmatched.second = __last;
  4296. __unmatched.matched = false;
  4297. __states.push_back(__state());
  4298. __states.back().__do_ = 0;
  4299. __states.back().__first_ = __first;
  4300. __states.back().__current_ = __first;
  4301. __states.back().__last_ = __last;
  4302. __states.back().__sub_matches_.resize(mark_count(), __unmatched);
  4303. __states.back().__loop_data_.resize(__loop_count());
  4304. __states.back().__node_ = __st;
  4305. __states.back().__flags_ = __flags;
  4306. __states.back().__at_first_ = __at_first;
  4307. int __counter = 0;
  4308. int __length = __last - __first;
  4309. do {
  4310. ++__counter;
  4311. if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
  4312. __throw_regex_error<regex_constants::error_complexity>();
  4313. __state& __s = __states.back();
  4314. if (__s.__node_)
  4315. __s.__node_->__exec(__s);
  4316. switch (__s.__do_) {
  4317. case __state::__end_state:
  4318. if ((__flags & regex_constants::match_not_null) && __s.__current_ == __first) {
  4319. __states.pop_back();
  4320. break;
  4321. }
  4322. if ((__flags & regex_constants::__full_match) && __s.__current_ != __last) {
  4323. __states.pop_back();
  4324. break;
  4325. }
  4326. __m.__matches_[0].first = __first;
  4327. __m.__matches_[0].second = std::next(__first, __s.__current_ - __first);
  4328. __m.__matches_[0].matched = true;
  4329. for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
  4330. __m.__matches_[__i + 1] = __s.__sub_matches_[__i];
  4331. return true;
  4332. case __state::__accept_and_consume:
  4333. case __state::__repeat:
  4334. case __state::__accept_but_not_consume:
  4335. break;
  4336. case __state::__split: {
  4337. __state __snext = __s;
  4338. __s.__node_->__exec_split(true, __s);
  4339. __snext.__node_->__exec_split(false, __snext);
  4340. __states.push_back(std::move(__snext));
  4341. } break;
  4342. case __state::__reject:
  4343. __states.pop_back();
  4344. break;
  4345. default:
  4346. __throw_regex_error<regex_constants::__re_err_unknown>();
  4347. break;
  4348. }
  4349. } while (!__states.empty());
  4350. }
  4351. return false;
  4352. }
  4353. template <class _CharT, class _Traits>
  4354. template <class _Allocator>
  4355. bool basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
  4356. const _CharT* __first,
  4357. const _CharT* __last,
  4358. match_results<const _CharT*, _Allocator>& __m,
  4359. regex_constants::match_flag_type __flags,
  4360. bool __at_first) const {
  4361. deque<__state> __states;
  4362. ptrdiff_t __highest_j = 0;
  4363. ptrdiff_t __np = std::distance(__first, __last);
  4364. __node* __st = __start_.get();
  4365. if (__st) {
  4366. __states.push_back(__state());
  4367. __states.back().__do_ = 0;
  4368. __states.back().__first_ = __first;
  4369. __states.back().__current_ = __first;
  4370. __states.back().__last_ = __last;
  4371. __states.back().__loop_data_.resize(__loop_count());
  4372. __states.back().__node_ = __st;
  4373. __states.back().__flags_ = __flags;
  4374. __states.back().__at_first_ = __at_first;
  4375. bool __matched = false;
  4376. int __counter = 0;
  4377. int __length = __last - __first;
  4378. do {
  4379. ++__counter;
  4380. if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
  4381. __throw_regex_error<regex_constants::error_complexity>();
  4382. __state& __s = __states.back();
  4383. if (__s.__node_)
  4384. __s.__node_->__exec(__s);
  4385. switch (__s.__do_) {
  4386. case __state::__end_state:
  4387. if ((__flags & regex_constants::match_not_null) && __s.__current_ == __first) {
  4388. __states.pop_back();
  4389. break;
  4390. }
  4391. if ((__flags & regex_constants::__full_match) && __s.__current_ != __last) {
  4392. __states.pop_back();
  4393. break;
  4394. }
  4395. if (!__matched || __highest_j < __s.__current_ - __s.__first_)
  4396. __highest_j = __s.__current_ - __s.__first_;
  4397. __matched = true;
  4398. if (__highest_j == __np)
  4399. __states.clear();
  4400. else
  4401. __states.pop_back();
  4402. break;
  4403. case __state::__consume_input:
  4404. break;
  4405. case __state::__accept_and_consume:
  4406. __states.push_front(std::move(__s));
  4407. __states.pop_back();
  4408. break;
  4409. case __state::__repeat:
  4410. case __state::__accept_but_not_consume:
  4411. break;
  4412. case __state::__split: {
  4413. __state __snext = __s;
  4414. __s.__node_->__exec_split(true, __s);
  4415. __snext.__node_->__exec_split(false, __snext);
  4416. __states.push_back(std::move(__snext));
  4417. } break;
  4418. case __state::__reject:
  4419. __states.pop_back();
  4420. break;
  4421. default:
  4422. __throw_regex_error<regex_constants::__re_err_unknown>();
  4423. break;
  4424. }
  4425. } while (!__states.empty());
  4426. if (__matched) {
  4427. __m.__matches_[0].first = __first;
  4428. __m.__matches_[0].second = std::next(__first, __highest_j);
  4429. __m.__matches_[0].matched = true;
  4430. return true;
  4431. }
  4432. }
  4433. return false;
  4434. }
  4435. template <class _CharT, class _Traits>
  4436. template <class _Allocator>
  4437. bool basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
  4438. const _CharT* __first,
  4439. const _CharT* __last,
  4440. match_results<const _CharT*, _Allocator>& __m,
  4441. regex_constants::match_flag_type __flags,
  4442. bool __at_first) const {
  4443. vector<__state> __states;
  4444. __state __best_state;
  4445. ptrdiff_t __highest_j = 0;
  4446. ptrdiff_t __np = std::distance(__first, __last);
  4447. __node* __st = __start_.get();
  4448. if (__st) {
  4449. sub_match<const _CharT*> __unmatched;
  4450. __unmatched.first = __last;
  4451. __unmatched.second = __last;
  4452. __unmatched.matched = false;
  4453. __states.push_back(__state());
  4454. __states.back().__do_ = 0;
  4455. __states.back().__first_ = __first;
  4456. __states.back().__current_ = __first;
  4457. __states.back().__last_ = __last;
  4458. __states.back().__sub_matches_.resize(mark_count(), __unmatched);
  4459. __states.back().__loop_data_.resize(__loop_count());
  4460. __states.back().__node_ = __st;
  4461. __states.back().__flags_ = __flags;
  4462. __states.back().__at_first_ = __at_first;
  4463. bool __matched = false;
  4464. int __counter = 0;
  4465. int __length = __last - __first;
  4466. do {
  4467. ++__counter;
  4468. if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
  4469. __throw_regex_error<regex_constants::error_complexity>();
  4470. __state& __s = __states.back();
  4471. if (__s.__node_)
  4472. __s.__node_->__exec(__s);
  4473. switch (__s.__do_) {
  4474. case __state::__end_state:
  4475. if ((__flags & regex_constants::match_not_null) && __s.__current_ == __first) {
  4476. __states.pop_back();
  4477. break;
  4478. }
  4479. if ((__flags & regex_constants::__full_match) && __s.__current_ != __last) {
  4480. __states.pop_back();
  4481. break;
  4482. }
  4483. if (!__matched || __highest_j < __s.__current_ - __s.__first_) {
  4484. __highest_j = __s.__current_ - __s.__first_;
  4485. __best_state = __s;
  4486. }
  4487. __matched = true;
  4488. if (__highest_j == __np)
  4489. __states.clear();
  4490. else
  4491. __states.pop_back();
  4492. break;
  4493. case __state::__accept_and_consume:
  4494. case __state::__repeat:
  4495. case __state::__accept_but_not_consume:
  4496. break;
  4497. case __state::__split: {
  4498. __state __snext = __s;
  4499. __s.__node_->__exec_split(true, __s);
  4500. __snext.__node_->__exec_split(false, __snext);
  4501. __states.push_back(std::move(__snext));
  4502. } break;
  4503. case __state::__reject:
  4504. __states.pop_back();
  4505. break;
  4506. default:
  4507. __throw_regex_error<regex_constants::__re_err_unknown>();
  4508. break;
  4509. }
  4510. } while (!__states.empty());
  4511. if (__matched) {
  4512. __m.__matches_[0].first = __first;
  4513. __m.__matches_[0].second = std::next(__first, __highest_j);
  4514. __m.__matches_[0].matched = true;
  4515. for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
  4516. __m.__matches_[__i + 1] = __best_state.__sub_matches_[__i];
  4517. return true;
  4518. }
  4519. }
  4520. return false;
  4521. }
  4522. template <class _CharT, class _Traits>
  4523. template <class _Allocator>
  4524. bool basic_regex<_CharT, _Traits>::__match_at_start(
  4525. const _CharT* __first,
  4526. const _CharT* __last,
  4527. match_results<const _CharT*, _Allocator>& __m,
  4528. regex_constants::match_flag_type __flags,
  4529. bool __at_first) const {
  4530. if (__get_grammar(__flags_) == ECMAScript)
  4531. return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
  4532. if (mark_count() == 0)
  4533. return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
  4534. return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
  4535. }
  4536. template <class _CharT, class _Traits>
  4537. template <class _Allocator>
  4538. bool basic_regex<_CharT, _Traits>::__search(
  4539. const _CharT* __first,
  4540. const _CharT* __last,
  4541. match_results<const _CharT*, _Allocator>& __m,
  4542. regex_constants::match_flag_type __flags) const {
  4543. if (__flags & regex_constants::match_prev_avail)
  4544. __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow);
  4545. __m.__init(1 + mark_count(), __first, __last, __flags & regex_constants::__no_update_pos);
  4546. if (__match_at_start(__first, __last, __m, __flags, !(__flags & regex_constants::__no_update_pos))) {
  4547. __m.__prefix_.second = __m[0].first;
  4548. __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
  4549. __m.__suffix_.first = __m[0].second;
  4550. __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
  4551. return true;
  4552. }
  4553. if (__first != __last && !(__flags & regex_constants::match_continuous)) {
  4554. __flags |= regex_constants::match_prev_avail;
  4555. for (++__first; __first != __last; ++__first) {
  4556. __m.__matches_.assign(__m.size(), __m.__unmatched_);
  4557. if (__match_at_start(__first, __last, __m, __flags, false)) {
  4558. __m.__prefix_.second = __m[0].first;
  4559. __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
  4560. __m.__suffix_.first = __m[0].second;
  4561. __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
  4562. return true;
  4563. }
  4564. __m.__matches_.assign(__m.size(), __m.__unmatched_);
  4565. }
  4566. __m.__matches_.assign(__m.size(), __m.__unmatched_);
  4567. if (__match_at_start(__first, __last, __m, __flags, false)) {
  4568. __m.__prefix_.second = __m[0].first;
  4569. __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
  4570. __m.__suffix_.first = __m[0].second;
  4571. __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
  4572. return true;
  4573. }
  4574. }
  4575. __m.__matches_.clear();
  4576. return false;
  4577. }
  4578. template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
  4579. inline _LIBCPP_HIDE_FROM_ABI bool
  4580. regex_search(_BidirectionalIterator __first,
  4581. _BidirectionalIterator __last,
  4582. match_results<_BidirectionalIterator, _Allocator>& __m,
  4583. const basic_regex<_CharT, _Traits>& __e,
  4584. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4585. int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
  4586. basic_string<_CharT> __s(std::prev(__first, __offset), __last);
  4587. match_results<const _CharT*> __mc;
  4588. bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
  4589. __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
  4590. return __r;
  4591. }
  4592. template <class _Iter, class _Allocator, class _CharT, class _Traits>
  4593. inline _LIBCPP_HIDE_FROM_ABI bool
  4594. regex_search(__wrap_iter<_Iter> __first,
  4595. __wrap_iter<_Iter> __last,
  4596. match_results<__wrap_iter<_Iter>, _Allocator>& __m,
  4597. const basic_regex<_CharT, _Traits>& __e,
  4598. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4599. match_results<const _CharT*> __mc;
  4600. bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
  4601. __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
  4602. return __r;
  4603. }
  4604. template <class _Allocator, class _CharT, class _Traits>
  4605. inline _LIBCPP_HIDE_FROM_ABI bool
  4606. regex_search(const _CharT* __first,
  4607. const _CharT* __last,
  4608. match_results<const _CharT*, _Allocator>& __m,
  4609. const basic_regex<_CharT, _Traits>& __e,
  4610. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4611. return __e.__search(__first, __last, __m, __flags);
  4612. }
  4613. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4614. inline _LIBCPP_HIDE_FROM_ABI bool
  4615. regex_search(_BidirectionalIterator __first,
  4616. _BidirectionalIterator __last,
  4617. const basic_regex<_CharT, _Traits>& __e,
  4618. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4619. basic_string<_CharT> __s(__first, __last);
  4620. match_results<const _CharT*> __mc;
  4621. return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
  4622. }
  4623. template <class _CharT, class _Traits>
  4624. inline _LIBCPP_HIDE_FROM_ABI bool
  4625. regex_search(const _CharT* __first,
  4626. const _CharT* __last,
  4627. const basic_regex<_CharT, _Traits>& __e,
  4628. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4629. match_results<const _CharT*> __mc;
  4630. return __e.__search(__first, __last, __mc, __flags);
  4631. }
  4632. template <class _CharT, class _Allocator, class _Traits>
  4633. inline _LIBCPP_HIDE_FROM_ABI bool
  4634. regex_search(const _CharT* __str,
  4635. match_results<const _CharT*, _Allocator>& __m,
  4636. const basic_regex<_CharT, _Traits>& __e,
  4637. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4638. return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
  4639. }
  4640. template <class _CharT, class _Traits>
  4641. inline _LIBCPP_HIDE_FROM_ABI bool
  4642. regex_search(const _CharT* __str,
  4643. const basic_regex<_CharT, _Traits>& __e,
  4644. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4645. match_results<const _CharT*> __m;
  4646. return std::regex_search(__str, __m, __e, __flags);
  4647. }
  4648. template <class _ST, class _SA, class _CharT, class _Traits>
  4649. inline _LIBCPP_HIDE_FROM_ABI bool
  4650. regex_search(const basic_string<_CharT, _ST, _SA>& __s,
  4651. const basic_regex<_CharT, _Traits>& __e,
  4652. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4653. match_results<const _CharT*> __mc;
  4654. return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
  4655. }
  4656. template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
  4657. inline _LIBCPP_HIDE_FROM_ABI bool
  4658. regex_search(const basic_string<_CharT, _ST, _SA>& __s,
  4659. match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
  4660. const basic_regex<_CharT, _Traits>& __e,
  4661. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4662. match_results<const _CharT*> __mc;
  4663. bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
  4664. __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
  4665. return __r;
  4666. }
  4667. #if _LIBCPP_STD_VER >= 14
  4668. template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
  4669. bool regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
  4670. match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
  4671. const basic_regex<_Cp, _Tp>& __e,
  4672. regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
  4673. #endif
  4674. // regex_match
  4675. template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
  4676. _LIBCPP_HIDE_FROM_ABI bool
  4677. regex_match(_BidirectionalIterator __first,
  4678. _BidirectionalIterator __last,
  4679. match_results<_BidirectionalIterator, _Allocator>& __m,
  4680. const basic_regex<_CharT, _Traits>& __e,
  4681. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4682. bool __r = std::regex_search(
  4683. __first, __last, __m, __e, __flags | regex_constants::match_continuous | regex_constants::__full_match);
  4684. if (__r) {
  4685. __r = !__m.suffix().matched;
  4686. if (!__r)
  4687. __m.__matches_.clear();
  4688. }
  4689. return __r;
  4690. }
  4691. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4692. inline _LIBCPP_HIDE_FROM_ABI bool
  4693. regex_match(_BidirectionalIterator __first,
  4694. _BidirectionalIterator __last,
  4695. const basic_regex<_CharT, _Traits>& __e,
  4696. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4697. match_results<_BidirectionalIterator> __m;
  4698. return std::regex_match(__first, __last, __m, __e, __flags);
  4699. }
  4700. template <class _CharT, class _Allocator, class _Traits>
  4701. inline _LIBCPP_HIDE_FROM_ABI bool
  4702. regex_match(const _CharT* __str,
  4703. match_results<const _CharT*, _Allocator>& __m,
  4704. const basic_regex<_CharT, _Traits>& __e,
  4705. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4706. return std::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
  4707. }
  4708. template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
  4709. inline _LIBCPP_HIDE_FROM_ABI bool
  4710. regex_match(const basic_string<_CharT, _ST, _SA>& __s,
  4711. match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
  4712. const basic_regex<_CharT, _Traits>& __e,
  4713. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4714. return std::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
  4715. }
  4716. #if _LIBCPP_STD_VER >= 14
  4717. template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
  4718. inline _LIBCPP_HIDE_FROM_ABI bool
  4719. regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
  4720. match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
  4721. const basic_regex<_CharT, _Traits>& __e,
  4722. regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
  4723. #endif
  4724. template <class _CharT, class _Traits>
  4725. inline _LIBCPP_HIDE_FROM_ABI bool
  4726. regex_match(const _CharT* __str,
  4727. const basic_regex<_CharT, _Traits>& __e,
  4728. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4729. return std::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
  4730. }
  4731. template <class _ST, class _SA, class _CharT, class _Traits>
  4732. inline _LIBCPP_HIDE_FROM_ABI bool
  4733. regex_match(const basic_string<_CharT, _ST, _SA>& __s,
  4734. const basic_regex<_CharT, _Traits>& __e,
  4735. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  4736. return std::regex_match(__s.begin(), __s.end(), __e, __flags);
  4737. }
  4738. // regex_iterator
  4739. template <class _BidirectionalIterator,
  4740. class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
  4741. class _Traits = regex_traits<_CharT> >
  4742. class _LIBCPP_TEMPLATE_VIS regex_iterator;
  4743. typedef regex_iterator<const char*> cregex_iterator;
  4744. typedef regex_iterator<string::const_iterator> sregex_iterator;
  4745. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  4746. typedef regex_iterator<const wchar_t*> wcregex_iterator;
  4747. typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
  4748. #endif
  4749. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4750. class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cregex_iterator)
  4751. _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator)) _LIBCPP_PREFERRED_NAME(sregex_iterator)
  4752. _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator)) regex_iterator {
  4753. public:
  4754. typedef basic_regex<_CharT, _Traits> regex_type;
  4755. typedef match_results<_BidirectionalIterator> value_type;
  4756. typedef ptrdiff_t difference_type;
  4757. typedef const value_type* pointer;
  4758. typedef const value_type& reference;
  4759. typedef forward_iterator_tag iterator_category;
  4760. #if _LIBCPP_STD_VER >= 20
  4761. typedef input_iterator_tag iterator_concept;
  4762. #endif
  4763. private:
  4764. _BidirectionalIterator __begin_;
  4765. _BidirectionalIterator __end_;
  4766. const regex_type* __pregex_;
  4767. regex_constants::match_flag_type __flags_;
  4768. value_type __match_;
  4769. public:
  4770. regex_iterator();
  4771. regex_iterator(_BidirectionalIterator __a,
  4772. _BidirectionalIterator __b,
  4773. const regex_type& __re,
  4774. regex_constants::match_flag_type __m = regex_constants::match_default);
  4775. #if _LIBCPP_STD_VER >= 14
  4776. regex_iterator(_BidirectionalIterator __a,
  4777. _BidirectionalIterator __b,
  4778. const regex_type&& __re,
  4779. regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
  4780. #endif
  4781. _LIBCPP_HIDE_FROM_ABI bool operator==(const regex_iterator& __x) const;
  4782. #if _LIBCPP_STD_VER >= 20
  4783. _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const { return *this == regex_iterator(); }
  4784. #endif
  4785. #if _LIBCPP_STD_VER < 20
  4786. _LIBCPP_HIDE_FROM_ABI bool operator!=(const regex_iterator& __x) const { return !(*this == __x); }
  4787. #endif
  4788. _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __match_; }
  4789. _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return std::addressof(__match_); }
  4790. regex_iterator& operator++();
  4791. _LIBCPP_HIDE_FROM_ABI regex_iterator operator++(int) {
  4792. regex_iterator __t(*this);
  4793. ++(*this);
  4794. return __t;
  4795. }
  4796. };
  4797. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4798. regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
  4799. : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() {}
  4800. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4801. regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator(
  4802. _BidirectionalIterator __a,
  4803. _BidirectionalIterator __b,
  4804. const regex_type& __re,
  4805. regex_constants::match_flag_type __m)
  4806. : __begin_(__a), __end_(__b), __pregex_(std::addressof(__re)), __flags_(__m) {
  4807. std::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
  4808. }
  4809. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4810. bool regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator==(const regex_iterator& __x) const {
  4811. if (__match_.empty() && __x.__match_.empty())
  4812. return true;
  4813. if (__match_.empty() || __x.__match_.empty())
  4814. return false;
  4815. return __begin_ == __x.__begin_ && __end_ == __x.__end_ && __pregex_ == __x.__pregex_ && __flags_ == __x.__flags_ &&
  4816. __match_[0] == __x.__match_[0];
  4817. }
  4818. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4819. regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
  4820. regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() {
  4821. __flags_ |= regex_constants::__no_update_pos;
  4822. _BidirectionalIterator __start = __match_[0].second;
  4823. if (__match_[0].first == __match_[0].second) {
  4824. if (__start == __end_) {
  4825. __match_ = value_type();
  4826. return *this;
  4827. } else if (std::regex_search(__start,
  4828. __end_,
  4829. __match_,
  4830. *__pregex_,
  4831. __flags_ | regex_constants::match_not_null | regex_constants::match_continuous))
  4832. return *this;
  4833. else
  4834. ++__start;
  4835. }
  4836. __flags_ |= regex_constants::match_prev_avail;
  4837. if (!std::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
  4838. __match_ = value_type();
  4839. return *this;
  4840. }
  4841. // regex_token_iterator
  4842. template <class _BidirectionalIterator,
  4843. class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
  4844. class _Traits = regex_traits<_CharT> >
  4845. class _LIBCPP_TEMPLATE_VIS regex_token_iterator;
  4846. typedef regex_token_iterator<const char*> cregex_token_iterator;
  4847. typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
  4848. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  4849. typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
  4850. typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
  4851. #endif
  4852. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4853. class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
  4854. _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator))
  4855. _LIBCPP_PREFERRED_NAME(sregex_token_iterator)
  4856. _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator)) regex_token_iterator {
  4857. public:
  4858. typedef basic_regex<_CharT, _Traits> regex_type;
  4859. typedef sub_match<_BidirectionalIterator> value_type;
  4860. typedef ptrdiff_t difference_type;
  4861. typedef const value_type* pointer;
  4862. typedef const value_type& reference;
  4863. typedef forward_iterator_tag iterator_category;
  4864. #if _LIBCPP_STD_VER >= 20
  4865. typedef input_iterator_tag iterator_concept;
  4866. #endif
  4867. private:
  4868. typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
  4869. _Position __position_;
  4870. const value_type* __result_;
  4871. value_type __suffix_;
  4872. ptrdiff_t __n_;
  4873. vector<int> __subs_;
  4874. public:
  4875. regex_token_iterator();
  4876. regex_token_iterator(_BidirectionalIterator __a,
  4877. _BidirectionalIterator __b,
  4878. const regex_type& __re,
  4879. int __submatch = 0,
  4880. regex_constants::match_flag_type __m = regex_constants::match_default);
  4881. #if _LIBCPP_STD_VER >= 14
  4882. regex_token_iterator(_BidirectionalIterator __a,
  4883. _BidirectionalIterator __b,
  4884. const regex_type&& __re,
  4885. int __submatch = 0,
  4886. regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
  4887. #endif
  4888. regex_token_iterator(_BidirectionalIterator __a,
  4889. _BidirectionalIterator __b,
  4890. const regex_type& __re,
  4891. const vector<int>& __submatches,
  4892. regex_constants::match_flag_type __m = regex_constants::match_default);
  4893. #if _LIBCPP_STD_VER >= 14
  4894. regex_token_iterator(_BidirectionalIterator __a,
  4895. _BidirectionalIterator __b,
  4896. const regex_type&& __re,
  4897. const vector<int>& __submatches,
  4898. regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
  4899. #endif
  4900. #ifndef _LIBCPP_CXX03_LANG
  4901. regex_token_iterator(_BidirectionalIterator __a,
  4902. _BidirectionalIterator __b,
  4903. const regex_type& __re,
  4904. initializer_list<int> __submatches,
  4905. regex_constants::match_flag_type __m = regex_constants::match_default);
  4906. # if _LIBCPP_STD_VER >= 14
  4907. regex_token_iterator(_BidirectionalIterator __a,
  4908. _BidirectionalIterator __b,
  4909. const regex_type&& __re,
  4910. initializer_list<int> __submatches,
  4911. regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
  4912. # endif
  4913. #endif // _LIBCPP_CXX03_LANG
  4914. template <size_t _Np>
  4915. regex_token_iterator(_BidirectionalIterator __a,
  4916. _BidirectionalIterator __b,
  4917. const regex_type& __re,
  4918. const int (&__submatches)[_Np],
  4919. regex_constants::match_flag_type __m = regex_constants::match_default);
  4920. #if _LIBCPP_STD_VER >= 14
  4921. template <size_t _Np>
  4922. regex_token_iterator(_BidirectionalIterator __a,
  4923. _BidirectionalIterator __b,
  4924. const regex_type&& __re,
  4925. const int (&__submatches)[_Np],
  4926. regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
  4927. #endif
  4928. regex_token_iterator(const regex_token_iterator&);
  4929. regex_token_iterator& operator=(const regex_token_iterator&);
  4930. _LIBCPP_HIDE_FROM_ABI bool operator==(const regex_token_iterator& __x) const;
  4931. #if _LIBCPP_STD_VER >= 20
  4932. _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const {
  4933. return *this == regex_token_iterator();
  4934. }
  4935. #endif
  4936. #if _LIBCPP_STD_VER < 20
  4937. _LIBCPP_HIDE_FROM_ABI bool operator!=(const regex_token_iterator& __x) const { return !(*this == __x); }
  4938. #endif
  4939. _LIBCPP_HIDE_FROM_ABI const value_type& operator*() const { return *__result_; }
  4940. _LIBCPP_HIDE_FROM_ABI const value_type* operator->() const { return __result_; }
  4941. regex_token_iterator& operator++();
  4942. _LIBCPP_HIDE_FROM_ABI regex_token_iterator operator++(int) {
  4943. regex_token_iterator __t(*this);
  4944. ++(*this);
  4945. return __t;
  4946. }
  4947. private:
  4948. void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
  4949. void __establish_result() {
  4950. if (__subs_[__n_] == -1)
  4951. __result_ = &__position_->prefix();
  4952. else
  4953. __result_ = &(*__position_)[__subs_[__n_]];
  4954. }
  4955. };
  4956. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4957. regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator()
  4958. : __result_(nullptr), __suffix_(), __n_(0) {}
  4959. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4960. void regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::__init(
  4961. _BidirectionalIterator __a, _BidirectionalIterator __b) {
  4962. if (__position_ != _Position())
  4963. __establish_result();
  4964. else if (__subs_[__n_] == -1) {
  4965. __suffix_.matched = true;
  4966. __suffix_.first = __a;
  4967. __suffix_.second = __b;
  4968. __result_ = &__suffix_;
  4969. } else
  4970. __result_ = nullptr;
  4971. }
  4972. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4973. regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
  4974. _BidirectionalIterator __a,
  4975. _BidirectionalIterator __b,
  4976. const regex_type& __re,
  4977. int __submatch,
  4978. regex_constants::match_flag_type __m)
  4979. : __position_(__a, __b, __re, __m), __n_(0), __subs_(1, __submatch) {
  4980. __init(__a, __b);
  4981. }
  4982. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4983. regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
  4984. _BidirectionalIterator __a,
  4985. _BidirectionalIterator __b,
  4986. const regex_type& __re,
  4987. const vector<int>& __submatches,
  4988. regex_constants::match_flag_type __m)
  4989. : __position_(__a, __b, __re, __m), __n_(0), __subs_(__submatches) {
  4990. __init(__a, __b);
  4991. }
  4992. #ifndef _LIBCPP_CXX03_LANG
  4993. template <class _BidirectionalIterator, class _CharT, class _Traits>
  4994. regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
  4995. _BidirectionalIterator __a,
  4996. _BidirectionalIterator __b,
  4997. const regex_type& __re,
  4998. initializer_list<int> __submatches,
  4999. regex_constants::match_flag_type __m)
  5000. : __position_(__a, __b, __re, __m), __n_(0), __subs_(__submatches) {
  5001. __init(__a, __b);
  5002. }
  5003. #endif // _LIBCPP_CXX03_LANG
  5004. template <class _BidirectionalIterator, class _CharT, class _Traits>
  5005. template <size_t _Np>
  5006. regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
  5007. _BidirectionalIterator __a,
  5008. _BidirectionalIterator __b,
  5009. const regex_type& __re,
  5010. const int (&__submatches)[_Np],
  5011. regex_constants::match_flag_type __m)
  5012. : __position_(__a, __b, __re, __m), __n_(0), __subs_(begin(__submatches), end(__submatches)) {
  5013. __init(__a, __b);
  5014. }
  5015. template <class _BidirectionalIterator, class _CharT, class _Traits>
  5016. regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(const regex_token_iterator& __x)
  5017. : __position_(__x.__position_),
  5018. __result_(__x.__result_),
  5019. __suffix_(__x.__suffix_),
  5020. __n_(__x.__n_),
  5021. __subs_(__x.__subs_) {
  5022. if (__x.__result_ == &__x.__suffix_)
  5023. __result_ = &__suffix_;
  5024. else if (__result_ != nullptr)
  5025. __establish_result();
  5026. }
  5027. template <class _BidirectionalIterator, class _CharT, class _Traits>
  5028. regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
  5029. regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator=(const regex_token_iterator& __x) {
  5030. if (this != &__x) {
  5031. __position_ = __x.__position_;
  5032. if (__x.__result_ == &__x.__suffix_)
  5033. __result_ = &__suffix_;
  5034. else
  5035. __result_ = __x.__result_;
  5036. __suffix_ = __x.__suffix_;
  5037. __n_ = __x.__n_;
  5038. __subs_ = __x.__subs_;
  5039. if (__result_ != nullptr && __result_ != &__suffix_)
  5040. __establish_result();
  5041. }
  5042. return *this;
  5043. }
  5044. template <class _BidirectionalIterator, class _CharT, class _Traits>
  5045. bool regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator==(const regex_token_iterator& __x) const {
  5046. if (__result_ == nullptr && __x.__result_ == nullptr)
  5047. return true;
  5048. if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && __suffix_ == __x.__suffix_)
  5049. return true;
  5050. if (__result_ == nullptr || __x.__result_ == nullptr)
  5051. return false;
  5052. if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
  5053. return false;
  5054. return __position_ == __x.__position_ && __n_ == __x.__n_ && __subs_ == __x.__subs_;
  5055. }
  5056. template <class _BidirectionalIterator, class _CharT, class _Traits>
  5057. regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
  5058. regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() {
  5059. _Position __prev = __position_;
  5060. if (__result_ == &__suffix_)
  5061. __result_ = nullptr;
  5062. else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) {
  5063. ++__n_;
  5064. __establish_result();
  5065. } else {
  5066. __n_ = 0;
  5067. ++__position_;
  5068. if (__position_ != _Position())
  5069. __establish_result();
  5070. else {
  5071. if (std::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() && __prev->suffix().length() != 0) {
  5072. __suffix_.matched = true;
  5073. __suffix_.first = __prev->suffix().first;
  5074. __suffix_.second = __prev->suffix().second;
  5075. __result_ = &__suffix_;
  5076. } else
  5077. __result_ = nullptr;
  5078. }
  5079. }
  5080. return *this;
  5081. }
  5082. // regex_replace
  5083. template <class _OutputIterator, class _BidirectionalIterator, class _Traits, class _CharT>
  5084. _LIBCPP_HIDE_FROM_ABI _OutputIterator regex_replace(
  5085. _OutputIterator __output_iter,
  5086. _BidirectionalIterator __first,
  5087. _BidirectionalIterator __last,
  5088. const basic_regex<_CharT, _Traits>& __e,
  5089. const _CharT* __fmt,
  5090. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  5091. typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
  5092. _Iter __i(__first, __last, __e, __flags);
  5093. _Iter __eof;
  5094. if (__i == __eof) {
  5095. if (!(__flags & regex_constants::format_no_copy))
  5096. __output_iter = std::copy(__first, __last, __output_iter);
  5097. } else {
  5098. sub_match<_BidirectionalIterator> __lm;
  5099. for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) {
  5100. if (!(__flags & regex_constants::format_no_copy))
  5101. __output_iter = std::copy(__i->prefix().first, __i->prefix().second, __output_iter);
  5102. __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags);
  5103. __lm = __i->suffix();
  5104. if (__flags & regex_constants::format_first_only)
  5105. break;
  5106. }
  5107. if (!(__flags & regex_constants::format_no_copy))
  5108. __output_iter = std::copy(__lm.first, __lm.second, __output_iter);
  5109. }
  5110. return __output_iter;
  5111. }
  5112. template <class _OutputIterator, class _BidirectionalIterator, class _Traits, class _CharT, class _ST, class _SA>
  5113. inline _LIBCPP_HIDE_FROM_ABI _OutputIterator regex_replace(
  5114. _OutputIterator __output_iter,
  5115. _BidirectionalIterator __first,
  5116. _BidirectionalIterator __last,
  5117. const basic_regex<_CharT, _Traits>& __e,
  5118. const basic_string<_CharT, _ST, _SA>& __fmt,
  5119. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  5120. return std::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags);
  5121. }
  5122. template <class _Traits, class _CharT, class _ST, class _SA, class _FST, class _FSA>
  5123. inline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, _ST, _SA>
  5124. regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
  5125. const basic_regex<_CharT, _Traits>& __e,
  5126. const basic_string<_CharT, _FST, _FSA>& __fmt,
  5127. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  5128. basic_string<_CharT, _ST, _SA> __r;
  5129. std::regex_replace(std::back_inserter(__r), __s.begin(), __s.end(), __e, __fmt.c_str(), __flags);
  5130. return __r;
  5131. }
  5132. template <class _Traits, class _CharT, class _ST, class _SA>
  5133. inline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, _ST, _SA>
  5134. regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
  5135. const basic_regex<_CharT, _Traits>& __e,
  5136. const _CharT* __fmt,
  5137. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  5138. basic_string<_CharT, _ST, _SA> __r;
  5139. std::regex_replace(std::back_inserter(__r), __s.begin(), __s.end(), __e, __fmt, __flags);
  5140. return __r;
  5141. }
  5142. template <class _Traits, class _CharT, class _ST, class _SA>
  5143. inline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT>
  5144. regex_replace(const _CharT* __s,
  5145. const basic_regex<_CharT, _Traits>& __e,
  5146. const basic_string<_CharT, _ST, _SA>& __fmt,
  5147. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  5148. basic_string<_CharT> __r;
  5149. std::regex_replace(std::back_inserter(__r), __s, __s + char_traits<_CharT>::length(__s), __e, __fmt.c_str(), __flags);
  5150. return __r;
  5151. }
  5152. template <class _Traits, class _CharT>
  5153. inline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT>
  5154. regex_replace(const _CharT* __s,
  5155. const basic_regex<_CharT, _Traits>& __e,
  5156. const _CharT* __fmt,
  5157. regex_constants::match_flag_type __flags = regex_constants::match_default) {
  5158. basic_string<_CharT> __r;
  5159. std::regex_replace(std::back_inserter(__r), __s, __s + char_traits<_CharT>::length(__s), __e, __fmt, __flags);
  5160. return __r;
  5161. }
  5162. _LIBCPP_END_NAMESPACE_STD
  5163. #if _LIBCPP_STD_VER >= 17
  5164. _LIBCPP_BEGIN_NAMESPACE_STD
  5165. namespace pmr {
  5166. template <class _BidirT>
  5167. using match_results _LIBCPP_AVAILABILITY_PMR =
  5168. std::match_results<_BidirT, polymorphic_allocator<std::sub_match<_BidirT>>>;
  5169. using cmatch _LIBCPP_AVAILABILITY_PMR = match_results<const char*>;
  5170. using smatch _LIBCPP_AVAILABILITY_PMR = match_results<std::pmr::string::const_iterator>;
  5171. # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  5172. using wcmatch _LIBCPP_AVAILABILITY_PMR = match_results<const wchar_t*>;
  5173. using wsmatch _LIBCPP_AVAILABILITY_PMR = match_results<std::pmr::wstring::const_iterator>;
  5174. # endif
  5175. } // namespace pmr
  5176. _LIBCPP_END_NAMESPACE_STD
  5177. #endif
  5178. _LIBCPP_POP_MACROS
  5179. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  5180. # include <atomic>
  5181. # include <concepts>
  5182. # include <cstdlib>
  5183. # include <iosfwd>
  5184. # include <iterator>
  5185. # include <mutex>
  5186. # include <new>
  5187. # include <type_traits>
  5188. # include <typeinfo>
  5189. # include <utility>
  5190. #endif
  5191. #endif // _LIBCPP_REGEX