Beispiel #1
0
	bool convert(int srcCodepage, int dstCodepage, const unsigned char * src, size_t * srcbytes, unsigned char * dest, size_t * destbytes)
	{
		bool bsucceeded;
#ifdef POCO_ARCH_BIG_ENDIAN
		if (srcCodepage == ucr::CP_UCS2BE)
#else
		if (srcCodepage == ucr::CP_UCS2LE)
#endif
		{
			size_t srcwchars = *srcbytes / sizeof(wchar_t);
			bsucceeded = convertFromUnicode(dstCodepage, (const wchar_t *)src, &srcwchars, (char *)dest, destbytes);
			*srcbytes = srcwchars * sizeof(wchar_t);
		}
		else
		{
			size_t wsize = *srcbytes * 2 + 6;
			std::unique_ptr<wchar_t[]> pbuf(new wchar_t[wsize]);
			bsucceeded = convertToUnicode(srcCodepage, (const char *)src, srcbytes, pbuf.get(), &wsize);
			if (!bsucceeded)
			{
				*destbytes = 0;
				return false;
			}
			bsucceeded = convertFromUnicode(dstCodepage, pbuf.get(), &wsize, (char *)dest, destbytes);
		}
		return bsucceeded;
	}
Beispiel #2
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Set data element as a string
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void dataHandlerString::setString(const imbxUint32 index, const std::string& value)
{
	PUNTOEXE_FUNCTION_START(L"dataHandlerString::setString");

	setUnicodeString(index, convertToUnicode(value));

	PUNTOEXE_FUNCTION_END();
}
Beispiel #3
0
  size_t CodePage2UnicodeConverter::convertBytes(UChar * pclTarget,
      size_t uiTargetMaxSize,
      const char * cpacSource,
      size_t uiSourceSize)
  /* ----------------------------------------------------------------------- */

  {
    size_t                     uiTargetSize;
    uiTargetSize = convertToUnicode(pclTarget, uiTargetMaxSize, cpacSource, uiSourceSize);
    return(uiSourceSize);
  }
/*!
    \overload

    \a chars contains the source characters.
*/
QString QTextCodec::toUnicode(const char *chars) const
{
    int len = qstrlen(chars);
    return convertToUnicode(chars, len, 0);
}
/*!
    \overload

    \a a contains the source characters; \a len contains the number of
    characters in \a a to use.
*/
QString QTextCodec::toUnicode(const QByteArray& a, int len) const
{
    len = qMin(a.size(), len);
    return convertToUnicode(a.constData(), len, 0);
}
/*!
    Converts \a a from the encoding of this codec to Unicode, and
    returns the result in a QString.
*/
QString QTextCodec::toUnicode(const QByteArray& a) const
{
    return convertToUnicode(a.constData(), a.length(), 0);
}
Beispiel #7
0
/*  7.4  */
WML_STATUS WML_GetDTDID(UINT32      iBytes,
                        const BYTE* wmlDoc,
                        const char* iCharEnc,
                        UINT16      idBufLenU16,
                        UINT16    * publicID,
                        UINT16    * systemID)
{
/*
-----------------------------------------------------------------------------
*/
/*  Data structures */

  WML_STATUS	rc = WML_OK;
  SEncBuffers _buffers;
  WCHAR*		_uBuffer;

/* Code */

  /***** CHECK ARGUMENTS *****/
  if(!s_isInitialized) {
      wmlLOGs(WSL_LOG_ERROR, "Not initialized");
      return WML_ERROR_NOT_INITIALIZED;
  }

  if(!wmlDoc || !iCharEnc || !publicID || !systemID) {
      wmlLOGs(WSL_LOG_ERROR, "WML_GetDTDID: NULL pointer as argument");
      return WML_ERROR_EMPTY_ARG;
  }

  if((!iBytes) || (iBytes>=XML_BUFFER_SIZE)) {
      wmlLOGs(WSL_LOG_ERROR, "WML_GetDTDID: Invalid buffer size.");
      return WML_ERROR_INVALID_BUFFER_SIZE;
  }


  if(!getCharEncoding(iCharEnc)) {
      wmlLOGss(WSL_LOG_ERROR, "Unknown character encoding: ",iCharEnc);
      return WML_ERROR_INVALID_ENCODING;
  }

  /***** PREPARE THE BUFFERS *****/
  _uBuffer           = XML_ALLOC((sizeof(WCHAR)*iBytes)+20);
  _buffers.m_enc     = getCharEncoding(iCharEnc);
  _buffers.m_src     = wmlDoc;
  _buffers.m_srcSize = iBytes;
  _buffers.m_dst     = _uBuffer;
  _buffers.m_dstSize = iBytes+(20/sizeof(WCHAR));

  /***** CONVERT *****/
  if(!convertToUnicode(&_buffers)) {
      rc = WML_ERROR_CONVERSION_FAILED;
  }
  /***** XML *****/
  else if(!getDTDID(0,
                    _uBuffer,
                    _buffers.m_dstSize,
                    idBufLenU16,
                    publicID,
                    systemID)) {
      rc = WML_ERROR_XMLPARSER_FAILED;
  }
  else {
      rc = WML_OK;
  }

  /***** RELEASE MEMORY *****/

  XML_FREE(_uBuffer);

  return rc;
}
Beispiel #8
0
/*  7.3  */
WML_STATUS WML_Encode(UINT32        iBytes,
                      const BYTE *  wmlDoc,
                      const char *  iCharEnc,
                      UINT32     *  oBytes,
                      BYTE       *  binDoc,
                      const char *  oCharEnc,
                      int        *  arraySize,
                      UINT16     ** metaHttpEquiv,
                      int        *  stringLength,
                      UINT16     ** metaContent,
                      const char *  altDTDID,
                      const BYTE *  URLofDoc)
{
/*
-----------------------------------------------------------------------------
*/
/*  Data structures */

  WML_STATUS	rc = WML_OK;
  SEncBuffers _buffers;
  WCHAR*		_uBuffer;
  SDocData   * _pWmlData;
  UINT32       _oSize = 0;

/* Code */

  if(oBytes) {
      _oSize  = *oBytes;
      *oBytes = 0;
  }


  /***** CHECK ARGUMENTS *****/
  if(!s_isInitialized) {
      wmlLOGs(WSL_LOG_ERROR, "Not initialized");
      return WML_ERROR_NOT_INITIALIZED;
  }

  if( !wmlDoc || !binDoc || !iCharEnc || !oCharEnc || !oBytes) {
      wmlLOGs(WSL_LOG_ERROR, "WML_Encode: NULL pointer as argument");
      return WML_ERROR_EMPTY_ARG;
  }

  if(!iBytes ||  !_oSize || (iBytes>=XML_BUFFER_SIZE)) {
      wmlLOGs(WSL_LOG_ERROR, "WML_Encode: Invalid buffer size.");
      return WML_ERROR_INVALID_BUFFER_SIZE;
  }

  if(!getCharEncoding(iCharEnc)) {
      wmlLOGss(WSL_LOG_ERROR,
             "WML_Encode: Character set does not exist: ",iCharEnc);
      return WML_ERROR_INVALID_ENCODING;
  }

  if(!getCharEncoding(oCharEnc)) {
      wmlLOGss(WSL_LOG_ERROR,
             "WML_Encode: Character set does not exist: ",oCharEnc);
      return WML_ERROR_INVALID_ENCODING;
  }

  /***** PREPARE THE BUFFERS *****/
  _uBuffer           = XML_ALLOC(sizeof(WCHAR)*iBytes);
  _buffers.m_enc     = getCharEncoding(iCharEnc);
  _buffers.m_src     = wmlDoc;
  _buffers.m_srcSize = iBytes;
  _buffers.m_dst     = _uBuffer;
  _buffers.m_dstSize = iBytes;

  /***** CONVERT *****/
  if(!convertToUnicode(&_buffers)) {
      XML_FREE(_uBuffer);
      return WML_ERROR_CONVERSION_FAILED;
  }

  /***** DATA STRUCTURES FOR CALLBACK FUNCTIONS *****/
  _pWmlData = newSDocData(oCharEnc,
                          oBytes,
                          binDoc,
                          arraySize,
                          metaHttpEquiv,
                          stringLength,
                          metaContent,
                          URLofDoc);

  /***** XML - WML *****/
  if (parseXML(_pWmlData,
               _uBuffer,
               _buffers.m_dstSize,
               TokenHandler,
               ErrorHandler,
               altDTDID,
               URLofDoc) != 0) {

      if(_pWmlData->m_error) {
          rc = _pWmlData->m_error;
      }
      else if(FIFO_EMPTY(_pWmlData->m_eventList)) {
          rc = WML_ERROR_XMLPARSER_FAILED;
      }
      else {
          *oBytes = _oSize;
          rc = isValidWMLDocument(_pWmlData);
          if(rc!=WML_OK) {
              *oBytes = 0;
          }
      }
  }
  else {
      rc = WML_ERROR_XMLPARSER_FAILED;
      if(_pWmlData->m_error) {
          rc = _pWmlData->m_error;
      }
  }

  /***** RELEASE MEMORY *****/
  deleteSDocData(_pWmlData);

  XML_FREE(_uBuffer);

  return rc;
}