Re: [xml] Target string size after transcoding



Thanks . But I mean to ask this.
 
To transcode a string of length 'n' bytes to UTF-8.. I need to allocate  4n bytes and pass it to xmlCharEncodingInputFunc.  4n bytes may not be fully used.
 
Allocating memory is expensive when I need to handle big xml documents. ( Passing input string and a null value for target string,  to MultiByteToWideChar() will return the buffer size required to transcode the input string  without performing actual transcoding ). Can I do the same with libxml2 API's ?
 
Thanks,
Mini

--- On Thu, 9/24/09, Daniel Veillard <veillard redhat com> wrote:

From: Daniel Veillard <veillard redhat com>
Subject: Re: [xml] Target string size after transcoding
To: "mini thomas" <mini_mol_thomas yahoo com>
Cc: "libxml use group" <xml gnome org>
Date: Thursday, September 24, 2009, 9:26 PM

On Wed, Sep 23, 2009 at 08:12:13AM -0700, mini thomas wrote:
>  
> APIs like MultiByteToWideChar has an option to give the number of bytes required by the output string after the input is transcoded.
>  
> I am using xmlGetCharEncodingHandler and related functions
> Is there any way to get the size of output string. ?

  an encoding handler routine does for input or output as a signature:

/**
* xmlCharEncodingInputFunc:
* @out:  a pointer to an array of bytes to store the UTF-8 result
* @outlen:  the length of @out
* @in:  a pointer to an array of chars in the original encoding
* @inlen:  the length of @in
*
* Take a block of chars in the original encoding and try to convert
* it to an UTF-8 block of chars out.
*
* Returns the number of bytes written, -1 if lack of space, or -2
*     if the transcoding failed.
* The value of @inlen after return is the number of octets consumed
*     if the return value is positive, else unpredictiable.
* The value of @outlen after return is the number of octets consumed.
*/
typedef int (* xmlCharEncodingInputFunc)(unsigned char *out, int *outlen,
                                         const unsigned char *in, int *inlen);

it certainly returned the number of bytes in the output, outlen and
inlen are also output parameter in addition to the returned value.

Daniel

--
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]