regex 224 KB

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