Logo Search packages:      
Sourcecode: libpodofo version File versions  Download package

PoDoFo::PdfString::PdfString ( const wchar_t *  pszString )

Construct a new PdfString from a 0 terminated string. The input string will be copied.

Parameters:
pszStringthe string to copy

Definition at line 102 of file PdfString.cpp.

References PoDoFo::ePdfError_InternalLogic, PoDoFo::PdfRefCountedBuffer::GetBuffer(), InitFromUtf8(), m_buffer, PoDoFo::PdfError::SetErrorInformation(), and SwapBytes().

    : m_bHex( false ), m_bUnicode( true ), m_pEncoding( NULL )
{
    if( pszString )
    {
      pdf_long lLen = wcslen( pszString );
      if( sizeof(wchar_t) == 2 ) 
      {
          // We have UTF16
          lLen *= sizeof(wchar_t);
          m_buffer = PdfRefCountedBuffer( lLen + 2 );
          memcpy( m_buffer.GetBuffer(), pszString, lLen );
          m_buffer.GetBuffer()[lLen] = '\0';
          m_buffer.GetBuffer()[lLen+1] = '\0';
          
          // if the buffer is a UTF-16LE string
          // convert it to UTF-16BE
#ifdef PODOFO_IS_LITTLE_ENDIAN
            SwapBytes( m_buffer.GetBuffer(), lLen );
#endif // PODOFO_IS_LITTLE_ENDIA
      }
      else
      {
          // Try to convert to UTF8
          pdf_long   lDest = 5 * lLen; // At max 5 bytes per UTF8 char
          char*  pDest = static_cast<char*>(malloc( lDest ));
          size_t cnt   = wcstombs(pDest, pszString, lDest);
          if( cnt != static_cast<size_t>(-1) )
          {
            // No error
            InitFromUtf8( reinterpret_cast<pdf_utf8*>(pDest), cnt );
            free( pDest );
          }
          else
          {
            free( pDest );
            PdfError e( ePdfError_InternalLogic, __FILE__, __LINE__ );
            e.SetErrorInformation( pszString );
            throw e;
          }
      }    
    }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index