regex 224 KB

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