encoding.c 130 KB

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