version 1.32, 2000/05/01 14:03:34
|
version 1.33, 2000/05/02 13:19:46
|
Line 47 xmlCharEncodingHandlerPtr xmlUTF16LEHand
|
Line 47 xmlCharEncodingHandlerPtr xmlUTF16LEHand
|
xmlCharEncodingHandlerPtr xmlUTF16BEHandler = NULL; |
xmlCharEncodingHandlerPtr xmlUTF16BEHandler = NULL; |
|
|
#ifdef LIBXML_ICONV_ENABLED |
#ifdef LIBXML_ICONV_ENABLED |
|
#if 0 |
#define DEBUG_ENCODING /* Define this to get encoding traces */ |
#define DEBUG_ENCODING /* Define this to get encoding traces */ |
#endif |
#endif |
|
#endif |
|
|
/* |
/* |
* From rfc2044: encoding of the Unicode values on UTF-8: |
* From rfc2044: encoding of the Unicode values on UTF-8: |
Line 114 xmlCheckUTF8(const unsigned char *utf)
|
Line 116 xmlCheckUTF8(const unsigned char *utf)
|
* |
* |
* Take a block of ISO Latin 1 chars in and try to convert it to an UTF-8 |
* Take a block of ISO Latin 1 chars in and try to convert it to an UTF-8 |
* block of chars out. |
* block of chars out. |
* Returns the number of byte written, or -1 by lack of space. |
* Returns 0 if success, or -1 otherwise |
|
* The value of @inlen after return is the number of octets consumed |
|
* as the return value is positive, else unpredictiable. |
|
* The value of @outlen after return is the number of ocetes consumed. |
*/ |
*/ |
int |
int |
isolat1ToUTF8(unsigned char* out, int outlen, |
isolat1ToUTF8(unsigned char* out, int *outlen, |
const unsigned char* in, int *inlen) { |
const unsigned char* in, int *inlen) { |
unsigned char* outstart= out; |
unsigned char* outstart = out; |
unsigned char* outend= out+outlen; |
const unsigned char* processed = in; |
const unsigned char* inend= in+*inlen; |
unsigned char* outend = out + *outlen; |
|
const unsigned char* inend = in + *inlen; |
unsigned char c; |
unsigned char c; |
|
|
while (in < inend) { |
while (in < inend) { |
c= *in++; |
c= *in++; |
if (c < 0x80) { |
if (c < 0x80) { |
if (out >= outend) return(-1); |
if (out >= outend) |
|
break; |
*out++ = c; |
*out++ = c; |
} |
} |
else { |
else { |
if (out >= outend) return(-1); |
if (out + 1 >= outend) break; |
*out++ = 0xC0 | (c >> 6); |
*out++ = 0xC0 | (c >> 6); |
if (out >= outend) return(-1); |
|
*out++ = 0x80 | (0x3F & c); |
*out++ = 0x80 | (0x3F & c); |
} |
} |
|
processed = in; |
} |
} |
return(out-outstart); |
*outlen = out - outstart; |
|
*inlen = processed - in; |
|
|
|
return(0); |
} |
} |
|
|
/** |
/** |
Line 151 isolat1ToUTF8(unsigned char* out, int ou
|
Line 161 isolat1ToUTF8(unsigned char* out, int ou
|
* block of chars out. |
* block of chars out. |
* TODO: UTF8Toisolat1 need a fallback mechanism ... |
* TODO: UTF8Toisolat1 need a fallback mechanism ... |
* |
* |
* Returns the number of byte written, or -1 by lack of space, or -2 |
* Returns 0 if success, -2 if the transcoding fails, or -1 otherwise |
* if the transcoding fails (for *in is not valid utf8 string or |
|
* the result of transformation can't fit into the encoding we want) |
|
* The value of @inlen after return is the number of octets consumed |
* The value of @inlen after return is the number of octets consumed |
* as the return value is positive, else unpredictiable. |
* as the return value is positive, else unpredictiable. |
|
* The value of @outlen after return is the number of ocetes consumed. |
*/ |
*/ |
int |
int |
UTF8Toisolat1(unsigned char* out, int outlen, |
UTF8Toisolat1(unsigned char* out, int *outlen, |
const unsigned char* in, int *inlen) { |
const unsigned char* in, int *inlen) { |
unsigned char* outstart= out; |
unsigned char* outstart = out; |
unsigned char* outend= out+outlen; |
const unsigned char* processed = in; |
const unsigned char* inend= in+*inlen; |
unsigned char* outend = out + *outlen; |
|
const unsigned char* inend = in + *inlen; |
unsigned char c; |
unsigned char c; |
|
|
while (in < inend) { |
while (in < inend) { |
Line 172 UTF8Toisolat1(unsigned char* out, int ou
|
Line 182 UTF8Toisolat1(unsigned char* out, int ou
|
*out++= c; |
*out++= c; |
} |
} |
else if (in == inend) { |
else if (in == inend) { |
*inlen -= 1; |
|
break; |
break; |
} |
} |
else if (((c & 0xFC) == 0xC0) && ((*in & 0xC0) == 0x80)) { |
else if (((c & 0xFC) == 0xC0) && ((*in & 0xC0) == 0x80)) { |
/* a two byte utf-8 and can be encoding as isolate1 */ |
/* a two byte utf-8 and can be encoding as isolate1 */ |
*out++= ((c & 0x03) << 6) | (*in++ & 0x3F); |
*out++= ((c & 0x03) << 6) | (*in++ & 0x3F); |
} |
} |
else |
else { |
|
*outlen = out - outstart; |
|
*inlen = processed - in; |
return(-2); |
return(-2); |
/* TODO : some should be represent as "&#x____;" */ |
} |
|
processed = in; |
} |
} |
return(out-outstart); |
*outlen = out - outstart; |
|
*inlen = processed - in; |
|
return(0); |
} |
} |
|
|
/** |
/** |
Line 204 UTF8Toisolat1(unsigned char* out, int ou
|
Line 218 UTF8Toisolat1(unsigned char* out, int ou
|
* as the return value is positive, else unpredictiable. |
* as the return value is positive, else unpredictiable. |
*/ |
*/ |
int |
int |
UTF16LEToUTF8(unsigned char* out, int outlen, |
UTF16LEToUTF8(unsigned char* out, int *outlen, |
const unsigned char* inb, int *inlenb) |
const unsigned char* inb, int *inlenb) |
{ |
{ |
unsigned char* outstart= out; |
unsigned char* outstart = out; |
unsigned char* outend= out+outlen; |
const unsigned char* processed = inb; |
|
unsigned char* outend = out + *outlen; |
unsigned short* in = (unsigned short*) inb; |
unsigned short* in = (unsigned short*) inb; |
unsigned short* inend; |
unsigned short* inend; |
unsigned int c, d, inlen; |
unsigned int c, d, inlen; |
Line 218 UTF16LEToUTF8(unsigned char* out, int ou
|
Line 233 UTF16LEToUTF8(unsigned char* out, int ou
|
if ((*inlenb % 2) == 1) |
if ((*inlenb % 2) == 1) |
(*inlenb)--; |
(*inlenb)--; |
inlen = *inlenb / 2; |
inlen = *inlenb / 2; |
inend= in + inlen; |
inend = in + inlen; |
while (in < inend) { |
while (in < inend) { |
#ifdef BIG_ENDIAN |
#ifdef BIG_ENDIAN |
tmp = (unsigned char *) in; |
tmp = (unsigned char *) in; |
Line 230 UTF16LEToUTF8(unsigned char* out, int ou
|
Line 245 UTF16LEToUTF8(unsigned char* out, int ou
|
#endif /* BIG_ENDIAN */ |
#endif /* BIG_ENDIAN */ |
if ((c & 0xFC00) == 0xD800) { /* surrogates */ |
if ((c & 0xFC00) == 0xD800) { /* surrogates */ |
if (in >= inend) { /* (in > inend) shouldn't happens */ |
if (in >= inend) { /* (in > inend) shouldn't happens */ |
(*inlenb) -= 2; |
|
break; |
break; |
} |
} |
#ifdef BIG_ENDIAN |
#ifdef BIG_ENDIAN |
Line 247 UTF16LEToUTF8(unsigned char* out, int ou
|
Line 261 UTF16LEToUTF8(unsigned char* out, int ou
|
c |= d & 0x03FF; |
c |= d & 0x03FF; |
c += 0x10000; |
c += 0x10000; |
} |
} |
else |
else { |
|
*outlen = out - outstart; |
|
*inlenb = processed - inb; |
return(-2); |
return(-2); |
|
} |
} |
} |
|
|
/* assertion: c is a single UTF-4 value */ |
/* assertion: c is a single UTF-4 value */ |
if (out >= outend) |
if (out >= outend) |
return(-1); |
break; |
if (c < 0x80) { *out++= c; bits= -6; } |
if (c < 0x80) { *out++= c; bits= -6; } |
else if (c < 0x800) { *out++= ((c >> 6) & 0x1F) | 0xC0; bits= 0; } |
else if (c < 0x800) { *out++= ((c >> 6) & 0x1F) | 0xC0; bits= 0; } |
else if (c < 0x10000) { *out++= ((c >> 12) & 0x0F) | 0xE0; bits= 6; } |
else if (c < 0x10000) { *out++= ((c >> 12) & 0x0F) | 0xE0; bits= 6; } |
Line 261 UTF16LEToUTF8(unsigned char* out, int ou
|
Line 278 UTF16LEToUTF8(unsigned char* out, int ou
|
|
|
for ( ; bits >= 0; bits-= 6) { |
for ( ; bits >= 0; bits-= 6) { |
if (out >= outend) |
if (out >= outend) |
return(-1); |
break; |
*out++= ((c >> bits) & 0x3F) | 0x80; |
*out++= ((c >> bits) & 0x3F) | 0x80; |
} |
} |
|
processed = (const unsigned char*) in; |
} |
} |
return(out-outstart); |
*outlen = out - outstart; |
|
*inlenb = processed - inb; |
|
return(0); |
} |
} |
|
|
/** |
/** |
Line 283 UTF16LEToUTF8(unsigned char* out, int ou
|
Line 303 UTF16LEToUTF8(unsigned char* out, int ou
|
* if the transcoding failed. |
* if the transcoding failed. |
*/ |
*/ |
int |
int |
UTF8ToUTF16LE(unsigned char* outb, int outlen, |
UTF8ToUTF16LE(unsigned char* outb, int *outlen, |
const unsigned char* in, int *inlen) |
const unsigned char* in, int *inlen) |
{ |
{ |
unsigned short* out = (unsigned short*) outb; |
unsigned short* out = (unsigned short*) outb; |
|
const unsigned char* processed = in; |
unsigned short* outstart= out; |
unsigned short* outstart= out; |
unsigned short* outend; |
unsigned short* outend; |
const unsigned char* inend= in+*inlen; |
const unsigned char* inend= in+*inlen; |
Line 296 UTF8ToUTF16LE(unsigned char* outb, int o
|
Line 317 UTF8ToUTF16LE(unsigned char* outb, int o
|
unsigned short tmp1, tmp2; |
unsigned short tmp1, tmp2; |
#endif /* BIG_ENDIAN */ |
#endif /* BIG_ENDIAN */ |
|
|
outlen /= 2; /* convert in short length */ |
outend = out + (*outlen / 2); |
outend = out + outlen; |
|
while (in < inend) { |
while (in < inend) { |
d= *in++; |
d= *in++; |
if (d < 0x80) { c= d; trailing= 0; } |
if (d < 0x80) { c= d; trailing= 0; } |
else if (d < 0xC0) |
else if (d < 0xC0) { |
return(-2); /* trailing byte in leading position */ |
/* trailing byte in leading position */ |
else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } |
*outlen = out - outstart; |
|
*inlen = processed - in; |
|
return(-2); |
|
} else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } |
else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } |
else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } |
else if (d < 0xF8) { c= d & 0x07; trailing= 3; } |
else if (d < 0xF8) { c= d & 0x07; trailing= 3; } |
else |
else { |
return(-2); /* no chance for this in UTF-16 */ |
/* no chance for this in UTF-16 */ |
|
*outlen = out - outstart; |
|
*inlen = processed - in; |
|
return(-2); |
|
} |
|
|
if (inend - in < trailing) { |
if (inend - in < trailing) { |
*inlen -= (inend - in); |
|
break; |
break; |
} |
} |
|
|
for ( ; trailing; trailing--) { |
for ( ; trailing; trailing--) { |
if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80)) |
if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80)) |
return(-1); |
break; |
c <<= 6; |
c <<= 6; |
c |= d & 0x3F; |
c |= d & 0x3F; |
} |
} |
Line 324 UTF8ToUTF16LE(unsigned char* outb, int o
|
Line 350 UTF8ToUTF16LE(unsigned char* outb, int o
|
/* assertion: c is a single UTF-4 value */ |
/* assertion: c is a single UTF-4 value */ |
if (c < 0x10000) { |
if (c < 0x10000) { |
if (out >= outend) |
if (out >= outend) |
return(-1); |
break; |
#ifdef BIG_ENDIAN |
#ifdef BIG_ENDIAN |
tmp = (unsigned char *) out; |
tmp = (unsigned char *) out; |
*tmp = c ; |
*tmp = c ; |
Line 336 UTF8ToUTF16LE(unsigned char* outb, int o
|
Line 362 UTF8ToUTF16LE(unsigned char* outb, int o
|
} |
} |
else if (c < 0x110000) { |
else if (c < 0x110000) { |
if (out+1 >= outend) |
if (out+1 >= outend) |
return(-1); |
break; |
c -= 0x10000; |
c -= 0x10000; |
#ifdef BIG_ENDIAN |
#ifdef BIG_ENDIAN |
tmp1 = 0xD800 | (c >> 10); |
tmp1 = 0xD800 | (c >> 10); |
Line 356 UTF8ToUTF16LE(unsigned char* outb, int o
|
Line 382 UTF8ToUTF16LE(unsigned char* outb, int o
|
#endif /* BIG_ENDIAN */ |
#endif /* BIG_ENDIAN */ |
} |
} |
else |
else |
return(-1); |
break; |
|
processed = in; |
} |
} |
return(out-outstart); |
*outlen = out - outstart; |
|
*inlen = processed - in; |
|
return(0); |
} |
} |
|
|
/** |
/** |
Line 379 UTF8ToUTF16LE(unsigned char* outb, int o
|
Line 408 UTF8ToUTF16LE(unsigned char* outb, int o
|
* as the return value is positive, else unpredictiable. |
* as the return value is positive, else unpredictiable. |
*/ |
*/ |
int |
int |
UTF16BEToUTF8(unsigned char* out, int outlen, |
UTF16BEToUTF8(unsigned char* out, int *outlen, |
const unsigned char* inb, int *inlenb) |
const unsigned char* inb, int *inlenb) |
{ |
{ |
unsigned char* outstart= out; |
unsigned char* outstart = out; |
unsigned char* outend= out+outlen; |
const unsigned char* processed = inb; |
|
unsigned char* outend = out + *outlen; |
unsigned short* in = (unsigned short*) inb; |
unsigned short* in = (unsigned short*) inb; |
unsigned short* inend; |
unsigned short* inend; |
unsigned int c, d, inlen; |
unsigned int c, d, inlen; |
Line 409 UTF16BEToUTF8(unsigned char* out, int ou
|
Line 439 UTF16BEToUTF8(unsigned char* out, int ou
|
#endif |
#endif |
if ((c & 0xFC00) == 0xD800) { /* surrogates */ |
if ((c & 0xFC00) == 0xD800) { /* surrogates */ |
if (in >= inend) { /* (in > inend) shouldn't happens */ |
if (in >= inend) { /* (in > inend) shouldn't happens */ |
(*inlenb) -= 2; |
*outlen = out - outstart; |
break; |
*inlenb = processed - inb; |
|
return(-2); |
} |
} |
|
|
#ifdef BIG_ENDIAN |
#ifdef BIG_ENDIAN |
Line 428 UTF16BEToUTF8(unsigned char* out, int ou
|
Line 459 UTF16BEToUTF8(unsigned char* out, int ou
|
c |= d & 0x03FF; |
c |= d & 0x03FF; |
c += 0x10000; |
c += 0x10000; |
} |
} |
else |
else { |
|
*outlen = out - outstart; |
|
*inlenb = processed - inb; |
return(-2); |
return(-2); |
|
} |
} |
} |
|
|
/* assertion: c is a single UTF-4 value */ |
/* assertion: c is a single UTF-4 value */ |
if (out >= outend) |
if (out >= outend) |
return(-1); |
break; |
if (c < 0x80) { *out++= c; bits= -6; } |
if (c < 0x80) { *out++= c; bits= -6; } |
else if (c < 0x800) { *out++= ((c >> 6) & 0x1F) | 0xC0; bits= 0; } |
else if (c < 0x800) { *out++= ((c >> 6) & 0x1F) | 0xC0; bits= 0; } |
else if (c < 0x10000) { *out++= ((c >> 12) & 0x0F) | 0xE0; bits= 6; } |
else if (c < 0x10000) { *out++= ((c >> 12) & 0x0F) | 0xE0; bits= 6; } |
Line 442 UTF16BEToUTF8(unsigned char* out, int ou
|
Line 476 UTF16BEToUTF8(unsigned char* out, int ou
|
|
|
for ( ; bits >= 0; bits-= 6) { |
for ( ; bits >= 0; bits-= 6) { |
if (out >= outend) |
if (out >= outend) |
return(-1); |
break; |
*out++= ((c >> bits) & 0x3F) | 0x80; |
*out++= ((c >> bits) & 0x3F) | 0x80; |
} |
} |
|
processed = (const unsigned char*) in; |
} |
} |
return(out-outstart); |
*outlen = out - outstart; |
|
*inlenb = processed - inb; |
|
return(0); |
} |
} |
|
|
/** |
/** |
Line 464 UTF16BEToUTF8(unsigned char* out, int ou
|
Line 501 UTF16BEToUTF8(unsigned char* out, int ou
|
* if the transcoding failed. |
* if the transcoding failed. |
*/ |
*/ |
int |
int |
UTF8ToUTF16BE(unsigned char* outb, int outlen, |
UTF8ToUTF16BE(unsigned char* outb, int *outlen, |
const unsigned char* in, int *inlen) |
const unsigned char* in, int *inlen) |
{ |
{ |
unsigned short* out = (unsigned short*) outb; |
unsigned short* out = (unsigned short*) outb; |
|
const unsigned char* processed = in; |
unsigned short* outstart= out; |
unsigned short* outstart= out; |
unsigned short* outend; |
unsigned short* outend; |
const unsigned char* inend= in+*inlen; |
const unsigned char* inend= in+*inlen; |
Line 478 UTF8ToUTF16BE(unsigned char* outb, int o
|
Line 516 UTF8ToUTF16BE(unsigned char* outb, int o
|
unsigned short tmp1, tmp2; |
unsigned short tmp1, tmp2; |
#endif /* BIG_ENDIAN */ |
#endif /* BIG_ENDIAN */ |
|
|
outlen /= 2; /* convert in short length */ |
outend = out + (*outlen / 2); |
outend = out + outlen; |
|
while (in < inend) { |
while (in < inend) { |
d= *in++; |
d= *in++; |
if (d < 0x80) { c= d; trailing= 0; } |
if (d < 0x80) { c= d; trailing= 0; } |
else if (d < 0xC0) |
else if (d < 0xC0) { |
return(-2); /* trailing byte in leading position */ |
/* trailing byte in leading position */ |
else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } |
*outlen = out - outstart; |
|
*inlen = processed - in; |
|
return(-2); |
|
} else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } |
else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } |
else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } |
else if (d < 0xF8) { c= d & 0x07; trailing= 3; } |
else if (d < 0xF8) { c= d & 0x07; trailing= 3; } |
else |
else { |
return(-2); /* no chance for this in UTF-16 */ |
/* no chance for this in UTF-16 */ |
|
*outlen = out - outstart; |
|
*inlen = processed - in; |
|
return(-2); |
|
} |
|
|
if (inend - in < trailing) { |
if (inend - in < trailing) { |
*inlen -= (inend - in); |
|
break; |
break; |
} |
} |
|
|
for ( ; trailing; trailing--) { |
for ( ; trailing; trailing--) { |
if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80)) return(-1); |
if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80)) break; |
c <<= 6; |
c <<= 6; |
c |= d & 0x3F; |
c |= d & 0x3F; |
} |
} |
|
|
/* assertion: c is a single UTF-4 value */ |
/* assertion: c is a single UTF-4 value */ |
if (c < 0x10000) { |
if (c < 0x10000) { |
if (out >= outend) return(-1); |
if (out >= outend) break; |
#ifdef BIG_ENDIAN |
#ifdef BIG_ENDIAN |
*out++ = c; |
*out++ = c; |
#else |
#else |
Line 515 UTF8ToUTF16BE(unsigned char* outb, int o
|
Line 558 UTF8ToUTF16BE(unsigned char* outb, int o
|
#endif /* BIG_ENDIAN */ |
#endif /* BIG_ENDIAN */ |
} |
} |
else if (c < 0x110000) { |
else if (c < 0x110000) { |
if (out+1 >= outend) return(-1); |
if (out+1 >= outend) break; |
c -= 0x10000; |
c -= 0x10000; |
#ifdef BIG_ENDIAN |
#ifdef BIG_ENDIAN |
*out++ = 0xD800 | (c >> 10); |
*out++ = 0xD800 | (c >> 10); |
Line 534 UTF8ToUTF16BE(unsigned char* outb, int o
|
Line 577 UTF8ToUTF16BE(unsigned char* outb, int o
|
out++; |
out++; |
#endif |
#endif |
} |
} |
else return(-1); |
else |
|
break; |
|
processed = in; |
} |
} |
return(out-outstart); |
*outlen = out - outstart; |
|
*inlen = processed - in; |
|
return(0); |
} |
} |
|
|
/** |
/** |
Line 1047 xmlCharEncInFunc(xmlCharEncodingHandler
|
Line 1094 xmlCharEncInFunc(xmlCharEncodingHandler
|
toconv = in->use; |
toconv = in->use; |
if (toconv * 2 >= written) { |
if (toconv * 2 >= written) { |
xmlBufferGrow(out, toconv * 2); |
xmlBufferGrow(out, toconv * 2); |
written = out->size - out->use; |
written = out->size - out->use - 1; |
} |
} |
if (handler->input != NULL) { |
if (handler->input != NULL) { |
ret = handler->input(&out->content[out->use], &written, |
ret = handler->input(&out->content[out->use], &written, |
in->content, &toconv); |
in->content, &toconv); |
xmlBufferShrink(in, toconv); |
xmlBufferShrink(in, toconv); |
out->use += written; |
out->use += written; |
|
out->content[out->use] = 0; |
} |
} |
#ifdef LIBXML_ICONV_ENABLED |
#ifdef LIBXML_ICONV_ENABLED |
else if (handler->iconv_in != NULL) { |
else if (handler->iconv_in != NULL) { |
Line 1061 xmlCharEncInFunc(xmlCharEncodingHandler
|
Line 1109 xmlCharEncInFunc(xmlCharEncodingHandler
|
&written, in->content, &toconv); |
&written, in->content, &toconv); |
xmlBufferShrink(in, toconv); |
xmlBufferShrink(in, toconv); |
out->use += written; |
out->use += written; |
|
out->content[out->use] = 0; |
|
if (ret == -1) ret = -3; |
} |
} |
#endif /* LIBXML_ICONV_ENABLED */ |
#endif /* LIBXML_ICONV_ENABLED */ |
#ifdef DEBUG_ENCODING |
#ifdef DEBUG_ENCODING |
Line 1084 xmlCharEncInFunc(xmlCharEncodingHandler
|
Line 1134 xmlCharEncInFunc(xmlCharEncodingHandler
|
fprintf(stderr,"Unknown input conversion failed %d\n", ret); |
fprintf(stderr,"Unknown input conversion failed %d\n", ret); |
} |
} |
#endif |
#endif |
|
/* |
|
* Ignore when input buffer is not on a boundary |
|
*/ |
|
if (ret == -3) ret = 0; |
return(ret); |
return(ret); |
} |
} |
|
|
Line 1111 xmlCharEncOutFunc(xmlCharEncodingHandler
|
Line 1165 xmlCharEncOutFunc(xmlCharEncodingHandler
|
if (out == NULL) return(-1); |
if (out == NULL) return(-1); |
if (in == NULL) return(-1); |
if (in == NULL) return(-1); |
|
|
|
written = out->size - out->use; |
|
toconv = in->use; |
|
if (toconv * 2 >= written) { |
|
xmlBufferGrow(out, toconv * 2); |
|
written = out->size - out->use - 1; |
|
} |
if (handler->output != NULL) { |
if (handler->output != NULL) { |
written = out->size - out->use; |
ret = handler->output(&out->content[out->use], &written, |
toconv = in->use; |
|
ret = handler->output(&out->content[out->use], written, |
|
in->content, &toconv); |
in->content, &toconv); |
if (ret >= 0) { |
|
written = ret; |
|
} else { |
|
written = 0; |
|
} |
|
xmlBufferShrink(in, toconv); |
xmlBufferShrink(in, toconv); |
out->use += written; |
out->use += written; |
|
out->content[out->use] = 0; |
} |
} |
#ifdef LIBXML_ICONV_ENABLED |
#ifdef LIBXML_ICONV_ENABLED |
else if (handler->iconv_out != NULL) { |
else if (handler->iconv_out != NULL) { |
written = out->size - out->use; |
|
toconv = in->use; |
|
ret = xmlIconvWrapper(handler->iconv_out, &out->content[out->use], |
ret = xmlIconvWrapper(handler->iconv_out, &out->content[out->use], |
&written, in->content, &toconv); |
&written, in->content, &toconv); |
xmlBufferShrink(in, toconv); |
xmlBufferShrink(in, toconv); |
out->use += written; |
out->use += written; |
|
out->content[out->use] = 0; |
|
if (ret == -1) ret = -3; |
} |
} |
#endif /* LIBXML_ICONV_ENABLED */ |
#endif /* LIBXML_ICONV_ENABLED */ |
#ifdef DEBUG_ENCODING |
#ifdef DEBUG_ENCODING |