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

void PoDoFo::PdfString::InitUtf8 (  ) [private]

Initialise the data member containing a UTF8 version of this string.

This is only done once and only if necessary.

Definition at line 538 of file PdfString.cpp.

References PoDoFo::ePdfError_OutOfMemory, PoDoFo::PdfRefCountedBuffer::GetBuffer(), GetStringUtf8(), GetUnicodeLength(), IsUnicode(), m_buffer, m_sUtf8, PODOFO_RAISE_ERROR, and ToUnicode().

{
    if( this->IsUnicode() )
    {
        // we can convert UTF16 to UTF8
        // UTF8 is at maximum 5 * characterlenght.

        pdf_long  lBufferLen = (5*this->GetUnicodeLength())+2;
        char* pBuffer    = static_cast<char*>(malloc(sizeof(char)*lBufferLen));
        if( !pBuffer )
        {
            PODOFO_RAISE_ERROR( ePdfError_OutOfMemory );
        }

        pdf_long lUtf8 = PdfString::ConvertUTF16toUTF8( reinterpret_cast<const pdf_utf16be*>(m_buffer.GetBuffer()), 
                                                    this->GetUnicodeLength(), 
                                                    reinterpret_cast<pdf_utf8*>(pBuffer), lBufferLen, ePdfStringConversion_Lenient );

        pBuffer[lUtf8-1] = '\0';
        pBuffer[lUtf8] = '\0';
        m_sUtf8 = pBuffer;
        free( pBuffer );
    }
    else
    {
        PdfString sTmp = this->ToUnicode();
        m_sUtf8 = sTmp.GetStringUtf8();
    }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index