mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
applied UTF-16 encoding handling patch provided by Mark Itzcovitz more
* encoding.c: applied UTF-16 encoding handling patch provided by Mark Itzcovitz * encoding.c parser.c: more cleanup and fixes for UTF-16 when not having iconv support. Daniel
This commit is contained in:
22
encoding.c
22
encoding.c
@ -875,6 +875,7 @@ UTF8ToUTF16LE(unsigned char* outb, int *outlen,
|
||||
{
|
||||
unsigned short* out = (unsigned short*) outb;
|
||||
const unsigned char* processed = in;
|
||||
const unsigned char *const instart = in;
|
||||
unsigned short* outstart= out;
|
||||
unsigned short* outend;
|
||||
const unsigned char* inend= in+*inlen;
|
||||
@ -909,7 +910,7 @@ UTF8ToUTF16LE(unsigned char* outb, int *outlen,
|
||||
else if (d < 0xC0) {
|
||||
/* trailing byte in leading position */
|
||||
*outlen = (out - outstart) * 2;
|
||||
*inlen = processed - in;
|
||||
*inlen = processed - instart;
|
||||
return(-2);
|
||||
} else if (d < 0xE0) { c= d & 0x1F; trailing= 1; }
|
||||
else if (d < 0xF0) { c= d & 0x0F; trailing= 2; }
|
||||
@ -917,7 +918,7 @@ UTF8ToUTF16LE(unsigned char* outb, int *outlen,
|
||||
else {
|
||||
/* no chance for this in UTF-16 */
|
||||
*outlen = (out - outstart) * 2;
|
||||
*inlen = processed - in;
|
||||
*inlen = processed - instart;
|
||||
return(-2);
|
||||
}
|
||||
|
||||
@ -971,7 +972,7 @@ UTF8ToUTF16LE(unsigned char* outb, int *outlen,
|
||||
processed = in;
|
||||
}
|
||||
*outlen = (out - outstart) * 2;
|
||||
*inlen = processed - in;
|
||||
*inlen = processed - instart;
|
||||
return(0);
|
||||
}
|
||||
|
||||
@ -1086,6 +1087,7 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen,
|
||||
{
|
||||
unsigned short* out = (unsigned short*) outb;
|
||||
const unsigned char* processed = in;
|
||||
const unsigned char *const instart = in;
|
||||
unsigned short* outstart= out;
|
||||
unsigned short* outend;
|
||||
const unsigned char* inend= in+*inlen;
|
||||
@ -1120,7 +1122,7 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen,
|
||||
else if (d < 0xC0) {
|
||||
/* trailing byte in leading position */
|
||||
*outlen = out - outstart;
|
||||
*inlen = processed - in;
|
||||
*inlen = processed - instart;
|
||||
return(-2);
|
||||
} else if (d < 0xE0) { c= d & 0x1F; trailing= 1; }
|
||||
else if (d < 0xF0) { c= d & 0x0F; trailing= 2; }
|
||||
@ -1128,7 +1130,7 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen,
|
||||
else {
|
||||
/* no chance for this in UTF-16 */
|
||||
*outlen = out - outstart;
|
||||
*inlen = processed - in;
|
||||
*inlen = processed - instart;
|
||||
return(-2);
|
||||
}
|
||||
|
||||
@ -1179,7 +1181,7 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen,
|
||||
processed = in;
|
||||
}
|
||||
*outlen = (out - outstart) * 2;
|
||||
*inlen = processed - in;
|
||||
*inlen = processed - instart;
|
||||
return(0);
|
||||
}
|
||||
|
||||
@ -1962,6 +1964,14 @@ xmlFindCharEncodingHandler(const char *name) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If nothing was found and it is "UTF-16" then use the Little indian
|
||||
* version.
|
||||
*/
|
||||
if ((xmlStrEqual(BAD_CAST upper, BAD_CAST "UTF-16")) ||
|
||||
(xmlStrEqual(BAD_CAST upper, BAD_CAST "UTF16")))
|
||||
return(xmlUTF16LEHandler);
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user