Dear List,

What would be the best of transcoding to an encoding. The following seems to be the prevailing approach

XMLTransService::Codes reasonForFailure;
unsigned TRANSCODER_MEMORY_BLOCK_SIZE = 16 * 1024;

XMLTranscoder* m_utf8Transcoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor( "ISO-8859-1" , reasonForFailure , TRANSCODER_MEMORY_BLOCK_SIZE );

XMLSize_t charsEaten;
size_t len = XMLString::stringLen( chars );
XMLByte* byte = new XMLByte[ (len*4) + 1 ];     
unsigned outLen = m_utf8Transcoder->transcodeTo( chars , len , byte , len*4 , charsEaten , XMLTranscoder::UnRep_Throw );
byte[outLen] = '\0';

Three questions arise:

1. Why is XMLByte* byte allocated almost 4 times the memory it should need?

2. Can XMLTranscoder* m_utf8Transcoder be created once and called repeatedly?

3. Is the above methof of trabscoding preferred to the simpler technique

TranscodeToStr transcoder( chars , "ISO-8859-1" );
const XMLByte* str = transcoder.str();

Thanks,

- Olumide


Reply via email to