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

void PoDoFo::PdfParser::FindToken ( const char *  pszToken,
const long  lRange 
) [protected]

Searches backwards from the end of the file and tries to find a token. The current file is positioned right after the token.

pszTokena token to find
lRangerange in bytes in which to search begining at the end of the file

Definition at line 1080 of file PdfParser.cpp.

References PoDoFo::PdfRefCountedInputDevice::Device(), PoDoFo::PdfInputDevice::Eof(), PoDoFo::ePdfError_InternalLogic, PoDoFo::ePdfError_NoXRef, PoDoFo::PdfRefCountedBuffer::GetBuffer(), PoDoFo::PDF_MIN(), PODOFO_RAISE_ERROR, PODOFO_RAISE_ERROR_INFO, PoDoFo::PdfInputDevice::Read(), PoDoFo::PdfInputDevice::Seek(), and PoDoFo::PdfInputDevice::Tell().

Referenced by ReadTrailer(), ReadXRef(), and ReadXRefContents().

    m_device.Device()->Seek( 0, std::ios_base::end );

    std::streamoff nFileSize = m_device.Device()->Tell();
    if (nFileSize == -1)
                "Failed to seek to EOF when looking for xref");

    pdf_long lXRefBuf  = PDF_MIN( static_cast<pdf_long>(nFileSize), static_cast<pdf_long>(lRange) );
    size_t   nTokenLen = strlen( pszToken );

    m_device.Device()->Seek( -lXRefBuf, std::ios_base::cur );
    if( m_device.Device()->Read( m_buffer.GetBuffer(), lXRefBuf ) != lXRefBuf && !m_device.Device()->Eof() )
        PODOFO_RAISE_ERROR( ePdfError_NoXRef );

    m_buffer.GetBuffer()[lXRefBuf] = '\0';

    int i; // Do not make this unsigned, this will cause infinte loops in files without trailer
    // search backwards in the buffer in case the buffer contains null bytes
    // because it is right after a stream (can't use strstr for this reason)
    for( i = lXRefBuf - nTokenLen; i >= 0; i-- )
        if( strncmp( m_buffer.GetBuffer()+i, pszToken, nTokenLen ) == 0 )

    if( !i )
        PODOFO_RAISE_ERROR( ePdfError_InternalLogic );

    m_device.Device()->Seek( (lXRefBuf-i)*-1, std::ios_base::end );

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  Doxygen 1.6.0   Back to index