encoding.c 142 KB

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