Are you sure you're *only* getting garbage? strncpy() doesn't null-terminate
unless the number of characters to copy is at least equal to the length of
the input string. Unless trancodeTo() null-terminates (which it may, for all
I know), I'd expect fLocalForm to contain the transcoded character followed
by whatever garbage was in the buffer when malloc() gave it to you. A
quick-and-dirty test would be to allocate your buffer with calloc() (which
sets all the bytes in the buffer to 0) instead.

-----Original Message-----
From: Jeremy Sheeley [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 04, 2001 11:15 AM
To: [EMAIL PROTECTED]
Subject: Transcoding help


I'm still struggling trying to figure this transcoding stuff out.

Given and XMLCh* toTranscode (which was in ISO8859-1 when it was read in)  I
want to print out the ISO8859-1 encoding of that string.

I do something like this:

  XMLPlatformUtils::Initialize();
  XMLTransService::Codes resCode;
  transcoder =
XMLPlatformUtils::fgTransService->makeNewTranscoderFor("ISO-8859-1",
resCode, 8192);
  XMLByte bufToFill[8192];
  unsigned int bytesEaten;
  const XMLTranscoder::UnRepOpts unRepOpts = XMLTranscoder::UnRep_Throw;
  transcoder->transcodeTo(toTranscode, (unsigned int)1, bufToFill, 8192,
bytesEaten, unRepOpts);
  fLocalForm = (char*)malloc(bytesEaten + 1);
  strncpy(fLocalForm, (char*)bufToFill, bytesEaten);
  cout << fLocalForm << endl;

That chunk of code should only take the first character of toTranscode and
send that to bufToFill as an ISO8859-1 string.  I then copy that string into
a regular unsigned char*.  I know I'm doing something wrong because all I
get is garbage and no exception thrown.  Any and all help would be
appreciated.

Jeremy Sheeley

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to