encoding.c 143 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986
  1. /*
  2. * encoding.c : implements the encoding conversion functions needed for XML
  3. *
  4. * Related specs:
  5. * rfc2044 (UTF-8 and UTF-16) F. Yergeau Alis Technologies
  6. * rfc2781 UTF-16, an encoding of ISO 10646, P. Hoffman, F. Yergeau
  7. * [ISO-10646] UTF-8 and UTF-16 in Annexes
  8. * [ISO-8859-1] ISO Latin-1 characters codes.
  9. * [UNICODE] The Unicode Consortium, "The Unicode Standard --
  10. * Worldwide Character Encoding -- Version 1.0", Addison-
  11. * Wesley, Volume 1, 1991, Volume 2, 1992. UTF-8 is
  12. * described in Unicode Technical Report #4.
  13. * [US-ASCII] Coded Character Set--7-bit American Standard Code for
  14. * Information Interchange, ANSI X3.4-1986.
  15. *
  16. * See Copyright for the status of this software.
  17. *
  18. * daniel@veillard.com
  19. *
  20. * Original code for IsoLatin1 and UTF-16 by "Martin J. Duerst" <duerst@w3.org>
  21. */
  22. #define IN_LIBXML
  23. #include "libxml.h"
  24. #include <string.h>
  25. #include <limits.h>
  26. #ifdef HAVE_CTYPE_H
  27. #include <ctype.h>
  28. #endif
  29. #ifdef HAVE_STDLIB_H
  30. #include <stdlib.h>
  31. #endif
  32. #ifdef LIBXML_ICONV_ENABLED
  33. #ifdef HAVE_ERRNO_H
  34. #include <errno.h>
  35. #endif
  36. #endif
  37. #include <libxml/encoding.h>
  38. #include <libxml/xmlmemory.h>
  39. #ifdef LIBXML_HTML_ENABLED
  40. #include <libxml/HTMLparser.h>
  41. #endif
  42. #include <libxml/globals.h>
  43. #include <libxml/xmlerror.h>
  44. #ifndef ARCADIA_LIBXML_DISABLE_EXTRA_ENCODINGS
  45. #include "yencoding.h"
  46. #endif
  47. #include "buf.h"
  48. #include "enc.h"
  49. static xmlCharEncodingHandlerPtr xmlUTF16LEHandler = NULL;
  50. static xmlCharEncodingHandlerPtr xmlUTF16BEHandler = NULL;
  51. typedef struct _xmlCharEncodingAlias xmlCharEncodingAlias;
  52. typedef xmlCharEncodingAlias *xmlCharEncodingAliasPtr;
  53. struct _xmlCharEncodingAlias {
  54. const char *name;
  55. const char *alias;
  56. };
  57. static xmlCharEncodingAliasPtr xmlCharEncodingAliases = NULL;
  58. static int xmlCharEncodingAliasesNb = 0;
  59. static int xmlCharEncodingAliasesMax = 0;
  60. #if defined(LIBXML_ICONV_ENABLED) || defined(LIBXML_ICU_ENABLED)
  61. #if 0
  62. #define DEBUG_ENCODING /* Define this to get encoding traces */
  63. #endif
  64. #else
  65. #ifdef LIBXML_ISO8859X_ENABLED
  66. static void xmlRegisterCharEncodingHandlersISO8859x (void);
  67. #endif
  68. #endif
  69. static int xmlLittleEndian = 1;
  70. /**
  71. * xmlEncodingErrMemory:
  72. * @extra: extra information
  73. *
  74. * Handle an out of memory condition
  75. */
  76. static void
  77. xmlEncodingErrMemory(const char *extra)
  78. {
  79. __xmlSimpleError(XML_FROM_I18N, XML_ERR_NO_MEMORY, NULL, NULL, extra);
  80. }
  81. /**
  82. * xmlErrEncoding:
  83. * @error: the error number
  84. * @msg: the error message
  85. *
  86. * n encoding error
  87. */
  88. static void LIBXML_ATTR_FORMAT(2,0)
  89. xmlEncodingErr(xmlParserErrors error, const char *msg, const char *val)
  90. {
  91. __xmlRaiseError(NULL, NULL, NULL, NULL, NULL,
  92. XML_FROM_I18N, error, XML_ERR_FATAL,
  93. NULL, 0, val, NULL, NULL, 0, 0, msg, val);
  94. }
  95. #ifdef LIBXML_ICU_ENABLED
  96. static uconv_t*
  97. openIcuConverter(const char* name, int toUnicode)
  98. {
  99. UErrorCode status = U_ZERO_ERROR;
  100. uconv_t *conv = (uconv_t *) xmlMalloc(sizeof(uconv_t));
  101. if (conv == NULL)
  102. return NULL;
  103. conv->pivot_source = conv->pivot_buf;
  104. conv->pivot_target = conv->pivot_buf;
  105. conv->uconv = ucnv_open(name, &status);
  106. if (U_FAILURE(status))
  107. goto error;
  108. status = U_ZERO_ERROR;
  109. if (toUnicode) {
  110. ucnv_setToUCallBack(conv->uconv, UCNV_TO_U_CALLBACK_STOP,
  111. NULL, NULL, NULL, &status);
  112. }
  113. else {
  114. ucnv_setFromUCallBack(conv->uconv, UCNV_FROM_U_CALLBACK_STOP,
  115. NULL, NULL, NULL, &status);
  116. }
  117. if (U_FAILURE(status))
  118. goto error;
  119. status = U_ZERO_ERROR;
  120. conv->utf8 = ucnv_open("UTF-8", &status);
  121. if (U_SUCCESS(status))
  122. return conv;
  123. error:
  124. if (conv->uconv)
  125. ucnv_close(conv->uconv);
  126. xmlFree(conv);
  127. return NULL;
  128. }
  129. static void
  130. closeIcuConverter(uconv_t *conv)
  131. {
  132. if (conv != NULL) {
  133. ucnv_close(conv->uconv);
  134. ucnv_close(conv->utf8);
  135. xmlFree(conv);
  136. }
  137. }
  138. #endif /* LIBXML_ICU_ENABLED */
  139. /************************************************************************
  140. * *
  141. * Conversions To/From UTF8 encoding *
  142. * *
  143. ************************************************************************/
  144. /**
  145. * asciiToUTF8:
  146. * @out: a pointer to an array of bytes to store the result
  147. * @outlen: the length of @out
  148. * @in: a pointer to an array of ASCII chars
  149. * @inlen: the length of @in
  150. *
  151. * Take a block of ASCII chars in and try to convert it to an UTF-8
  152. * block of chars out.
  153. * Returns 0 if success, or -1 otherwise
  154. * The value of @inlen after return is the number of octets consumed
  155. * if the return value is positive, else unpredictable.
  156. * The value of @outlen after return is the number of octets produced.
  157. */
  158. static int
  159. asciiToUTF8(unsigned char* out, int *outlen,
  160. const unsigned char* in, int *inlen) {
  161. unsigned char* outstart = out;
  162. const unsigned char* base = in;
  163. const unsigned char* processed = in;
  164. unsigned char* outend = out + *outlen;
  165. const unsigned char* inend;
  166. unsigned int c;
  167. inend = in + (*inlen);
  168. while ((in < inend) && (out - outstart + 5 < *outlen)) {
  169. c= *in++;
  170. if (out >= outend)
  171. break;
  172. if (c < 0x80) {
  173. *out++ = c;
  174. } else {
  175. *outlen = out - outstart;
  176. *inlen = processed - base;
  177. return(-1);
  178. }
  179. processed = (const unsigned char*) in;
  180. }
  181. *outlen = out - outstart;
  182. *inlen = processed - base;
  183. return(*outlen);
  184. }
  185. #ifdef LIBXML_OUTPUT_ENABLED
  186. /**
  187. * UTF8Toascii:
  188. * @out: a pointer to an array of bytes to store the result
  189. * @outlen: the length of @out
  190. * @in: a pointer to an array of UTF-8 chars
  191. * @inlen: the length of @in
  192. *
  193. * Take a block of UTF-8 chars in and try to convert it to an ASCII
  194. * block of chars out.
  195. *
  196. * Returns 0 if success, -2 if the transcoding fails, or -1 otherwise
  197. * The value of @inlen after return is the number of octets consumed
  198. * if the return value is positive, else unpredictable.
  199. * The value of @outlen after return is the number of octets produced.
  200. */
  201. static int
  202. UTF8Toascii(unsigned char* out, int *outlen,
  203. const unsigned char* in, int *inlen) {
  204. const unsigned char* processed = in;
  205. const unsigned char* outend;
  206. const unsigned char* outstart = out;
  207. const unsigned char* instart = in;
  208. const unsigned char* inend;
  209. unsigned int c, d;
  210. int trailing;
  211. if ((out == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1);
  212. if (in == NULL) {
  213. /*
  214. * initialization nothing to do
  215. */
  216. *outlen = 0;
  217. *inlen = 0;
  218. return(0);
  219. }
  220. inend = in + (*inlen);
  221. outend = out + (*outlen);
  222. while (in < inend) {
  223. d = *in++;
  224. if (d < 0x80) { c= d; trailing= 0; }
  225. else if (d < 0xC0) {
  226. /* trailing byte in leading position */
  227. *outlen = out - outstart;
  228. *inlen = processed - instart;
  229. return(-2);
  230. } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; }
  231. else if (d < 0xF0) { c= d & 0x0F; trailing= 2; }
  232. else if (d < 0xF8) { c= d & 0x07; trailing= 3; }
  233. else {
  234. /* no chance for this in Ascii */
  235. *outlen = out - outstart;
  236. *inlen = processed - instart;
  237. return(-2);
  238. }
  239. if (inend - in < trailing) {
  240. break;
  241. }
  242. for ( ; trailing; trailing--) {
  243. if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80))
  244. break;
  245. c <<= 6;
  246. c |= d & 0x3F;
  247. }
  248. /* assertion: c is a single UTF-4 value */
  249. if (c < 0x80) {
  250. if (out >= outend)
  251. break;
  252. *out++ = c;
  253. } else {
  254. /* no chance for this in Ascii */
  255. *outlen = out - outstart;
  256. *inlen = processed - instart;
  257. return(-2);
  258. }
  259. processed = in;
  260. }
  261. *outlen = out - outstart;
  262. *inlen = processed - instart;
  263. return(*outlen);
  264. }
  265. #endif /* LIBXML_OUTPUT_ENABLED */
  266. /**
  267. * isolat1ToUTF8:
  268. * @out: a pointer to an array of bytes to store the result
  269. * @outlen: the length of @out
  270. * @in: a pointer to an array of ISO Latin 1 chars
  271. * @inlen: the length of @in
  272. *
  273. * Take a block of ISO Latin 1 chars in and try to convert it to an UTF-8
  274. * block of chars out.
  275. * Returns the number of bytes written if success, or -1 otherwise
  276. * The value of @inlen after return is the number of octets consumed
  277. * if the return value is positive, else unpredictable.
  278. * The value of @outlen after return is the number of octets produced.
  279. */
  280. int
  281. isolat1ToUTF8(unsigned char* out, int *outlen,
  282. const unsigned char* in, int *inlen) {
  283. unsigned char* outstart = out;
  284. const unsigned char* base = in;
  285. unsigned char* outend;
  286. const unsigned char* inend;
  287. const unsigned char* instop;
  288. if ((out == NULL) || (in == NULL) || (outlen == NULL) || (inlen == NULL))
  289. return(-1);
  290. outend = out + *outlen;
  291. inend = in + (*inlen);
  292. instop = inend;
  293. while ((in < inend) && (out < outend - 1)) {
  294. if (*in >= 0x80) {
  295. *out++ = (((*in) >> 6) & 0x1F) | 0xC0;
  296. *out++ = ((*in) & 0x3F) | 0x80;
  297. ++in;
  298. }
  299. if ((instop - in) > (outend - out)) instop = in + (outend - out);
  300. while ((in < instop) && (*in < 0x80)) {
  301. *out++ = *in++;
  302. }
  303. }
  304. if ((in < inend) && (out < outend) && (*in < 0x80)) {
  305. *out++ = *in++;
  306. }
  307. *outlen = out - outstart;
  308. *inlen = in - base;
  309. return(*outlen);
  310. }
  311. /**
  312. * UTF8ToUTF8:
  313. * @out: a pointer to an array of bytes to store the result
  314. * @outlen: the length of @out
  315. * @inb: a pointer to an array of UTF-8 chars
  316. * @inlenb: the length of @in in UTF-8 chars
  317. *
  318. * No op copy operation for UTF8 handling.
  319. *
  320. * Returns the number of bytes written, or -1 if lack of space.
  321. * The value of *inlen after return is the number of octets consumed
  322. * if the return value is positive, else unpredictable.
  323. */
  324. static int
  325. UTF8ToUTF8(unsigned char* out, int *outlen,
  326. const unsigned char* inb, int *inlenb)
  327. {
  328. int len;
  329. if ((out == NULL) || (outlen == NULL) || (inlenb == NULL))
  330. return(-1);
  331. if (inb == NULL) {
  332. /* inb == NULL means output is initialized. */
  333. *outlen = 0;
  334. *inlenb = 0;
  335. return(0);
  336. }
  337. if (*outlen > *inlenb) {
  338. len = *inlenb;
  339. } else {
  340. len = *outlen;
  341. }
  342. if (len < 0)
  343. return(-1);
  344. /*
  345. * FIXME: Conversion functions must assure valid UTF-8, so we have
  346. * to check for UTF-8 validity. Preferably, this converter shouldn't
  347. * be used at all.
  348. */
  349. memcpy(out, inb, len);
  350. *outlen = len;
  351. *inlenb = len;
  352. return(*outlen);
  353. }
  354. #ifdef LIBXML_OUTPUT_ENABLED
  355. /**
  356. * UTF8Toisolat1:
  357. * @out: a pointer to an array of bytes to store the result
  358. * @outlen: the length of @out
  359. * @in: a pointer to an array of UTF-8 chars
  360. * @inlen: the length of @in
  361. *
  362. * Take a block of UTF-8 chars in and try to convert it to an ISO Latin 1
  363. * block of chars out.
  364. *
  365. * Returns the number of bytes written if success, -2 if the transcoding fails,
  366. or -1 otherwise
  367. * The value of @inlen after return is the number of octets consumed
  368. * if the return value is positive, else unpredictable.
  369. * The value of @outlen after return is the number of octets produced.
  370. */
  371. int
  372. UTF8Toisolat1(unsigned char* out, int *outlen,
  373. const unsigned char* in, int *inlen) {
  374. const unsigned char* processed = in;
  375. const unsigned char* outend;
  376. const unsigned char* outstart = out;
  377. const unsigned char* instart = in;
  378. const unsigned char* inend;
  379. unsigned int c, d;
  380. int trailing;
  381. if ((out == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1);
  382. if (in == NULL) {
  383. /*
  384. * initialization nothing to do
  385. */
  386. *outlen = 0;
  387. *inlen = 0;
  388. return(0);
  389. }
  390. inend = in + (*inlen);
  391. outend = out + (*outlen);
  392. while (in < inend) {
  393. d = *in++;
  394. if (d < 0x80) { c= d; trailing= 0; }
  395. else if (d < 0xC0) {
  396. /* trailing byte in leading position */
  397. *outlen = out - outstart;
  398. *inlen = processed - instart;
  399. return(-2);
  400. } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; }
  401. else if (d < 0xF0) { c= d & 0x0F; trailing= 2; }
  402. else if (d < 0xF8) { c= d & 0x07; trailing= 3; }
  403. else {
  404. /* no chance for this in IsoLat1 */
  405. *outlen = out - outstart;
  406. *inlen = processed - instart;
  407. return(-2);
  408. }
  409. if (inend - in < trailing) {
  410. break;
  411. }
  412. for ( ; trailing; trailing--) {
  413. if (in >= inend)
  414. break;
  415. if (((d= *in++) & 0xC0) != 0x80) {
  416. *outlen = out - outstart;
  417. *inlen = processed - instart;
  418. return(-2);
  419. }
  420. c <<= 6;
  421. c |= d & 0x3F;
  422. }
  423. /* assertion: c is a single UTF-4 value */
  424. if (c <= 0xFF) {
  425. if (out >= outend)
  426. break;
  427. *out++ = c;
  428. } else {
  429. /* no chance for this in IsoLat1 */
  430. *outlen = out - outstart;
  431. *inlen = processed - instart;
  432. return(-2);
  433. }
  434. processed = in;
  435. }
  436. *outlen = out - outstart;
  437. *inlen = processed - instart;
  438. return(*outlen);
  439. }
  440. #endif /* LIBXML_OUTPUT_ENABLED */
  441. /**
  442. * UTF16LEToUTF8:
  443. * @out: a pointer to an array of bytes to store the result
  444. * @outlen: the length of @out
  445. * @inb: a pointer to an array of UTF-16LE passwd as a byte array
  446. * @inlenb: the length of @in in UTF-16LE chars
  447. *
  448. * Take a block of UTF-16LE ushorts in and try to convert it to an UTF-8
  449. * block of chars out. This function assumes the endian property
  450. * is the same between the native type of this machine and the
  451. * inputed one.
  452. *
  453. * Returns the number of bytes written, or -1 if lack of space, or -2
  454. * if the transcoding fails (if *in is not a valid utf16 string)
  455. * The value of *inlen after return is the number of octets consumed
  456. * if the return value is positive, else unpredictable.
  457. */
  458. static int
  459. UTF16LEToUTF8(unsigned char* out, int *outlen,
  460. const unsigned char* inb, int *inlenb)
  461. {
  462. unsigned char* outstart = out;
  463. const unsigned char* processed = inb;
  464. unsigned char* outend;
  465. unsigned short* in = (unsigned short*) inb;
  466. unsigned short* inend;
  467. unsigned int c, d, inlen;
  468. unsigned char *tmp;
  469. int bits;
  470. if (*outlen == 0) {
  471. *inlenb = 0;
  472. return(0);
  473. }
  474. outend = out + *outlen;
  475. if ((*inlenb % 2) == 1)
  476. (*inlenb)--;
  477. inlen = *inlenb / 2;
  478. inend = in + inlen;
  479. while ((in < inend) && (out - outstart + 5 < *outlen)) {
  480. if (xmlLittleEndian) {
  481. c= *in++;
  482. } else {
  483. tmp = (unsigned char *) in;
  484. c = *tmp++;
  485. c = c | (((unsigned int)*tmp) << 8);
  486. in++;
  487. }
  488. if ((c & 0xFC00) == 0xD800) { /* surrogates */
  489. if (in >= inend) { /* handle split mutli-byte characters */
  490. break;
  491. }
  492. if (xmlLittleEndian) {
  493. d = *in++;
  494. } else {
  495. tmp = (unsigned char *) in;
  496. d = *tmp++;
  497. d = d | (((unsigned int)*tmp) << 8);
  498. in++;
  499. }
  500. if ((d & 0xFC00) == 0xDC00) {
  501. c &= 0x03FF;
  502. c <<= 10;
  503. c |= d & 0x03FF;
  504. c += 0x10000;
  505. }
  506. else {
  507. *outlen = out - outstart;
  508. *inlenb = processed - inb;
  509. return(-2);
  510. }
  511. }
  512. /* assertion: c is a single UTF-4 value */
  513. if (out >= outend)
  514. break;
  515. if (c < 0x80) { *out++= c; bits= -6; }
  516. else if (c < 0x800) { *out++= ((c >> 6) & 0x1F) | 0xC0; bits= 0; }
  517. else if (c < 0x10000) { *out++= ((c >> 12) & 0x0F) | 0xE0; bits= 6; }
  518. else { *out++= ((c >> 18) & 0x07) | 0xF0; bits= 12; }
  519. for ( ; bits >= 0; bits-= 6) {
  520. if (out >= outend)
  521. break;
  522. *out++= ((c >> bits) & 0x3F) | 0x80;
  523. }
  524. processed = (const unsigned char*) in;
  525. }
  526. *outlen = out - outstart;
  527. *inlenb = processed - inb;
  528. return(*outlen);
  529. }
  530. #ifdef LIBXML_OUTPUT_ENABLED
  531. /**
  532. * UTF8ToUTF16LE:
  533. * @outb: a pointer to an array of bytes to store the result
  534. * @outlen: the length of @outb
  535. * @in: a pointer to an array of UTF-8 chars
  536. * @inlen: the length of @in
  537. *
  538. * Take a block of UTF-8 chars in and try to convert it to an UTF-16LE
  539. * block of chars out.
  540. *
  541. * Returns the number of bytes written, or -1 if lack of space, or -2
  542. * if the transcoding failed.
  543. */
  544. static int
  545. UTF8ToUTF16LE(unsigned char* outb, int *outlen,
  546. const unsigned char* in, int *inlen)
  547. {
  548. unsigned short* out = (unsigned short*) outb;
  549. const unsigned char* processed = in;
  550. const unsigned char *const instart = in;
  551. unsigned short* outstart= out;
  552. unsigned short* outend;
  553. const unsigned char* inend;
  554. unsigned int c, d;
  555. int trailing;
  556. unsigned char *tmp;
  557. unsigned short tmp1, tmp2;
  558. /* UTF16LE encoding has no BOM */
  559. if ((out == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1);
  560. if (in == NULL) {
  561. *outlen = 0;
  562. *inlen = 0;
  563. return(0);
  564. }
  565. inend= in + *inlen;
  566. outend = out + (*outlen / 2);
  567. while (in < inend) {
  568. d= *in++;
  569. if (d < 0x80) { c= d; trailing= 0; }
  570. else if (d < 0xC0) {
  571. /* trailing byte in leading position */
  572. *outlen = (out - outstart) * 2;
  573. *inlen = processed - instart;
  574. return(-2);
  575. } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; }
  576. else if (d < 0xF0) { c= d & 0x0F; trailing= 2; }
  577. else if (d < 0xF8) { c= d & 0x07; trailing= 3; }
  578. else {
  579. /* no chance for this in UTF-16 */
  580. *outlen = (out - outstart) * 2;
  581. *inlen = processed - instart;
  582. return(-2);
  583. }
  584. if (inend - in < trailing) {
  585. break;
  586. }
  587. for ( ; trailing; trailing--) {
  588. if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80))
  589. break;
  590. c <<= 6;
  591. c |= d & 0x3F;
  592. }
  593. /* assertion: c is a single UTF-4 value */
  594. if (c < 0x10000) {
  595. if (out >= outend)
  596. break;
  597. if (xmlLittleEndian) {
  598. *out++ = c;
  599. } else {
  600. tmp = (unsigned char *) out;
  601. *tmp = c ;
  602. *(tmp + 1) = c >> 8 ;
  603. out++;
  604. }
  605. }
  606. else if (c < 0x110000) {
  607. if (out+1 >= outend)
  608. break;
  609. c -= 0x10000;
  610. if (xmlLittleEndian) {
  611. *out++ = 0xD800 | (c >> 10);
  612. *out++ = 0xDC00 | (c & 0x03FF);
  613. } else {
  614. tmp1 = 0xD800 | (c >> 10);
  615. tmp = (unsigned char *) out;
  616. *tmp = (unsigned char) tmp1;
  617. *(tmp + 1) = tmp1 >> 8;
  618. out++;
  619. tmp2 = 0xDC00 | (c & 0x03FF);
  620. tmp = (unsigned char *) out;
  621. *tmp = (unsigned char) tmp2;
  622. *(tmp + 1) = tmp2 >> 8;
  623. out++;
  624. }
  625. }
  626. else
  627. break;
  628. processed = in;
  629. }
  630. *outlen = (out - outstart) * 2;
  631. *inlen = processed - instart;
  632. return(*outlen);
  633. }
  634. /**
  635. * UTF8ToUTF16:
  636. * @outb: a pointer to an array of bytes to store the result
  637. * @outlen: the length of @outb
  638. * @in: a pointer to an array of UTF-8 chars
  639. * @inlen: the length of @in
  640. *
  641. * Take a block of UTF-8 chars in and try to convert it to an UTF-16
  642. * block of chars out.
  643. *
  644. * Returns the number of bytes written, or -1 if lack of space, or -2
  645. * if the transcoding failed.
  646. */
  647. static int
  648. UTF8ToUTF16(unsigned char* outb, int *outlen,
  649. const unsigned char* in, int *inlen)
  650. {
  651. if (in == NULL) {
  652. /*
  653. * initialization, add the Byte Order Mark for UTF-16LE
  654. */
  655. if (*outlen >= 2) {
  656. outb[0] = 0xFF;
  657. outb[1] = 0xFE;
  658. *outlen = 2;
  659. *inlen = 0;
  660. #ifdef DEBUG_ENCODING
  661. xmlGenericError(xmlGenericErrorContext,
  662. "Added FFFE Byte Order Mark\n");
  663. #endif
  664. return(2);
  665. }
  666. *outlen = 0;
  667. *inlen = 0;
  668. return(0);
  669. }
  670. return (UTF8ToUTF16LE(outb, outlen, in, inlen));
  671. }
  672. #endif /* LIBXML_OUTPUT_ENABLED */
  673. /**
  674. * UTF16BEToUTF8:
  675. * @out: a pointer to an array of bytes to store the result
  676. * @outlen: the length of @out
  677. * @inb: a pointer to an array of UTF-16 passed as a byte array
  678. * @inlenb: the length of @in in UTF-16 chars
  679. *
  680. * Take a block of UTF-16 ushorts in and try to convert it to an UTF-8
  681. * block of chars out. This function assumes the endian property
  682. * is the same between the native type of this machine and the
  683. * inputed one.
  684. *
  685. * Returns the number of bytes written, or -1 if lack of space, or -2
  686. * if the transcoding fails (if *in is not a valid utf16 string)
  687. * The value of *inlen after return is the number of octets consumed
  688. * if the return value is positive, else unpredictable.
  689. */
  690. static int
  691. UTF16BEToUTF8(unsigned char* out, int *outlen,
  692. const unsigned char* inb, int *inlenb)
  693. {
  694. unsigned char* outstart = out;
  695. const unsigned char* processed = inb;
  696. unsigned char* outend;
  697. unsigned short* in = (unsigned short*) inb;
  698. unsigned short* inend;
  699. unsigned int c, d, inlen;
  700. unsigned char *tmp;
  701. int bits;
  702. if (*outlen == 0) {
  703. *inlenb = 0;
  704. return(0);
  705. }
  706. outend = out + *outlen;
  707. if ((*inlenb % 2) == 1)
  708. (*inlenb)--;
  709. inlen = *inlenb / 2;
  710. inend= in + inlen;
  711. while ((in < inend) && (out - outstart + 5 < *outlen)) {
  712. if (xmlLittleEndian) {
  713. tmp = (unsigned char *) in;
  714. c = *tmp++;
  715. c = (c << 8) | (unsigned int) *tmp;
  716. in++;
  717. } else {
  718. c= *in++;
  719. }
  720. if ((c & 0xFC00) == 0xD800) { /* surrogates */
  721. if (in >= inend) { /* handle split mutli-byte characters */
  722. break;
  723. }
  724. if (xmlLittleEndian) {
  725. tmp = (unsigned char *) in;
  726. d = *tmp++;
  727. d = (d << 8) | (unsigned int) *tmp;
  728. in++;
  729. } else {
  730. d= *in++;
  731. }
  732. if ((d & 0xFC00) == 0xDC00) {
  733. c &= 0x03FF;
  734. c <<= 10;
  735. c |= d & 0x03FF;
  736. c += 0x10000;
  737. }
  738. else {
  739. *outlen = out - outstart;
  740. *inlenb = processed - inb;
  741. return(-2);
  742. }
  743. }
  744. /* assertion: c is a single UTF-4 value */
  745. if (out >= outend)
  746. break;
  747. if (c < 0x80) { *out++= c; bits= -6; }
  748. else if (c < 0x800) { *out++= ((c >> 6) & 0x1F) | 0xC0; bits= 0; }
  749. else if (c < 0x10000) { *out++= ((c >> 12) & 0x0F) | 0xE0; bits= 6; }
  750. else { *out++= ((c >> 18) & 0x07) | 0xF0; bits= 12; }
  751. for ( ; bits >= 0; bits-= 6) {
  752. if (out >= outend)
  753. break;
  754. *out++= ((c >> bits) & 0x3F) | 0x80;
  755. }
  756. processed = (const unsigned char*) in;
  757. }
  758. *outlen = out - outstart;
  759. *inlenb = processed - inb;
  760. return(*outlen);
  761. }
  762. #ifdef LIBXML_OUTPUT_ENABLED
  763. /**
  764. * UTF8ToUTF16BE:
  765. * @outb: a pointer to an array of bytes to store the result
  766. * @outlen: the length of @outb
  767. * @in: a pointer to an array of UTF-8 chars
  768. * @inlen: the length of @in
  769. *
  770. * Take a block of UTF-8 chars in and try to convert it to an UTF-16BE
  771. * block of chars out.
  772. *
  773. * Returns the number of byte written, or -1 by lack of space, or -2
  774. * if the transcoding failed.
  775. */
  776. static int
  777. UTF8ToUTF16BE(unsigned char* outb, int *outlen,
  778. const unsigned char* in, int *inlen)
  779. {
  780. unsigned short* out = (unsigned short*) outb;
  781. const unsigned char* processed = in;
  782. const unsigned char *const instart = in;
  783. unsigned short* outstart= out;
  784. unsigned short* outend;
  785. const unsigned char* inend;
  786. unsigned int c, d;
  787. int trailing;
  788. unsigned char *tmp;
  789. unsigned short tmp1, tmp2;
  790. /* UTF-16BE has no BOM */
  791. if ((outb == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1);
  792. if (in == NULL) {
  793. *outlen = 0;
  794. *inlen = 0;
  795. return(0);
  796. }
  797. inend= in + *inlen;
  798. outend = out + (*outlen / 2);
  799. while (in < inend) {
  800. d= *in++;
  801. if (d < 0x80) { c= d; trailing= 0; }
  802. else if (d < 0xC0) {
  803. /* trailing byte in leading position */
  804. *outlen = out - outstart;
  805. *inlen = processed - instart;
  806. return(-2);
  807. } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; }
  808. else if (d < 0xF0) { c= d & 0x0F; trailing= 2; }
  809. else if (d < 0xF8) { c= d & 0x07; trailing= 3; }
  810. else {
  811. /* no chance for this in UTF-16 */
  812. *outlen = out - outstart;
  813. *inlen = processed - instart;
  814. return(-2);
  815. }
  816. if (inend - in < trailing) {
  817. break;
  818. }
  819. for ( ; trailing; trailing--) {
  820. if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80)) break;
  821. c <<= 6;
  822. c |= d & 0x3F;
  823. }
  824. /* assertion: c is a single UTF-4 value */
  825. if (c < 0x10000) {
  826. if (out >= outend) break;
  827. if (xmlLittleEndian) {
  828. tmp = (unsigned char *) out;
  829. *tmp = c >> 8;
  830. *(tmp + 1) = c;
  831. out++;
  832. } else {
  833. *out++ = c;
  834. }
  835. }
  836. else if (c < 0x110000) {
  837. if (out+1 >= outend) break;
  838. c -= 0x10000;
  839. if (xmlLittleEndian) {
  840. tmp1 = 0xD800 | (c >> 10);
  841. tmp = (unsigned char *) out;
  842. *tmp = tmp1 >> 8;
  843. *(tmp + 1) = (unsigned char) tmp1;
  844. out++;
  845. tmp2 = 0xDC00 | (c & 0x03FF);
  846. tmp = (unsigned char *) out;
  847. *tmp = tmp2 >> 8;
  848. *(tmp + 1) = (unsigned char) tmp2;
  849. out++;
  850. } else {
  851. *out++ = 0xD800 | (c >> 10);
  852. *out++ = 0xDC00 | (c & 0x03FF);
  853. }
  854. }
  855. else
  856. break;
  857. processed = in;
  858. }
  859. *outlen = (out - outstart) * 2;
  860. *inlen = processed - instart;
  861. return(*outlen);
  862. }
  863. #endif /* LIBXML_OUTPUT_ENABLED */
  864. /************************************************************************
  865. * *
  866. * Generic encoding handling routines *
  867. * *
  868. ************************************************************************/
  869. /**
  870. * xmlDetectCharEncoding:
  871. * @in: a pointer to the first bytes of the XML entity, must be at least
  872. * 2 bytes long (at least 4 if encoding is UTF4 variant).
  873. * @len: pointer to the length of the buffer
  874. *
  875. * Guess the encoding of the entity using the first bytes of the entity content
  876. * according to the non-normative appendix F of the XML-1.0 recommendation.
  877. *
  878. * Returns one of the XML_CHAR_ENCODING_... values.
  879. */
  880. xmlCharEncoding
  881. xmlDetectCharEncoding(const unsigned char* in, int len)
  882. {
  883. if (in == NULL)
  884. return(XML_CHAR_ENCODING_NONE);
  885. if (len >= 4) {
  886. if ((in[0] == 0x00) && (in[1] == 0x00) &&
  887. (in[2] == 0x00) && (in[3] == 0x3C))
  888. return(XML_CHAR_ENCODING_UCS4BE);
  889. if ((in[0] == 0x3C) && (in[1] == 0x00) &&
  890. (in[2] == 0x00) && (in[3] == 0x00))
  891. return(XML_CHAR_ENCODING_UCS4LE);
  892. if ((in[0] == 0x00) && (in[1] == 0x00) &&
  893. (in[2] == 0x3C) && (in[3] == 0x00))
  894. return(XML_CHAR_ENCODING_UCS4_2143);
  895. if ((in[0] == 0x00) && (in[1] == 0x3C) &&
  896. (in[2] == 0x00) && (in[3] == 0x00))
  897. return(XML_CHAR_ENCODING_UCS4_3412);
  898. if ((in[0] == 0x4C) && (in[1] == 0x6F) &&
  899. (in[2] == 0xA7) && (in[3] == 0x94))
  900. return(XML_CHAR_ENCODING_EBCDIC);
  901. if ((in[0] == 0x3C) && (in[1] == 0x3F) &&
  902. (in[2] == 0x78) && (in[3] == 0x6D))
  903. return(XML_CHAR_ENCODING_UTF8);
  904. /*
  905. * Although not part of the recommendation, we also
  906. * attempt an "auto-recognition" of UTF-16LE and
  907. * UTF-16BE encodings.
  908. */
  909. if ((in[0] == 0x3C) && (in[1] == 0x00) &&
  910. (in[2] == 0x3F) && (in[3] == 0x00))
  911. return(XML_CHAR_ENCODING_UTF16LE);
  912. if ((in[0] == 0x00) && (in[1] == 0x3C) &&
  913. (in[2] == 0x00) && (in[3] == 0x3F))
  914. return(XML_CHAR_ENCODING_UTF16BE);
  915. }
  916. if (len >= 3) {
  917. /*
  918. * Errata on XML-1.0 June 20 2001
  919. * We now allow an UTF8 encoded BOM
  920. */
  921. if ((in[0] == 0xEF) && (in[1] == 0xBB) &&
  922. (in[2] == 0xBF))
  923. return(XML_CHAR_ENCODING_UTF8);
  924. }
  925. /* For UTF-16 we can recognize by the BOM */
  926. if (len >= 2) {
  927. if ((in[0] == 0xFE) && (in[1] == 0xFF))
  928. return(XML_CHAR_ENCODING_UTF16BE);
  929. if ((in[0] == 0xFF) && (in[1] == 0xFE))
  930. return(XML_CHAR_ENCODING_UTF16LE);
  931. }
  932. return(XML_CHAR_ENCODING_NONE);
  933. }
  934. /**
  935. * xmlCleanupEncodingAliases:
  936. *
  937. * Unregisters all aliases
  938. */
  939. void
  940. xmlCleanupEncodingAliases(void) {
  941. int i;
  942. if (xmlCharEncodingAliases == NULL)
  943. return;
  944. for (i = 0;i < xmlCharEncodingAliasesNb;i++) {
  945. if (xmlCharEncodingAliases[i].name != NULL)
  946. xmlFree((char *) xmlCharEncodingAliases[i].name);
  947. if (xmlCharEncodingAliases[i].alias != NULL)
  948. xmlFree((char *) xmlCharEncodingAliases[i].alias);
  949. }
  950. xmlCharEncodingAliasesNb = 0;
  951. xmlCharEncodingAliasesMax = 0;
  952. xmlFree(xmlCharEncodingAliases);
  953. xmlCharEncodingAliases = NULL;
  954. }
  955. /**
  956. * xmlGetEncodingAlias:
  957. * @alias: the alias name as parsed, in UTF-8 format (ASCII actually)
  958. *
  959. * Lookup an encoding name for the given alias.
  960. *
  961. * Returns NULL if not found, otherwise the original name
  962. */
  963. const char *
  964. xmlGetEncodingAlias(const char *alias) {
  965. int i;
  966. char upper[100];
  967. if (alias == NULL)
  968. return(NULL);
  969. if (xmlCharEncodingAliases == NULL)
  970. return(NULL);
  971. for (i = 0;i < 99;i++) {
  972. upper[i] = toupper(alias[i]);
  973. if (upper[i] == 0) break;
  974. }
  975. upper[i] = 0;
  976. /*
  977. * Walk down the list looking for a definition of the alias
  978. */
  979. for (i = 0;i < xmlCharEncodingAliasesNb;i++) {
  980. if (!strcmp(xmlCharEncodingAliases[i].alias, upper)) {
  981. return(xmlCharEncodingAliases[i].name);
  982. }
  983. }
  984. return(NULL);
  985. }
  986. /**
  987. * xmlAddEncodingAlias:
  988. * @name: the encoding name as parsed, in UTF-8 format (ASCII actually)
  989. * @alias: the alias name as parsed, in UTF-8 format (ASCII actually)
  990. *
  991. * Registers an alias @alias for an encoding named @name. Existing alias
  992. * will be overwritten.
  993. *
  994. * Returns 0 in case of success, -1 in case of error
  995. */
  996. int
  997. xmlAddEncodingAlias(const char *name, const char *alias) {
  998. int i;
  999. char upper[100];
  1000. if ((name == NULL) || (alias == NULL))
  1001. return(-1);
  1002. for (i = 0;i < 99;i++) {
  1003. upper[i] = toupper(alias[i]);
  1004. if (upper[i] == 0) break;
  1005. }
  1006. upper[i] = 0;
  1007. if (xmlCharEncodingAliases == NULL) {
  1008. xmlCharEncodingAliasesNb = 0;
  1009. xmlCharEncodingAliasesMax = 20;
  1010. xmlCharEncodingAliases = (xmlCharEncodingAliasPtr)
  1011. xmlMalloc(xmlCharEncodingAliasesMax * sizeof(xmlCharEncodingAlias));
  1012. if (xmlCharEncodingAliases == NULL)
  1013. return(-1);
  1014. } else if (xmlCharEncodingAliasesNb >= xmlCharEncodingAliasesMax) {
  1015. xmlCharEncodingAliasesMax *= 2;
  1016. xmlCharEncodingAliases = (xmlCharEncodingAliasPtr)
  1017. xmlRealloc(xmlCharEncodingAliases,
  1018. xmlCharEncodingAliasesMax * sizeof(xmlCharEncodingAlias));
  1019. }
  1020. /*
  1021. * Walk down the list looking for a definition of the alias
  1022. */
  1023. for (i = 0;i < xmlCharEncodingAliasesNb;i++) {
  1024. if (!strcmp(xmlCharEncodingAliases[i].alias, upper)) {
  1025. /*
  1026. * Replace the definition.
  1027. */
  1028. xmlFree((char *) xmlCharEncodingAliases[i].name);
  1029. xmlCharEncodingAliases[i].name = xmlMemStrdup(name);
  1030. return(0);
  1031. }
  1032. }
  1033. /*
  1034. * Add the definition
  1035. */
  1036. xmlCharEncodingAliases[xmlCharEncodingAliasesNb].name = xmlMemStrdup(name);
  1037. xmlCharEncodingAliases[xmlCharEncodingAliasesNb].alias = xmlMemStrdup(upper);
  1038. xmlCharEncodingAliasesNb++;
  1039. return(0);
  1040. }
  1041. /**
  1042. * xmlDelEncodingAlias:
  1043. * @alias: the alias name as parsed, in UTF-8 format (ASCII actually)
  1044. *
  1045. * Unregisters an encoding alias @alias
  1046. *
  1047. * Returns 0 in case of success, -1 in case of error
  1048. */
  1049. int
  1050. xmlDelEncodingAlias(const char *alias) {
  1051. int i;
  1052. if (alias == NULL)
  1053. return(-1);
  1054. if (xmlCharEncodingAliases == NULL)
  1055. return(-1);
  1056. /*
  1057. * Walk down the list looking for a definition of the alias
  1058. */
  1059. for (i = 0;i < xmlCharEncodingAliasesNb;i++) {
  1060. if (!strcmp(xmlCharEncodingAliases[i].alias, alias)) {
  1061. xmlFree((char *) xmlCharEncodingAliases[i].name);
  1062. xmlFree((char *) xmlCharEncodingAliases[i].alias);
  1063. xmlCharEncodingAliasesNb--;
  1064. memmove(&xmlCharEncodingAliases[i], &xmlCharEncodingAliases[i + 1],
  1065. sizeof(xmlCharEncodingAlias) * (xmlCharEncodingAliasesNb - i));
  1066. return(0);
  1067. }
  1068. }
  1069. return(-1);
  1070. }
  1071. /**
  1072. * xmlParseCharEncoding:
  1073. * @name: the encoding name as parsed, in UTF-8 format (ASCII actually)
  1074. *
  1075. * Compare the string to the encoding schemes already known. Note
  1076. * that the comparison is case insensitive accordingly to the section
  1077. * [XML] 4.3.3 Character Encoding in Entities.
  1078. *
  1079. * Returns one of the XML_CHAR_ENCODING_... values or XML_CHAR_ENCODING_NONE
  1080. * if not recognized.
  1081. */
  1082. xmlCharEncoding
  1083. xmlParseCharEncoding(const char* name)
  1084. {
  1085. const char *alias;
  1086. char upper[500];
  1087. int i;
  1088. if (name == NULL)
  1089. return(XML_CHAR_ENCODING_NONE);
  1090. /*
  1091. * Do the alias resolution
  1092. */
  1093. alias = xmlGetEncodingAlias(name);
  1094. if (alias != NULL)
  1095. name = alias;
  1096. for (i = 0;i < 499;i++) {
  1097. upper[i] = toupper(name[i]);
  1098. if (upper[i] == 0) break;
  1099. }
  1100. upper[i] = 0;
  1101. if (!strcmp(upper, "")) return(XML_CHAR_ENCODING_NONE);
  1102. if (!strcmp(upper, "UTF-8")) return(XML_CHAR_ENCODING_UTF8);
  1103. if (!strcmp(upper, "UTF8")) return(XML_CHAR_ENCODING_UTF8);
  1104. /*
  1105. * NOTE: if we were able to parse this, the endianness of UTF16 is
  1106. * already found and in use
  1107. */
  1108. if (!strcmp(upper, "UTF-16")) return(XML_CHAR_ENCODING_UTF16LE);
  1109. if (!strcmp(upper, "UTF16")) return(XML_CHAR_ENCODING_UTF16LE);
  1110. if (!strcmp(upper, "ISO-10646-UCS-2")) return(XML_CHAR_ENCODING_UCS2);
  1111. if (!strcmp(upper, "UCS-2")) return(XML_CHAR_ENCODING_UCS2);
  1112. if (!strcmp(upper, "UCS2")) return(XML_CHAR_ENCODING_UCS2);
  1113. /*
  1114. * NOTE: if we were able to parse this, the endianness of UCS4 is
  1115. * already found and in use
  1116. */
  1117. if (!strcmp(upper, "ISO-10646-UCS-4")) return(XML_CHAR_ENCODING_UCS4LE);
  1118. if (!strcmp(upper, "UCS-4")) return(XML_CHAR_ENCODING_UCS4LE);
  1119. if (!strcmp(upper, "UCS4")) return(XML_CHAR_ENCODING_UCS4LE);
  1120. if (!strcmp(upper, "ISO-8859-1")) return(XML_CHAR_ENCODING_8859_1);
  1121. if (!strcmp(upper, "ISO-LATIN-1")) return(XML_CHAR_ENCODING_8859_1);
  1122. if (!strcmp(upper, "ISO LATIN 1")) return(XML_CHAR_ENCODING_8859_1);
  1123. if (!strcmp(upper, "ISO-8859-2")) return(XML_CHAR_ENCODING_8859_2);
  1124. if (!strcmp(upper, "ISO-LATIN-2")) return(XML_CHAR_ENCODING_8859_2);
  1125. if (!strcmp(upper, "ISO LATIN 2")) return(XML_CHAR_ENCODING_8859_2);
  1126. if (!strcmp(upper, "ISO-8859-3")) return(XML_CHAR_ENCODING_8859_3);
  1127. if (!strcmp(upper, "ISO-8859-4")) return(XML_CHAR_ENCODING_8859_4);
  1128. if (!strcmp(upper, "ISO-8859-5")) return(XML_CHAR_ENCODING_8859_5);
  1129. if (!strcmp(upper, "ISO-8859-6")) return(XML_CHAR_ENCODING_8859_6);
  1130. if (!strcmp(upper, "ISO-8859-7")) return(XML_CHAR_ENCODING_8859_7);
  1131. if (!strcmp(upper, "ISO-8859-8")) return(XML_CHAR_ENCODING_8859_8);
  1132. if (!strcmp(upper, "ISO-8859-9")) return(XML_CHAR_ENCODING_8859_9);
  1133. if (!strcmp(upper, "ISO-2022-JP")) return(XML_CHAR_ENCODING_2022_JP);
  1134. if (!strcmp(upper, "SHIFT_JIS")) return(XML_CHAR_ENCODING_SHIFT_JIS);
  1135. if (!strcmp(upper, "EUC-JP")) return(XML_CHAR_ENCODING_EUC_JP);
  1136. #ifdef DEBUG_ENCODING
  1137. xmlGenericError(xmlGenericErrorContext, "Unknown encoding %s\n", name);
  1138. #endif
  1139. return(XML_CHAR_ENCODING_ERROR);
  1140. }
  1141. /**
  1142. * xmlGetCharEncodingName:
  1143. * @enc: the encoding
  1144. *
  1145. * The "canonical" name for XML encoding.
  1146. * C.f. http://www.w3.org/TR/REC-xml#charencoding
  1147. * Section 4.3.3 Character Encoding in Entities
  1148. *
  1149. * Returns the canonical name for the given encoding
  1150. */
  1151. const char*
  1152. xmlGetCharEncodingName(xmlCharEncoding enc) {
  1153. switch (enc) {
  1154. case XML_CHAR_ENCODING_ERROR:
  1155. return(NULL);
  1156. case XML_CHAR_ENCODING_NONE:
  1157. return(NULL);
  1158. case XML_CHAR_ENCODING_UTF8:
  1159. return("UTF-8");
  1160. case XML_CHAR_ENCODING_UTF16LE:
  1161. return("UTF-16");
  1162. case XML_CHAR_ENCODING_UTF16BE:
  1163. return("UTF-16");
  1164. case XML_CHAR_ENCODING_EBCDIC:
  1165. return("EBCDIC");
  1166. case XML_CHAR_ENCODING_UCS4LE:
  1167. return("ISO-10646-UCS-4");
  1168. case XML_CHAR_ENCODING_UCS4BE:
  1169. return("ISO-10646-UCS-4");
  1170. case XML_CHAR_ENCODING_UCS4_2143:
  1171. return("ISO-10646-UCS-4");
  1172. case XML_CHAR_ENCODING_UCS4_3412:
  1173. return("ISO-10646-UCS-4");
  1174. case XML_CHAR_ENCODING_UCS2:
  1175. return("ISO-10646-UCS-2");
  1176. case XML_CHAR_ENCODING_8859_1:
  1177. return("ISO-8859-1");
  1178. case XML_CHAR_ENCODING_8859_2:
  1179. return("ISO-8859-2");
  1180. case XML_CHAR_ENCODING_8859_3:
  1181. return("ISO-8859-3");
  1182. case XML_CHAR_ENCODING_8859_4:
  1183. return("ISO-8859-4");
  1184. case XML_CHAR_ENCODING_8859_5:
  1185. return("ISO-8859-5");
  1186. case XML_CHAR_ENCODING_8859_6:
  1187. return("ISO-8859-6");
  1188. case XML_CHAR_ENCODING_8859_7:
  1189. return("ISO-8859-7");
  1190. case XML_CHAR_ENCODING_8859_8:
  1191. return("ISO-8859-8");
  1192. case XML_CHAR_ENCODING_8859_9:
  1193. return("ISO-8859-9");
  1194. case XML_CHAR_ENCODING_2022_JP:
  1195. return("ISO-2022-JP");
  1196. case XML_CHAR_ENCODING_SHIFT_JIS:
  1197. return("Shift-JIS");
  1198. case XML_CHAR_ENCODING_EUC_JP:
  1199. return("EUC-JP");
  1200. case XML_CHAR_ENCODING_ASCII:
  1201. return(NULL);
  1202. }
  1203. return(NULL);
  1204. }
  1205. /************************************************************************
  1206. * *
  1207. * Char encoding handlers *
  1208. * *
  1209. ************************************************************************/
  1210. /* the size should be growable, but it's not a big deal ... */
  1211. #define MAX_ENCODING_HANDLERS 50
  1212. static xmlCharEncodingHandlerPtr *handlers = NULL;
  1213. static int nbCharEncodingHandler = 0;
  1214. /*
  1215. * The default is UTF-8 for XML, that's also the default used for the
  1216. * parser internals, so the default encoding handler is NULL
  1217. */
  1218. static xmlCharEncodingHandlerPtr xmlDefaultCharEncodingHandler = NULL;
  1219. /**
  1220. * xmlNewCharEncodingHandler:
  1221. * @name: the encoding name, in UTF-8 format (ASCII actually)
  1222. * @input: the xmlCharEncodingInputFunc to read that encoding
  1223. * @output: the xmlCharEncodingOutputFunc to write that encoding
  1224. *
  1225. * Create and registers an xmlCharEncodingHandler.
  1226. *
  1227. * Returns the xmlCharEncodingHandlerPtr created (or NULL in case of error).
  1228. */
  1229. xmlCharEncodingHandlerPtr
  1230. xmlNewCharEncodingHandler(const char *name,
  1231. xmlCharEncodingInputFunc input,
  1232. xmlCharEncodingOutputFunc output) {
  1233. xmlCharEncodingHandlerPtr handler;
  1234. const char *alias;
  1235. char upper[500];
  1236. int i;
  1237. char *up = NULL;
  1238. /*
  1239. * Do the alias resolution
  1240. */
  1241. alias = xmlGetEncodingAlias(name);
  1242. if (alias != NULL)
  1243. name = alias;
  1244. /*
  1245. * Keep only the uppercase version of the encoding.
  1246. */
  1247. if (name == NULL) {
  1248. xmlEncodingErr(XML_I18N_NO_NAME,
  1249. "xmlNewCharEncodingHandler : no name !\n", NULL);
  1250. return(NULL);
  1251. }
  1252. for (i = 0;i < 499;i++) {
  1253. upper[i] = toupper(name[i]);
  1254. if (upper[i] == 0) break;
  1255. }
  1256. upper[i] = 0;
  1257. up = xmlMemStrdup(upper);
  1258. if (up == NULL) {
  1259. xmlEncodingErrMemory("xmlNewCharEncodingHandler : out of memory !\n");
  1260. return(NULL);
  1261. }
  1262. /*
  1263. * allocate and fill-up an handler block.
  1264. */
  1265. handler = (xmlCharEncodingHandlerPtr)
  1266. xmlMalloc(sizeof(xmlCharEncodingHandler));
  1267. if (handler == NULL) {
  1268. xmlFree(up);
  1269. xmlEncodingErrMemory("xmlNewCharEncodingHandler : out of memory !\n");
  1270. return(NULL);
  1271. }
  1272. memset(handler, 0, sizeof(xmlCharEncodingHandler));
  1273. handler->input = input;
  1274. handler->output = output;
  1275. handler->name = up;
  1276. #ifdef LIBXML_ICONV_ENABLED
  1277. handler->iconv_in = NULL;
  1278. handler->iconv_out = NULL;
  1279. #endif
  1280. #ifdef LIBXML_ICU_ENABLED
  1281. handler->uconv_in = NULL;
  1282. handler->uconv_out = NULL;
  1283. #endif
  1284. /*
  1285. * registers and returns the handler.
  1286. */
  1287. xmlRegisterCharEncodingHandler(handler);
  1288. #ifdef DEBUG_ENCODING
  1289. xmlGenericError(xmlGenericErrorContext,
  1290. "Registered encoding handler for %s\n", name);
  1291. #endif
  1292. return(handler);
  1293. }
  1294. /**
  1295. * xmlInitCharEncodingHandlers:
  1296. *
  1297. * Initialize the char encoding support, it registers the default
  1298. * encoding supported.
  1299. * NOTE: while public, this function usually doesn't need to be called
  1300. * in normal processing.
  1301. */
  1302. void
  1303. xmlInitCharEncodingHandlers(void) {
  1304. unsigned short int tst = 0x1234;
  1305. unsigned char *ptr = (unsigned char *) &tst;
  1306. if (handlers != NULL) return;
  1307. handlers = (xmlCharEncodingHandlerPtr *)
  1308. xmlMalloc(MAX_ENCODING_HANDLERS * sizeof(xmlCharEncodingHandlerPtr));
  1309. if (*ptr == 0x12) xmlLittleEndian = 0;
  1310. else if (*ptr == 0x34) xmlLittleEndian = 1;
  1311. else {
  1312. xmlEncodingErr(XML_ERR_INTERNAL_ERROR,
  1313. "Odd problem at endianness detection\n", NULL);
  1314. }
  1315. if (handlers == NULL) {
  1316. xmlEncodingErrMemory("xmlInitCharEncodingHandlers : out of memory !\n");
  1317. return;
  1318. }
  1319. xmlNewCharEncodingHandler("UTF-8", UTF8ToUTF8, UTF8ToUTF8);
  1320. #ifdef LIBXML_OUTPUT_ENABLED
  1321. xmlUTF16LEHandler =
  1322. xmlNewCharEncodingHandler("UTF-16LE", UTF16LEToUTF8, UTF8ToUTF16LE);
  1323. xmlUTF16BEHandler =
  1324. xmlNewCharEncodingHandler("UTF-16BE", UTF16BEToUTF8, UTF8ToUTF16BE);
  1325. xmlNewCharEncodingHandler("UTF-16", UTF16LEToUTF8, UTF8ToUTF16);
  1326. xmlNewCharEncodingHandler("ISO-8859-1", isolat1ToUTF8, UTF8Toisolat1);
  1327. xmlNewCharEncodingHandler("ASCII", asciiToUTF8, UTF8Toascii);
  1328. xmlNewCharEncodingHandler("US-ASCII", asciiToUTF8, UTF8Toascii);
  1329. #ifndef ARCADIA_LIBXML_DISABLE_EXTRA_ENCODINGS
  1330. xmlNewCharEncodingHandler("windows-1251", win1251ToUTF8, UTF8Towin1251);
  1331. xmlNewCharEncodingHandler("koi8-r", koi8ToUTF8, UTF8Tokoi8);
  1332. #endif
  1333. #ifdef LIBXML_HTML_ENABLED
  1334. xmlNewCharEncodingHandler("HTML", NULL, UTF8ToHtml);
  1335. #endif
  1336. #else
  1337. xmlUTF16LEHandler =
  1338. xmlNewCharEncodingHandler("UTF-16LE", UTF16LEToUTF8, NULL);
  1339. xmlUTF16BEHandler =
  1340. xmlNewCharEncodingHandler("UTF-16BE", UTF16BEToUTF8, NULL);
  1341. xmlNewCharEncodingHandler("UTF-16", UTF16LEToUTF8, NULL);
  1342. xmlNewCharEncodingHandler("ISO-8859-1", isolat1ToUTF8, NULL);
  1343. xmlNewCharEncodingHandler("ASCII", asciiToUTF8, NULL);
  1344. xmlNewCharEncodingHandler("US-ASCII", asciiToUTF8, NULL);
  1345. #endif /* LIBXML_OUTPUT_ENABLED */
  1346. #if !defined(LIBXML_ICONV_ENABLED) && !defined(LIBXML_ICU_ENABLED)
  1347. #ifdef LIBXML_ISO8859X_ENABLED
  1348. xmlRegisterCharEncodingHandlersISO8859x ();
  1349. #endif
  1350. #endif
  1351. }
  1352. /**
  1353. * xmlCleanupCharEncodingHandlers:
  1354. *
  1355. * Cleanup the memory allocated for the char encoding support, it
  1356. * unregisters all the encoding handlers and the aliases.
  1357. */
  1358. void
  1359. xmlCleanupCharEncodingHandlers(void) {
  1360. xmlCleanupEncodingAliases();
  1361. if (handlers == NULL) return;
  1362. for (;nbCharEncodingHandler > 0;) {
  1363. nbCharEncodingHandler--;
  1364. if (handlers[nbCharEncodingHandler] != NULL) {
  1365. if (handlers[nbCharEncodingHandler]->name != NULL)
  1366. xmlFree(handlers[nbCharEncodingHandler]->name);
  1367. xmlFree(handlers[nbCharEncodingHandler]);
  1368. }
  1369. }
  1370. xmlFree(handlers);
  1371. handlers = NULL;
  1372. nbCharEncodingHandler = 0;
  1373. xmlDefaultCharEncodingHandler = NULL;
  1374. }
  1375. /**
  1376. * xmlRegisterCharEncodingHandler:
  1377. * @handler: the xmlCharEncodingHandlerPtr handler block
  1378. *
  1379. * Register the char encoding handler, surprising, isn't it ?
  1380. */
  1381. void
  1382. xmlRegisterCharEncodingHandler(xmlCharEncodingHandlerPtr handler) {
  1383. if (handlers == NULL) xmlInitCharEncodingHandlers();
  1384. if ((handler == NULL) || (handlers == NULL)) {
  1385. xmlEncodingErr(XML_I18N_NO_HANDLER,
  1386. "xmlRegisterCharEncodingHandler: NULL handler !\n", NULL);
  1387. goto free_handler;
  1388. }
  1389. if (nbCharEncodingHandler >= MAX_ENCODING_HANDLERS) {
  1390. xmlEncodingErr(XML_I18N_EXCESS_HANDLER,
  1391. "xmlRegisterCharEncodingHandler: Too many handler registered, see %s\n",
  1392. "MAX_ENCODING_HANDLERS");
  1393. goto free_handler;
  1394. }
  1395. handlers[nbCharEncodingHandler++] = handler;
  1396. return;
  1397. free_handler:
  1398. if (handler != NULL) {
  1399. if (handler->name != NULL) {
  1400. xmlFree(handler->name);
  1401. }
  1402. xmlFree(handler);
  1403. }
  1404. }
  1405. /**
  1406. * xmlGetCharEncodingHandler:
  1407. * @enc: an xmlCharEncoding value.
  1408. *
  1409. * Search in the registered set the handler able to read/write that encoding.
  1410. *
  1411. * Returns the handler or NULL if not found
  1412. */
  1413. xmlCharEncodingHandlerPtr
  1414. xmlGetCharEncodingHandler(xmlCharEncoding enc) {
  1415. xmlCharEncodingHandlerPtr handler;
  1416. if (handlers == NULL) xmlInitCharEncodingHandlers();
  1417. switch (enc) {
  1418. case XML_CHAR_ENCODING_ERROR:
  1419. return(NULL);
  1420. case XML_CHAR_ENCODING_NONE:
  1421. return(NULL);
  1422. case XML_CHAR_ENCODING_UTF8:
  1423. return(NULL);
  1424. case XML_CHAR_ENCODING_UTF16LE:
  1425. return(xmlUTF16LEHandler);
  1426. case XML_CHAR_ENCODING_UTF16BE:
  1427. return(xmlUTF16BEHandler);
  1428. case XML_CHAR_ENCODING_EBCDIC:
  1429. handler = xmlFindCharEncodingHandler("EBCDIC");
  1430. if (handler != NULL) return(handler);
  1431. handler = xmlFindCharEncodingHandler("ebcdic");
  1432. if (handler != NULL) return(handler);
  1433. handler = xmlFindCharEncodingHandler("EBCDIC-US");
  1434. if (handler != NULL) return(handler);
  1435. handler = xmlFindCharEncodingHandler("IBM-037");
  1436. if (handler != NULL) return(handler);
  1437. break;
  1438. case XML_CHAR_ENCODING_UCS4BE:
  1439. handler = xmlFindCharEncodingHandler("ISO-10646-UCS-4");
  1440. if (handler != NULL) return(handler);
  1441. handler = xmlFindCharEncodingHandler("UCS-4");
  1442. if (handler != NULL) return(handler);
  1443. handler = xmlFindCharEncodingHandler("UCS4");
  1444. if (handler != NULL) return(handler);
  1445. break;
  1446. case XML_CHAR_ENCODING_UCS4LE:
  1447. handler = xmlFindCharEncodingHandler("ISO-10646-UCS-4");
  1448. if (handler != NULL) return(handler);
  1449. handler = xmlFindCharEncodingHandler("UCS-4");
  1450. if (handler != NULL) return(handler);
  1451. handler = xmlFindCharEncodingHandler("UCS4");
  1452. if (handler != NULL) return(handler);
  1453. break;
  1454. case XML_CHAR_ENCODING_UCS4_2143:
  1455. break;
  1456. case XML_CHAR_ENCODING_UCS4_3412:
  1457. break;
  1458. case XML_CHAR_ENCODING_UCS2:
  1459. handler = xmlFindCharEncodingHandler("ISO-10646-UCS-2");
  1460. if (handler != NULL) return(handler);
  1461. handler = xmlFindCharEncodingHandler("UCS-2");
  1462. if (handler != NULL) return(handler);
  1463. handler = xmlFindCharEncodingHandler("UCS2");
  1464. if (handler != NULL) return(handler);
  1465. break;
  1466. /*
  1467. * We used to keep ISO Latin encodings native in the
  1468. * generated data. This led to so many problems that
  1469. * this has been removed. One can still change this
  1470. * back by registering no-ops encoders for those
  1471. */
  1472. case XML_CHAR_ENCODING_8859_1:
  1473. handler = xmlFindCharEncodingHandler("ISO-8859-1");
  1474. if (handler != NULL) return(handler);
  1475. break;
  1476. case XML_CHAR_ENCODING_8859_2:
  1477. handler = xmlFindCharEncodingHandler("ISO-8859-2");
  1478. if (handler != NULL) return(handler);
  1479. break;
  1480. case XML_CHAR_ENCODING_8859_3:
  1481. handler = xmlFindCharEncodingHandler("ISO-8859-3");
  1482. if (handler != NULL) return(handler);
  1483. break;
  1484. case XML_CHAR_ENCODING_8859_4:
  1485. handler = xmlFindCharEncodingHandler("ISO-8859-4");
  1486. if (handler != NULL) return(handler);
  1487. break;
  1488. case XML_CHAR_ENCODING_8859_5:
  1489. handler = xmlFindCharEncodingHandler("ISO-8859-5");
  1490. if (handler != NULL) return(handler);
  1491. break;
  1492. case XML_CHAR_ENCODING_8859_6:
  1493. handler = xmlFindCharEncodingHandler("ISO-8859-6");
  1494. if (handler != NULL) return(handler);
  1495. break;
  1496. case XML_CHAR_ENCODING_8859_7:
  1497. handler = xmlFindCharEncodingHandler("ISO-8859-7");
  1498. if (handler != NULL) return(handler);
  1499. break;
  1500. case XML_CHAR_ENCODING_8859_8:
  1501. handler = xmlFindCharEncodingHandler("ISO-8859-8");
  1502. if (handler != NULL) return(handler);
  1503. break;
  1504. case XML_CHAR_ENCODING_8859_9:
  1505. handler = xmlFindCharEncodingHandler("ISO-8859-9");
  1506. if (handler != NULL) return(handler);
  1507. break;
  1508. case XML_CHAR_ENCODING_2022_JP:
  1509. handler = xmlFindCharEncodingHandler("ISO-2022-JP");
  1510. if (handler != NULL) return(handler);
  1511. break;
  1512. case XML_CHAR_ENCODING_SHIFT_JIS:
  1513. handler = xmlFindCharEncodingHandler("SHIFT-JIS");
  1514. if (handler != NULL) return(handler);
  1515. handler = xmlFindCharEncodingHandler("SHIFT_JIS");
  1516. if (handler != NULL) return(handler);
  1517. handler = xmlFindCharEncodingHandler("Shift_JIS");
  1518. if (handler != NULL) return(handler);
  1519. break;
  1520. case XML_CHAR_ENCODING_EUC_JP:
  1521. handler = xmlFindCharEncodingHandler("EUC-JP");
  1522. if (handler != NULL) return(handler);
  1523. break;
  1524. default:
  1525. break;
  1526. }
  1527. #ifdef DEBUG_ENCODING
  1528. xmlGenericError(xmlGenericErrorContext,
  1529. "No handler found for encoding %d\n", enc);
  1530. #endif
  1531. return(NULL);
  1532. }
  1533. /**
  1534. * xmlFindCharEncodingHandler:
  1535. * @name: a string describing the char encoding.
  1536. *
  1537. * Search in the registered set the handler able to read/write that encoding.
  1538. *
  1539. * Returns the handler or NULL if not found
  1540. */
  1541. xmlCharEncodingHandlerPtr
  1542. xmlFindCharEncodingHandler(const char *name) {
  1543. const char *nalias;
  1544. const char *norig;
  1545. xmlCharEncoding alias;
  1546. #ifdef LIBXML_ICONV_ENABLED
  1547. xmlCharEncodingHandlerPtr enc;
  1548. iconv_t icv_in, icv_out;
  1549. #endif /* LIBXML_ICONV_ENABLED */
  1550. #ifdef LIBXML_ICU_ENABLED
  1551. xmlCharEncodingHandlerPtr encu;
  1552. uconv_t *ucv_in, *ucv_out;
  1553. #endif /* LIBXML_ICU_ENABLED */
  1554. char upper[100];
  1555. int i;
  1556. if (handlers == NULL) xmlInitCharEncodingHandlers();
  1557. if (name == NULL) return(xmlDefaultCharEncodingHandler);
  1558. if (name[0] == 0) return(xmlDefaultCharEncodingHandler);
  1559. /*
  1560. * Do the alias resolution
  1561. */
  1562. norig = name;
  1563. nalias = xmlGetEncodingAlias(name);
  1564. if (nalias != NULL)
  1565. name = nalias;
  1566. /*
  1567. * Check first for directly registered encoding names
  1568. */
  1569. for (i = 0;i < 99;i++) {
  1570. upper[i] = toupper(name[i]);
  1571. if (upper[i] == 0) break;
  1572. }
  1573. upper[i] = 0;
  1574. if (handlers != NULL) {
  1575. for (i = 0;i < nbCharEncodingHandler; i++) {
  1576. if (!strcmp(upper, handlers[i]->name)) {
  1577. #ifdef DEBUG_ENCODING
  1578. xmlGenericError(xmlGenericErrorContext,
  1579. "Found registered handler for encoding %s\n", name);
  1580. #endif
  1581. return(handlers[i]);
  1582. }
  1583. }
  1584. }
  1585. #ifdef LIBXML_ICONV_ENABLED
  1586. /* check whether iconv can handle this */
  1587. icv_in = iconv_open("UTF-8", name);
  1588. icv_out = iconv_open(name, "UTF-8");
  1589. if (icv_in == (iconv_t) -1) {
  1590. icv_in = iconv_open("UTF-8", upper);
  1591. }
  1592. if (icv_out == (iconv_t) -1) {
  1593. icv_out = iconv_open(upper, "UTF-8");
  1594. }
  1595. if ((icv_in != (iconv_t) -1) && (icv_out != (iconv_t) -1)) {
  1596. enc = (xmlCharEncodingHandlerPtr)
  1597. xmlMalloc(sizeof(xmlCharEncodingHandler));
  1598. if (enc == NULL) {
  1599. iconv_close(icv_in);
  1600. iconv_close(icv_out);
  1601. return(NULL);
  1602. }
  1603. memset(enc, 0, sizeof(xmlCharEncodingHandler));
  1604. enc->name = xmlMemStrdup(name);
  1605. enc->input = NULL;
  1606. enc->output = NULL;
  1607. enc->iconv_in = icv_in;
  1608. enc->iconv_out = icv_out;
  1609. #ifdef DEBUG_ENCODING
  1610. xmlGenericError(xmlGenericErrorContext,
  1611. "Found iconv handler for encoding %s\n", name);
  1612. #endif
  1613. return enc;
  1614. } else if ((icv_in != (iconv_t) -1) || icv_out != (iconv_t) -1) {
  1615. xmlEncodingErr(XML_ERR_INTERNAL_ERROR,
  1616. "iconv : problems with filters for '%s'\n", name);
  1617. }
  1618. #endif /* LIBXML_ICONV_ENABLED */
  1619. #ifdef LIBXML_ICU_ENABLED
  1620. /* check whether icu can handle this */
  1621. ucv_in = openIcuConverter(name, 1);
  1622. ucv_out = openIcuConverter(name, 0);
  1623. if (ucv_in != NULL && ucv_out != NULL) {
  1624. encu = (xmlCharEncodingHandlerPtr)
  1625. xmlMalloc(sizeof(xmlCharEncodingHandler));
  1626. if (encu == NULL) {
  1627. closeIcuConverter(ucv_in);
  1628. closeIcuConverter(ucv_out);
  1629. return(NULL);
  1630. }
  1631. memset(encu, 0, sizeof(xmlCharEncodingHandler));
  1632. encu->name = xmlMemStrdup(name);
  1633. encu->input = NULL;
  1634. encu->output = NULL;
  1635. encu->uconv_in = ucv_in;
  1636. encu->uconv_out = ucv_out;
  1637. #ifdef DEBUG_ENCODING
  1638. xmlGenericError(xmlGenericErrorContext,
  1639. "Found ICU converter handler for encoding %s\n", name);
  1640. #endif
  1641. return encu;
  1642. } else if (ucv_in != NULL || ucv_out != NULL) {
  1643. closeIcuConverter(ucv_in);
  1644. closeIcuConverter(ucv_out);
  1645. xmlEncodingErr(XML_ERR_INTERNAL_ERROR,
  1646. "ICU converter : problems with filters for '%s'\n", name);
  1647. }
  1648. #endif /* LIBXML_ICU_ENABLED */
  1649. #ifdef DEBUG_ENCODING
  1650. xmlGenericError(xmlGenericErrorContext,
  1651. "No handler found for encoding %s\n", name);
  1652. #endif
  1653. /*
  1654. * Fallback using the canonical names
  1655. */
  1656. alias = xmlParseCharEncoding(norig);
  1657. if (alias != XML_CHAR_ENCODING_ERROR) {
  1658. const char* canon;
  1659. canon = xmlGetCharEncodingName(alias);
  1660. if ((canon != NULL) && (strcmp(name, canon))) {
  1661. return(xmlFindCharEncodingHandler(canon));
  1662. }
  1663. }
  1664. /* If "none of the above", give up */
  1665. return(NULL);
  1666. }
  1667. /************************************************************************
  1668. * *
  1669. * ICONV based generic conversion functions *
  1670. * *
  1671. ************************************************************************/
  1672. #ifdef LIBXML_ICONV_ENABLED
  1673. /**
  1674. * xmlIconvWrapper:
  1675. * @cd: iconv converter data structure
  1676. * @out: a pointer to an array of bytes to store the result
  1677. * @outlen: the length of @out
  1678. * @in: a pointer to an array of input bytes
  1679. * @inlen: the length of @in
  1680. *
  1681. * Returns 0 if success, or
  1682. * -1 by lack of space, or
  1683. * -2 if the transcoding fails (for *in is not valid utf8 string or
  1684. * the result of transformation can't fit into the encoding we want), or
  1685. * -3 if there the last byte can't form a single output char.
  1686. *
  1687. * The value of @inlen after return is the number of octets consumed
  1688. * as the return value is positive, else unpredictable.
  1689. * The value of @outlen after return is the number of octets produced.
  1690. */
  1691. static int
  1692. xmlIconvWrapper(iconv_t cd, unsigned char *out, int *outlen,
  1693. const unsigned char *in, int *inlen) {
  1694. size_t icv_inlen, icv_outlen;
  1695. const char *icv_in = (const char *) in;
  1696. char *icv_out = (char *) out;
  1697. size_t ret;
  1698. if ((out == NULL) || (outlen == NULL) || (inlen == NULL) || (in == NULL)) {
  1699. if (outlen != NULL) *outlen = 0;
  1700. return(-1);
  1701. }
  1702. icv_inlen = *inlen;
  1703. icv_outlen = *outlen;
  1704. ret = iconv(cd, (ICONV_CONST char **) &icv_in, &icv_inlen, &icv_out, &icv_outlen);
  1705. *inlen -= icv_inlen;
  1706. *outlen -= icv_outlen;
  1707. if ((icv_inlen != 0) || (ret == (size_t) -1)) {
  1708. #ifdef EILSEQ
  1709. if (errno == EILSEQ) {
  1710. return -2;
  1711. } else
  1712. #endif
  1713. #ifdef E2BIG
  1714. if (errno == E2BIG) {
  1715. return -1;
  1716. } else
  1717. #endif
  1718. #ifdef EINVAL
  1719. if (errno == EINVAL) {
  1720. return -3;
  1721. } else
  1722. #endif
  1723. {
  1724. return -3;
  1725. }
  1726. }
  1727. return 0;
  1728. }
  1729. #endif /* LIBXML_ICONV_ENABLED */
  1730. /************************************************************************
  1731. * *
  1732. * ICU based generic conversion functions *
  1733. * *
  1734. ************************************************************************/
  1735. #ifdef LIBXML_ICU_ENABLED
  1736. /**
  1737. * xmlUconvWrapper:
  1738. * @cd: ICU uconverter data structure
  1739. * @toUnicode : non-zero if toUnicode. 0 otherwise.
  1740. * @out: a pointer to an array of bytes to store the result
  1741. * @outlen: the length of @out
  1742. * @in: a pointer to an array of input bytes
  1743. * @inlen: the length of @in
  1744. * @flush: if true, indicates end of input
  1745. *
  1746. * Returns 0 if success, or
  1747. * -1 by lack of space, or
  1748. * -2 if the transcoding fails (for *in is not valid utf8 string or
  1749. * the result of transformation can't fit into the encoding we want), or
  1750. * -3 if there the last byte can't form a single output char.
  1751. *
  1752. * The value of @inlen after return is the number of octets consumed
  1753. * as the return value is positive, else unpredictable.
  1754. * The value of @outlen after return is the number of octets produced.
  1755. */
  1756. static int
  1757. xmlUconvWrapper(uconv_t *cd, int toUnicode, unsigned char *out, int *outlen,
  1758. const unsigned char *in, int *inlen, int flush) {
  1759. const char *ucv_in = (const char *) in;
  1760. char *ucv_out = (char *) out;
  1761. UErrorCode err = U_ZERO_ERROR;
  1762. if ((out == NULL) || (outlen == NULL) || (inlen == NULL) || (in == NULL)) {
  1763. if (outlen != NULL) *outlen = 0;
  1764. return(-1);
  1765. }
  1766. if (toUnicode) {
  1767. /* encoding => UTF-16 => UTF-8 */
  1768. ucnv_convertEx(cd->utf8, cd->uconv, &ucv_out, ucv_out + *outlen,
  1769. &ucv_in, ucv_in + *inlen, cd->pivot_buf,
  1770. &cd->pivot_source, &cd->pivot_target,
  1771. cd->pivot_buf + ICU_PIVOT_BUF_SIZE, 0, flush, &err);
  1772. } else {
  1773. /* UTF-8 => UTF-16 => encoding */
  1774. ucnv_convertEx(cd->uconv, cd->utf8, &ucv_out, ucv_out + *outlen,
  1775. &ucv_in, ucv_in + *inlen, cd->pivot_buf,
  1776. &cd->pivot_source, &cd->pivot_target,
  1777. cd->pivot_buf + ICU_PIVOT_BUF_SIZE, 0, flush, &err);
  1778. }
  1779. *inlen = ucv_in - (const char*) in;
  1780. *outlen = ucv_out - (char *) out;
  1781. if (U_SUCCESS(err)) {
  1782. /* reset pivot buf if this is the last call for input (flush==TRUE) */
  1783. if (flush)
  1784. cd->pivot_source = cd->pivot_target = cd->pivot_buf;
  1785. return 0;
  1786. }
  1787. if (err == U_BUFFER_OVERFLOW_ERROR)
  1788. return -1;
  1789. if (err == U_INVALID_CHAR_FOUND || err == U_ILLEGAL_CHAR_FOUND)
  1790. return -2;
  1791. return -3;
  1792. }
  1793. #endif /* LIBXML_ICU_ENABLED */
  1794. /************************************************************************
  1795. * *
  1796. * The real API used by libxml for on-the-fly conversion *
  1797. * *
  1798. ************************************************************************/
  1799. /**
  1800. * xmlEncInputChunk:
  1801. * @handler: encoding handler
  1802. * @out: a pointer to an array of bytes to store the result
  1803. * @outlen: the length of @out
  1804. * @in: a pointer to an array of input bytes
  1805. * @inlen: the length of @in
  1806. * @flush: flush (ICU-related)
  1807. *
  1808. * Returns 0 if success, or
  1809. * -1 by lack of space, or
  1810. * -2 if the transcoding fails (for *in is not valid utf8 string or
  1811. * the result of transformation can't fit into the encoding we want), or
  1812. * -3 if there the last byte can't form a single output char.
  1813. *
  1814. * The value of @inlen after return is the number of octets consumed
  1815. * as the return value is 0, else unpredictable.
  1816. * The value of @outlen after return is the number of octets produced.
  1817. */
  1818. static int
  1819. xmlEncInputChunk(xmlCharEncodingHandler *handler, unsigned char *out,
  1820. int *outlen, const unsigned char *in, int *inlen, int flush) {
  1821. int ret;
  1822. (void)flush;
  1823. if (handler->input != NULL) {
  1824. ret = handler->input(out, outlen, in, inlen);
  1825. if (ret > 0)
  1826. ret = 0;
  1827. }
  1828. #ifdef LIBXML_ICONV_ENABLED
  1829. else if (handler->iconv_in != NULL) {
  1830. ret = xmlIconvWrapper(handler->iconv_in, out, outlen, in, inlen);
  1831. }
  1832. #endif /* LIBXML_ICONV_ENABLED */
  1833. #ifdef LIBXML_ICU_ENABLED
  1834. else if (handler->uconv_in != NULL) {
  1835. ret = xmlUconvWrapper(handler->uconv_in, 1, out, outlen, in, inlen,
  1836. flush);
  1837. }
  1838. #endif /* LIBXML_ICU_ENABLED */
  1839. else {
  1840. *outlen = 0;
  1841. *inlen = 0;
  1842. ret = -2;
  1843. }
  1844. return(ret);
  1845. }
  1846. /**
  1847. * xmlEncOutputChunk:
  1848. * @handler: encoding handler
  1849. * @out: a pointer to an array of bytes to store the result
  1850. * @outlen: the length of @out
  1851. * @in: a pointer to an array of input bytes
  1852. * @inlen: the length of @in
  1853. *
  1854. * Returns 0 if success, or
  1855. * -1 by lack of space, or
  1856. * -2 if the transcoding fails (for *in is not valid utf8 string or
  1857. * the result of transformation can't fit into the encoding we want), or
  1858. * -3 if there the last byte can't form a single output char.
  1859. * -4 if no output function was found.
  1860. *
  1861. * The value of @inlen after return is the number of octets consumed
  1862. * as the return value is 0, else unpredictable.
  1863. * The value of @outlen after return is the number of octets produced.
  1864. */
  1865. static int
  1866. xmlEncOutputChunk(xmlCharEncodingHandler *handler, unsigned char *out,
  1867. int *outlen, const unsigned char *in, int *inlen) {
  1868. int ret;
  1869. if (handler->output != NULL) {
  1870. ret = handler->output(out, outlen, in, inlen);
  1871. if (ret > 0)
  1872. ret = 0;
  1873. }
  1874. #ifdef LIBXML_ICONV_ENABLED
  1875. else if (handler->iconv_out != NULL) {
  1876. ret = xmlIconvWrapper(handler->iconv_out, out, outlen, in, inlen);
  1877. }
  1878. #endif /* LIBXML_ICONV_ENABLED */
  1879. #ifdef LIBXML_ICU_ENABLED
  1880. else if (handler->uconv_out != NULL) {
  1881. ret = xmlUconvWrapper(handler->uconv_out, 0, out, outlen, in, inlen,
  1882. 1);
  1883. }
  1884. #endif /* LIBXML_ICU_ENABLED */
  1885. else {
  1886. *outlen = 0;
  1887. *inlen = 0;
  1888. ret = -4;
  1889. }
  1890. return(ret);
  1891. }
  1892. /**
  1893. * xmlCharEncFirstLineInt:
  1894. * @handler: char encoding transformation data structure
  1895. * @out: an xmlBuffer for the output.
  1896. * @in: an xmlBuffer for the input
  1897. * @len: number of bytes to convert for the first line, or -1
  1898. *
  1899. * Front-end for the encoding handler input function, but handle only
  1900. * the very first line, i.e. limit itself to 45 chars.
  1901. *
  1902. * Returns the number of byte written if success, or
  1903. * -1 general error
  1904. * -2 if the transcoding fails (for *in is not valid utf8 string or
  1905. * the result of transformation can't fit into the encoding we want), or
  1906. */
  1907. int
  1908. xmlCharEncFirstLineInt(xmlCharEncodingHandler *handler, xmlBufferPtr out,
  1909. xmlBufferPtr in, int len) {
  1910. int ret;
  1911. int written;
  1912. int toconv;
  1913. if (handler == NULL) return(-1);
  1914. if (out == NULL) return(-1);
  1915. if (in == NULL) return(-1);
  1916. /* calculate space available */
  1917. written = out->size - out->use - 1; /* count '\0' */
  1918. toconv = in->use;
  1919. /*
  1920. * echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
  1921. * 45 chars should be sufficient to reach the end of the encoding
  1922. * declaration without going too far inside the document content.
  1923. * on UTF-16 this means 90bytes, on UCS4 this means 180
  1924. * The actual value depending on guessed encoding is passed as @len
  1925. * if provided
  1926. */
  1927. if (len >= 0) {
  1928. if (toconv > len)
  1929. toconv = len;
  1930. } else {
  1931. if (toconv > 180)
  1932. toconv = 180;
  1933. }
  1934. if (toconv * 2 >= written) {
  1935. xmlBufferGrow(out, toconv * 2);
  1936. written = out->size - out->use - 1;
  1937. }
  1938. ret = xmlEncInputChunk(handler, &out->content[out->use], &written,
  1939. in->content, &toconv, 0);
  1940. xmlBufferShrink(in, toconv);
  1941. out->use += written;
  1942. out->content[out->use] = 0;
  1943. if (ret == -1) ret = -3;
  1944. #ifdef DEBUG_ENCODING
  1945. switch (ret) {
  1946. case 0:
  1947. xmlGenericError(xmlGenericErrorContext,
  1948. "converted %d bytes to %d bytes of input\n",
  1949. toconv, written);
  1950. break;
  1951. case -1:
  1952. xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of input, %d left\n",
  1953. toconv, written, in->use);
  1954. break;
  1955. case -2:
  1956. xmlGenericError(xmlGenericErrorContext,
  1957. "input conversion failed due to input error\n");
  1958. break;
  1959. case -3:
  1960. xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of input, %d left\n",
  1961. toconv, written, in->use);
  1962. break;
  1963. default:
  1964. xmlGenericError(xmlGenericErrorContext,"Unknown input conversion failed %d\n", ret);
  1965. }
  1966. #endif /* DEBUG_ENCODING */
  1967. /*
  1968. * Ignore when input buffer is not on a boundary
  1969. */
  1970. if (ret == -3) ret = 0;
  1971. if (ret == -1) ret = 0;
  1972. return(written ? written : ret);
  1973. }
  1974. /**
  1975. * xmlCharEncFirstLine:
  1976. * @handler: char encoding transformation data structure
  1977. * @out: an xmlBuffer for the output.
  1978. * @in: an xmlBuffer for the input
  1979. *
  1980. * Front-end for the encoding handler input function, but handle only
  1981. * the very first line, i.e. limit itself to 45 chars.
  1982. *
  1983. * Returns the number of byte written if success, or
  1984. * -1 general error
  1985. * -2 if the transcoding fails (for *in is not valid utf8 string or
  1986. * the result of transformation can't fit into the encoding we want), or
  1987. */
  1988. int
  1989. xmlCharEncFirstLine(xmlCharEncodingHandler *handler, xmlBufferPtr out,
  1990. xmlBufferPtr in) {
  1991. return(xmlCharEncFirstLineInt(handler, out, in, -1));
  1992. }
  1993. /**
  1994. * xmlCharEncFirstLineInput:
  1995. * @input: a parser input buffer
  1996. * @len: number of bytes to convert for the first line, or -1
  1997. *
  1998. * Front-end for the encoding handler input function, but handle only
  1999. * the very first line. Point is that this is based on autodetection
  2000. * of the encoding and once that first line is converted we may find
  2001. * out that a different decoder is needed to process the input.
  2002. *
  2003. * Returns the number of byte written if success, or
  2004. * -1 general error
  2005. * -2 if the transcoding fails (for *in is not valid utf8 string or
  2006. * the result of transformation can't fit into the encoding we want), or
  2007. */
  2008. int
  2009. xmlCharEncFirstLineInput(xmlParserInputBufferPtr input, int len)
  2010. {
  2011. int ret;
  2012. size_t written;
  2013. size_t toconv;
  2014. int c_in;
  2015. int c_out;
  2016. xmlBufPtr in;
  2017. xmlBufPtr out;
  2018. if ((input == NULL) || (input->encoder == NULL) ||
  2019. (input->buffer == NULL) || (input->raw == NULL))
  2020. return (-1);
  2021. out = input->buffer;
  2022. in = input->raw;
  2023. toconv = xmlBufUse(in);
  2024. if (toconv == 0)
  2025. return (0);
  2026. written = xmlBufAvail(out) - 1; /* count '\0' */
  2027. /*
  2028. * echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
  2029. * 45 chars should be sufficient to reach the end of the encoding
  2030. * declaration without going too far inside the document content.
  2031. * on UTF-16 this means 90bytes, on UCS4 this means 180
  2032. * The actual value depending on guessed encoding is passed as @len
  2033. * if provided
  2034. */
  2035. if (len >= 0) {
  2036. if (toconv > (unsigned int) len)
  2037. toconv = len;
  2038. } else {
  2039. if (toconv > 180)
  2040. toconv = 180;
  2041. }
  2042. if (toconv * 2 >= written) {
  2043. xmlBufGrow(out, toconv * 2);
  2044. written = xmlBufAvail(out) - 1;
  2045. }
  2046. if (written > 360)
  2047. written = 360;
  2048. c_in = toconv;
  2049. c_out = written;
  2050. ret = xmlEncInputChunk(input->encoder, xmlBufEnd(out), &c_out,
  2051. xmlBufContent(in), &c_in, 0);
  2052. xmlBufShrink(in, c_in);
  2053. xmlBufAddLen(out, c_out);
  2054. if (ret == -1)
  2055. ret = -3;
  2056. switch (ret) {
  2057. case 0:
  2058. #ifdef DEBUG_ENCODING
  2059. xmlGenericError(xmlGenericErrorContext,
  2060. "converted %d bytes to %d bytes of input\n",
  2061. c_in, c_out);
  2062. #endif
  2063. break;
  2064. case -1:
  2065. #ifdef DEBUG_ENCODING
  2066. xmlGenericError(xmlGenericErrorContext,
  2067. "converted %d bytes to %d bytes of input, %d left\n",
  2068. c_in, c_out, (int)xmlBufUse(in));
  2069. #endif
  2070. break;
  2071. case -3:
  2072. #ifdef DEBUG_ENCODING
  2073. xmlGenericError(xmlGenericErrorContext,
  2074. "converted %d bytes to %d bytes of input, %d left\n",
  2075. c_in, c_out, (int)xmlBufUse(in));
  2076. #endif
  2077. break;
  2078. case -2: {
  2079. char buf[50];
  2080. const xmlChar *content = xmlBufContent(in);
  2081. snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
  2082. content[0], content[1],
  2083. content[2], content[3]);
  2084. buf[49] = 0;
  2085. xmlEncodingErr(XML_I18N_CONV_FAILED,
  2086. "input conversion failed due to input error, bytes %s\n",
  2087. buf);
  2088. }
  2089. }
  2090. /*
  2091. * Ignore when input buffer is not on a boundary
  2092. */
  2093. if (ret == -3) ret = 0;
  2094. if (ret == -1) ret = 0;
  2095. return(c_out ? c_out : ret);
  2096. }
  2097. /**
  2098. * xmlCharEncInput:
  2099. * @input: a parser input buffer
  2100. * @flush: try to flush all the raw buffer
  2101. *
  2102. * Generic front-end for the encoding handler on parser input
  2103. *
  2104. * Returns the number of byte written if success, or
  2105. * -1 general error
  2106. * -2 if the transcoding fails (for *in is not valid utf8 string or
  2107. * the result of transformation can't fit into the encoding we want), or
  2108. */
  2109. int
  2110. xmlCharEncInput(xmlParserInputBufferPtr input, int flush)
  2111. {
  2112. int ret;
  2113. size_t written;
  2114. size_t toconv;
  2115. int c_in;
  2116. int c_out;
  2117. xmlBufPtr in;
  2118. xmlBufPtr out;
  2119. if ((input == NULL) || (input->encoder == NULL) ||
  2120. (input->buffer == NULL) || (input->raw == NULL))
  2121. return (-1);
  2122. out = input->buffer;
  2123. in = input->raw;
  2124. toconv = xmlBufUse(in);
  2125. if (toconv == 0)
  2126. return (0);
  2127. if ((toconv > 64 * 1024) && (flush == 0))
  2128. toconv = 64 * 1024;
  2129. written = xmlBufAvail(out);
  2130. if (written > 0)
  2131. written--; /* count '\0' */
  2132. if (toconv * 2 >= written) {
  2133. xmlBufGrow(out, toconv * 2);
  2134. written = xmlBufAvail(out);
  2135. if (written > 0)
  2136. written--; /* count '\0' */
  2137. }
  2138. if ((written > 128 * 1024) && (flush == 0))
  2139. written = 128 * 1024;
  2140. c_in = toconv;
  2141. c_out = written;
  2142. ret = xmlEncInputChunk(input->encoder, xmlBufEnd(out), &c_out,
  2143. xmlBufContent(in), &c_in, flush);
  2144. xmlBufShrink(in, c_in);
  2145. xmlBufAddLen(out, c_out);
  2146. if (ret == -1)
  2147. ret = -3;
  2148. switch (ret) {
  2149. case 0:
  2150. #ifdef DEBUG_ENCODING
  2151. xmlGenericError(xmlGenericErrorContext,
  2152. "converted %d bytes to %d bytes of input\n",
  2153. c_in, c_out);
  2154. #endif
  2155. break;
  2156. case -1:
  2157. #ifdef DEBUG_ENCODING
  2158. xmlGenericError(xmlGenericErrorContext,
  2159. "converted %d bytes to %d bytes of input, %d left\n",
  2160. c_in, c_out, (int)xmlBufUse(in));
  2161. #endif
  2162. break;
  2163. case -3:
  2164. #ifdef DEBUG_ENCODING
  2165. xmlGenericError(xmlGenericErrorContext,
  2166. "converted %d bytes to %d bytes of input, %d left\n",
  2167. c_in, c_out, (int)xmlBufUse(in));
  2168. #endif
  2169. break;
  2170. case -2: {
  2171. char buf[50];
  2172. const xmlChar *content = xmlBufContent(in);
  2173. snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
  2174. content[0], content[1],
  2175. content[2], content[3]);
  2176. buf[49] = 0;
  2177. xmlEncodingErr(XML_I18N_CONV_FAILED,
  2178. "input conversion failed due to input error, bytes %s\n",
  2179. buf);
  2180. }
  2181. }
  2182. /*
  2183. * Ignore when input buffer is not on a boundary
  2184. */
  2185. if (ret == -3)
  2186. ret = 0;
  2187. return (c_out? c_out : ret);
  2188. }
  2189. /**
  2190. * xmlCharEncInFunc:
  2191. * @handler: char encoding transformation data structure
  2192. * @out: an xmlBuffer for the output.
  2193. * @in: an xmlBuffer for the input
  2194. *
  2195. * Generic front-end for the encoding handler input function
  2196. *
  2197. * Returns the number of byte written if success, or
  2198. * -1 general error
  2199. * -2 if the transcoding fails (for *in is not valid utf8 string or
  2200. * the result of transformation can't fit into the encoding we want), or
  2201. */
  2202. int
  2203. xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out,
  2204. xmlBufferPtr in)
  2205. {
  2206. int ret;
  2207. int written;
  2208. int toconv;
  2209. if (handler == NULL)
  2210. return (-1);
  2211. if (out == NULL)
  2212. return (-1);
  2213. if (in == NULL)
  2214. return (-1);
  2215. toconv = in->use;
  2216. if (toconv == 0)
  2217. return (0);
  2218. written = out->size - out->use -1; /* count '\0' */
  2219. if (toconv * 2 >= written) {
  2220. xmlBufferGrow(out, out->size + toconv * 2);
  2221. written = out->size - out->use - 1;
  2222. }
  2223. ret = xmlEncInputChunk(handler, &out->content[out->use], &written,
  2224. in->content, &toconv, 1);
  2225. xmlBufferShrink(in, toconv);
  2226. out->use += written;
  2227. out->content[out->use] = 0;
  2228. if (ret == -1)
  2229. ret = -3;
  2230. switch (ret) {
  2231. case 0:
  2232. #ifdef DEBUG_ENCODING
  2233. xmlGenericError(xmlGenericErrorContext,
  2234. "converted %d bytes to %d bytes of input\n",
  2235. toconv, written);
  2236. #endif
  2237. break;
  2238. case -1:
  2239. #ifdef DEBUG_ENCODING
  2240. xmlGenericError(xmlGenericErrorContext,
  2241. "converted %d bytes to %d bytes of input, %d left\n",
  2242. toconv, written, in->use);
  2243. #endif
  2244. break;
  2245. case -3:
  2246. #ifdef DEBUG_ENCODING
  2247. xmlGenericError(xmlGenericErrorContext,
  2248. "converted %d bytes to %d bytes of input, %d left\n",
  2249. toconv, written, in->use);
  2250. #endif
  2251. break;
  2252. case -2: {
  2253. char buf[50];
  2254. snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
  2255. in->content[0], in->content[1],
  2256. in->content[2], in->content[3]);
  2257. buf[49] = 0;
  2258. xmlEncodingErr(XML_I18N_CONV_FAILED,
  2259. "input conversion failed due to input error, bytes %s\n",
  2260. buf);
  2261. }
  2262. }
  2263. /*
  2264. * Ignore when input buffer is not on a boundary
  2265. */
  2266. if (ret == -3)
  2267. ret = 0;
  2268. return (written? written : ret);
  2269. }
  2270. #ifdef LIBXML_OUTPUT_ENABLED
  2271. /**
  2272. * xmlCharEncOutput:
  2273. * @output: a parser output buffer
  2274. * @init: is this an initialization call without data
  2275. *
  2276. * Generic front-end for the encoding handler on parser output
  2277. * a first call with @init == 1 has to be made first to initiate the
  2278. * output in case of non-stateless encoding needing to initiate their
  2279. * state or the output (like the BOM in UTF16).
  2280. * In case of UTF8 sequence conversion errors for the given encoder,
  2281. * the content will be automatically remapped to a CharRef sequence.
  2282. *
  2283. * Returns the number of byte written if success, or
  2284. * -1 general error
  2285. * -2 if the transcoding fails (for *in is not valid utf8 string or
  2286. * the result of transformation can't fit into the encoding we want), or
  2287. */
  2288. int
  2289. xmlCharEncOutput(xmlOutputBufferPtr output, int init)
  2290. {
  2291. int ret;
  2292. size_t written;
  2293. int writtentot = 0;
  2294. size_t toconv;
  2295. int c_in;
  2296. int c_out;
  2297. xmlBufPtr in;
  2298. xmlBufPtr out;
  2299. if ((output == NULL) || (output->encoder == NULL) ||
  2300. (output->buffer == NULL) || (output->conv == NULL))
  2301. return (-1);
  2302. out = output->conv;
  2303. in = output->buffer;
  2304. retry:
  2305. written = xmlBufAvail(out);
  2306. if (written > 0)
  2307. written--; /* count '\0' */
  2308. /*
  2309. * First specific handling of the initialization call
  2310. */
  2311. if (init) {
  2312. c_in = 0;
  2313. c_out = written;
  2314. /* TODO: Check return value. */
  2315. xmlEncOutputChunk(output->encoder, xmlBufEnd(out), &c_out,
  2316. NULL, &c_in);
  2317. xmlBufAddLen(out, c_out);
  2318. #ifdef DEBUG_ENCODING
  2319. xmlGenericError(xmlGenericErrorContext,
  2320. "initialized encoder\n");
  2321. #endif
  2322. return(c_out);
  2323. }
  2324. /*
  2325. * Conversion itself.
  2326. */
  2327. toconv = xmlBufUse(in);
  2328. if (toconv == 0)
  2329. return (writtentot);
  2330. if (toconv > 64 * 1024)
  2331. toconv = 64 * 1024;
  2332. if (toconv * 4 >= written) {
  2333. xmlBufGrow(out, toconv * 4);
  2334. written = xmlBufAvail(out) - 1;
  2335. }
  2336. if (written > 256 * 1024)
  2337. written = 256 * 1024;
  2338. c_in = toconv;
  2339. c_out = written;
  2340. ret = xmlEncOutputChunk(output->encoder, xmlBufEnd(out), &c_out,
  2341. xmlBufContent(in), &c_in);
  2342. xmlBufShrink(in, c_in);
  2343. xmlBufAddLen(out, c_out);
  2344. writtentot += c_out;
  2345. if (ret == -1) {
  2346. if (c_out > 0) {
  2347. /* Can be a limitation of iconv or uconv */
  2348. goto retry;
  2349. }
  2350. ret = -3;
  2351. }
  2352. /*
  2353. * Attempt to handle error cases
  2354. */
  2355. switch (ret) {
  2356. case 0:
  2357. #ifdef DEBUG_ENCODING
  2358. xmlGenericError(xmlGenericErrorContext,
  2359. "converted %d bytes to %d bytes of output\n",
  2360. c_in, c_out);
  2361. #endif
  2362. break;
  2363. case -1:
  2364. #ifdef DEBUG_ENCODING
  2365. xmlGenericError(xmlGenericErrorContext,
  2366. "output conversion failed by lack of space\n");
  2367. #endif
  2368. break;
  2369. case -3:
  2370. #ifdef DEBUG_ENCODING
  2371. xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of output %d left\n",
  2372. c_in, c_out, (int) xmlBufUse(in));
  2373. #endif
  2374. break;
  2375. case -4:
  2376. xmlEncodingErr(XML_I18N_NO_OUTPUT,
  2377. "xmlCharEncOutFunc: no output function !\n", NULL);
  2378. ret = -1;
  2379. break;
  2380. case -2: {
  2381. xmlChar charref[20];
  2382. int len = (int) xmlBufUse(in);
  2383. xmlChar *content = xmlBufContent(in);
  2384. int cur, charrefLen;
  2385. cur = xmlGetUTF8Char(content, &len);
  2386. if (cur <= 0)
  2387. break;
  2388. #ifdef DEBUG_ENCODING
  2389. xmlGenericError(xmlGenericErrorContext,
  2390. "handling output conversion error\n");
  2391. xmlGenericError(xmlGenericErrorContext,
  2392. "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
  2393. content[0], content[1],
  2394. content[2], content[3]);
  2395. #endif
  2396. /*
  2397. * Removes the UTF8 sequence, and replace it by a charref
  2398. * and continue the transcoding phase, hoping the error
  2399. * did not mangle the encoder state.
  2400. */
  2401. charrefLen = snprintf((char *) &charref[0], sizeof(charref),
  2402. "&#%d;", cur);
  2403. xmlBufShrink(in, len);
  2404. xmlBufGrow(out, charrefLen * 4);
  2405. c_out = xmlBufAvail(out) - 1;
  2406. c_in = charrefLen;
  2407. ret = xmlEncOutputChunk(output->encoder, xmlBufEnd(out), &c_out,
  2408. charref, &c_in);
  2409. if ((ret < 0) || (c_in != charrefLen)) {
  2410. char buf[50];
  2411. snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
  2412. content[0], content[1],
  2413. content[2], content[3]);
  2414. buf[49] = 0;
  2415. xmlEncodingErr(XML_I18N_CONV_FAILED,
  2416. "output conversion failed due to conv error, bytes %s\n",
  2417. buf);
  2418. if (xmlBufGetAllocationScheme(in) != XML_BUFFER_ALLOC_IMMUTABLE)
  2419. content[0] = ' ';
  2420. break;
  2421. }
  2422. xmlBufAddLen(out, c_out);
  2423. writtentot += c_out;
  2424. goto retry;
  2425. }
  2426. }
  2427. return(writtentot ? writtentot : ret);
  2428. }
  2429. #endif
  2430. /**
  2431. * xmlCharEncOutFunc:
  2432. * @handler: char encoding transformation data structure
  2433. * @out: an xmlBuffer for the output.
  2434. * @in: an xmlBuffer for the input
  2435. *
  2436. * Generic front-end for the encoding handler output function
  2437. * a first call with @in == NULL has to be made firs to initiate the
  2438. * output in case of non-stateless encoding needing to initiate their
  2439. * state or the output (like the BOM in UTF16).
  2440. * In case of UTF8 sequence conversion errors for the given encoder,
  2441. * the content will be automatically remapped to a CharRef sequence.
  2442. *
  2443. * Returns the number of byte written if success, or
  2444. * -1 general error
  2445. * -2 if the transcoding fails (for *in is not valid utf8 string or
  2446. * the result of transformation can't fit into the encoding we want), or
  2447. */
  2448. int
  2449. xmlCharEncOutFunc(xmlCharEncodingHandler *handler, xmlBufferPtr out,
  2450. xmlBufferPtr in) {
  2451. int ret;
  2452. int written;
  2453. int writtentot = 0;
  2454. int toconv;
  2455. if (handler == NULL) return(-1);
  2456. if (out == NULL) return(-1);
  2457. retry:
  2458. written = out->size - out->use;
  2459. if (written > 0)
  2460. written--; /* Gennady: count '/0' */
  2461. /*
  2462. * First specific handling of in = NULL, i.e. the initialization call
  2463. */
  2464. if (in == NULL) {
  2465. toconv = 0;
  2466. /* TODO: Check return value. */
  2467. xmlEncOutputChunk(handler, &out->content[out->use], &written,
  2468. NULL, &toconv);
  2469. out->use += written;
  2470. out->content[out->use] = 0;
  2471. #ifdef DEBUG_ENCODING
  2472. xmlGenericError(xmlGenericErrorContext,
  2473. "initialized encoder\n");
  2474. #endif
  2475. return(0);
  2476. }
  2477. /*
  2478. * Conversion itself.
  2479. */
  2480. toconv = in->use;
  2481. if (toconv == 0)
  2482. return(0);
  2483. if (toconv * 4 >= written) {
  2484. xmlBufferGrow(out, toconv * 4);
  2485. written = out->size - out->use - 1;
  2486. }
  2487. ret = xmlEncOutputChunk(handler, &out->content[out->use], &written,
  2488. in->content, &toconv);
  2489. xmlBufferShrink(in, toconv);
  2490. out->use += written;
  2491. writtentot += written;
  2492. out->content[out->use] = 0;
  2493. if (ret == -1) {
  2494. if (written > 0) {
  2495. /* Can be a limitation of iconv or uconv */
  2496. goto retry;
  2497. }
  2498. ret = -3;
  2499. }
  2500. /*
  2501. * Attempt to handle error cases
  2502. */
  2503. switch (ret) {
  2504. case 0:
  2505. #ifdef DEBUG_ENCODING
  2506. xmlGenericError(xmlGenericErrorContext,
  2507. "converted %d bytes to %d bytes of output\n",
  2508. toconv, written);
  2509. #endif
  2510. break;
  2511. case -1:
  2512. #ifdef DEBUG_ENCODING
  2513. xmlGenericError(xmlGenericErrorContext,
  2514. "output conversion failed by lack of space\n");
  2515. #endif
  2516. break;
  2517. case -3:
  2518. #ifdef DEBUG_ENCODING
  2519. xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of output %d left\n",
  2520. toconv, written, in->use);
  2521. #endif
  2522. break;
  2523. case -4:
  2524. xmlEncodingErr(XML_I18N_NO_OUTPUT,
  2525. "xmlCharEncOutFunc: no output function !\n", NULL);
  2526. ret = -1;
  2527. break;
  2528. case -2: {
  2529. xmlChar charref[20];
  2530. int len = in->use;
  2531. const xmlChar *utf = (const xmlChar *) in->content;
  2532. int cur, charrefLen;
  2533. cur = xmlGetUTF8Char(utf, &len);
  2534. if (cur <= 0)
  2535. break;
  2536. #ifdef DEBUG_ENCODING
  2537. xmlGenericError(xmlGenericErrorContext,
  2538. "handling output conversion error\n");
  2539. xmlGenericError(xmlGenericErrorContext,
  2540. "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
  2541. in->content[0], in->content[1],
  2542. in->content[2], in->content[3]);
  2543. #endif
  2544. /*
  2545. * Removes the UTF8 sequence, and replace it by a charref
  2546. * and continue the transcoding phase, hoping the error
  2547. * did not mangle the encoder state.
  2548. */
  2549. charrefLen = snprintf((char *) &charref[0], sizeof(charref),
  2550. "&#%d;", cur);
  2551. xmlBufferShrink(in, len);
  2552. xmlBufferGrow(out, charrefLen * 4);
  2553. written = out->size - out->use - 1;
  2554. toconv = charrefLen;
  2555. ret = xmlEncOutputChunk(handler, &out->content[out->use], &written,
  2556. charref, &toconv);
  2557. if ((ret < 0) || (toconv != charrefLen)) {
  2558. char buf[50];
  2559. snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
  2560. in->content[0], in->content[1],
  2561. in->content[2], in->content[3]);
  2562. buf[49] = 0;
  2563. xmlEncodingErr(XML_I18N_CONV_FAILED,
  2564. "output conversion failed due to conv error, bytes %s\n",
  2565. buf);
  2566. if (in->alloc != XML_BUFFER_ALLOC_IMMUTABLE)
  2567. in->content[0] = ' ';
  2568. break;
  2569. }
  2570. out->use += written;
  2571. writtentot += written;
  2572. out->content[out->use] = 0;
  2573. goto retry;
  2574. }
  2575. }
  2576. return(writtentot ? writtentot : ret);
  2577. }
  2578. /**
  2579. * xmlCharEncCloseFunc:
  2580. * @handler: char encoding transformation data structure
  2581. *
  2582. * Generic front-end for encoding handler close function
  2583. *
  2584. * Returns 0 if success, or -1 in case of error
  2585. */
  2586. int
  2587. xmlCharEncCloseFunc(xmlCharEncodingHandler *handler) {
  2588. int ret = 0;
  2589. int tofree = 0;
  2590. int i, handler_in_list = 0;
  2591. if (handler == NULL) return(-1);
  2592. if (handler->name == NULL) return(-1);
  2593. if (handlers != NULL) {
  2594. for (i = 0;i < nbCharEncodingHandler; i++) {
  2595. if (handler == handlers[i]) {
  2596. handler_in_list = 1;
  2597. break;
  2598. }
  2599. }
  2600. }
  2601. #ifdef LIBXML_ICONV_ENABLED
  2602. /*
  2603. * Iconv handlers can be used only once, free the whole block.
  2604. * and the associated icon resources.
  2605. */
  2606. if ((handler_in_list == 0) &&
  2607. ((handler->iconv_out != NULL) || (handler->iconv_in != NULL))) {
  2608. tofree = 1;
  2609. if (handler->iconv_out != NULL) {
  2610. if (iconv_close(handler->iconv_out))
  2611. ret = -1;
  2612. handler->iconv_out = NULL;
  2613. }
  2614. if (handler->iconv_in != NULL) {
  2615. if (iconv_close(handler->iconv_in))
  2616. ret = -1;
  2617. handler->iconv_in = NULL;
  2618. }
  2619. }
  2620. #endif /* LIBXML_ICONV_ENABLED */
  2621. #ifdef LIBXML_ICU_ENABLED
  2622. if ((handler_in_list == 0) &&
  2623. ((handler->uconv_out != NULL) || (handler->uconv_in != NULL))) {
  2624. tofree = 1;
  2625. if (handler->uconv_out != NULL) {
  2626. closeIcuConverter(handler->uconv_out);
  2627. handler->uconv_out = NULL;
  2628. }
  2629. if (handler->uconv_in != NULL) {
  2630. closeIcuConverter(handler->uconv_in);
  2631. handler->uconv_in = NULL;
  2632. }
  2633. }
  2634. #endif
  2635. if (tofree) {
  2636. /* free up only dynamic handlers iconv/uconv */
  2637. if (handler->name != NULL)
  2638. xmlFree(handler->name);
  2639. handler->name = NULL;
  2640. xmlFree(handler);
  2641. }
  2642. #ifdef DEBUG_ENCODING
  2643. if (ret)
  2644. xmlGenericError(xmlGenericErrorContext,
  2645. "failed to close the encoding handler\n");
  2646. else
  2647. xmlGenericError(xmlGenericErrorContext,
  2648. "closed the encoding handler\n");
  2649. #endif
  2650. return(ret);
  2651. }
  2652. /**
  2653. * xmlByteConsumed:
  2654. * @ctxt: an XML parser context
  2655. *
  2656. * This function provides the current index of the parser relative
  2657. * to the start of the current entity. This function is computed in
  2658. * bytes from the beginning starting at zero and finishing at the
  2659. * size in byte of the file if parsing a file. The function is
  2660. * of constant cost if the input is UTF-8 but can be costly if run
  2661. * on non-UTF-8 input.
  2662. *
  2663. * Returns the index in bytes from the beginning of the entity or -1
  2664. * in case the index could not be computed.
  2665. */
  2666. long
  2667. xmlByteConsumed(xmlParserCtxtPtr ctxt) {
  2668. xmlParserInputPtr in;
  2669. if (ctxt == NULL) return(-1);
  2670. in = ctxt->input;
  2671. if (in == NULL) return(-1);
  2672. if ((in->buf != NULL) && (in->buf->encoder != NULL)) {
  2673. unsigned int unused = 0;
  2674. xmlCharEncodingHandler * handler = in->buf->encoder;
  2675. /*
  2676. * Encoding conversion, compute the number of unused original
  2677. * bytes from the input not consumed and subtract that from
  2678. * the raw consumed value, this is not a cheap operation
  2679. */
  2680. if (in->end - in->cur > 0) {
  2681. unsigned char convbuf[32000];
  2682. const unsigned char *cur = (const unsigned char *)in->cur;
  2683. int toconv = in->end - in->cur, written = 32000;
  2684. int ret;
  2685. do {
  2686. toconv = in->end - cur;
  2687. written = 32000;
  2688. ret = xmlEncOutputChunk(handler, &convbuf[0], &written,
  2689. cur, &toconv);
  2690. if (ret < 0) {
  2691. if (written > 0)
  2692. ret = -2;
  2693. else
  2694. return(-1);
  2695. }
  2696. unused += written;
  2697. cur += toconv;
  2698. } while (ret == -2);
  2699. }
  2700. if (in->buf->rawconsumed < unused)
  2701. return(-1);
  2702. return(in->buf->rawconsumed - unused);
  2703. }
  2704. return(in->consumed + (in->cur - in->base));
  2705. }
  2706. #if !defined(LIBXML_ICONV_ENABLED) && !defined(LIBXML_ICU_ENABLED)
  2707. #ifdef LIBXML_ISO8859X_ENABLED
  2708. /**
  2709. * UTF8ToISO8859x:
  2710. * @out: a pointer to an array of bytes to store the result
  2711. * @outlen: the length of @out
  2712. * @in: a pointer to an array of UTF-8 chars
  2713. * @inlen: the length of @in
  2714. * @xlattable: the 2-level transcoding table
  2715. *
  2716. * Take a block of UTF-8 chars in and try to convert it to an ISO 8859-*
  2717. * block of chars out.
  2718. *
  2719. * Returns 0 if success, -2 if the transcoding fails, or -1 otherwise
  2720. * The value of @inlen after return is the number of octets consumed
  2721. * as the return value is positive, else unpredictable.
  2722. * The value of @outlen after return is the number of octets consumed.
  2723. */
  2724. static int
  2725. UTF8ToISO8859x(unsigned char* out, int *outlen,
  2726. const unsigned char* in, int *inlen,
  2727. unsigned char const *xlattable) {
  2728. const unsigned char* outstart = out;
  2729. const unsigned char* inend;
  2730. const unsigned char* instart = in;
  2731. const unsigned char* processed = in;
  2732. if ((out == NULL) || (outlen == NULL) || (inlen == NULL) ||
  2733. (xlattable == NULL))
  2734. return(-1);
  2735. if (in == NULL) {
  2736. /*
  2737. * initialization nothing to do
  2738. */
  2739. *outlen = 0;
  2740. *inlen = 0;
  2741. return(0);
  2742. }
  2743. inend = in + (*inlen);
  2744. while (in < inend) {
  2745. unsigned char d = *in++;
  2746. if (d < 0x80) {
  2747. *out++ = d;
  2748. } else if (d < 0xC0) {
  2749. /* trailing byte in leading position */
  2750. *outlen = out - outstart;
  2751. *inlen = processed - instart;
  2752. return(-2);
  2753. } else if (d < 0xE0) {
  2754. unsigned char c;
  2755. if (!(in < inend)) {
  2756. /* trailing byte not in input buffer */
  2757. *outlen = out - outstart;
  2758. *inlen = processed - instart;
  2759. return(-3);
  2760. }
  2761. c = *in++;
  2762. if ((c & 0xC0) != 0x80) {
  2763. /* not a trailing byte */
  2764. *outlen = out - outstart;
  2765. *inlen = processed - instart;
  2766. return(-2);
  2767. }
  2768. c = c & 0x3F;
  2769. d = d & 0x1F;
  2770. d = xlattable [48 + c + xlattable [d] * 64];
  2771. if (d == 0) {
  2772. /* not in character set */
  2773. *outlen = out - outstart;
  2774. *inlen = processed - instart;
  2775. return(-2);
  2776. }
  2777. *out++ = d;
  2778. } else if (d < 0xF0) {
  2779. unsigned char c1;
  2780. unsigned char c2;
  2781. if (!(in < inend - 1)) {
  2782. /* trailing bytes not in input buffer */
  2783. *outlen = out - outstart;
  2784. *inlen = processed - instart;
  2785. return(-3);
  2786. }
  2787. c1 = *in++;
  2788. if ((c1 & 0xC0) != 0x80) {
  2789. /* not a trailing byte (c1) */
  2790. *outlen = out - outstart;
  2791. *inlen = processed - instart;
  2792. return(-2);
  2793. }
  2794. c2 = *in++;
  2795. if ((c2 & 0xC0) != 0x80) {
  2796. /* not a trailing byte (c2) */
  2797. *outlen = out - outstart;
  2798. *inlen = processed - instart;
  2799. return(-2);
  2800. }
  2801. c1 = c1 & 0x3F;
  2802. c2 = c2 & 0x3F;
  2803. d = d & 0x0F;
  2804. d = xlattable [48 + c2 + xlattable [48 + c1 +
  2805. xlattable [32 + d] * 64] * 64];
  2806. if (d == 0) {
  2807. /* not in character set */
  2808. *outlen = out - outstart;
  2809. *inlen = processed - instart;
  2810. return(-2);
  2811. }
  2812. *out++ = d;
  2813. } else {
  2814. /* cannot transcode >= U+010000 */
  2815. *outlen = out - outstart;
  2816. *inlen = processed - instart;
  2817. return(-2);
  2818. }
  2819. processed = in;
  2820. }
  2821. *outlen = out - outstart;
  2822. *inlen = processed - instart;
  2823. return(*outlen);
  2824. }
  2825. /**
  2826. * ISO8859xToUTF8
  2827. * @out: a pointer to an array of bytes to store the result
  2828. * @outlen: the length of @out
  2829. * @in: a pointer to an array of ISO Latin 1 chars
  2830. * @inlen: the length of @in
  2831. *
  2832. * Take a block of ISO 8859-* chars in and try to convert it to an UTF-8
  2833. * block of chars out.
  2834. * Returns 0 if success, or -1 otherwise
  2835. * The value of @inlen after return is the number of octets consumed
  2836. * The value of @outlen after return is the number of octets produced.
  2837. */
  2838. static int
  2839. ISO8859xToUTF8(unsigned char* out, int *outlen,
  2840. const unsigned char* in, int *inlen,
  2841. unsigned short const *unicodetable) {
  2842. unsigned char* outstart = out;
  2843. unsigned char* outend;
  2844. const unsigned char* instart = in;
  2845. const unsigned char* inend;
  2846. const unsigned char* instop;
  2847. unsigned int c;
  2848. if ((out == NULL) || (outlen == NULL) || (inlen == NULL) ||
  2849. (in == NULL) || (unicodetable == NULL))
  2850. return(-1);
  2851. outend = out + *outlen;
  2852. inend = in + *inlen;
  2853. instop = inend;
  2854. while ((in < inend) && (out < outend - 2)) {
  2855. if (*in >= 0x80) {
  2856. c = unicodetable [*in - 0x80];
  2857. if (c == 0) {
  2858. /* undefined code point */
  2859. *outlen = out - outstart;
  2860. *inlen = in - instart;
  2861. return (-1);
  2862. }
  2863. if (c < 0x800) {
  2864. *out++ = ((c >> 6) & 0x1F) | 0xC0;
  2865. *out++ = (c & 0x3F) | 0x80;
  2866. } else {
  2867. *out++ = ((c >> 12) & 0x0F) | 0xE0;
  2868. *out++ = ((c >> 6) & 0x3F) | 0x80;
  2869. *out++ = (c & 0x3F) | 0x80;
  2870. }
  2871. ++in;
  2872. }
  2873. if (instop - in > outend - out) instop = in + (outend - out);
  2874. while ((*in < 0x80) && (in < instop)) {
  2875. *out++ = *in++;
  2876. }
  2877. }
  2878. if ((in < inend) && (out < outend) && (*in < 0x80)) {
  2879. *out++ = *in++;
  2880. }
  2881. if ((in < inend) && (out < outend) && (*in < 0x80)) {
  2882. *out++ = *in++;
  2883. }
  2884. *outlen = out - outstart;
  2885. *inlen = in - instart;
  2886. return (*outlen);
  2887. }
  2888. /************************************************************************
  2889. * Lookup tables for ISO-8859-2..ISO-8859-16 transcoding *
  2890. ************************************************************************/
  2891. static unsigned short const xmlunicodetable_ISO8859_2 [128] = {
  2892. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  2893. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  2894. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  2895. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  2896. 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7,
  2897. 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b,
  2898. 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7,
  2899. 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c,
  2900. 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7,
  2901. 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e,
  2902. 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7,
  2903. 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df,
  2904. 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7,
  2905. 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f,
  2906. 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7,
  2907. 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9,
  2908. };
  2909. static unsigned char const xmltranscodetable_ISO8859_2 [48 + 6 * 64] = {
  2910. "\x00\x00\x01\x05\x02\x04\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00"
  2911. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2912. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2913. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2914. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2915. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2916. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2917. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  2918. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  2919. "\xa0\x00\x00\x00\xa4\x00\x00\xa7\xa8\x00\x00\x00\x00\xad\x00\x00"
  2920. "\xb0\x00\x00\x00\xb4\x00\x00\x00\xb8\x00\x00\x00\x00\x00\x00\x00"
  2921. "\x00\x00\xc3\xe3\xa1\xb1\xc6\xe6\x00\x00\x00\x00\xc8\xe8\xcf\xef"
  2922. "\xd0\xf0\x00\x00\x00\x00\x00\x00\xca\xea\xcc\xec\x00\x00\x00\x00"
  2923. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2924. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc5\xe5\x00\x00\xa5\xb5\x00"
  2925. "\x00\x00\x00\x00\x00\x00\x00\xb7\x00\x00\x00\x00\x00\x00\x00\x00"
  2926. "\x00\x00\x00\x00\x00\x00\x00\x00\xa2\xff\x00\xb2\x00\xbd\x00\x00"
  2927. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2928. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2929. "\x00\xa3\xb3\xd1\xf1\x00\x00\xd2\xf2\x00\x00\x00\x00\x00\x00\x00"
  2930. "\xd5\xf5\x00\x00\xc0\xe0\x00\x00\xd8\xf8\xa6\xb6\x00\x00\xaa\xba"
  2931. "\xa9\xb9\xde\xfe\xab\xbb\x00\x00\x00\x00\x00\x00\x00\x00\xd9\xf9"
  2932. "\xdb\xfb\x00\x00\x00\x00\x00\x00\x00\xac\xbc\xaf\xbf\xae\xbe\x00"
  2933. "\x00\xc1\xc2\x00\xc4\x00\x00\xc7\x00\xc9\x00\xcb\x00\xcd\xce\x00"
  2934. "\x00\x00\x00\xd3\xd4\x00\xd6\xd7\x00\x00\xda\x00\xdc\xdd\x00\xdf"
  2935. "\x00\xe1\xe2\x00\xe4\x00\x00\xe7\x00\xe9\x00\xeb\x00\xed\xee\x00"
  2936. "\x00\x00\x00\xf3\xf4\x00\xf6\xf7\x00\x00\xfa\x00\xfc\xfd\x00\x00"
  2937. };
  2938. static unsigned short const xmlunicodetable_ISO8859_3 [128] = {
  2939. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  2940. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  2941. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  2942. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  2943. 0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0x0000, 0x0124, 0x00a7,
  2944. 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0x0000, 0x017b,
  2945. 0x00b0, 0x0127, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x0125, 0x00b7,
  2946. 0x00b8, 0x0131, 0x015f, 0x011f, 0x0135, 0x00bd, 0x0000, 0x017c,
  2947. 0x00c0, 0x00c1, 0x00c2, 0x0000, 0x00c4, 0x010a, 0x0108, 0x00c7,
  2948. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
  2949. 0x0000, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x0120, 0x00d6, 0x00d7,
  2950. 0x011c, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x016c, 0x015c, 0x00df,
  2951. 0x00e0, 0x00e1, 0x00e2, 0x0000, 0x00e4, 0x010b, 0x0109, 0x00e7,
  2952. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
  2953. 0x0000, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7,
  2954. 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9,
  2955. };
  2956. static unsigned char const xmltranscodetable_ISO8859_3 [48 + 7 * 64] = {
  2957. "\x04\x00\x01\x06\x02\x05\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00"
  2958. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2959. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2960. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2961. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2962. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2963. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2964. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  2965. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  2966. "\xa0\x00\x00\xa3\xa4\x00\x00\xa7\xa8\x00\x00\x00\x00\xad\x00\x00"
  2967. "\xb0\x00\xb2\xb3\xb4\xb5\x00\xb7\xb8\x00\x00\x00\x00\xbd\x00\x00"
  2968. "\x00\x00\x00\x00\x00\x00\x00\x00\xc6\xe6\xc5\xe5\x00\x00\x00\x00"
  2969. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd8\xf8\xab\xbb"
  2970. "\xd5\xf5\x00\x00\xa6\xb6\xa1\xb1\x00\x00\x00\x00\x00\x00\x00\x00"
  2971. "\xa9\xb9\x00\x00\xac\xbc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2972. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2973. "\x00\x00\x00\x00\x00\x00\x00\x00\xa2\xff\x00\x00\x00\x00\x00\x00"
  2974. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2975. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2976. "\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2977. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2978. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2979. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2980. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  2981. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xfe\xaa\xba"
  2982. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xdd\xfd\x00\x00"
  2983. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaf\xbf\x00\x00\x00"
  2984. "\xc0\xc1\xc2\x00\xc4\x00\x00\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
  2985. "\x00\xd1\xd2\xd3\xd4\x00\xd6\xd7\x00\xd9\xda\xdb\xdc\x00\x00\xdf"
  2986. "\xe0\xe1\xe2\x00\xe4\x00\x00\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
  2987. "\x00\xf1\xf2\xf3\xf4\x00\xf6\xf7\x00\xf9\xfa\xfb\xfc\x00\x00\x00"
  2988. };
  2989. static unsigned short const xmlunicodetable_ISO8859_4 [128] = {
  2990. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  2991. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  2992. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  2993. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  2994. 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7,
  2995. 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af,
  2996. 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7,
  2997. 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b,
  2998. 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e,
  2999. 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a,
  3000. 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
  3001. 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df,
  3002. 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f,
  3003. 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b,
  3004. 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7,
  3005. 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9,
  3006. };
  3007. static unsigned char const xmltranscodetable_ISO8859_4 [48 + 6 * 64] = {
  3008. "\x00\x00\x01\x05\x02\x03\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00"
  3009. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3010. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3011. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3012. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3013. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3014. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3015. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3016. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3017. "\xa0\x00\x00\x00\xa4\x00\x00\xa7\xa8\x00\x00\x00\x00\xad\x00\xaf"
  3018. "\xb0\x00\x00\x00\xb4\x00\x00\x00\xb8\x00\x00\x00\x00\x00\x00\x00"
  3019. "\xc0\xe0\x00\x00\xa1\xb1\x00\x00\x00\x00\x00\x00\xc8\xe8\x00\x00"
  3020. "\xd0\xf0\xaa\xba\x00\x00\xcc\xec\xca\xea\x00\x00\x00\x00\x00\x00"
  3021. "\x00\x00\xab\xbb\x00\x00\x00\x00\xa5\xb5\xcf\xef\x00\x00\xc7\xe7"
  3022. "\x00\x00\x00\x00\x00\x00\xd3\xf3\xa2\x00\x00\xa6\xb6\x00\x00\x00"
  3023. "\x00\x00\x00\x00\x00\xd1\xf1\x00\x00\x00\xbd\xbf\xd2\xf2\x00\x00"
  3024. "\x00\x00\x00\x00\x00\x00\xa3\xb3\x00\x00\x00\x00\x00\x00\x00\x00"
  3025. "\xa9\xb9\x00\x00\x00\x00\xac\xbc\xdd\xfd\xde\xfe\x00\x00\x00\x00"
  3026. "\x00\x00\xd9\xf9\x00\x00\x00\x00\x00\x00\x00\x00\x00\xae\xbe\x00"
  3027. "\x00\x00\x00\x00\x00\x00\x00\xb7\x00\x00\x00\x00\x00\x00\x00\x00"
  3028. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\xb2\x00\x00\x00\x00"
  3029. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3030. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3031. "\x00\xc1\xc2\xc3\xc4\xc5\xc6\x00\x00\xc9\x00\xcb\x00\xcd\xce\x00"
  3032. "\x00\x00\x00\x00\xd4\xd5\xd6\xd7\xd8\x00\xda\xdb\xdc\x00\x00\xdf"
  3033. "\x00\xe1\xe2\xe3\xe4\xe5\xe6\x00\x00\xe9\x00\xeb\x00\xed\xee\x00"
  3034. "\x00\x00\x00\x00\xf4\xf5\xf6\xf7\xf8\x00\xfa\xfb\xfc\x00\x00\x00"
  3035. };
  3036. static unsigned short const xmlunicodetable_ISO8859_5 [128] = {
  3037. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3038. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3039. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3040. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3041. 0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407,
  3042. 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f,
  3043. 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
  3044. 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f,
  3045. 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
  3046. 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f,
  3047. 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
  3048. 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f,
  3049. 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
  3050. 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f,
  3051. 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457,
  3052. 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f,
  3053. };
  3054. static unsigned char const xmltranscodetable_ISO8859_5 [48 + 6 * 64] = {
  3055. "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3056. "\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3057. "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3058. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3059. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3060. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3061. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3062. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3063. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3064. "\xa0\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\xad\x00\x00"
  3065. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3066. "\x00\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\x00\xae\xaf"
  3067. "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
  3068. "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
  3069. "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
  3070. "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
  3071. "\x00\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\x00\xfe\xff"
  3072. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3073. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3074. "\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3075. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3076. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3077. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3078. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3079. "\x00\x00\x00\x00\x00\x00\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3080. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3081. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3082. };
  3083. static unsigned short const xmlunicodetable_ISO8859_6 [128] = {
  3084. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3085. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3086. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3087. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3088. 0x00a0, 0x0000, 0x0000, 0x0000, 0x00a4, 0x0000, 0x0000, 0x0000,
  3089. 0x0000, 0x0000, 0x0000, 0x0000, 0x060c, 0x00ad, 0x0000, 0x0000,
  3090. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  3091. 0x0000, 0x0000, 0x0000, 0x061b, 0x0000, 0x0000, 0x0000, 0x061f,
  3092. 0x0000, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
  3093. 0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f,
  3094. 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637,
  3095. 0x0638, 0x0639, 0x063a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  3096. 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647,
  3097. 0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, 0x064e, 0x064f,
  3098. 0x0650, 0x0651, 0x0652, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  3099. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  3100. };
  3101. static unsigned char const xmltranscodetable_ISO8859_6 [48 + 5 * 64] = {
  3102. "\x02\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3103. "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x04\x00\x00\x00\x00\x00\x00"
  3104. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3105. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3106. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3107. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3108. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3109. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3110. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3111. "\xa0\x00\x00\x00\xa4\x00\x00\x00\x00\x00\x00\x00\x00\xad\x00\x00"
  3112. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3113. "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3114. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3115. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3116. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3117. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xac\x00\x00\x00"
  3118. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbb\x00\x00\x00\xbf"
  3119. "\x00\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
  3120. "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\x00\x00\x00\x00\x00"
  3121. "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
  3122. "\xf0\xf1\xf2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3123. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3124. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3125. };
  3126. static unsigned short const xmlunicodetable_ISO8859_7 [128] = {
  3127. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3128. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3129. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3130. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3131. 0x00a0, 0x2018, 0x2019, 0x00a3, 0x0000, 0x0000, 0x00a6, 0x00a7,
  3132. 0x00a8, 0x00a9, 0x0000, 0x00ab, 0x00ac, 0x00ad, 0x0000, 0x2015,
  3133. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x0384, 0x0385, 0x0386, 0x00b7,
  3134. 0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f,
  3135. 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
  3136. 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f,
  3137. 0x03a0, 0x03a1, 0x0000, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7,
  3138. 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af,
  3139. 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7,
  3140. 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
  3141. 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7,
  3142. 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0000,
  3143. };
  3144. static unsigned char const xmltranscodetable_ISO8859_7 [48 + 7 * 64] = {
  3145. "\x04\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x06"
  3146. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3147. "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3148. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3149. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3150. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3151. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3152. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3153. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3154. "\xa0\x00\x00\xa3\x00\x00\xa6\xa7\xa8\xa9\x00\xab\xac\xad\x00\x00"
  3155. "\xb0\xb1\xb2\xb3\x00\x00\x00\xb7\x00\x00\x00\xbb\x00\xbd\x00\x00"
  3156. "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3157. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3158. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3159. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3160. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3161. "\x00\x00\x00\x00\x00\xaf\x00\x00\xa1\xa2\x00\x00\x00\x00\x00\x00"
  3162. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3163. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3164. "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3165. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3166. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3167. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3168. "\x00\x00\x00\x00\xb4\xb5\xb6\x00\xb8\xb9\xba\x00\xbc\x00\xbe\xbf"
  3169. "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
  3170. "\xd0\xd1\x00\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
  3171. "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
  3172. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\x00"
  3173. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3174. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3175. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3176. };
  3177. static unsigned short const xmlunicodetable_ISO8859_8 [128] = {
  3178. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3179. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3180. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3181. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3182. 0x00a0, 0x0000, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7,
  3183. 0x00a8, 0x00a9, 0x00d7, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
  3184. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7,
  3185. 0x00b8, 0x00b9, 0x00f7, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x0000,
  3186. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  3187. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  3188. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  3189. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2017,
  3190. 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7,
  3191. 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df,
  3192. 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7,
  3193. 0x05e8, 0x05e9, 0x05ea, 0x0000, 0x0000, 0x200e, 0x200f, 0x0000,
  3194. };
  3195. static unsigned char const xmltranscodetable_ISO8859_8 [48 + 7 * 64] = {
  3196. "\x02\x00\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3197. "\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00"
  3198. "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3199. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3200. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3201. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3202. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3203. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3204. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3205. "\xa0\x00\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\x00\xab\xac\xad\xae\xaf"
  3206. "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\x00\xbb\xbc\xbd\xbe\x00"
  3207. "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3208. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3209. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3210. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3211. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3212. "\x00\x00\x00\x00\x00\x00\x00\xaa\x00\x00\x00\x00\x00\x00\x00\x00"
  3213. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3214. "\x00\x00\x00\x00\x00\x00\x00\xba\x00\x00\x00\x00\x00\x00\x00\x00"
  3215. "\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3216. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3217. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3218. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3219. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\xfe"
  3220. "\x00\x00\x00\x00\x00\x00\x00\xdf\x00\x00\x00\x00\x00\x00\x00\x00"
  3221. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3222. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3223. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3224. "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
  3225. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\x00\x00\x00\x00\x00"
  3226. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3227. };
  3228. static unsigned short const xmlunicodetable_ISO8859_9 [128] = {
  3229. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3230. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3231. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3232. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3233. 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7,
  3234. 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
  3235. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7,
  3236. 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
  3237. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7,
  3238. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
  3239. 0x011e, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
  3240. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0130, 0x015e, 0x00df,
  3241. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7,
  3242. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
  3243. 0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7,
  3244. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff,
  3245. };
  3246. static unsigned char const xmltranscodetable_ISO8859_9 [48 + 5 * 64] = {
  3247. "\x00\x00\x01\x02\x03\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3248. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3249. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3250. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3251. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3252. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3253. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3254. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3255. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3256. "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
  3257. "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
  3258. "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
  3259. "\x00\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\x00\x00\xdf"
  3260. "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
  3261. "\x00\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\x00\x00\xff"
  3262. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3263. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd0\xf0"
  3264. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3265. "\xdd\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3266. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3267. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xfe"
  3268. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3269. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3270. };
  3271. static unsigned short const xmlunicodetable_ISO8859_10 [128] = {
  3272. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3273. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3274. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3275. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3276. 0x00a0, 0x0104, 0x0112, 0x0122, 0x012a, 0x0128, 0x0136, 0x00a7,
  3277. 0x013b, 0x0110, 0x0160, 0x0166, 0x017d, 0x00ad, 0x016a, 0x014a,
  3278. 0x00b0, 0x0105, 0x0113, 0x0123, 0x012b, 0x0129, 0x0137, 0x00b7,
  3279. 0x013c, 0x0111, 0x0161, 0x0167, 0x017e, 0x2015, 0x016b, 0x014b,
  3280. 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e,
  3281. 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x00cf,
  3282. 0x00d0, 0x0145, 0x014c, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x0168,
  3283. 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
  3284. 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f,
  3285. 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x00ef,
  3286. 0x00f0, 0x0146, 0x014d, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x0169,
  3287. 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x0138,
  3288. };
  3289. static unsigned char const xmltranscodetable_ISO8859_10 [48 + 7 * 64] = {
  3290. "\x00\x00\x01\x06\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3291. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3292. "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3293. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3294. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3295. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3296. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3297. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3298. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3299. "\xa0\x00\x00\x00\x00\x00\x00\xa7\x00\x00\x00\x00\x00\xad\x00\x00"
  3300. "\xb0\x00\x00\x00\x00\x00\x00\xb7\x00\x00\x00\x00\x00\x00\x00\x00"
  3301. "\xc0\xe0\x00\x00\xa1\xb1\x00\x00\x00\x00\x00\x00\xc8\xe8\x00\x00"
  3302. "\xa9\xb9\xa2\xb2\x00\x00\xcc\xec\xca\xea\x00\x00\x00\x00\x00\x00"
  3303. "\x00\x00\xa3\xb3\x00\x00\x00\x00\xa5\xb5\xa4\xb4\x00\x00\xc7\xe7"
  3304. "\x00\x00\x00\x00\x00\x00\xa6\xb6\xff\x00\x00\xa8\xb8\x00\x00\x00"
  3305. "\x00\x00\x00\x00\x00\xd1\xf1\x00\x00\x00\xaf\xbf\xd2\xf2\x00\x00"
  3306. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3307. "\xaa\xba\x00\x00\x00\x00\xab\xbb\xd7\xf7\xae\xbe\x00\x00\x00\x00"
  3308. "\x00\x00\xd9\xf9\x00\x00\x00\x00\x00\x00\x00\x00\x00\xac\xbc\x00"
  3309. "\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3310. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3311. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3312. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3313. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3314. "\x00\x00\x00\x00\x00\xbd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3315. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3316. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3317. "\x00\xc1\xc2\xc3\xc4\xc5\xc6\x00\x00\xc9\x00\xcb\x00\xcd\xce\xcf"
  3318. "\xd0\x00\x00\xd3\xd4\xd5\xd6\x00\xd8\x00\xda\xdb\xdc\xdd\xde\xdf"
  3319. "\x00\xe1\xe2\xe3\xe4\xe5\xe6\x00\x00\xe9\x00\xeb\x00\xed\xee\xef"
  3320. "\xf0\x00\x00\xf3\xf4\xf5\xf6\x00\xf8\x00\xfa\xfb\xfc\xfd\xfe\x00"
  3321. };
  3322. static unsigned short const xmlunicodetable_ISO8859_11 [128] = {
  3323. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3324. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3325. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3326. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3327. 0x00a0, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07,
  3328. 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f,
  3329. 0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17,
  3330. 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f,
  3331. 0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27,
  3332. 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f,
  3333. 0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37,
  3334. 0x0e38, 0x0e39, 0x0e3a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0e3f,
  3335. 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47,
  3336. 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e4e, 0x0e4f,
  3337. 0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57,
  3338. 0x0e58, 0x0e59, 0x0e5a, 0x0e5b, 0x0000, 0x0000, 0x0000, 0x0000,
  3339. };
  3340. static unsigned char const xmltranscodetable_ISO8859_11 [48 + 6 * 64] = {
  3341. "\x04\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3342. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3343. "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3344. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3345. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3346. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3347. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3348. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3349. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3350. "\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3351. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3352. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3353. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3354. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3355. "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x05\x00\x00\x00\x00\x00\x00"
  3356. "\x00\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
  3357. "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
  3358. "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
  3359. "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\x00\x00\x00\x00\xdf"
  3360. "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3361. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3362. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3363. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3364. "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
  3365. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\x00\x00\x00\x00"
  3366. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3367. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3368. };
  3369. static unsigned short const xmlunicodetable_ISO8859_13 [128] = {
  3370. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3371. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3372. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3373. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3374. 0x00a0, 0x201d, 0x00a2, 0x00a3, 0x00a4, 0x201e, 0x00a6, 0x00a7,
  3375. 0x00d8, 0x00a9, 0x0156, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00c6,
  3376. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x201c, 0x00b5, 0x00b6, 0x00b7,
  3377. 0x00f8, 0x00b9, 0x0157, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00e6,
  3378. 0x0104, 0x012e, 0x0100, 0x0106, 0x00c4, 0x00c5, 0x0118, 0x0112,
  3379. 0x010c, 0x00c9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012a, 0x013b,
  3380. 0x0160, 0x0143, 0x0145, 0x00d3, 0x014c, 0x00d5, 0x00d6, 0x00d7,
  3381. 0x0172, 0x0141, 0x015a, 0x016a, 0x00dc, 0x017b, 0x017d, 0x00df,
  3382. 0x0105, 0x012f, 0x0101, 0x0107, 0x00e4, 0x00e5, 0x0119, 0x0113,
  3383. 0x010d, 0x00e9, 0x017a, 0x0117, 0x0123, 0x0137, 0x012b, 0x013c,
  3384. 0x0161, 0x0144, 0x0146, 0x00f3, 0x014d, 0x00f5, 0x00f6, 0x00f7,
  3385. 0x0173, 0x0142, 0x015b, 0x016b, 0x00fc, 0x017c, 0x017e, 0x2019,
  3386. };
  3387. static unsigned char const xmltranscodetable_ISO8859_13 [48 + 7 * 64] = {
  3388. "\x00\x00\x01\x04\x06\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3389. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3390. "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3391. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3392. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3393. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3394. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3395. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3396. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3397. "\xa0\x00\xa2\xa3\xa4\x00\xa6\xa7\x00\xa9\x00\xab\xac\xad\xae\x00"
  3398. "\xb0\xb1\xb2\xb3\x00\xb5\xb6\xb7\x00\xb9\x00\xbb\xbc\xbd\xbe\x00"
  3399. "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3400. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3401. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3402. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3403. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3404. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\xb4\xa1\xa5\x00"
  3405. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3406. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3407. "\x00\x00\x00\x00\xc4\xc5\xaf\x00\x00\xc9\x00\x00\x00\x00\x00\x00"
  3408. "\x00\x00\x00\xd3\x00\xd5\xd6\xd7\xa8\x00\x00\x00\xdc\x00\x00\xdf"
  3409. "\x00\x00\x00\x00\xe4\xe5\xbf\x00\x00\xe9\x00\x00\x00\x00\x00\x00"
  3410. "\x00\x00\x00\xf3\x00\xf5\xf6\xf7\xb8\x00\x00\x00\xfc\x00\x00\x00"
  3411. "\x00\xd9\xf9\xd1\xf1\xd2\xf2\x00\x00\x00\x00\x00\xd4\xf4\x00\x00"
  3412. "\x00\x00\x00\x00\x00\x00\xaa\xba\x00\x00\xda\xfa\x00\x00\x00\x00"
  3413. "\xd0\xf0\x00\x00\x00\x00\x00\x00\x00\x00\xdb\xfb\x00\x00\x00\x00"
  3414. "\x00\x00\xd8\xf8\x00\x00\x00\x00\x00\xca\xea\xdd\xfd\xde\xfe\x00"
  3415. "\xc2\xe2\x00\x00\xc0\xe0\xc3\xe3\x00\x00\x00\x00\xc8\xe8\x00\x00"
  3416. "\x00\x00\xc7\xe7\x00\x00\xcb\xeb\xc6\xe6\x00\x00\x00\x00\x00\x00"
  3417. "\x00\x00\xcc\xec\x00\x00\x00\x00\x00\x00\xce\xee\x00\x00\xc1\xe1"
  3418. "\x00\x00\x00\x00\x00\x00\xcd\xed\x00\x00\x00\xcf\xef\x00\x00\x00"
  3419. };
  3420. static unsigned short const xmlunicodetable_ISO8859_14 [128] = {
  3421. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3422. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3423. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3424. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3425. 0x00a0, 0x1e02, 0x1e03, 0x00a3, 0x010a, 0x010b, 0x1e0a, 0x00a7,
  3426. 0x1e80, 0x00a9, 0x1e82, 0x1e0b, 0x1ef2, 0x00ad, 0x00ae, 0x0178,
  3427. 0x1e1e, 0x1e1f, 0x0120, 0x0121, 0x1e40, 0x1e41, 0x00b6, 0x1e56,
  3428. 0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61,
  3429. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7,
  3430. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
  3431. 0x0174, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x1e6a,
  3432. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x0176, 0x00df,
  3433. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7,
  3434. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
  3435. 0x0175, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x1e6b,
  3436. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, 0x00ff,
  3437. };
  3438. static unsigned char const xmltranscodetable_ISO8859_14 [48 + 10 * 64] = {
  3439. "\x00\x00\x01\x09\x04\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3440. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3441. "\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3442. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3443. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3444. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3445. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3446. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3447. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3448. "\xa0\x00\x00\xa3\x00\x00\x00\xa7\x00\xa9\x00\x00\x00\xad\xae\x00"
  3449. "\x00\x00\x00\x00\x00\x00\xb6\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3450. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3451. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3452. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3453. "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x08\x05\x06\x00\x00\x00\x00"
  3454. "\x00\x00\xa1\xa2\x00\x00\x00\x00\x00\x00\xa6\xab\x00\x00\x00\x00"
  3455. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb1"
  3456. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3457. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3458. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\xa5\x00\x00\x00\x00"
  3459. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3460. "\xb2\xb3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3461. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3462. "\xa8\xb8\xaa\xba\xbd\xbe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3463. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3464. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3465. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3466. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3467. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3468. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3469. "\x00\x00\xac\xbc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3470. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3471. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3472. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3473. "\x00\x00\x00\x00\xd0\xf0\xde\xfe\xaf\x00\x00\x00\x00\x00\x00\x00"
  3474. "\xb4\xb5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3475. "\x00\x00\x00\x00\x00\x00\xb7\xb9\x00\x00\x00\x00\x00\x00\x00\x00"
  3476. "\xbb\xbf\x00\x00\x00\x00\x00\x00\x00\x00\xd7\xf7\x00\x00\x00\x00"
  3477. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3478. "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
  3479. "\x00\xd1\xd2\xd3\xd4\xd5\xd6\x00\xd8\xd9\xda\xdb\xdc\xdd\x00\xdf"
  3480. "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
  3481. "\x00\xf1\xf2\xf3\xf4\xf5\xf6\x00\xf8\xf9\xfa\xfb\xfc\xfd\x00\xff"
  3482. };
  3483. static unsigned short const xmlunicodetable_ISO8859_15 [128] = {
  3484. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3485. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3486. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3487. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3488. 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x20ac, 0x00a5, 0x0160, 0x00a7,
  3489. 0x0161, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
  3490. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x017d, 0x00b5, 0x00b6, 0x00b7,
  3491. 0x017e, 0x00b9, 0x00ba, 0x00bb, 0x0152, 0x0153, 0x0178, 0x00bf,
  3492. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7,
  3493. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
  3494. 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
  3495. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
  3496. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7,
  3497. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
  3498. 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7,
  3499. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff,
  3500. };
  3501. static unsigned char const xmltranscodetable_ISO8859_15 [48 + 6 * 64] = {
  3502. "\x00\x00\x01\x05\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3503. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3504. "\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3505. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3506. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3507. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3508. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3509. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3510. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3511. "\xa0\xa1\xa2\xa3\x00\xa5\x00\xa7\x00\xa9\xaa\xab\xac\xad\xae\xaf"
  3512. "\xb0\xb1\xb2\xb3\x00\xb5\xb6\xb7\x00\xb9\xba\xbb\x00\x00\x00\xbf"
  3513. "\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3514. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3515. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3516. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3517. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3518. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3519. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x00\x00\x00"
  3520. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3521. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3522. "\x00\x00\xbc\xbd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3523. "\xa6\xa8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3524. "\x00\x00\x00\x00\x00\x00\x00\x00\xbe\x00\x00\x00\x00\xb4\xb8\x00"
  3525. "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
  3526. "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
  3527. "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
  3528. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
  3529. };
  3530. static unsigned short const xmlunicodetable_ISO8859_16 [128] = {
  3531. 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
  3532. 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
  3533. 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
  3534. 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
  3535. 0x00a0, 0x0104, 0x0105, 0x0141, 0x20ac, 0x201e, 0x0160, 0x00a7,
  3536. 0x0161, 0x00a9, 0x0218, 0x00ab, 0x0179, 0x00ad, 0x017a, 0x017b,
  3537. 0x00b0, 0x00b1, 0x010c, 0x0142, 0x017d, 0x201d, 0x00b6, 0x00b7,
  3538. 0x017e, 0x010d, 0x0219, 0x00bb, 0x0152, 0x0153, 0x0178, 0x017c,
  3539. 0x00c0, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0106, 0x00c6, 0x00c7,
  3540. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
  3541. 0x0110, 0x0143, 0x00d2, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x015a,
  3542. 0x0170, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0118, 0x021a, 0x00df,
  3543. 0x00e0, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x0107, 0x00e6, 0x00e7,
  3544. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
  3545. 0x0111, 0x0144, 0x00f2, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x015b,
  3546. 0x0171, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0119, 0x021b, 0x00ff,
  3547. };
  3548. static unsigned char const xmltranscodetable_ISO8859_16 [48 + 9 * 64] = {
  3549. "\x00\x00\x01\x08\x02\x03\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00"
  3550. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3551. "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3552. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3553. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3554. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3555. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3556. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
  3557. "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
  3558. "\xa0\x00\x00\x00\x00\x00\x00\xa7\x00\xa9\x00\xab\x00\xad\x00\x00"
  3559. "\xb0\xb1\x00\x00\x00\x00\xb6\xb7\x00\x00\x00\xbb\x00\x00\x00\x00"
  3560. "\x00\x00\xc3\xe3\xa1\xa2\xc5\xe5\x00\x00\x00\x00\xb2\xb9\x00\x00"
  3561. "\xd0\xf0\x00\x00\x00\x00\x00\x00\xdd\xfd\x00\x00\x00\x00\x00\x00"
  3562. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3563. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3564. "\x00\xa3\xb3\xd1\xf1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3565. "\xd5\xf5\xbc\xbd\x00\x00\x00\x00\x00\x00\xd7\xf7\x00\x00\x00\x00"
  3566. "\xa6\xa8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3567. "\xd8\xf8\x00\x00\x00\x00\x00\x00\xbe\xac\xae\xaf\xbf\xb4\xb8\x00"
  3568. "\x06\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3569. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3570. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3571. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3572. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3573. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3574. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x00\x00\x00"
  3575. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3576. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3577. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb5\xa5\x00"
  3578. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3579. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3580. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3581. "\x00\x00\x00\x00\x00\x00\x00\x00\xaa\xba\xde\xfe\x00\x00\x00\x00"
  3582. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3583. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  3584. "\xc0\xc1\xc2\x00\xc4\x00\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
  3585. "\x00\x00\xd2\xd3\xd4\x00\xd6\x00\x00\xd9\xda\xdb\xdc\x00\x00\xdf"
  3586. "\xe0\xe1\xe2\x00\xe4\x00\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
  3587. "\x00\x00\xf2\xf3\xf4\x00\xf6\x00\x00\xf9\xfa\xfb\xfc\x00\x00\xff"
  3588. };
  3589. /*
  3590. * auto-generated functions for ISO-8859-2 .. ISO-8859-16
  3591. */
  3592. static int ISO8859_2ToUTF8 (unsigned char* out, int *outlen,
  3593. const unsigned char* in, int *inlen) {
  3594. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_2);
  3595. }
  3596. static int UTF8ToISO8859_2 (unsigned char* out, int *outlen,
  3597. const unsigned char* in, int *inlen) {
  3598. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_2);
  3599. }
  3600. static int ISO8859_3ToUTF8 (unsigned char* out, int *outlen,
  3601. const unsigned char* in, int *inlen) {
  3602. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_3);
  3603. }
  3604. static int UTF8ToISO8859_3 (unsigned char* out, int *outlen,
  3605. const unsigned char* in, int *inlen) {
  3606. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_3);
  3607. }
  3608. static int ISO8859_4ToUTF8 (unsigned char* out, int *outlen,
  3609. const unsigned char* in, int *inlen) {
  3610. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_4);
  3611. }
  3612. static int UTF8ToISO8859_4 (unsigned char* out, int *outlen,
  3613. const unsigned char* in, int *inlen) {
  3614. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_4);
  3615. }
  3616. static int ISO8859_5ToUTF8 (unsigned char* out, int *outlen,
  3617. const unsigned char* in, int *inlen) {
  3618. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_5);
  3619. }
  3620. static int UTF8ToISO8859_5 (unsigned char* out, int *outlen,
  3621. const unsigned char* in, int *inlen) {
  3622. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_5);
  3623. }
  3624. static int ISO8859_6ToUTF8 (unsigned char* out, int *outlen,
  3625. const unsigned char* in, int *inlen) {
  3626. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_6);
  3627. }
  3628. static int UTF8ToISO8859_6 (unsigned char* out, int *outlen,
  3629. const unsigned char* in, int *inlen) {
  3630. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_6);
  3631. }
  3632. static int ISO8859_7ToUTF8 (unsigned char* out, int *outlen,
  3633. const unsigned char* in, int *inlen) {
  3634. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_7);
  3635. }
  3636. static int UTF8ToISO8859_7 (unsigned char* out, int *outlen,
  3637. const unsigned char* in, int *inlen) {
  3638. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_7);
  3639. }
  3640. static int ISO8859_8ToUTF8 (unsigned char* out, int *outlen,
  3641. const unsigned char* in, int *inlen) {
  3642. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_8);
  3643. }
  3644. static int UTF8ToISO8859_8 (unsigned char* out, int *outlen,
  3645. const unsigned char* in, int *inlen) {
  3646. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_8);
  3647. }
  3648. static int ISO8859_9ToUTF8 (unsigned char* out, int *outlen,
  3649. const unsigned char* in, int *inlen) {
  3650. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_9);
  3651. }
  3652. static int UTF8ToISO8859_9 (unsigned char* out, int *outlen,
  3653. const unsigned char* in, int *inlen) {
  3654. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_9);
  3655. }
  3656. static int ISO8859_10ToUTF8 (unsigned char* out, int *outlen,
  3657. const unsigned char* in, int *inlen) {
  3658. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_10);
  3659. }
  3660. static int UTF8ToISO8859_10 (unsigned char* out, int *outlen,
  3661. const unsigned char* in, int *inlen) {
  3662. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_10);
  3663. }
  3664. static int ISO8859_11ToUTF8 (unsigned char* out, int *outlen,
  3665. const unsigned char* in, int *inlen) {
  3666. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_11);
  3667. }
  3668. static int UTF8ToISO8859_11 (unsigned char* out, int *outlen,
  3669. const unsigned char* in, int *inlen) {
  3670. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_11);
  3671. }
  3672. static int ISO8859_13ToUTF8 (unsigned char* out, int *outlen,
  3673. const unsigned char* in, int *inlen) {
  3674. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_13);
  3675. }
  3676. static int UTF8ToISO8859_13 (unsigned char* out, int *outlen,
  3677. const unsigned char* in, int *inlen) {
  3678. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_13);
  3679. }
  3680. static int ISO8859_14ToUTF8 (unsigned char* out, int *outlen,
  3681. const unsigned char* in, int *inlen) {
  3682. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_14);
  3683. }
  3684. static int UTF8ToISO8859_14 (unsigned char* out, int *outlen,
  3685. const unsigned char* in, int *inlen) {
  3686. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_14);
  3687. }
  3688. static int ISO8859_15ToUTF8 (unsigned char* out, int *outlen,
  3689. const unsigned char* in, int *inlen) {
  3690. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_15);
  3691. }
  3692. static int UTF8ToISO8859_15 (unsigned char* out, int *outlen,
  3693. const unsigned char* in, int *inlen) {
  3694. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_15);
  3695. }
  3696. static int ISO8859_16ToUTF8 (unsigned char* out, int *outlen,
  3697. const unsigned char* in, int *inlen) {
  3698. return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_16);
  3699. }
  3700. static int UTF8ToISO8859_16 (unsigned char* out, int *outlen,
  3701. const unsigned char* in, int *inlen) {
  3702. return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_16);
  3703. }
  3704. static void
  3705. xmlRegisterCharEncodingHandlersISO8859x (void) {
  3706. xmlNewCharEncodingHandler ("ISO-8859-2", ISO8859_2ToUTF8, UTF8ToISO8859_2);
  3707. xmlNewCharEncodingHandler ("ISO-8859-3", ISO8859_3ToUTF8, UTF8ToISO8859_3);
  3708. xmlNewCharEncodingHandler ("ISO-8859-4", ISO8859_4ToUTF8, UTF8ToISO8859_4);
  3709. xmlNewCharEncodingHandler ("ISO-8859-5", ISO8859_5ToUTF8, UTF8ToISO8859_5);
  3710. xmlNewCharEncodingHandler ("ISO-8859-6", ISO8859_6ToUTF8, UTF8ToISO8859_6);
  3711. xmlNewCharEncodingHandler ("ISO-8859-7", ISO8859_7ToUTF8, UTF8ToISO8859_7);
  3712. xmlNewCharEncodingHandler ("ISO-8859-8", ISO8859_8ToUTF8, UTF8ToISO8859_8);
  3713. xmlNewCharEncodingHandler ("ISO-8859-9", ISO8859_9ToUTF8, UTF8ToISO8859_9);
  3714. xmlNewCharEncodingHandler ("ISO-8859-10", ISO8859_10ToUTF8, UTF8ToISO8859_10);
  3715. xmlNewCharEncodingHandler ("ISO-8859-11", ISO8859_11ToUTF8, UTF8ToISO8859_11);
  3716. xmlNewCharEncodingHandler ("ISO-8859-13", ISO8859_13ToUTF8, UTF8ToISO8859_13);
  3717. xmlNewCharEncodingHandler ("ISO-8859-14", ISO8859_14ToUTF8, UTF8ToISO8859_14);
  3718. xmlNewCharEncodingHandler ("ISO-8859-15", ISO8859_15ToUTF8, UTF8ToISO8859_15);
  3719. xmlNewCharEncodingHandler ("ISO-8859-16", ISO8859_16ToUTF8, UTF8ToISO8859_16);
  3720. }
  3721. #endif
  3722. #endif
  3723. #define bottom_encoding
  3724. #include "elfgcchack.h"