You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by jb...@apache.org on 2005/06/08 16:20:06 UTC
svn commit: r189582 -
/xerces/c/branches/jberry/3.0-unstable/src/xercesc/util/Transcoders/Iconv/IconvTransService.cpp
Author: jberry
Date: Wed Jun 8 07:20:05 2005
New Revision: 189582
URL: http://svn.apache.org/viewcvs?rev=189582&view=rev
Log:
Restore some of IconvTranscoder, broken by commit 179673
Modified:
xerces/c/branches/jberry/3.0-unstable/src/xercesc/util/Transcoders/Iconv/IconvTransService.cpp
Modified: xerces/c/branches/jberry/3.0-unstable/src/xercesc/util/Transcoders/Iconv/IconvTransService.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/branches/jberry/3.0-unstable/src/xercesc/util/Transcoders/Iconv/IconvTransService.cpp?rev=189582&r1=189581&r2=189582&view=diff
==============================================================================
--- xerces/c/branches/jberry/3.0-unstable/src/xercesc/util/Transcoders/Iconv/IconvTransService.cpp (original)
+++ xerces/c/branches/jberry/3.0-unstable/src/xercesc/util/Transcoders/Iconv/IconvTransService.cpp Wed Jun 8 07:20:05 2005
@@ -278,23 +278,115 @@
return retVal;
}
+
bool IconvLCPTranscoder::transcode( const XMLCh* const toTranscode
, char* const toFill
, const unsigned int maxBytes
, MemoryManager* const manager)
{
- size_t bytesWritten, lettersConsumed;
- return transcode(toTranscode, toFill, maxBytes, bytesWritten, lettersConsumed);
+ // Watch for a couple of pyscho corner cases
+ if (!toTranscode || !maxBytes)
+ {
+ toFill[0] = 0;
+ return true;
+ }
+
+ if (!*toTranscode)
+ {
+ toFill[0] = 0;
+ return true;
+ }
+
+ unsigned int wLent = getWideCharLength(toTranscode);
+ wchar_t tmpWideCharArr[gTempBuffArraySize];
+ wchar_t* allocatedArray = 0;
+ wchar_t* wideCharBuf = 0;
+
+ if (wLent > maxBytes) {
+ wLent = maxBytes;
+ }
+
+ if (maxBytes >= gTempBuffArraySize) {
+ wideCharBuf = allocatedArray = (wchar_t*)
+ manager->allocate
+ (
+ (maxBytes + 1) * sizeof(wchar_t)
+ );//new wchar_t[maxBytes + 1];
+ }
+ else
+ wideCharBuf = tmpWideCharArr;
+
+ for (unsigned int i = 0; i < wLent; i++)
+ {
+ wideCharBuf[i] = toTranscode[i];
+ }
+ wideCharBuf[wLent] = 0x00;
+
+ // Ok, go ahead and try the transcoding. If it fails, then ...
+ size_t mblen = ::wcstombs(toFill, wideCharBuf, maxBytes);
+ if (mblen == -1)
+ {
+ manager->deallocate(allocatedArray);//delete [] allocatedArray;
+ return false;
+ }
+
+ // Cap it off just in case
+ toFill[mblen] = 0;
+ manager->deallocate(allocatedArray);//delete [] allocatedArray;
+ return true;
}
+
bool IconvLCPTranscoder::transcode( const char* const toTranscode
, XMLCh* const toFill
, const unsigned int maxChars
, MemoryManager* const manager)
{
- size_t bytesWritten, lettersConsumed;
- return transcode(toTranscode, toFill, maxBytes, bytesWritten, lettersConsumed);
+ // Check for a couple of psycho corner cases
+ if (!toTranscode || !maxChars)
+ {
+ toFill[0] = 0;
+ return true;
+ }
+
+ if (!*toTranscode)
+ {
+ toFill[0] = 0;
+ return true;
+ }
+
+ unsigned int len = calcRequiredSize(toTranscode);
+ wchar_t tmpWideCharArr[gTempBuffArraySize];
+ wchar_t* allocatedArray = 0;
+ wchar_t* wideCharBuf = 0;
+
+ if (len > maxChars) {
+ len = maxChars;
+ }
+
+ if (maxChars >= gTempBuffArraySize)
+ wideCharBuf = allocatedArray = (wchar_t*) manager->allocate
+ (
+ (maxChars + 1) * sizeof(wchar_t)
+ );//new wchar_t[maxChars + 1];
+ else
+ wideCharBuf = tmpWideCharArr;
+
+ if (::mbstowcs(wideCharBuf, toTranscode, maxChars) == -1)
+ {
+ manager->deallocate(allocatedArray);//delete [] allocatedArray;
+ return false;
+ }
+
+ for (unsigned int i = 0; i < len; i++)
+ {
+ toFill[i] = (XMLCh) wideCharBuf[i];
+ }
+ toFill[len] = 0x00;
+ manager->deallocate(allocatedArray);//delete [] allocatedArray;
+ return true;
}
+
static void reallocString(char *&ref, size_t &size, MemoryManager* const manager, bool releaseOld)
{
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org