encoding.c 143 KB

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