regex 232 KB

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