regex 209 KB

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