encoding.c 123 KB

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