regex 218 KB

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