123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123 |
- //===------------------------- locale.cpp ---------------------------------===//
- //
- // The LLVM Compiler Infrastructure
- //
- // This file is dual licensed under the MIT and the University of Illinois Open
- // Source Licenses. See LICENSE.TXT for details.
- //
- //===----------------------------------------------------------------------===//
- #include "__config"
- #if !defined(_LIBCPP_SGX_CONFIG)
- // On Solaris, we need to define something to make the C99 parts of localeconv
- // visible.
- #ifdef __sun__
- #define _LCONV_C99
- #endif
- #include "string"
- #include "locale"
- #include "codecvt"
- #include "vector"
- #include "algorithm"
- #include "typeinfo"
- #ifndef _LIBCPP_NO_EXCEPTIONS
- # include "type_traits"
- #endif
- #include "clocale"
- #include "cstring"
- #include "cwctype"
- #include "__sso_allocator"
- #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- #include "support/win32/locale_win32.h"
- #elif !defined(__ANDROID__)
- #include <langinfo.h>
- #endif
- #include <stdlib.h>
- #include <stdio.h>
- // On Linux, wint_t and wchar_t have different signed-ness, and this causes
- // lots of noise in the build log, but no bugs that I know of.
- #if defined(__clang__)
- #pragma clang diagnostic ignored "-Wsign-conversion"
- #endif
- _LIBCPP_BEGIN_NAMESPACE_STD
- #ifdef __cloc_defined
- locale_t __cloc() {
- // In theory this could create a race condition. In practice
- // the race condition is non-fatal since it will just create
- // a little resource leak. Better approach would be appreciated.
- static locale_t result = newlocale(LC_ALL_MASK, "C", 0);
- return result;
- }
- #endif // __cloc_defined
- namespace {
- struct release
- {
- void operator()(locale::facet* p) {p->__release_shared();}
- };
- template <class T, class A0>
- inline
- T&
- make(A0 a0)
- {
- static typename aligned_storage<sizeof(T)>::type buf;
- ::new (&buf) T(a0);
- return *reinterpret_cast<T*>(&buf);
- }
- template <class T, class A0, class A1>
- inline
- T&
- make(A0 a0, A1 a1)
- {
- static typename aligned_storage<sizeof(T)>::type buf;
- ::new (&buf) T(a0, a1);
- return *reinterpret_cast<T*>(&buf);
- }
- template <class T, class A0, class A1, class A2>
- inline
- T&
- make(A0 a0, A1 a1, A2 a2)
- {
- static typename aligned_storage<sizeof(T)>::type buf;
- ::new (&buf) T(a0, a1, a2);
- return *reinterpret_cast<T*>(&buf);
- }
- template <typename T, size_t N>
- inline
- _LIBCPP_CONSTEXPR
- size_t
- countof(const T (&)[N])
- {
- return N;
- }
- template <typename T>
- inline
- _LIBCPP_CONSTEXPR
- size_t
- countof(const T * const begin, const T * const end)
- {
- return static_cast<size_t>(end - begin);
- }
- }
- #if defined(_AIX)
- // Set priority to INT_MIN + 256 + 150
- # pragma priority ( -2147483242 )
- #endif
- const locale::category locale::none;
- const locale::category locale::collate;
- const locale::category locale::ctype;
- const locale::category locale::monetary;
- const locale::category locale::numeric;
- const locale::category locale::time;
- const locale::category locale::messages;
- const locale::category locale::all;
- class _LIBCPP_HIDDEN locale::__imp
- : public facet
- {
- enum {N = 28};
- #if defined(_LIBCPP_MSVC)
- // FIXME: MSVC doesn't support aligned parameters by value.
- // I can't get the __sso_allocator to work here
- // for MSVC I think for this reason.
- vector<facet*> facets_;
- #else
- vector<facet*, __sso_allocator<facet*, N> > facets_;
- #endif
- string name_;
- public:
- explicit __imp(size_t refs = 0);
- explicit __imp(const string& name, size_t refs = 0);
- __imp(const __imp&);
- __imp(const __imp&, const string&, locale::category c);
- __imp(const __imp& other, const __imp& one, locale::category c);
- __imp(const __imp&, facet* f, long id);
- ~__imp();
- const string& name() const {return name_;}
- bool has_facet(long id) const
- {return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)];}
- const locale::facet* use_facet(long id) const;
- static const locale& make_classic();
- static locale& make_global();
- private:
- void install(facet* f, long id);
- template <class F> void install(F* f) {install(f, f->id.__get());}
- template <class F> void install_from(const __imp& other);
- };
- locale::__imp::__imp(size_t refs)
- : facet(refs),
- facets_(N),
- name_("C")
- {
- facets_.clear();
- install(&make<_VSTD::collate<char> >(1u));
- install(&make<_VSTD::collate<wchar_t> >(1u));
- install(&make<_VSTD::ctype<char> >(nullptr, false, 1u));
- install(&make<_VSTD::ctype<wchar_t> >(1u));
- install(&make<codecvt<char, char, mbstate_t> >(1u));
- install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
- install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
- install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
- install(&make<numpunct<char> >(1u));
- install(&make<numpunct<wchar_t> >(1u));
- install(&make<num_get<char> >(1u));
- install(&make<num_get<wchar_t> >(1u));
- install(&make<num_put<char> >(1u));
- install(&make<num_put<wchar_t> >(1u));
- install(&make<moneypunct<char, false> >(1u));
- install(&make<moneypunct<char, true> >(1u));
- install(&make<moneypunct<wchar_t, false> >(1u));
- install(&make<moneypunct<wchar_t, true> >(1u));
- install(&make<money_get<char> >(1u));
- install(&make<money_get<wchar_t> >(1u));
- install(&make<money_put<char> >(1u));
- install(&make<money_put<wchar_t> >(1u));
- install(&make<time_get<char> >(1u));
- install(&make<time_get<wchar_t> >(1u));
- install(&make<time_put<char> >(1u));
- install(&make<time_put<wchar_t> >(1u));
- install(&make<_VSTD::messages<char> >(1u));
- install(&make<_VSTD::messages<wchar_t> >(1u));
- }
- locale::__imp::__imp(const string& name, size_t refs)
- : facet(refs),
- facets_(N),
- name_(name)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- facets_ = locale::classic().__locale_->facets_;
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__add_shared();
- install(new collate_byname<char>(name_));
- install(new collate_byname<wchar_t>(name_));
- install(new ctype_byname<char>(name_));
- install(new ctype_byname<wchar_t>(name_));
- install(new codecvt_byname<char, char, mbstate_t>(name_));
- install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
- install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
- install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
- install(new numpunct_byname<char>(name_));
- install(new numpunct_byname<wchar_t>(name_));
- install(new moneypunct_byname<char, false>(name_));
- install(new moneypunct_byname<char, true>(name_));
- install(new moneypunct_byname<wchar_t, false>(name_));
- install(new moneypunct_byname<wchar_t, true>(name_));
- install(new time_get_byname<char>(name_));
- install(new time_get_byname<wchar_t>(name_));
- install(new time_put_byname<char>(name_));
- install(new time_put_byname<wchar_t>(name_));
- install(new messages_byname<char>(name_));
- install(new messages_byname<wchar_t>(name_));
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__release_shared();
- throw;
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- // NOTE avoid the `base class should be explicitly initialized in the
- // copy constructor` warning emitted by GCC
- #if defined(__clang__) || _GNUC_VER >= 406
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wextra"
- #endif
- locale::__imp::__imp(const __imp& other)
- : facets_(max<size_t>(N, other.facets_.size())),
- name_(other.name_)
- {
- facets_ = other.facets_;
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__add_shared();
- }
- #if defined(__clang__) || _GNUC_VER >= 406
- #pragma GCC diagnostic pop
- #endif
- locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
- : facets_(N),
- name_("*")
- {
- facets_ = other.facets_;
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__add_shared();
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- if (c & locale::collate)
- {
- install(new collate_byname<char>(name));
- install(new collate_byname<wchar_t>(name));
- }
- if (c & locale::ctype)
- {
- install(new ctype_byname<char>(name));
- install(new ctype_byname<wchar_t>(name));
- install(new codecvt_byname<char, char, mbstate_t>(name));
- install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
- install(new codecvt_byname<char16_t, char, mbstate_t>(name));
- install(new codecvt_byname<char32_t, char, mbstate_t>(name));
- }
- if (c & locale::monetary)
- {
- install(new moneypunct_byname<char, false>(name));
- install(new moneypunct_byname<char, true>(name));
- install(new moneypunct_byname<wchar_t, false>(name));
- install(new moneypunct_byname<wchar_t, true>(name));
- }
- if (c & locale::numeric)
- {
- install(new numpunct_byname<char>(name));
- install(new numpunct_byname<wchar_t>(name));
- }
- if (c & locale::time)
- {
- install(new time_get_byname<char>(name));
- install(new time_get_byname<wchar_t>(name));
- install(new time_put_byname<char>(name));
- install(new time_put_byname<wchar_t>(name));
- }
- if (c & locale::messages)
- {
- install(new messages_byname<char>(name));
- install(new messages_byname<wchar_t>(name));
- }
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__release_shared();
- throw;
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- template<class F>
- inline
- void
- locale::__imp::install_from(const locale::__imp& one)
- {
- long id = F::id.__get();
- install(const_cast<F*>(static_cast<const F*>(one.use_facet(id))), id);
- }
- locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
- : facets_(N),
- name_("*")
- {
- facets_ = other.facets_;
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__add_shared();
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- if (c & locale::collate)
- {
- install_from<_VSTD::collate<char> >(one);
- install_from<_VSTD::collate<wchar_t> >(one);
- }
- if (c & locale::ctype)
- {
- install_from<_VSTD::ctype<char> >(one);
- install_from<_VSTD::ctype<wchar_t> >(one);
- install_from<_VSTD::codecvt<char, char, mbstate_t> >(one);
- install_from<_VSTD::codecvt<char16_t, char, mbstate_t> >(one);
- install_from<_VSTD::codecvt<char32_t, char, mbstate_t> >(one);
- install_from<_VSTD::codecvt<wchar_t, char, mbstate_t> >(one);
- }
- if (c & locale::monetary)
- {
- install_from<moneypunct<char, false> >(one);
- install_from<moneypunct<char, true> >(one);
- install_from<moneypunct<wchar_t, false> >(one);
- install_from<moneypunct<wchar_t, true> >(one);
- install_from<money_get<char> >(one);
- install_from<money_get<wchar_t> >(one);
- install_from<money_put<char> >(one);
- install_from<money_put<wchar_t> >(one);
- }
- if (c & locale::numeric)
- {
- install_from<numpunct<char> >(one);
- install_from<numpunct<wchar_t> >(one);
- install_from<num_get<char> >(one);
- install_from<num_get<wchar_t> >(one);
- install_from<num_put<char> >(one);
- install_from<num_put<wchar_t> >(one);
- }
- if (c & locale::time)
- {
- install_from<time_get<char> >(one);
- install_from<time_get<wchar_t> >(one);
- install_from<time_put<char> >(one);
- install_from<time_put<wchar_t> >(one);
- }
- if (c & locale::messages)
- {
- install_from<_VSTD::messages<char> >(one);
- install_from<_VSTD::messages<wchar_t> >(one);
- }
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__release_shared();
- throw;
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- locale::__imp::__imp(const __imp& other, facet* f, long id)
- : facets_(max<size_t>(N, other.facets_.size()+1)),
- name_("*")
- {
- f->__add_shared();
- unique_ptr<facet, release> hold(f);
- facets_ = other.facets_;
- for (unsigned i = 0; i < other.facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__add_shared();
- install(hold.get(), id);
- }
- locale::__imp::~__imp()
- {
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__release_shared();
- }
- void
- locale::__imp::install(facet* f, long id)
- {
- f->__add_shared();
- unique_ptr<facet, release> hold(f);
- if (static_cast<size_t>(id) >= facets_.size())
- facets_.resize(static_cast<size_t>(id+1));
- if (facets_[static_cast<size_t>(id)])
- facets_[static_cast<size_t>(id)]->__release_shared();
- facets_[static_cast<size_t>(id)] = hold.release();
- }
- const locale::facet*
- locale::__imp::use_facet(long id) const
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (!has_facet(id))
- throw bad_cast();
- #endif // _LIBCPP_NO_EXCEPTIONS
- return facets_[static_cast<size_t>(id)];
- }
- // locale
- const locale&
- locale::__imp::make_classic()
- {
- // only one thread can get in here and it only gets in once
- static aligned_storage<sizeof(locale)>::type buf;
- locale* c = reinterpret_cast<locale*>(&buf);
- c->__locale_ = &make<__imp>(1u);
- return *c;
- }
- const locale&
- locale::classic()
- {
- static const locale& c = __imp::make_classic();
- return c;
- }
- locale&
- locale::__imp::make_global()
- {
- // only one thread can get in here and it only gets in once
- static aligned_storage<sizeof(locale)>::type buf;
- ::new (&buf) locale(locale::classic());
- return *reinterpret_cast<locale*>(&buf);
- }
- locale&
- locale::__global()
- {
- static locale& g = __imp::make_global();
- return g;
- }
- locale::locale() _NOEXCEPT
- : __locale_(__global().__locale_)
- {
- __locale_->__add_shared();
- }
- locale::locale(const locale& l) _NOEXCEPT
- : __locale_(l.__locale_)
- {
- __locale_->__add_shared();
- }
- locale::~locale()
- {
- __locale_->__release_shared();
- }
- const locale&
- locale::operator=(const locale& other) _NOEXCEPT
- {
- other.__locale_->__add_shared();
- __locale_->__release_shared();
- __locale_ = other.__locale_;
- return *this;
- }
- locale::locale(const char* name)
- #ifndef _LIBCPP_NO_EXCEPTIONS
- : __locale_(name ? new __imp(name)
- : throw runtime_error("locale constructed with null"))
- #else // _LIBCPP_NO_EXCEPTIONS
- : __locale_(new __imp(name))
- #endif
- {
- __locale_->__add_shared();
- }
- locale::locale(const string& name)
- : __locale_(new __imp(name))
- {
- __locale_->__add_shared();
- }
- locale::locale(const locale& other, const char* name, category c)
- #ifndef _LIBCPP_NO_EXCEPTIONS
- : __locale_(name ? new __imp(*other.__locale_, name, c)
- : throw runtime_error("locale constructed with null"))
- #else // _LIBCPP_NO_EXCEPTIONS
- : __locale_(new __imp(*other.__locale_, name, c))
- #endif
- {
- __locale_->__add_shared();
- }
- locale::locale(const locale& other, const string& name, category c)
- : __locale_(new __imp(*other.__locale_, name, c))
- {
- __locale_->__add_shared();
- }
- locale::locale(const locale& other, const locale& one, category c)
- : __locale_(new __imp(*other.__locale_, *one.__locale_, c))
- {
- __locale_->__add_shared();
- }
- string
- locale::name() const
- {
- return __locale_->name();
- }
- void
- locale::__install_ctor(const locale& other, facet* f, long id)
- {
- if (f)
- __locale_ = new __imp(*other.__locale_, f, id);
- else
- __locale_ = other.__locale_;
- __locale_->__add_shared();
- }
- locale
- locale::global(const locale& loc)
- {
- locale& g = __global();
- locale r = g;
- g = loc;
- #ifndef __CloudABI__
- if (g.name() != "*")
- setlocale(LC_ALL, g.name().c_str());
- #endif
- return r;
- }
- bool
- locale::has_facet(id& x) const
- {
- return __locale_->has_facet(x.__get());
- }
- const locale::facet*
- locale::use_facet(id& x) const
- {
- return __locale_->use_facet(x.__get());
- }
- bool
- locale::operator==(const locale& y) const
- {
- return (__locale_ == y.__locale_)
- || (__locale_->name() != "*" && __locale_->name() == y.__locale_->name());
- }
- // locale::facet
- locale::facet::~facet()
- {
- }
- void
- locale::facet::__on_zero_shared() _NOEXCEPT
- {
- delete this;
- }
- // locale::id
- int32_t locale::id::__next_id = 0;
- namespace
- {
- class __fake_bind
- {
- locale::id* id_;
- void (locale::id::* pmf_)();
- public:
- __fake_bind(void (locale::id::* pmf)(), locale::id* id)
- : id_(id), pmf_(pmf) {}
- void operator()() const
- {
- (id_->*pmf_)();
- }
- };
- }
- long
- locale::id::__get()
- {
- call_once(__flag_, __fake_bind(&locale::id::__init, this));
- return __id_ - 1;
- }
- void
- locale::id::__init()
- {
- __id_ = __sync_add_and_fetch(&__next_id, 1);
- }
- // template <> class collate_byname<char>
- collate_byname<char>::collate_byname(const char* n, size_t refs)
- : collate<char>(refs),
- __l(newlocale(LC_ALL_MASK, n, 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__l == 0)
- throw runtime_error("collate_byname<char>::collate_byname"
- " failed to construct for " + string(n));
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- collate_byname<char>::collate_byname(const string& name, size_t refs)
- : collate<char>(refs),
- __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__l == 0)
- throw runtime_error("collate_byname<char>::collate_byname"
- " failed to construct for " + name);
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- collate_byname<char>::~collate_byname()
- {
- freelocale(__l);
- }
- int
- collate_byname<char>::do_compare(const char_type* __lo1, const char_type* __hi1,
- const char_type* __lo2, const char_type* __hi2) const
- {
- string_type lhs(__lo1, __hi1);
- string_type rhs(__lo2, __hi2);
- int r = strcoll_l(lhs.c_str(), rhs.c_str(), __l);
- if (r < 0)
- return -1;
- if (r > 0)
- return 1;
- return r;
- }
- collate_byname<char>::string_type
- collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) const
- {
- const string_type in(lo, hi);
- string_type out(strxfrm_l(0, in.c_str(), 0, __l), char());
- strxfrm_l(const_cast<char*>(out.c_str()), in.c_str(), out.size()+1, __l);
- return out;
- }
- // template <> class collate_byname<wchar_t>
- collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
- : collate<wchar_t>(refs),
- __l(newlocale(LC_ALL_MASK, n, 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__l == 0)
- throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
- " failed to construct for " + string(n));
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
- : collate<wchar_t>(refs),
- __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__l == 0)
- throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
- " failed to construct for " + name);
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- collate_byname<wchar_t>::~collate_byname()
- {
- freelocale(__l);
- }
- int
- collate_byname<wchar_t>::do_compare(const char_type* __lo1, const char_type* __hi1,
- const char_type* __lo2, const char_type* __hi2) const
- {
- string_type lhs(__lo1, __hi1);
- string_type rhs(__lo2, __hi2);
- int r = wcscoll_l(lhs.c_str(), rhs.c_str(), __l);
- if (r < 0)
- return -1;
- if (r > 0)
- return 1;
- return r;
- }
- collate_byname<wchar_t>::string_type
- collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi) const
- {
- const string_type in(lo, hi);
- string_type out(wcsxfrm_l(0, in.c_str(), 0, __l), wchar_t());
- wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size()+1, __l);
- return out;
- }
- // template <> class ctype<wchar_t>;
- const ctype_base::mask ctype_base::space;
- const ctype_base::mask ctype_base::print;
- const ctype_base::mask ctype_base::cntrl;
- const ctype_base::mask ctype_base::upper;
- const ctype_base::mask ctype_base::lower;
- const ctype_base::mask ctype_base::alpha;
- const ctype_base::mask ctype_base::digit;
- const ctype_base::mask ctype_base::punct;
- const ctype_base::mask ctype_base::xdigit;
- const ctype_base::mask ctype_base::blank;
- const ctype_base::mask ctype_base::alnum;
- const ctype_base::mask ctype_base::graph;
-
- locale::id ctype<wchar_t>::id;
- ctype<wchar_t>::~ctype()
- {
- }
- bool
- ctype<wchar_t>::do_is(mask m, char_type c) const
- {
- return isascii(c) ? (ctype<char>::classic_table()[c] & m) != 0 : false;
- }
- const wchar_t*
- ctype<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
- {
- for (; low != high; ++low, ++vec)
- *vec = static_cast<mask>(isascii(*low) ?
- ctype<char>::classic_table()[*low] : 0);
- return low;
- }
- const wchar_t*
- ctype<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- if (isascii(*low) && (ctype<char>::classic_table()[*low] & m))
- break;
- return low;
- }
- const wchar_t*
- ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
- break;
- return low;
- }
- wchar_t
- ctype<wchar_t>::do_toupper(char_type c) const
- {
- #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
- #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
- defined(__NetBSD__)
- return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
- #else
- return (isascii(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'a'+L'A' : c;
- #endif
- }
- const wchar_t*
- ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
- #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
- defined(__NetBSD__)
- *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
- : *low;
- #else
- *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? (*low-L'a'+L'A') : *low;
- #endif
- return low;
- }
- wchar_t
- ctype<wchar_t>::do_tolower(char_type c) const
- {
- #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
- #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
- defined(__NetBSD__)
- return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
- #else
- return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'A'+'a' : c;
- #endif
- }
- const wchar_t*
- ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
- #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
- defined(__NetBSD__)
- *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
- : *low;
- #else
- *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-L'A'+L'a' : *low;
- #endif
- return low;
- }
- wchar_t
- ctype<wchar_t>::do_widen(char c) const
- {
- return c;
- }
- const char*
- ctype<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
- {
- for (; low != high; ++low, ++dest)
- *dest = *low;
- return low;
- }
- char
- ctype<wchar_t>::do_narrow(char_type c, char dfault) const
- {
- if (isascii(c))
- return static_cast<char>(c);
- return dfault;
- }
- const wchar_t*
- ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
- {
- for (; low != high; ++low, ++dest)
- if (isascii(*low))
- *dest = static_cast<char>(*low);
- else
- *dest = dfault;
- return low;
- }
- // template <> class ctype<char>;
- locale::id ctype<char>::id;
- ctype<char>::ctype(const mask* tab, bool del, size_t refs)
- : locale::facet(refs),
- __tab_(tab),
- __del_(del)
- {
- if (__tab_ == 0)
- __tab_ = classic_table();
- }
- ctype<char>::~ctype()
- {
- if (__tab_ && __del_)
- delete [] __tab_;
- }
- char
- ctype<char>::do_toupper(char_type c) const
- {
- #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- return isascii(c) ?
- static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
- #elif defined(__NetBSD__)
- return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
- #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
- return isascii(c) ?
- static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
- #else
- return (isascii(c) && islower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'a'+'A' : c;
- #endif
- }
- const char*
- ctype<char>::do_toupper(char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- *low = isascii(*low) ?
- static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
- #elif defined(__NetBSD__)
- *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
- #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
- *low = isascii(*low) ?
- static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
- #else
- *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'a'+'A' : *low;
- #endif
- return low;
- }
- char
- ctype<char>::do_tolower(char_type c) const
- {
- #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- return isascii(c) ?
- static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
- #elif defined(__NetBSD__)
- return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
- #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
- return isascii(c) ?
- static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
- #else
- return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'A'+'a' : c;
- #endif
- }
- const char*
- ctype<char>::do_tolower(char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
- #elif defined(__NetBSD__)
- *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
- #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
- *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
- #else
- *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'A'+'a' : *low;
- #endif
- return low;
- }
- char
- ctype<char>::do_widen(char c) const
- {
- return c;
- }
- const char*
- ctype<char>::do_widen(const char* low, const char* high, char_type* dest) const
- {
- for (; low != high; ++low, ++dest)
- *dest = *low;
- return low;
- }
- char
- ctype<char>::do_narrow(char_type c, char dfault) const
- {
- if (isascii(c))
- return static_cast<char>(c);
- return dfault;
- }
- const char*
- ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
- {
- for (; low != high; ++low, ++dest)
- if (isascii(*low))
- *dest = *low;
- else
- *dest = dfault;
- return low;
- }
- #if defined(__EMSCRIPTEN__)
- extern "C" const unsigned short ** __ctype_b_loc();
- extern "C" const int ** __ctype_tolower_loc();
- extern "C" const int ** __ctype_toupper_loc();
- #endif
- #ifdef _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
- const ctype<char>::mask*
- ctype<char>::classic_table() _NOEXCEPT
- {
- static _LIBCPP_CONSTEXPR const ctype<char>::mask builtin_table[table_size] = {
- cntrl, cntrl,
- cntrl, cntrl,
- cntrl, cntrl,
- cntrl, cntrl,
- cntrl, cntrl | space | blank,
- cntrl | space, cntrl | space,
- cntrl | space, cntrl | space,
- cntrl, cntrl,
- cntrl, cntrl,
- cntrl, cntrl,
- cntrl, cntrl,
- cntrl, cntrl,
- cntrl, cntrl,
- cntrl, cntrl,
- cntrl, cntrl,
- cntrl, cntrl,
- space | blank | print, punct | print,
- punct | print, punct | print,
- punct | print, punct | print,
- punct | print, punct | print,
- punct | print, punct | print,
- punct | print, punct | print,
- punct | print, punct | print,
- punct | print, punct | print,
- digit | print | xdigit, digit | print | xdigit,
- digit | print | xdigit, digit | print | xdigit,
- digit | print | xdigit, digit | print | xdigit,
- digit | print | xdigit, digit | print | xdigit,
- digit | print | xdigit, digit | print | xdigit,
- punct | print, punct | print,
- punct | print, punct | print,
- punct | print, punct | print,
- punct | print, upper | xdigit | print | alpha,
- upper | xdigit | print | alpha, upper | xdigit | print | alpha,
- upper | xdigit | print | alpha, upper | xdigit | print | alpha,
- upper | xdigit | print | alpha, upper | print | alpha,
- upper | print | alpha, upper | print | alpha,
- upper | print | alpha, upper | print | alpha,
- upper | print | alpha, upper | print | alpha,
- upper | print | alpha, upper | print | alpha,
- upper | print | alpha, upper | print | alpha,
- upper | print | alpha, upper | print | alpha,
- upper | print | alpha, upper | print | alpha,
- upper | print | alpha, upper | print | alpha,
- upper | print | alpha, upper | print | alpha,
- upper | print | alpha, punct | print,
- punct | print, punct | print,
- punct | print, punct | print,
- punct | print, lower | xdigit | print | alpha,
- lower | xdigit | print | alpha, lower | xdigit | print | alpha,
- lower | xdigit | print | alpha, lower | xdigit | print | alpha,
- lower | xdigit | print | alpha, lower | print | alpha,
- lower | print | alpha, lower | print | alpha,
- lower | print | alpha, lower | print | alpha,
- lower | print | alpha, lower | print | alpha,
- lower | print | alpha, lower | print | alpha,
- lower | print | alpha, lower | print | alpha,
- lower | print | alpha, lower | print | alpha,
- lower | print | alpha, lower | print | alpha,
- lower | print | alpha, lower | print | alpha,
- lower | print | alpha, lower | print | alpha,
- lower | print | alpha, punct | print,
- punct | print, punct | print,
- punct | print, cntrl,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- };
- return builtin_table;
- }
- #else
- const ctype<char>::mask*
- ctype<char>::classic_table() _NOEXCEPT
- {
- #if defined(__APPLE__) || defined(__FreeBSD__)
- return _DefaultRuneLocale.__runetype;
- #elif defined(__NetBSD__)
- return _C_ctype_tab_ + 1;
- #elif defined(__GLIBC__)
- return _LIBCPP_GET_C_LOCALE->__ctype_b;
- #elif __sun__
- return __ctype_mask;
- #elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- return _ctype+1; // internal ctype mask table defined in msvcrt.dll
- // This is assumed to be safe, which is a nonsense assumption because we're
- // going to end up dereferencing it later...
- #elif defined(__EMSCRIPTEN__)
- return *__ctype_b_loc();
- #elif defined(_NEWLIB_VERSION)
- // Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
- return _ctype_ + 1;
- #elif defined(_AIX)
- return (const unsigned int *)__lc_ctype_ptr->obj->mask;
- #else
- // Platform not supported: abort so the person doing the port knows what to
- // fix
- # warning ctype<char>::classic_table() is not implemented
- printf("ctype<char>::classic_table() is not implemented\n");
- abort();
- return NULL;
- #endif
- }
- #endif
- #if defined(__GLIBC__)
- const int*
- ctype<char>::__classic_lower_table() _NOEXCEPT
- {
- return _LIBCPP_GET_C_LOCALE->__ctype_tolower;
- }
- const int*
- ctype<char>::__classic_upper_table() _NOEXCEPT
- {
- return _LIBCPP_GET_C_LOCALE->__ctype_toupper;
- }
- #elif __NetBSD__
- const short*
- ctype<char>::__classic_lower_table() _NOEXCEPT
- {
- return _C_tolower_tab_ + 1;
- }
- const short*
- ctype<char>::__classic_upper_table() _NOEXCEPT
- {
- return _C_toupper_tab_ + 1;
- }
- #elif defined(__EMSCRIPTEN__)
- const int*
- ctype<char>::__classic_lower_table() _NOEXCEPT
- {
- return *__ctype_tolower_loc();
- }
- const int*
- ctype<char>::__classic_upper_table() _NOEXCEPT
- {
- return *__ctype_toupper_loc();
- }
- #endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__
- // template <> class ctype_byname<char>
- ctype_byname<char>::ctype_byname(const char* name, size_t refs)
- : ctype<char>(0, false, refs),
- __l(newlocale(LC_ALL_MASK, name, 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__l == 0)
- throw runtime_error("ctype_byname<char>::ctype_byname"
- " failed to construct for " + string(name));
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- ctype_byname<char>::ctype_byname(const string& name, size_t refs)
- : ctype<char>(0, false, refs),
- __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__l == 0)
- throw runtime_error("ctype_byname<char>::ctype_byname"
- " failed to construct for " + name);
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- ctype_byname<char>::~ctype_byname()
- {
- freelocale(__l);
- }
- char
- ctype_byname<char>::do_toupper(char_type c) const
- {
- return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l));
- }
- const char*
- ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l));
- return low;
- }
- char
- ctype_byname<char>::do_tolower(char_type c) const
- {
- return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l));
- }
- const char*
- ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l));
- return low;
- }
- // template <> class ctype_byname<wchar_t>
- ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
- : ctype<wchar_t>(refs),
- __l(newlocale(LC_ALL_MASK, name, 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__l == 0)
- throw runtime_error("ctype_byname<wchar_t>::ctype_byname"
- " failed to construct for " + string(name));
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
- : ctype<wchar_t>(refs),
- __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__l == 0)
- throw runtime_error("ctype_byname<wchar_t>::ctype_byname"
- " failed to construct for " + name);
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- ctype_byname<wchar_t>::~ctype_byname()
- {
- freelocale(__l);
- }
- bool
- ctype_byname<wchar_t>::do_is(mask m, char_type c) const
- {
- #ifdef _LIBCPP_WCTYPE_IS_MASK
- return static_cast<bool>(iswctype_l(c, m, __l));
- #else
- bool result = false;
- wint_t ch = static_cast<wint_t>(c);
- if ((m & space) == space) result |= (iswspace_l(ch, __l) != 0);
- if ((m & print) == print) result |= (iswprint_l(ch, __l) != 0);
- if ((m & cntrl) == cntrl) result |= (iswcntrl_l(ch, __l) != 0);
- if ((m & upper) == upper) result |= (iswupper_l(ch, __l) != 0);
- if ((m & lower) == lower) result |= (iswlower_l(ch, __l) != 0);
- if ((m & alpha) == alpha) result |= (iswalpha_l(ch, __l) != 0);
- if ((m & digit) == digit) result |= (iswdigit_l(ch, __l) != 0);
- if ((m & punct) == punct) result |= (iswpunct_l(ch, __l) != 0);
- if ((m & xdigit) == xdigit) result |= (iswxdigit_l(ch, __l) != 0);
- if ((m & blank) == blank) result |= (iswblank_l(ch, __l) != 0);
- return result;
- #endif
- }
- const wchar_t*
- ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
- {
- for (; low != high; ++low, ++vec)
- {
- if (isascii(*low))
- *vec = static_cast<mask>(ctype<char>::classic_table()[*low]);
- else
- {
- *vec = 0;
- wint_t ch = static_cast<wint_t>(*low);
- if (iswspace_l(ch, __l))
- *vec |= space;
- #ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
- if (iswprint_l(ch, __l))
- *vec |= print;
- #endif
- if (iswcntrl_l(ch, __l))
- *vec |= cntrl;
- if (iswupper_l(ch, __l))
- *vec |= upper;
- if (iswlower_l(ch, __l))
- *vec |= lower;
- #ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
- if (iswalpha_l(ch, __l))
- *vec |= alpha;
- #endif
- if (iswdigit_l(ch, __l))
- *vec |= digit;
- if (iswpunct_l(ch, __l))
- *vec |= punct;
- #ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
- if (iswxdigit_l(ch, __l))
- *vec |= xdigit;
- #endif
- #if !defined(__sun__)
- if (iswblank_l(ch, __l))
- *vec |= blank;
- #endif
- }
- }
- return low;
- }
- const wchar_t*
- ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- {
- #ifdef _LIBCPP_WCTYPE_IS_MASK
- if (iswctype_l(*low, m, __l))
- break;
- #else
- wint_t ch = static_cast<wint_t>(*low);
- if ((m & space) == space && iswspace_l(ch, __l)) break;
- if ((m & print) == print && iswprint_l(ch, __l)) break;
- if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l)) break;
- if ((m & upper) == upper && iswupper_l(ch, __l)) break;
- if ((m & lower) == lower && iswlower_l(ch, __l)) break;
- if ((m & alpha) == alpha && iswalpha_l(ch, __l)) break;
- if ((m & digit) == digit && iswdigit_l(ch, __l)) break;
- if ((m & punct) == punct && iswpunct_l(ch, __l)) break;
- if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l)) break;
- if ((m & blank) == blank && iswblank_l(ch, __l)) break;
- #endif
- }
- return low;
- }
- const wchar_t*
- ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- {
- #ifdef _LIBCPP_WCTYPE_IS_MASK
- if (!iswctype_l(*low, m, __l))
- break;
- #else
- wint_t ch = static_cast<wint_t>(*low);
- if ((m & space) == space && iswspace_l(ch, __l)) continue;
- if ((m & print) == print && iswprint_l(ch, __l)) continue;
- if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l)) continue;
- if ((m & upper) == upper && iswupper_l(ch, __l)) continue;
- if ((m & lower) == lower && iswlower_l(ch, __l)) continue;
- if ((m & alpha) == alpha && iswalpha_l(ch, __l)) continue;
- if ((m & digit) == digit && iswdigit_l(ch, __l)) continue;
- if ((m & punct) == punct && iswpunct_l(ch, __l)) continue;
- if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l)) continue;
- if ((m & blank) == blank && iswblank_l(ch, __l)) continue;
- break;
- #endif
- }
- return low;
- }
- wchar_t
- ctype_byname<wchar_t>::do_toupper(char_type c) const
- {
- return towupper_l(c, __l);
- }
- const wchar_t*
- ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- *low = towupper_l(*low, __l);
- return low;
- }
- wchar_t
- ctype_byname<wchar_t>::do_tolower(char_type c) const
- {
- return towlower_l(c, __l);
- }
- const wchar_t*
- ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const
- {
- for (; low != high; ++low)
- *low = towlower_l(*low, __l);
- return low;
- }
- wchar_t
- ctype_byname<wchar_t>::do_widen(char c) const
- {
- return __libcpp_btowc_l(c, __l);
- }
- const char*
- ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
- {
- for (; low != high; ++low, ++dest)
- *dest = __libcpp_btowc_l(*low, __l);
- return low;
- }
- char
- ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
- {
- int r = __libcpp_wctob_l(c, __l);
- return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
- }
- const wchar_t*
- ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
- {
- for (; low != high; ++low, ++dest)
- {
- int r = __libcpp_wctob_l(*low, __l);
- *dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
- }
- return low;
- }
- // template <> class codecvt<char, char, mbstate_t>
- locale::id codecvt<char, char, mbstate_t>::id;
- codecvt<char, char, mbstate_t>::~codecvt()
- {
- }
- codecvt<char, char, mbstate_t>::result
- codecvt<char, char, mbstate_t>::do_out(state_type&,
- const intern_type* frm, const intern_type*, const intern_type*& frm_nxt,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- frm_nxt = frm;
- to_nxt = to;
- return noconv;
- }
- codecvt<char, char, mbstate_t>::result
- codecvt<char, char, mbstate_t>::do_in(state_type&,
- const extern_type* frm, const extern_type*, const extern_type*& frm_nxt,
- intern_type* to, intern_type*, intern_type*& to_nxt) const
- {
- frm_nxt = frm;
- to_nxt = to;
- return noconv;
- }
- codecvt<char, char, mbstate_t>::result
- codecvt<char, char, mbstate_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- codecvt<char, char, mbstate_t>::do_encoding() const _NOEXCEPT
- {
- return 1;
- }
- bool
- codecvt<char, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
- {
- return true;
- }
- int
- codecvt<char, char, mbstate_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* end, size_t mx) const
- {
- return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end-frm)));
- }
- int
- codecvt<char, char, mbstate_t>::do_max_length() const _NOEXCEPT
- {
- return 1;
- }
- // template <> class codecvt<wchar_t, char, mbstate_t>
- locale::id codecvt<wchar_t, char, mbstate_t>::id;
- codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
- : locale::facet(refs),
- __l(_LIBCPP_GET_C_LOCALE)
- {
- }
- codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
- : locale::facet(refs),
- __l(newlocale(LC_ALL_MASK, nm, 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__l == 0)
- throw runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
- " failed to construct for " + string(nm));
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- codecvt<wchar_t, char, mbstate_t>::~codecvt()
- {
- if (__l != _LIBCPP_GET_C_LOCALE)
- freelocale(__l);
- }
- codecvt<wchar_t, char, mbstate_t>::result
- codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- // look for first internal null in frm
- const intern_type* fend = frm;
- for (; fend != frm_end; ++fend)
- if (*fend == 0)
- break;
- // loop over all null-terminated sequences in frm
- to_nxt = to;
- for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
- {
- // save state in case it is needed to recover to_nxt on error
- mbstate_t save_state = st;
- size_t n = __libcpp_wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
- static_cast<size_t>(to_end-to), &st, __l);
- if (n == size_t(-1))
- {
- // need to recover to_nxt
- for (to_nxt = to; frm != frm_nxt; ++frm)
- {
- n = __libcpp_wcrtomb_l(to_nxt, *frm, &save_state, __l);
- if (n == size_t(-1))
- break;
- to_nxt += n;
- }
- frm_nxt = frm;
- return error;
- }
- if (n == 0)
- return partial;
- to_nxt += n;
- if (to_nxt == to_end)
- break;
- if (fend != frm_end) // set up next null terminated sequence
- {
- // Try to write the terminating null
- extern_type tmp[MB_LEN_MAX];
- n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l);
- if (n == size_t(-1)) // on error
- return error;
- if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
- return partial;
- for (extern_type* p = tmp; n; --n) // write it
- *to_nxt++ = *p++;
- ++frm_nxt;
- // look for next null in frm
- for (fend = frm_nxt; fend != frm_end; ++fend)
- if (*fend == 0)
- break;
- }
- }
- return frm_nxt == frm_end ? ok : partial;
- }
- codecvt<wchar_t, char, mbstate_t>::result
- codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- // look for first internal null in frm
- const extern_type* fend = frm;
- for (; fend != frm_end; ++fend)
- if (*fend == 0)
- break;
- // loop over all null-terminated sequences in frm
- to_nxt = to;
- for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
- {
- // save state in case it is needed to recover to_nxt on error
- mbstate_t save_state = st;
- size_t n = __libcpp_mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
- static_cast<size_t>(to_end-to), &st, __l);
- if (n == size_t(-1))
- {
- // need to recover to_nxt
- for (to_nxt = to; frm != frm_nxt; ++to_nxt)
- {
- n = __libcpp_mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm),
- &save_state, __l);
- switch (n)
- {
- case 0:
- ++frm;
- break;
- case size_t(-1):
- frm_nxt = frm;
- return error;
- case size_t(-2):
- frm_nxt = frm;
- return partial;
- default:
- frm += n;
- break;
- }
- }
- frm_nxt = frm;
- return frm_nxt == frm_end ? ok : partial;
- }
- if (n == size_t(-1))
- return error;
- to_nxt += n;
- if (to_nxt == to_end)
- break;
- if (fend != frm_end) // set up next null terminated sequence
- {
- // Try to write the terminating null
- n = __libcpp_mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
- if (n != 0) // on error
- return error;
- ++to_nxt;
- ++frm_nxt;
- // look for next null in frm
- for (fend = frm_nxt; fend != frm_end; ++fend)
- if (*fend == 0)
- break;
- }
- }
- return frm_nxt == frm_end ? ok : partial;
- }
- codecvt<wchar_t, char, mbstate_t>::result
- codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- to_nxt = to;
- extern_type tmp[MB_LEN_MAX];
- size_t n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l);
- if (n == size_t(-1) || n == 0) // on error
- return error;
- --n;
- if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
- return partial;
- for (extern_type* p = tmp; n; --n) // write it
- *to_nxt++ = *p++;
- return ok;
- }
- int
- codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
- {
- if (__libcpp_mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0)
- return -1;
- // stateless encoding
- if (__l == 0 || __libcpp_mb_cur_max_l(__l) == 1) // there are no known constant length encodings
- return 1; // which take more than 1 char to form a wchar_t
- return 0;
- }
- bool
- codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- int nbytes = 0;
- for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
- {
- size_t n = __libcpp_mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l);
- switch (n)
- {
- case 0:
- ++nbytes;
- ++frm;
- break;
- case size_t(-1):
- case size_t(-2):
- return nbytes;
- default:
- nbytes += n;
- frm += n;
- break;
- }
- }
- return nbytes;
- }
- int
- codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
- {
- return __l == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l));
- }
- // Valid UTF ranges
- // UTF-32 UTF-16 UTF-8 # of code points
- // first second first second third fourth
- // 000000 - 00007F 0000 - 007F 00 - 7F 127
- // 000080 - 0007FF 0080 - 07FF C2 - DF, 80 - BF 1920
- // 000800 - 000FFF 0800 - 0FFF E0 - E0, A0 - BF, 80 - BF 2048
- // 001000 - 00CFFF 1000 - CFFF E1 - EC, 80 - BF, 80 - BF 49152
- // 00D000 - 00D7FF D000 - D7FF ED - ED, 80 - 9F, 80 - BF 2048
- // 00D800 - 00DFFF invalid
- // 00E000 - 00FFFF E000 - FFFF EE - EF, 80 - BF, 80 - BF 8192
- // 010000 - 03FFFF D800 - D8BF, DC00 - DFFF F0 - F0, 90 - BF, 80 - BF, 80 - BF 196608
- // 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 786432
- // 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 65536
- static
- codecvt_base::result
- utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xEF);
- *to_nxt++ = static_cast<uint8_t>(0xBB);
- *to_nxt++ = static_cast<uint8_t>(0xBF);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint16_t wc1 = *frm_nxt;
- if (wc1 > Maxcode)
- return codecvt_base::error;
- if (wc1 < 0x0080)
- {
- if (to_end-to_nxt < 1)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc1);
- }
- else if (wc1 < 0x0800)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
- }
- else if (wc1 < 0xD800)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
- }
- else if (wc1 < 0xDC00)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint16_t wc2 = frm_nxt[1];
- if ((wc2 & 0xFC00) != 0xDC00)
- return codecvt_base::error;
- if (to_end-to_nxt < 4)
- return codecvt_base::partial;
- if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
- ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
- return codecvt_base::error;
- ++frm_nxt;
- uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
- *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
- }
- else if (wc1 < 0xE000)
- {
- return codecvt_base::error;
- }
- else
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
- }
- }
- return codecvt_base::ok;
- }
- static
- codecvt_base::result
- utf16_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xEF);
- *to_nxt++ = static_cast<uint8_t>(0xBB);
- *to_nxt++ = static_cast<uint8_t>(0xBF);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint16_t wc1 = static_cast<uint16_t>(*frm_nxt);
- if (wc1 > Maxcode)
- return codecvt_base::error;
- if (wc1 < 0x0080)
- {
- if (to_end-to_nxt < 1)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc1);
- }
- else if (wc1 < 0x0800)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
- }
- else if (wc1 < 0xD800)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
- }
- else if (wc1 < 0xDC00)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]);
- if ((wc2 & 0xFC00) != 0xDC00)
- return codecvt_base::error;
- if (to_end-to_nxt < 4)
- return codecvt_base::partial;
- if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
- ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
- return codecvt_base::error;
- ++frm_nxt;
- uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
- *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
- }
- else if (wc1 < 0xE000)
- {
- return codecvt_base::error;
- }
- else
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
- }
- }
- return codecvt_base::ok;
- }
- static
- codecvt_base::result
- utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
- {
- uint8_t c1 = *frm_nxt;
- if (c1 > Maxcode)
- return codecvt_base::error;
- if (c1 < 0x80)
- {
- *to_nxt = static_cast<uint16_t>(c1);
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- return codecvt_base::error;
- }
- else if (c1 < 0xE0)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return codecvt_base::error;
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
- | ((c2 & 0x3F) << 6)
- | (c3 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 3;
- }
- else if (c1 < 0xF5)
- {
- if (frm_end-frm_nxt < 4)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- uint8_t c4 = frm_nxt[3];
- switch (c1)
- {
- case 0xF0:
- if (!(0x90 <= c2 && c2 <= 0xBF))
- return codecvt_base::error;
- break;
- case 0xF4:
- if ((c2 & 0xF0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
- return codecvt_base::error;
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- if ((((c1 & 7UL) << 18) +
- ((c2 & 0x3FUL) << 12) +
- ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint16_t>(
- 0xD800
- | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
- | ((c2 & 0x0F) << 2)
- | ((c3 & 0x30) >> 4));
- *++to_nxt = static_cast<uint16_t>(
- 0xDC00
- | ((c3 & 0x0F) << 6)
- | (c4 & 0x3F));
- frm_nxt += 4;
- }
- else
- {
- return codecvt_base::error;
- }
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
- }
- static
- codecvt_base::result
- utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
- {
- uint8_t c1 = *frm_nxt;
- if (c1 > Maxcode)
- return codecvt_base::error;
- if (c1 < 0x80)
- {
- *to_nxt = static_cast<uint32_t>(c1);
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- return codecvt_base::error;
- }
- else if (c1 < 0xE0)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(t);
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return codecvt_base::error;
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
- | ((c2 & 0x3F) << 6)
- | (c3 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(t);
- frm_nxt += 3;
- }
- else if (c1 < 0xF5)
- {
- if (frm_end-frm_nxt < 4)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- uint8_t c4 = frm_nxt[3];
- switch (c1)
- {
- case 0xF0:
- if (!(0x90 <= c2 && c2 <= 0xBF))
- return codecvt_base::error;
- break;
- case 0xF4:
- if ((c2 & 0xF0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
- return codecvt_base::error;
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- if ((((c1 & 7UL) << 18) +
- ((c2 & 0x3FUL) << 12) +
- ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(
- 0xD800
- | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
- | ((c2 & 0x0F) << 2)
- | ((c3 & 0x30) >> 4));
- *++to_nxt = static_cast<uint32_t>(
- 0xDC00
- | ((c3 & 0x0F) << 6)
- | (c4 & 0x3F));
- frm_nxt += 4;
- }
- else
- {
- return codecvt_base::error;
- }
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
- }
- static
- int
- utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
- {
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t)
- {
- uint8_t c1 = *frm_nxt;
- if (c1 > Maxcode)
- break;
- if (c1 < 0x80)
- {
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- break;
- }
- else if (c1 < 0xE0)
- {
- if ((frm_end-frm_nxt < 2) || (frm_nxt[1] & 0xC0) != 0x80)
- break;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F));
- if (t > Maxcode)
- break;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- break;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return static_cast<int>(frm_nxt - frm);
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- break;
- if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 3;
- }
- else if (c1 < 0xF5)
- {
- if (frm_end-frm_nxt < 4 || mx-nchar16_t < 2)
- break;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- uint8_t c4 = frm_nxt[3];
- switch (c1)
- {
- case 0xF0:
- if (!(0x90 <= c2 && c2 <= 0xBF))
- return static_cast<int>(frm_nxt - frm);
- break;
- case 0xF4:
- if ((c2 & 0xF0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- }
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
- break;
- if ((((c1 & 7UL) << 18) +
- ((c2 & 0x3FUL) << 12) +
- ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
- break;
- ++nchar16_t;
- frm_nxt += 4;
- }
- else
- {
- break;
- }
- }
- return static_cast<int>(frm_nxt - frm);
- }
- static
- codecvt_base::result
- ucs4_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xEF);
- *to_nxt++ = static_cast<uint8_t>(0xBB);
- *to_nxt++ = static_cast<uint8_t>(0xBF);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint32_t wc = *frm_nxt;
- if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
- return codecvt_base::error;
- if (wc < 0x000080)
- {
- if (to_end-to_nxt < 1)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc);
- }
- else if (wc < 0x000800)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
- }
- else if (wc < 0x010000)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
- }
- else // if (wc < 0x110000)
- {
- if (to_end-to_nxt < 4)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F));
- }
- }
- return codecvt_base::ok;
- }
- static
- codecvt_base::result
- utf8_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
- {
- uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
- if (c1 < 0x80)
- {
- if (c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(c1);
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- return codecvt_base::error;
- }
- else if (c1 < 0xE0)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6)
- | (c2 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return codecvt_base::error;
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12)
- | ((c2 & 0x3F) << 6)
- | (c3 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 3;
- }
- else if (c1 < 0xF5)
- {
- if (frm_end-frm_nxt < 4)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- uint8_t c4 = frm_nxt[3];
- switch (c1)
- {
- case 0xF0:
- if (!(0x90 <= c2 && c2 <= 0xBF))
- return codecvt_base::error;
- break;
- case 0xF4:
- if ((c2 & 0xF0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18)
- | ((c2 & 0x3F) << 12)
- | ((c3 & 0x3F) << 6)
- | (c4 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 4;
- }
- else
- {
- return codecvt_base::error;
- }
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
- }
- static
- int
- utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
- {
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
- {
- uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
- if (c1 < 0x80)
- {
- if (c1 > Maxcode)
- break;
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- break;
- }
- else if (c1 < 0xE0)
- {
- if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
- break;
- if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- break;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return static_cast<int>(frm_nxt - frm);
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- break;
- if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 3;
- }
- else if (c1 < 0xF5)
- {
- if (frm_end-frm_nxt < 4)
- break;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- uint8_t c4 = frm_nxt[3];
- switch (c1)
- {
- case 0xF0:
- if (!(0x90 <= c2 && c2 <= 0xBF))
- return static_cast<int>(frm_nxt - frm);
- break;
- case 0xF4:
- if ((c2 & 0xF0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- }
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
- break;
- if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) |
- ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 4;
- }
- else
- {
- break;
- }
- }
- return static_cast<int>(frm_nxt - frm);
- }
- static
- codecvt_base::result
- ucs2_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xEF);
- *to_nxt++ = static_cast<uint8_t>(0xBB);
- *to_nxt++ = static_cast<uint8_t>(0xBF);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint16_t wc = *frm_nxt;
- if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
- return codecvt_base::error;
- if (wc < 0x0080)
- {
- if (to_end-to_nxt < 1)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc);
- }
- else if (wc < 0x0800)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
- }
- else // if (wc <= 0xFFFF)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
- }
- }
- return codecvt_base::ok;
- }
- static
- codecvt_base::result
- utf8_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
- {
- uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
- if (c1 < 0x80)
- {
- if (c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint16_t>(c1);
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- return codecvt_base::error;
- }
- else if (c1 < 0xE0)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6)
- | (c2 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return codecvt_base::error;
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
- | ((c2 & 0x3F) << 6)
- | (c3 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 3;
- }
- else
- {
- return codecvt_base::error;
- }
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
- }
- static
- int
- utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
- {
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
- {
- uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
- if (c1 < 0x80)
- {
- if (c1 > Maxcode)
- break;
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- break;
- }
- else if (c1 < 0xE0)
- {
- if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
- break;
- if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- break;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return static_cast<int>(frm_nxt - frm);
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- break;
- if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 3;
- }
- else
- {
- break;
- }
- }
- return static_cast<int>(frm_nxt - frm);
- }
- static
- codecvt_base::result
- ucs4_to_utf16be(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xFE);
- *to_nxt++ = static_cast<uint8_t>(0xFF);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint32_t wc = *frm_nxt;
- if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
- return codecvt_base::error;
- if (wc < 0x010000)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc >> 8);
- *to_nxt++ = static_cast<uint8_t>(wc);
- }
- else
- {
- if (to_end-to_nxt < 4)
- return codecvt_base::partial;
- uint16_t t = static_cast<uint16_t>(
- 0xD800
- | ((((wc & 0x1F0000) >> 16) - 1) << 6)
- | ((wc & 0x00FC00) >> 10));
- *to_nxt++ = static_cast<uint8_t>(t >> 8);
- *to_nxt++ = static_cast<uint8_t>(t);
- t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
- *to_nxt++ = static_cast<uint8_t>(t >> 8);
- *to_nxt++ = static_cast<uint8_t>(t);
- }
- }
- return codecvt_base::ok;
- }
- static
- codecvt_base::result
- utf16be_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
- frm_nxt += 2;
- }
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
- if ((c1 & 0xFC00) == 0xDC00)
- return codecvt_base::error;
- if ((c1 & 0xFC00) != 0xD800)
- {
- if (c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(c1);
- frm_nxt += 2;
- }
- else
- {
- if (frm_end-frm_nxt < 4)
- return codecvt_base::partial;
- uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
- if ((c2 & 0xFC00) != 0xDC00)
- return codecvt_base::error;
- uint32_t t = static_cast<uint32_t>(
- ((((c1 & 0x03C0) >> 6) + 1) << 16)
- | ((c1 & 0x003F) << 10)
- | (c2 & 0x03FF));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 4;
- }
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
- }
- static
- int
- utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
- {
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
- frm_nxt += 2;
- }
- for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
- if ((c1 & 0xFC00) == 0xDC00)
- break;
- if ((c1 & 0xFC00) != 0xD800)
- {
- if (c1 > Maxcode)
- break;
- frm_nxt += 2;
- }
- else
- {
- if (frm_end-frm_nxt < 4)
- break;
- uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
- if ((c2 & 0xFC00) != 0xDC00)
- break;
- uint32_t t = static_cast<uint32_t>(
- ((((c1 & 0x03C0) >> 6) + 1) << 16)
- | ((c1 & 0x003F) << 10)
- | (c2 & 0x03FF));
- if (t > Maxcode)
- break;
- frm_nxt += 4;
- }
- }
- return static_cast<int>(frm_nxt - frm);
- }
- static
- codecvt_base::result
- ucs4_to_utf16le(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end - to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xFF);
- *to_nxt++ = static_cast<uint8_t>(0xFE);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint32_t wc = *frm_nxt;
- if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
- return codecvt_base::error;
- if (wc < 0x010000)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc);
- *to_nxt++ = static_cast<uint8_t>(wc >> 8);
- }
- else
- {
- if (to_end-to_nxt < 4)
- return codecvt_base::partial;
- uint16_t t = static_cast<uint16_t>(
- 0xD800
- | ((((wc & 0x1F0000) >> 16) - 1) << 6)
- | ((wc & 0x00FC00) >> 10));
- *to_nxt++ = static_cast<uint8_t>(t);
- *to_nxt++ = static_cast<uint8_t>(t >> 8);
- t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
- *to_nxt++ = static_cast<uint8_t>(t);
- *to_nxt++ = static_cast<uint8_t>(t >> 8);
- }
- }
- return codecvt_base::ok;
- }
- static
- codecvt_base::result
- utf16le_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
- frm_nxt += 2;
- }
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
- if ((c1 & 0xFC00) == 0xDC00)
- return codecvt_base::error;
- if ((c1 & 0xFC00) != 0xD800)
- {
- if (c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(c1);
- frm_nxt += 2;
- }
- else
- {
- if (frm_end-frm_nxt < 4)
- return codecvt_base::partial;
- uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
- if ((c2 & 0xFC00) != 0xDC00)
- return codecvt_base::error;
- uint32_t t = static_cast<uint32_t>(
- ((((c1 & 0x03C0) >> 6) + 1) << 16)
- | ((c1 & 0x003F) << 10)
- | (c2 & 0x03FF));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 4;
- }
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
- }
- static
- int
- utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
- {
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
- frm_nxt += 2;
- }
- for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
- if ((c1 & 0xFC00) == 0xDC00)
- break;
- if ((c1 & 0xFC00) != 0xD800)
- {
- if (c1 > Maxcode)
- break;
- frm_nxt += 2;
- }
- else
- {
- if (frm_end-frm_nxt < 4)
- break;
- uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
- if ((c2 & 0xFC00) != 0xDC00)
- break;
- uint32_t t = static_cast<uint32_t>(
- ((((c1 & 0x03C0) >> 6) + 1) << 16)
- | ((c1 & 0x003F) << 10)
- | (c2 & 0x03FF));
- if (t > Maxcode)
- break;
- frm_nxt += 4;
- }
- }
- return static_cast<int>(frm_nxt - frm);
- }
- static
- codecvt_base::result
- ucs2_to_utf16be(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xFE);
- *to_nxt++ = static_cast<uint8_t>(0xFF);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint16_t wc = *frm_nxt;
- if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
- return codecvt_base::error;
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc >> 8);
- *to_nxt++ = static_cast<uint8_t>(wc);
- }
- return codecvt_base::ok;
- }
- static
- codecvt_base::result
- utf16be_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
- frm_nxt += 2;
- }
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = c1;
- frm_nxt += 2;
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
- }
- static
- int
- utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
- {
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
- frm_nxt += 2;
- }
- for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
- break;
- frm_nxt += 2;
- }
- return static_cast<int>(frm_nxt - frm);
- }
- static
- codecvt_base::result
- ucs2_to_utf16le(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xFF);
- *to_nxt++ = static_cast<uint8_t>(0xFE);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint16_t wc = *frm_nxt;
- if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
- return codecvt_base::error;
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc);
- *to_nxt++ = static_cast<uint8_t>(wc >> 8);
- }
- return codecvt_base::ok;
- }
- static
- codecvt_base::result
- utf16le_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
- {
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
- frm_nxt += 2;
- }
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = c1;
- frm_nxt += 2;
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
- }
- static
- int
- utf16le_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
- {
- const uint8_t* frm_nxt = frm;
- frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
- frm_nxt += 2;
- }
- for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
- break;
- frm_nxt += 2;
- }
- return static_cast<int>(frm_nxt - frm);
- }
- // template <> class codecvt<char16_t, char, mbstate_t>
- locale::id codecvt<char16_t, char, mbstate_t>::id;
- codecvt<char16_t, char, mbstate_t>::~codecvt()
- {
- }
- codecvt<char16_t, char, mbstate_t>::result
- codecvt<char16_t, char, mbstate_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- codecvt<char16_t, char, mbstate_t>::result
- codecvt<char16_t, char, mbstate_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- codecvt<char16_t, char, mbstate_t>::result
- codecvt<char16_t, char, mbstate_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- codecvt<char16_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- codecvt<char16_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- codecvt<char16_t, char, mbstate_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_utf16_length(_frm, _frm_end, mx);
- }
- int
- codecvt<char16_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
- {
- return 4;
- }
- // template <> class codecvt<char32_t, char, mbstate_t>
- locale::id codecvt<char32_t, char, mbstate_t>::id;
- codecvt<char32_t, char, mbstate_t>::~codecvt()
- {
- }
- codecvt<char32_t, char, mbstate_t>::result
- codecvt<char32_t, char, mbstate_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- codecvt<char32_t, char, mbstate_t>::result
- codecvt<char32_t, char, mbstate_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- codecvt<char32_t, char, mbstate_t>::result
- codecvt<char32_t, char, mbstate_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- codecvt<char32_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- codecvt<char32_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- codecvt<char32_t, char, mbstate_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_ucs4_length(_frm, _frm_end, mx);
- }
- int
- codecvt<char32_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
- {
- return 4;
- }
- // __codecvt_utf8<wchar_t>
- __codecvt_utf8<wchar_t>::result
- __codecvt_utf8<wchar_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- #if _WIN32
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- #else
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- #endif
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- #if _WIN32
- result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- #else
- result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- #endif
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8<wchar_t>::result
- __codecvt_utf8<wchar_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- #if _WIN32
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- #else
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- #endif
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8<wchar_t>::result
- __codecvt_utf8<wchar_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf8<wchar_t>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf8<wchar_t>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf8<wchar_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf8<wchar_t>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 7;
- return 4;
- }
- // __codecvt_utf8<char16_t>
- __codecvt_utf8<char16_t>::result
- __codecvt_utf8<char16_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8<char16_t>::result
- __codecvt_utf8<char16_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8<char16_t>::result
- __codecvt_utf8<char16_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf8<char16_t>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf8<char16_t>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf8<char16_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf8<char16_t>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 6;
- return 3;
- }
- // __codecvt_utf8<char32_t>
- __codecvt_utf8<char32_t>::result
- __codecvt_utf8<char32_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8<char32_t>::result
- __codecvt_utf8<char32_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8<char32_t>::result
- __codecvt_utf8<char32_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf8<char32_t>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf8<char32_t>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf8<char32_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf8<char32_t>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 7;
- return 4;
- }
- // __codecvt_utf16<wchar_t, false>
- __codecvt_utf16<wchar_t, false>::result
- __codecvt_utf16<wchar_t, false>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<wchar_t, false>::result
- __codecvt_utf16<wchar_t, false>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<wchar_t, false>::result
- __codecvt_utf16<wchar_t, false>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf16<wchar_t, false>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf16<wchar_t, false>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf16<wchar_t, false>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf16<wchar_t, false>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 6;
- return 4;
- }
- // __codecvt_utf16<wchar_t, true>
- __codecvt_utf16<wchar_t, true>::result
- __codecvt_utf16<wchar_t, true>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<wchar_t, true>::result
- __codecvt_utf16<wchar_t, true>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<wchar_t, true>::result
- __codecvt_utf16<wchar_t, true>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf16<wchar_t, true>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf16<wchar_t, true>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf16<wchar_t, true>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf16<wchar_t, true>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 6;
- return 4;
- }
- // __codecvt_utf16<char16_t, false>
- __codecvt_utf16<char16_t, false>::result
- __codecvt_utf16<char16_t, false>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<char16_t, false>::result
- __codecvt_utf16<char16_t, false>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<char16_t, false>::result
- __codecvt_utf16<char16_t, false>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf16<char16_t, false>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf16<char16_t, false>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf16<char16_t, false>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf16<char16_t, false>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 4;
- return 2;
- }
- // __codecvt_utf16<char16_t, true>
- __codecvt_utf16<char16_t, true>::result
- __codecvt_utf16<char16_t, true>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<char16_t, true>::result
- __codecvt_utf16<char16_t, true>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<char16_t, true>::result
- __codecvt_utf16<char16_t, true>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf16<char16_t, true>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf16<char16_t, true>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf16<char16_t, true>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf16<char16_t, true>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 4;
- return 2;
- }
- // __codecvt_utf16<char32_t, false>
- __codecvt_utf16<char32_t, false>::result
- __codecvt_utf16<char32_t, false>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<char32_t, false>::result
- __codecvt_utf16<char32_t, false>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<char32_t, false>::result
- __codecvt_utf16<char32_t, false>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf16<char32_t, false>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf16<char32_t, false>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf16<char32_t, false>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf16<char32_t, false>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 6;
- return 4;
- }
- // __codecvt_utf16<char32_t, true>
- __codecvt_utf16<char32_t, true>::result
- __codecvt_utf16<char32_t, true>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<char32_t, true>::result
- __codecvt_utf16<char32_t, true>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf16<char32_t, true>::result
- __codecvt_utf16<char32_t, true>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf16<char32_t, true>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf16<char32_t, true>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf16<char32_t, true>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf16<char32_t, true>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 6;
- return 4;
- }
- // __codecvt_utf8_utf16<wchar_t>
- __codecvt_utf8_utf16<wchar_t>::result
- __codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8_utf16<wchar_t>::result
- __codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8_utf16<wchar_t>::result
- __codecvt_utf8_utf16<wchar_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf8_utf16<wchar_t>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf8_utf16<wchar_t>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf8_utf16<wchar_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf8_utf16<wchar_t>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 7;
- return 4;
- }
- // __codecvt_utf8_utf16<char16_t>
- __codecvt_utf8_utf16<char16_t>::result
- __codecvt_utf8_utf16<char16_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8_utf16<char16_t>::result
- __codecvt_utf8_utf16<char16_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8_utf16<char16_t>::result
- __codecvt_utf8_utf16<char16_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf8_utf16<char16_t>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf8_utf16<char16_t>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf8_utf16<char16_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf8_utf16<char16_t>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 7;
- return 4;
- }
- // __codecvt_utf8_utf16<char32_t>
- __codecvt_utf8_utf16<char32_t>::result
- __codecvt_utf8_utf16<char32_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
- {
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8_utf16<char32_t>::result
- __codecvt_utf8_utf16<char32_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
- }
- __codecvt_utf8_utf16<char32_t>::result
- __codecvt_utf8_utf16<char32_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
- {
- to_nxt = to;
- return noconv;
- }
- int
- __codecvt_utf8_utf16<char32_t>::do_encoding() const _NOEXCEPT
- {
- return 0;
- }
- bool
- __codecvt_utf8_utf16<char32_t>::do_always_noconv() const _NOEXCEPT
- {
- return false;
- }
- int
- __codecvt_utf8_utf16<char32_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
- {
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
- }
- int
- __codecvt_utf8_utf16<char32_t>::do_max_length() const _NOEXCEPT
- {
- if (_Mode_ & consume_header)
- return 7;
- return 4;
- }
- // __narrow_to_utf8<16>
- __narrow_to_utf8<16>::~__narrow_to_utf8()
- {
- }
- // __narrow_to_utf8<32>
- __narrow_to_utf8<32>::~__narrow_to_utf8()
- {
- }
- // __widen_from_utf8<16>
- __widen_from_utf8<16>::~__widen_from_utf8()
- {
- }
- // __widen_from_utf8<32>
- __widen_from_utf8<32>::~__widen_from_utf8()
- {
- }
- // numpunct<char> && numpunct<wchar_t>
- locale::id numpunct< char >::id;
- locale::id numpunct<wchar_t>::id;
- numpunct<char>::numpunct(size_t refs)
- : locale::facet(refs),
- __decimal_point_('.'),
- __thousands_sep_(',')
- {
- }
- numpunct<wchar_t>::numpunct(size_t refs)
- : locale::facet(refs),
- __decimal_point_(L'.'),
- __thousands_sep_(L',')
- {
- }
- numpunct<char>::~numpunct()
- {
- }
- numpunct<wchar_t>::~numpunct()
- {
- }
- char numpunct< char >::do_decimal_point() const {return __decimal_point_;}
- wchar_t numpunct<wchar_t>::do_decimal_point() const {return __decimal_point_;}
- char numpunct< char >::do_thousands_sep() const {return __thousands_sep_;}
- wchar_t numpunct<wchar_t>::do_thousands_sep() const {return __thousands_sep_;}
- string numpunct< char >::do_grouping() const {return __grouping_;}
- string numpunct<wchar_t>::do_grouping() const {return __grouping_;}
- string numpunct< char >::do_truename() const {return "true";}
- wstring numpunct<wchar_t>::do_truename() const {return L"true";}
- string numpunct< char >::do_falsename() const {return "false";}
- wstring numpunct<wchar_t>::do_falsename() const {return L"false";}
- // numpunct_byname<char>
- numpunct_byname<char>::numpunct_byname(const char* nm, size_t refs)
- : numpunct<char>(refs)
- {
- __init(nm);
- }
- numpunct_byname<char>::numpunct_byname(const string& nm, size_t refs)
- : numpunct<char>(refs)
- {
- __init(nm.c_str());
- }
- numpunct_byname<char>::~numpunct_byname()
- {
- }
- void
- numpunct_byname<char>::__init(const char* nm)
- {
- if (strcmp(nm, "C") != 0)
- {
- __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == nullptr)
- throw runtime_error("numpunct_byname<char>::numpunct_byname"
- " failed to construct for " + string(nm));
- #endif // _LIBCPP_NO_EXCEPTIONS
- lconv* lc = __libcpp_localeconv_l(loc.get());
- if (*lc->decimal_point)
- __decimal_point_ = *lc->decimal_point;
- if (*lc->thousands_sep)
- __thousands_sep_ = *lc->thousands_sep;
- __grouping_ = lc->grouping;
- // localization for truename and falsename is not available
- }
- }
- // numpunct_byname<wchar_t>
- numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs)
- : numpunct<wchar_t>(refs)
- {
- __init(nm);
- }
- numpunct_byname<wchar_t>::numpunct_byname(const string& nm, size_t refs)
- : numpunct<wchar_t>(refs)
- {
- __init(nm.c_str());
- }
- numpunct_byname<wchar_t>::~numpunct_byname()
- {
- }
- void
- numpunct_byname<wchar_t>::__init(const char* nm)
- {
- if (strcmp(nm, "C") != 0)
- {
- __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == nullptr)
- throw runtime_error("numpunct_byname<char>::numpunct_byname"
- " failed to construct for " + string(nm));
- #endif // _LIBCPP_NO_EXCEPTIONS
- lconv* lc = __libcpp_localeconv_l(loc.get());
- if (*lc->decimal_point)
- __decimal_point_ = *lc->decimal_point;
- if (*lc->thousands_sep)
- __thousands_sep_ = *lc->thousands_sep;
- __grouping_ = lc->grouping;
- // locallization for truename and falsename is not available
- }
- }
- // num_get helpers
- int
- __num_get_base::__get_base(ios_base& iob)
- {
- ios_base::fmtflags __basefield = iob.flags() & ios_base::basefield;
- if (__basefield == ios_base::oct)
- return 8;
- else if (__basefield == ios_base::hex)
- return 16;
- else if (__basefield == 0)
- return 0;
- return 10;
- }
- const char __num_get_base::__src[33] = "0123456789abcdefABCDEFxX+-pPiInN";
- void
- __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
- ios_base::iostate& __err)
- {
- if (__grouping.size() != 0)
- {
- reverse(__g, __g_end);
- const char* __ig = __grouping.data();
- const char* __eg = __ig + __grouping.size();
- for (unsigned* __r = __g; __r < __g_end-1; ++__r)
- {
- if (0 < *__ig && *__ig < numeric_limits<char>::max())
- {
- if (static_cast<unsigned>(*__ig) != *__r)
- {
- __err = ios_base::failbit;
- return;
- }
- }
- if (__eg - __ig > 1)
- ++__ig;
- }
- if (0 < *__ig && *__ig < numeric_limits<char>::max())
- {
- if (static_cast<unsigned>(*__ig) < __g_end[-1] || __g_end[-1] == 0)
- __err = ios_base::failbit;
- }
- }
- }
- void
- __num_put_base::__format_int(char* __fmtp, const char* __len, bool __signd,
- ios_base::fmtflags __flags)
- {
- if (__flags & ios_base::showpos)
- *__fmtp++ = '+';
- if (__flags & ios_base::showbase)
- *__fmtp++ = '#';
- while(*__len)
- *__fmtp++ = *__len++;
- if ((__flags & ios_base::basefield) == ios_base::oct)
- *__fmtp = 'o';
- else if ((__flags & ios_base::basefield) == ios_base::hex)
- {
- if (__flags & ios_base::uppercase)
- *__fmtp = 'X';
- else
- *__fmtp = 'x';
- }
- else if (__signd)
- *__fmtp = 'd';
- else
- *__fmtp = 'u';
- }
- bool
- __num_put_base::__format_float(char* __fmtp, const char* __len,
- ios_base::fmtflags __flags)
- {
- bool specify_precision = true;
- if (__flags & ios_base::showpos)
- *__fmtp++ = '+';
- if (__flags & ios_base::showpoint)
- *__fmtp++ = '#';
- ios_base::fmtflags floatfield = __flags & ios_base::floatfield;
- bool uppercase = (__flags & ios_base::uppercase) != 0;
- if (floatfield == (ios_base::fixed | ios_base::scientific))
- specify_precision = false;
- else
- {
- *__fmtp++ = '.';
- *__fmtp++ = '*';
- }
- while(*__len)
- *__fmtp++ = *__len++;
- if (floatfield == ios_base::fixed)
- {
- if (uppercase)
- *__fmtp = 'F';
- else
- *__fmtp = 'f';
- }
- else if (floatfield == ios_base::scientific)
- {
- if (uppercase)
- *__fmtp = 'E';
- else
- *__fmtp = 'e';
- }
- else if (floatfield == (ios_base::fixed | ios_base::scientific))
- {
- if (uppercase)
- *__fmtp = 'A';
- else
- *__fmtp = 'a';
- }
- else
- {
- if (uppercase)
- *__fmtp = 'G';
- else
- *__fmtp = 'g';
- }
- return specify_precision;
- }
- char*
- __num_put_base::__identify_padding(char* __nb, char* __ne,
- const ios_base& __iob)
- {
- switch (__iob.flags() & ios_base::adjustfield)
- {
- case ios_base::internal:
- if (__nb[0] == '-' || __nb[0] == '+')
- return __nb+1;
- if (__ne - __nb >= 2 && __nb[0] == '0'
- && (__nb[1] == 'x' || __nb[1] == 'X'))
- return __nb+2;
- break;
- case ios_base::left:
- return __ne;
- case ios_base::right:
- default:
- break;
- }
- return __nb;
- }
- // time_get
- static
- string*
- init_weeks()
- {
- static string weeks[14];
- weeks[0] = "Sunday";
- weeks[1] = "Monday";
- weeks[2] = "Tuesday";
- weeks[3] = "Wednesday";
- weeks[4] = "Thursday";
- weeks[5] = "Friday";
- weeks[6] = "Saturday";
- weeks[7] = "Sun";
- weeks[8] = "Mon";
- weeks[9] = "Tue";
- weeks[10] = "Wed";
- weeks[11] = "Thu";
- weeks[12] = "Fri";
- weeks[13] = "Sat";
- return weeks;
- }
- static
- wstring*
- init_wweeks()
- {
- static wstring weeks[14];
- weeks[0] = L"Sunday";
- weeks[1] = L"Monday";
- weeks[2] = L"Tuesday";
- weeks[3] = L"Wednesday";
- weeks[4] = L"Thursday";
- weeks[5] = L"Friday";
- weeks[6] = L"Saturday";
- weeks[7] = L"Sun";
- weeks[8] = L"Mon";
- weeks[9] = L"Tue";
- weeks[10] = L"Wed";
- weeks[11] = L"Thu";
- weeks[12] = L"Fri";
- weeks[13] = L"Sat";
- return weeks;
- }
- template <>
- const string*
- __time_get_c_storage<char>::__weeks() const
- {
- static const string* weeks = init_weeks();
- return weeks;
- }
- template <>
- const wstring*
- __time_get_c_storage<wchar_t>::__weeks() const
- {
- static const wstring* weeks = init_wweeks();
- return weeks;
- }
- static
- string*
- init_months()
- {
- static string months[24];
- months[0] = "January";
- months[1] = "February";
- months[2] = "March";
- months[3] = "April";
- months[4] = "May";
- months[5] = "June";
- months[6] = "July";
- months[7] = "August";
- months[8] = "September";
- months[9] = "October";
- months[10] = "November";
- months[11] = "December";
- months[12] = "Jan";
- months[13] = "Feb";
- months[14] = "Mar";
- months[15] = "Apr";
- months[16] = "May";
- months[17] = "Jun";
- months[18] = "Jul";
- months[19] = "Aug";
- months[20] = "Sep";
- months[21] = "Oct";
- months[22] = "Nov";
- months[23] = "Dec";
- return months;
- }
- static
- wstring*
- init_wmonths()
- {
- static wstring months[24];
- months[0] = L"January";
- months[1] = L"February";
- months[2] = L"March";
- months[3] = L"April";
- months[4] = L"May";
- months[5] = L"June";
- months[6] = L"July";
- months[7] = L"August";
- months[8] = L"September";
- months[9] = L"October";
- months[10] = L"November";
- months[11] = L"December";
- months[12] = L"Jan";
- months[13] = L"Feb";
- months[14] = L"Mar";
- months[15] = L"Apr";
- months[16] = L"May";
- months[17] = L"Jun";
- months[18] = L"Jul";
- months[19] = L"Aug";
- months[20] = L"Sep";
- months[21] = L"Oct";
- months[22] = L"Nov";
- months[23] = L"Dec";
- return months;
- }
- template <>
- const string*
- __time_get_c_storage<char>::__months() const
- {
- static const string* months = init_months();
- return months;
- }
- template <>
- const wstring*
- __time_get_c_storage<wchar_t>::__months() const
- {
- static const wstring* months = init_wmonths();
- return months;
- }
- static
- string*
- init_am_pm()
- {
- static string am_pm[24];
- am_pm[0] = "AM";
- am_pm[1] = "PM";
- return am_pm;
- }
- static
- wstring*
- init_wam_pm()
- {
- static wstring am_pm[24];
- am_pm[0] = L"AM";
- am_pm[1] = L"PM";
- return am_pm;
- }
- template <>
- const string*
- __time_get_c_storage<char>::__am_pm() const
- {
- static const string* am_pm = init_am_pm();
- return am_pm;
- }
- template <>
- const wstring*
- __time_get_c_storage<wchar_t>::__am_pm() const
- {
- static const wstring* am_pm = init_wam_pm();
- return am_pm;
- }
- template <>
- const string&
- __time_get_c_storage<char>::__x() const
- {
- static string s("%m/%d/%y");
- return s;
- }
- template <>
- const wstring&
- __time_get_c_storage<wchar_t>::__x() const
- {
- static wstring s(L"%m/%d/%y");
- return s;
- }
- template <>
- const string&
- __time_get_c_storage<char>::__X() const
- {
- static string s("%H:%M:%S");
- return s;
- }
- template <>
- const wstring&
- __time_get_c_storage<wchar_t>::__X() const
- {
- static wstring s(L"%H:%M:%S");
- return s;
- }
- template <>
- const string&
- __time_get_c_storage<char>::__c() const
- {
- static string s("%a %b %d %H:%M:%S %Y");
- return s;
- }
- template <>
- const wstring&
- __time_get_c_storage<wchar_t>::__c() const
- {
- static wstring s(L"%a %b %d %H:%M:%S %Y");
- return s;
- }
- template <>
- const string&
- __time_get_c_storage<char>::__r() const
- {
- static string s("%I:%M:%S %p");
- return s;
- }
- template <>
- const wstring&
- __time_get_c_storage<wchar_t>::__r() const
- {
- static wstring s(L"%I:%M:%S %p");
- return s;
- }
- // time_get_byname
- __time_get::__time_get(const char* nm)
- : __loc_(newlocale(LC_ALL_MASK, nm, 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__loc_ == 0)
- throw runtime_error("time_get_byname"
- " failed to construct for " + string(nm));
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- __time_get::__time_get(const string& nm)
- : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__loc_ == 0)
- throw runtime_error("time_get_byname"
- " failed to construct for " + nm);
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- __time_get::~__time_get()
- {
- freelocale(__loc_);
- }
- #if defined(__clang__)
- #pragma clang diagnostic ignored "-Wmissing-field-initializers"
- #endif
- #if defined(__GNUG__)
- #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
- #endif
- template <>
- string
- __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
- {
- tm t = {0};
- t.tm_sec = 59;
- t.tm_min = 55;
- t.tm_hour = 23;
- t.tm_mday = 31;
- t.tm_mon = 11;
- t.tm_year = 161;
- t.tm_wday = 6;
- t.tm_yday = 364;
- t.tm_isdst = -1;
- char buf[100];
- char f[3] = {0};
- f[0] = '%';
- f[1] = fmt;
- size_t n = strftime_l(buf, countof(buf), f, &t, __loc_);
- char* bb = buf;
- char* be = buf + n;
- string result;
- while (bb != be)
- {
- if (ct.is(ctype_base::space, *bb))
- {
- result.push_back(' ');
- for (++bb; bb != be && ct.is(ctype_base::space, *bb); ++bb)
- ;
- continue;
- }
- char* w = bb;
- ios_base::iostate err = ios_base::goodbit;
- ptrdiff_t i = __scan_keyword(w, be, this->__weeks_, this->__weeks_+14,
- ct, err, false)
- - this->__weeks_;
- if (i < 14)
- {
- result.push_back('%');
- if (i < 7)
- result.push_back('A');
- else
- result.push_back('a');
- bb = w;
- continue;
- }
- w = bb;
- i = __scan_keyword(w, be, this->__months_, this->__months_+24,
- ct, err, false)
- - this->__months_;
- if (i < 24)
- {
- result.push_back('%');
- if (i < 12)
- result.push_back('B');
- else
- result.push_back('b');
- if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
- result.back() = 'm';
- bb = w;
- continue;
- }
- if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
- {
- w = bb;
- i = __scan_keyword(w, be, this->__am_pm_, this->__am_pm_+2,
- ct, err, false) - this->__am_pm_;
- if (i < 2)
- {
- result.push_back('%');
- result.push_back('p');
- bb = w;
- continue;
- }
- }
- w = bb;
- if (ct.is(ctype_base::digit, *bb))
- {
- switch(__get_up_to_n_digits(bb, be, err, ct, 4))
- {
- case 6:
- result.push_back('%');
- result.push_back('w');
- break;
- case 7:
- result.push_back('%');
- result.push_back('u');
- break;
- case 11:
- result.push_back('%');
- result.push_back('I');
- break;
- case 12:
- result.push_back('%');
- result.push_back('m');
- break;
- case 23:
- result.push_back('%');
- result.push_back('H');
- break;
- case 31:
- result.push_back('%');
- result.push_back('d');
- break;
- case 55:
- result.push_back('%');
- result.push_back('M');
- break;
- case 59:
- result.push_back('%');
- result.push_back('S');
- break;
- case 61:
- result.push_back('%');
- result.push_back('y');
- break;
- case 364:
- result.push_back('%');
- result.push_back('j');
- break;
- case 2061:
- result.push_back('%');
- result.push_back('Y');
- break;
- default:
- for (; w != bb; ++w)
- result.push_back(*w);
- break;
- }
- continue;
- }
- if (*bb == '%')
- {
- result.push_back('%');
- result.push_back('%');
- ++bb;
- continue;
- }
- result.push_back(*bb);
- ++bb;
- }
- return result;
- }
- #if defined(__clang__)
- #pragma clang diagnostic ignored "-Wmissing-braces"
- #endif
- template <>
- wstring
- __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
- {
- tm t = {0};
- t.tm_sec = 59;
- t.tm_min = 55;
- t.tm_hour = 23;
- t.tm_mday = 31;
- t.tm_mon = 11;
- t.tm_year = 161;
- t.tm_wday = 6;
- t.tm_yday = 364;
- t.tm_isdst = -1;
- char buf[100];
- char f[3] = {0};
- f[0] = '%';
- f[1] = fmt;
- strftime_l(buf, countof(buf), f, &t, __loc_);
- wchar_t wbuf[100];
- wchar_t* wbb = wbuf;
- mbstate_t mb = {0};
- const char* bb = buf;
- size_t j = __libcpp_mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wchar_t* wbe = wbb + j;
- wstring result;
- while (wbb != wbe)
- {
- if (ct.is(ctype_base::space, *wbb))
- {
- result.push_back(L' ');
- for (++wbb; wbb != wbe && ct.is(ctype_base::space, *wbb); ++wbb)
- ;
- continue;
- }
- wchar_t* w = wbb;
- ios_base::iostate err = ios_base::goodbit;
- ptrdiff_t i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_+14,
- ct, err, false)
- - this->__weeks_;
- if (i < 14)
- {
- result.push_back(L'%');
- if (i < 7)
- result.push_back(L'A');
- else
- result.push_back(L'a');
- wbb = w;
- continue;
- }
- w = wbb;
- i = __scan_keyword(w, wbe, this->__months_, this->__months_+24,
- ct, err, false)
- - this->__months_;
- if (i < 24)
- {
- result.push_back(L'%');
- if (i < 12)
- result.push_back(L'B');
- else
- result.push_back(L'b');
- if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
- result.back() = L'm';
- wbb = w;
- continue;
- }
- if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
- {
- w = wbb;
- i = __scan_keyword(w, wbe, this->__am_pm_, this->__am_pm_+2,
- ct, err, false) - this->__am_pm_;
- if (i < 2)
- {
- result.push_back(L'%');
- result.push_back(L'p');
- wbb = w;
- continue;
- }
- }
- w = wbb;
- if (ct.is(ctype_base::digit, *wbb))
- {
- switch(__get_up_to_n_digits(wbb, wbe, err, ct, 4))
- {
- case 6:
- result.push_back(L'%');
- result.push_back(L'w');
- break;
- case 7:
- result.push_back(L'%');
- result.push_back(L'u');
- break;
- case 11:
- result.push_back(L'%');
- result.push_back(L'I');
- break;
- case 12:
- result.push_back(L'%');
- result.push_back(L'm');
- break;
- case 23:
- result.push_back(L'%');
- result.push_back(L'H');
- break;
- case 31:
- result.push_back(L'%');
- result.push_back(L'd');
- break;
- case 55:
- result.push_back(L'%');
- result.push_back(L'M');
- break;
- case 59:
- result.push_back(L'%');
- result.push_back(L'S');
- break;
- case 61:
- result.push_back(L'%');
- result.push_back(L'y');
- break;
- case 364:
- result.push_back(L'%');
- result.push_back(L'j');
- break;
- case 2061:
- result.push_back(L'%');
- result.push_back(L'Y');
- break;
- default:
- for (; w != wbb; ++w)
- result.push_back(*w);
- break;
- }
- continue;
- }
- if (ct.narrow(*wbb, 0) == '%')
- {
- result.push_back(L'%');
- result.push_back(L'%');
- ++wbb;
- continue;
- }
- result.push_back(*wbb);
- ++wbb;
- }
- return result;
- }
- template <>
- void
- __time_get_storage<char>::init(const ctype<char>& ct)
- {
- tm t = {0};
- char buf[100];
- // __weeks_
- for (int i = 0; i < 7; ++i)
- {
- t.tm_wday = i;
- strftime_l(buf, countof(buf), "%A", &t, __loc_);
- __weeks_[i] = buf;
- strftime_l(buf, countof(buf), "%a", &t, __loc_);
- __weeks_[i+7] = buf;
- }
- // __months_
- for (int i = 0; i < 12; ++i)
- {
- t.tm_mon = i;
- strftime_l(buf, countof(buf), "%B", &t, __loc_);
- __months_[i] = buf;
- strftime_l(buf, countof(buf), "%b", &t, __loc_);
- __months_[i+12] = buf;
- }
- // __am_pm_
- t.tm_hour = 1;
- strftime_l(buf, countof(buf), "%p", &t, __loc_);
- __am_pm_[0] = buf;
- t.tm_hour = 13;
- strftime_l(buf, countof(buf), "%p", &t, __loc_);
- __am_pm_[1] = buf;
- __c_ = __analyze('c', ct);
- __r_ = __analyze('r', ct);
- __x_ = __analyze('x', ct);
- __X_ = __analyze('X', ct);
- }
- template <>
- void
- __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
- {
- tm t = {0};
- char buf[100];
- wchar_t wbuf[100];
- wchar_t* wbe;
- mbstate_t mb = {0};
- // __weeks_
- for (int i = 0; i < 7; ++i)
- {
- t.tm_wday = i;
- strftime_l(buf, countof(buf), "%A", &t, __loc_);
- mb = mbstate_t();
- const char* bb = buf;
- size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __weeks_[i].assign(wbuf, wbe);
- strftime_l(buf, countof(buf), "%a", &t, __loc_);
- mb = mbstate_t();
- bb = buf;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __weeks_[i+7].assign(wbuf, wbe);
- }
- // __months_
- for (int i = 0; i < 12; ++i)
- {
- t.tm_mon = i;
- strftime_l(buf, countof(buf), "%B", &t, __loc_);
- mb = mbstate_t();
- const char* bb = buf;
- size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __months_[i].assign(wbuf, wbe);
- strftime_l(buf, countof(buf), "%b", &t, __loc_);
- mb = mbstate_t();
- bb = buf;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __months_[i+12].assign(wbuf, wbe);
- }
- // __am_pm_
- t.tm_hour = 1;
- strftime_l(buf, countof(buf), "%p", &t, __loc_);
- mb = mbstate_t();
- const char* bb = buf;
- size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __am_pm_[0].assign(wbuf, wbe);
- t.tm_hour = 13;
- strftime_l(buf, countof(buf), "%p", &t, __loc_);
- mb = mbstate_t();
- bb = buf;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __am_pm_[1].assign(wbuf, wbe);
- __c_ = __analyze('c', ct);
- __r_ = __analyze('r', ct);
- __x_ = __analyze('x', ct);
- __X_ = __analyze('X', ct);
- }
- template <class CharT>
- struct _LIBCPP_HIDDEN __time_get_temp
- : public ctype_byname<CharT>
- {
- explicit __time_get_temp(const char* nm)
- : ctype_byname<CharT>(nm, 1) {}
- explicit __time_get_temp(const string& nm)
- : ctype_byname<CharT>(nm, 1) {}
- };
- template <>
- __time_get_storage<char>::__time_get_storage(const char* __nm)
- : __time_get(__nm)
- {
- const __time_get_temp<char> ct(__nm);
- init(ct);
- }
- template <>
- __time_get_storage<char>::__time_get_storage(const string& __nm)
- : __time_get(__nm)
- {
- const __time_get_temp<char> ct(__nm);
- init(ct);
- }
- template <>
- __time_get_storage<wchar_t>::__time_get_storage(const char* __nm)
- : __time_get(__nm)
- {
- const __time_get_temp<wchar_t> ct(__nm);
- init(ct);
- }
- template <>
- __time_get_storage<wchar_t>::__time_get_storage(const string& __nm)
- : __time_get(__nm)
- {
- const __time_get_temp<wchar_t> ct(__nm);
- init(ct);
- }
- template <>
- time_base::dateorder
- __time_get_storage<char>::__do_date_order() const
- {
- unsigned i;
- for (i = 0; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- ++i;
- switch (__x_[i])
- {
- case 'y':
- case 'Y':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- switch (__x_[i])
- {
- case 'm':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'd')
- return time_base::ymd;
- break;
- case 'd':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'm')
- return time_base::ydm;
- break;
- }
- break;
- case 'm':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'd')
- {
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'y' || __x_[i] == 'Y')
- return time_base::mdy;
- break;
- }
- break;
- case 'd':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'm')
- {
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'y' || __x_[i] == 'Y')
- return time_base::dmy;
- break;
- }
- break;
- }
- return time_base::no_order;
- }
- template <>
- time_base::dateorder
- __time_get_storage<wchar_t>::__do_date_order() const
- {
- unsigned i;
- for (i = 0; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- ++i;
- switch (__x_[i])
- {
- case L'y':
- case L'Y':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- switch (__x_[i])
- {
- case L'm':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'd')
- return time_base::ymd;
- break;
- case L'd':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'm')
- return time_base::ydm;
- break;
- }
- break;
- case L'm':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'd')
- {
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'y' || __x_[i] == L'Y')
- return time_base::mdy;
- break;
- }
- break;
- case L'd':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'm')
- {
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'y' || __x_[i] == L'Y')
- return time_base::dmy;
- break;
- }
- break;
- }
- return time_base::no_order;
- }
- // time_put
- __time_put::__time_put(const char* nm)
- : __loc_(newlocale(LC_ALL_MASK, nm, 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__loc_ == 0)
- throw runtime_error("time_put_byname"
- " failed to construct for " + string(nm));
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- __time_put::__time_put(const string& nm)
- : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (__loc_ == 0)
- throw runtime_error("time_put_byname"
- " failed to construct for " + nm);
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- __time_put::~__time_put()
- {
- if (__loc_ != _LIBCPP_GET_C_LOCALE)
- freelocale(__loc_);
- }
- void
- __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,
- char __fmt, char __mod) const
- {
- char fmt[] = {'%', __fmt, __mod, 0};
- if (__mod != 0)
- swap(fmt[1], fmt[2]);
- size_t n = strftime_l(__nb, countof(__nb, __ne), fmt, __tm, __loc_);
- __ne = __nb + n;
- }
- void
- __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
- char __fmt, char __mod) const
- {
- char __nar[100];
- char* __ne = __nar + 100;
- __do_put(__nar, __ne, __tm, __fmt, __mod);
- mbstate_t mb = {0};
- const char* __nb = __nar;
- size_t j = __libcpp_mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- __we = __wb + j;
- }
- // moneypunct_byname
- template <class charT>
- static
- void
- __init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
- bool intl, char cs_precedes, char sep_by_space, char sign_posn,
- charT space_char)
- {
- const char sign = static_cast<char>(money_base::sign);
- const char space = static_cast<char>(money_base::space);
- const char none = static_cast<char>(money_base::none);
- const char symbol = static_cast<char>(money_base::symbol);
- const char value = static_cast<char>(money_base::value);
- const bool symbol_contains_sep = intl && __curr_symbol_.size() == 4;
- // Comments on case branches reflect 'C11 7.11.2.1 The localeconv
- // function'. "Space between sign and symbol or value" means that
- // if the sign is adjacent to the symbol, there's a space between
- // them, and otherwise there's a space between the sign and value.
- //
- // C11's localeconv specifies that the fourth character of an
- // international curr_symbol is used to separate the sign and
- // value when sep_by_space says to do so. C++ can't represent
- // that, so we just use a space. When sep_by_space says to
- // separate the symbol and value-or-sign with a space, we rearrange the
- // curr_symbol to put its spacing character on the correct side of
- // the symbol.
- //
- // We also need to avoid adding an extra space between the sign
- // and value when the currency symbol is suppressed (by not
- // setting showbase). We match glibc's strfmon by interpreting
- // sep_by_space==1 as "omit the space when the currency symbol is
- // absent".
- //
- // Users who want to get this right should use ICU instead.
- switch (cs_precedes)
- {
- case 0: // value before curr_symbol
- if (symbol_contains_sep) {
- // Move the separator to before the symbol, to place it
- // between the value and symbol.
- rotate(__curr_symbol_.begin(), __curr_symbol_.begin() + 3,
- __curr_symbol_.end());
- }
- switch (sign_posn)
- {
- case 0: // Parentheses surround the quantity and currency symbol.
- pat.field[0] = sign;
- pat.field[1] = value;
- pat.field[2] = none; // Any space appears in the symbol.
- pat.field[3] = symbol;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- // This case may have changed between C99 and C11;
- // assume the currency symbol matches the intention.
- case 2: // Space between sign and currency or value.
- // The "sign" is two parentheses, so no space here either.
- return;
- case 1: // Space between currency-and-sign or currency and value.
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- return;
- default:
- break;
- }
- break;
- case 1: // The sign string precedes the quantity and currency symbol.
- pat.field[0] = sign;
- pat.field[3] = symbol;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = value;
- pat.field[2] = none;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = value;
- pat.field[2] = none;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = space;
- pat.field[2] = value;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // has already appeared after the sign.
- __curr_symbol_.erase(__curr_symbol_.begin());
- }
- return;
- default:
- break;
- }
- break;
- case 2: // The sign string succeeds the quantity and currency symbol.
- pat.field[0] = value;
- pat.field[3] = sign;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = none;
- pat.field[2] = symbol;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[1]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- pat.field[1] = none;
- pat.field[2] = symbol;
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = symbol;
- pat.field[2] = space;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // should not be removed if showbase is absent.
- __curr_symbol_.erase(__curr_symbol_.begin());
- }
- return;
- default:
- break;
- }
- break;
- case 3: // The sign string immediately precedes the currency symbol.
- pat.field[0] = value;
- pat.field[3] = symbol;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = none;
- pat.field[2] = sign;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = space;
- pat.field[2] = sign;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // has already appeared before the sign.
- __curr_symbol_.erase(__curr_symbol_.begin());
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = sign;
- pat.field[2] = none;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- return;
- default:
- break;
- }
- break;
- case 4: // The sign string immediately succeeds the currency symbol.
- pat.field[0] = value;
- pat.field[3] = sign;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = none;
- pat.field[2] = symbol;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = none;
- pat.field[2] = symbol;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[1]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = symbol;
- pat.field[2] = space;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // should not disappear when showbase is absent.
- __curr_symbol_.erase(__curr_symbol_.begin());
- }
- return;
- default:
- break;
- }
- break;
- default:
- break;
- }
- break;
- case 1: // curr_symbol before value
- switch (sign_posn)
- {
- case 0: // Parentheses surround the quantity and currency symbol.
- pat.field[0] = sign;
- pat.field[1] = symbol;
- pat.field[2] = none; // Any space appears in the symbol.
- pat.field[3] = value;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- // This case may have changed between C99 and C11;
- // assume the currency symbol matches the intention.
- case 2: // Space between sign and currency or value.
- // The "sign" is two parentheses, so no space here either.
- return;
- case 1: // Space between currency-and-sign or currency and value.
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- return;
- default:
- break;
- }
- break;
- case 1: // The sign string precedes the quantity and currency symbol.
- pat.field[0] = sign;
- pat.field[3] = value;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = symbol;
- pat.field[2] = none;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = symbol;
- pat.field[2] = none;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.push_back(space_char);
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = space;
- pat.field[2] = symbol;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // has already appeared after the sign.
- __curr_symbol_.pop_back();
- }
- return;
- default:
- break;
- }
- break;
- case 2: // The sign string succeeds the quantity and currency symbol.
- pat.field[0] = symbol;
- pat.field[3] = sign;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = none;
- pat.field[2] = value;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = none;
- pat.field[2] = value;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[1]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.push_back(space_char);
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = value;
- pat.field[2] = space;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // will appear before the sign.
- __curr_symbol_.pop_back();
- }
- return;
- default:
- break;
- }
- break;
- case 3: // The sign string immediately precedes the currency symbol.
- pat.field[0] = sign;
- pat.field[3] = value;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = symbol;
- pat.field[2] = none;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = symbol;
- pat.field[2] = none;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.push_back(space_char);
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = space;
- pat.field[2] = symbol;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // has already appeared after the sign.
- __curr_symbol_.pop_back();
- }
- return;
- default:
- break;
- }
- break;
- case 4: // The sign string immediately succeeds the currency symbol.
- pat.field[0] = symbol;
- pat.field[3] = value;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = sign;
- pat.field[2] = none;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = sign;
- pat.field[2] = space;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // should not disappear when showbase is absent.
- __curr_symbol_.pop_back();
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = none;
- pat.field[2] = sign;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[1]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.push_back(space_char);
- }
- return;
- default:
- break;
- }
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- pat.field[0] = symbol;
- pat.field[1] = sign;
- pat.field[2] = none;
- pat.field[3] = value;
- }
- template<>
- void
- moneypunct_byname<char, false>::init(const char* nm)
- {
- typedef moneypunct<char, false> base;
- __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == nullptr)
- throw runtime_error("moneypunct_byname"
- " failed to construct for " + string(nm));
- #endif // _LIBCPP_NO_EXCEPTIONS
- lconv* lc = __libcpp_localeconv_l(loc.get());
- if (*lc->mon_decimal_point)
- __decimal_point_ = *lc->mon_decimal_point;
- else
- __decimal_point_ = base::do_decimal_point();
- if (*lc->mon_thousands_sep)
- __thousands_sep_ = *lc->mon_thousands_sep;
- else
- __thousands_sep_ = base::do_thousands_sep();
- __grouping_ = lc->mon_grouping;
- __curr_symbol_ = lc->currency_symbol;
- if (lc->frac_digits != CHAR_MAX)
- __frac_digits_ = lc->frac_digits;
- else
- __frac_digits_ = base::do_frac_digits();
- if (lc->p_sign_posn == 0)
- __positive_sign_ = "()";
- else
- __positive_sign_ = lc->positive_sign;
- if (lc->n_sign_posn == 0)
- __negative_sign_ = "()";
- else
- __negative_sign_ = lc->negative_sign;
- // Assume the positive and negative formats will want spaces in
- // the same places in curr_symbol since there's no way to
- // represent anything else.
- string_type __dummy_curr_symbol = __curr_symbol_;
- __init_pat(__pos_format_, __dummy_curr_symbol, false,
- lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
- __init_pat(__neg_format_, __curr_symbol_, false,
- lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
- }
- template<>
- void
- moneypunct_byname<char, true>::init(const char* nm)
- {
- typedef moneypunct<char, true> base;
- __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == nullptr)
- throw runtime_error("moneypunct_byname"
- " failed to construct for " + string(nm));
- #endif // _LIBCPP_NO_EXCEPTIONS
- lconv* lc = __libcpp_localeconv_l(loc.get());
- if (*lc->mon_decimal_point)
- __decimal_point_ = *lc->mon_decimal_point;
- else
- __decimal_point_ = base::do_decimal_point();
- if (*lc->mon_thousands_sep)
- __thousands_sep_ = *lc->mon_thousands_sep;
- else
- __thousands_sep_ = base::do_thousands_sep();
- __grouping_ = lc->mon_grouping;
- __curr_symbol_ = lc->int_curr_symbol;
- if (lc->int_frac_digits != CHAR_MAX)
- __frac_digits_ = lc->int_frac_digits;
- else
- __frac_digits_ = base::do_frac_digits();
- #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- if (lc->p_sign_posn == 0)
- #else // _LIBCPP_MSVCRT
- if (lc->int_p_sign_posn == 0)
- #endif // !_LIBCPP_MSVCRT
- __positive_sign_ = "()";
- else
- __positive_sign_ = lc->positive_sign;
- #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- if(lc->n_sign_posn == 0)
- #else // _LIBCPP_MSVCRT
- if (lc->int_n_sign_posn == 0)
- #endif // !_LIBCPP_MSVCRT
- __negative_sign_ = "()";
- else
- __negative_sign_ = lc->negative_sign;
- // Assume the positive and negative formats will want spaces in
- // the same places in curr_symbol since there's no way to
- // represent anything else.
- string_type __dummy_curr_symbol = __curr_symbol_;
- #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- __init_pat(__pos_format_, __dummy_curr_symbol, true,
- lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
- __init_pat(__neg_format_, __curr_symbol_, true,
- lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
- #else // _LIBCPP_MSVCRT
- __init_pat(__pos_format_, __dummy_curr_symbol, true,
- lc->int_p_cs_precedes, lc->int_p_sep_by_space,
- lc->int_p_sign_posn, ' ');
- __init_pat(__neg_format_, __curr_symbol_, true,
- lc->int_n_cs_precedes, lc->int_n_sep_by_space,
- lc->int_n_sign_posn, ' ');
- #endif // !_LIBCPP_MSVCRT
- }
- template<>
- void
- moneypunct_byname<wchar_t, false>::init(const char* nm)
- {
- typedef moneypunct<wchar_t, false> base;
- __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == nullptr)
- throw runtime_error("moneypunct_byname"
- " failed to construct for " + string(nm));
- #endif // _LIBCPP_NO_EXCEPTIONS
- lconv* lc = __libcpp_localeconv_l(loc.get());
- if (*lc->mon_decimal_point)
- __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
- else
- __decimal_point_ = base::do_decimal_point();
- if (*lc->mon_thousands_sep)
- __thousands_sep_ = static_cast<wchar_t>(*lc->mon_thousands_sep);
- else
- __thousands_sep_ = base::do_thousands_sep();
- __grouping_ = lc->mon_grouping;
- wchar_t wbuf[100];
- mbstate_t mb = {0};
- const char* bb = lc->currency_symbol;
- size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wchar_t* wbe = wbuf + j;
- __curr_symbol_.assign(wbuf, wbe);
- if (lc->frac_digits != CHAR_MAX)
- __frac_digits_ = lc->frac_digits;
- else
- __frac_digits_ = base::do_frac_digits();
- if (lc->p_sign_posn == 0)
- __positive_sign_ = L"()";
- else
- {
- mb = mbstate_t();
- bb = lc->positive_sign;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __positive_sign_.assign(wbuf, wbe);
- }
- if (lc->n_sign_posn == 0)
- __negative_sign_ = L"()";
- else
- {
- mb = mbstate_t();
- bb = lc->negative_sign;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __negative_sign_.assign(wbuf, wbe);
- }
- // Assume the positive and negative formats will want spaces in
- // the same places in curr_symbol since there's no way to
- // represent anything else.
- string_type __dummy_curr_symbol = __curr_symbol_;
- __init_pat(__pos_format_, __dummy_curr_symbol, false,
- lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
- __init_pat(__neg_format_, __curr_symbol_, false,
- lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
- }
- template<>
- void
- moneypunct_byname<wchar_t, true>::init(const char* nm)
- {
- typedef moneypunct<wchar_t, true> base;
- __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == nullptr)
- throw runtime_error("moneypunct_byname"
- " failed to construct for " + string(nm));
- #endif // _LIBCPP_NO_EXCEPTIONS
- lconv* lc = __libcpp_localeconv_l(loc.get());
- if (*lc->mon_decimal_point)
- __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
- else
- __decimal_point_ = base::do_decimal_point();
- if (*lc->mon_thousands_sep)
- __thousands_sep_ = static_cast<wchar_t>(*lc->mon_thousands_sep);
- else
- __thousands_sep_ = base::do_thousands_sep();
- __grouping_ = lc->mon_grouping;
- wchar_t wbuf[100];
- mbstate_t mb = {0};
- const char* bb = lc->int_curr_symbol;
- size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wchar_t* wbe = wbuf + j;
- __curr_symbol_.assign(wbuf, wbe);
- if (lc->int_frac_digits != CHAR_MAX)
- __frac_digits_ = lc->int_frac_digits;
- else
- __frac_digits_ = base::do_frac_digits();
- #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- if (lc->p_sign_posn == 0)
- #else // _LIBCPP_MSVCRT
- if (lc->int_p_sign_posn == 0)
- #endif // !_LIBCPP_MSVCRT
- __positive_sign_ = L"()";
- else
- {
- mb = mbstate_t();
- bb = lc->positive_sign;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __positive_sign_.assign(wbuf, wbe);
- }
- #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- if (lc->n_sign_posn == 0)
- #else // _LIBCPP_MSVCRT
- if (lc->int_n_sign_posn == 0)
- #endif // !_LIBCPP_MSVCRT
- __negative_sign_ = L"()";
- else
- {
- mb = mbstate_t();
- bb = lc->negative_sign;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __negative_sign_.assign(wbuf, wbe);
- }
- // Assume the positive and negative formats will want spaces in
- // the same places in curr_symbol since there's no way to
- // represent anything else.
- string_type __dummy_curr_symbol = __curr_symbol_;
- #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- __init_pat(__pos_format_, __dummy_curr_symbol, true,
- lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
- __init_pat(__neg_format_, __curr_symbol_, true,
- lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
- #else // _LIBCPP_MSVCRT
- __init_pat(__pos_format_, __dummy_curr_symbol, true,
- lc->int_p_cs_precedes, lc->int_p_sep_by_space,
- lc->int_p_sign_posn, L' ');
- __init_pat(__neg_format_, __curr_symbol_, true,
- lc->int_n_cs_precedes, lc->int_n_sep_by_space,
- lc->int_n_sign_posn, L' ');
- #endif // !_LIBCPP_MSVCRT
- }
- void __do_nothing(void*) {}
- void __throw_runtime_error(const char* msg)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- throw runtime_error(msg);
- #else
- (void)msg;
- #endif
- }
- template class collate<char>;
- template class collate<wchar_t>;
- template class num_get<char>;
- template class num_get<wchar_t>;
- template struct __num_get<char>;
- template struct __num_get<wchar_t>;
- template class num_put<char>;
- template class num_put<wchar_t>;
- template struct __num_put<char>;
- template struct __num_put<wchar_t>;
- template class time_get<char>;
- template class time_get<wchar_t>;
- template class time_get_byname<char>;
- template class time_get_byname<wchar_t>;
- template class time_put<char>;
- template class time_put<wchar_t>;
- template class time_put_byname<char>;
- template class time_put_byname<wchar_t>;
- template class moneypunct<char, false>;
- template class moneypunct<char, true>;
- template class moneypunct<wchar_t, false>;
- template class moneypunct<wchar_t, true>;
- template class moneypunct_byname<char, false>;
- template class moneypunct_byname<char, true>;
- template class moneypunct_byname<wchar_t, false>;
- template class moneypunct_byname<wchar_t, true>;
- template class money_get<char>;
- template class money_get<wchar_t>;
- template class __money_get<char>;
- template class __money_get<wchar_t>;
- template class money_put<char>;
- template class money_put<wchar_t>;
- template class __money_put<char>;
- template class __money_put<wchar_t>;
- template class messages<char>;
- template class messages<wchar_t>;
- template class messages_byname<char>;
- template class messages_byname<wchar_t>;
- template class codecvt_byname<char, char, mbstate_t>;
- template class codecvt_byname<wchar_t, char, mbstate_t>;
- template class codecvt_byname<char16_t, char, mbstate_t>;
- template class codecvt_byname<char32_t, char, mbstate_t>;
- template class __vector_base_common<true>;
- _LIBCPP_END_NAMESPACE_STD
- #endif // !defined(_LIBCPP_SGX_CONFIG)
|