souri datta wrote:
Thanks David for all the replies.
I am using the following code :
XMLByte *s1;
const XMLCh *s2 = (args[0]->str()).c_str();
unsigned int charsEaten;
XMLTransService::Codes code;
try{
CdxNote<<"(args[0]->str()="<<(args[0]->str())<<CdxEndl;
XMLTranscoder* t =
XMLPlatformUtils::fgTransService->makeNewTranscoderFor((const XMLCh*)
"UTF-32", code, (unsigned int) 16*1024);
I can't believe this code actually works. You can't cast a C-style
string to a UTF-16. You'll either need to transcode this string to
UTF-16 yourself, or rely in the XalanDOMString constructor that converts
from the local code page:
const XalanDOMString encoding("UTF-32");
Then use the following code:
XMLTranscoder* t =
XMLPlatformUtils::fgTransService->makeNewTranscoderFor(encoding.c_str(),
code, 16*1024);
Also, please check the "code" variable, in case there's an error.
Finally, I'm not sure why you're transcoding to UTF-32, which is not a
byte-based encoding. Are you sure about this?
t->transcodeTo(s2, (unsigned int)(args[0]->str()).length(),
s1, 200, charsEaten, XMLTranscoder::UnRep_Throw);
You've told the transcoder there's room for 200 bytes in "s1", but s1 is
an uninitialized pointer. You can either use a stack-based buffer:
XMLByte s1[200];
or a dynamically-allocated buffer:
XMLByte s1 = new XMLByte[200];
If you use the dynamically-allocated buffer, remember to delete it:
delete [] s1;
You'll also need to either take into account the case where the
transcoded string doesn't fit into your buffer, or ensure you allocate a
large enough buffer. For most byte-based encoding the maximum number of
bytes per UTF-16 code unit is 4. For UTF-8, it's 3. For UTF-32, it's
usually 1, although there are cases where a character will be encoded
using 2 UTF-16 code units, but only need 1 UTF-32 code unit.
//char *s1 = XMLString::transcode(((args[0]->str()).c_str()));
CdxNote<<"s1 = "<<s1<<CdxEndl;
catch(XalanDOMException xExcp)
{
CdxNote<<"Exception caught
="<<xExcp.getExceptionCode()<<CdxEndl;
}
I am getting args[0]->str() already UTF-16 encoded.So,when i try to
encode it to UTF-32 , i am getting a segmentation fault in the line
t->transcodeTo(s2, (u....)
I suspect the transcoder pointer is a null pointer value. Use a
debugger to see what's going on.
Dave