regex 225 KB

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