From 81601f9834667bb47b4b2c9d15b52579ffbe4088 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 14 Jan 2003 13:42:37 +0000 Subject: [PATCH] fixing bug #103100 with a dummy UTF8ToUTF8 copy Daniel * encoding.c: fixing bug #103100 with a dummy UTF8ToUTF8 copy Daniel --- ChangeLog | 4 ++++ encoding.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a271002c..ebbf6d69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Jan 14 14:41:18 CET 2003 Daniel Veillard + + * encoding.c: fixing bug #103100 with a dummy UTF8ToUTF8 copy + Tue Jan 14 12:40:29 CET 2003 Daniel Veillard * python/generator.py python/libxml.c python/libxml.py diff --git a/encoding.c b/encoding.c index 69d67cd6..c2d0b2db 100644 --- a/encoding.c +++ b/encoding.c @@ -591,6 +591,43 @@ isolat1ToUTF8(unsigned char* out, int *outlen, return(0); } +/** + * UTF8ToUTF8: + * @out: a pointer to an array of bytes to store the result + * @outlen: the length of @out + * @inb: a pointer to an array of UTF-8 chars + * @inlenb: the length of @in in UTF-8 chars + * + * No op copy operation for UTF8 handling. + * + * Returns the number of byte written, or -1 by lack of space, or -2 + * if the transcoding fails (for *in is not valid utf16 string) + * The value of *inlen after return is the number of octets consumed + * as the return value is positive, else unpredictable. + */ +static int +UTF8ToUTF8(unsigned char* out, int *outlen, + const unsigned char* inb, int *inlenb) +{ + int len; + + if ((out == NULL) || (inb == NULL) || (outlen == NULL) || (inlenb == NULL)) + return(-1); + if (*outlen > *inlenb) { + len = *inlenb; + } else { + len = *outlen; + } + if (len < 0) + return(-1); + + memcpy(out, inb, len); + + *outlen = len; + *inlenb = len; + return(0); +} + /** * UTF8Toisolat1: @@ -1579,7 +1616,7 @@ xmlInitCharEncodingHandlers(void) { "xmlInitCharEncodingHandlers : out of memory !\n"); return; } - xmlNewCharEncodingHandler("UTF-8", NULL, NULL); + xmlNewCharEncodingHandler("UTF-8", UTF8ToUTF8, UTF8ToUTF8); xmlUTF16LEHandler = xmlNewCharEncodingHandler("UTF-16LE", UTF16LEToUTF8, UTF8ToUTF16LE); xmlUTF16BEHandler =