regex 213 KB

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