--- /dev/null 2004-08-25 23:04:59.000000000 +0530 +++ sw/source/filter/lwp/lwpparser.cxx 2005-05-02 15:23:25.578659656 +0530 @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include + +class LwpParser +{ + SwDoc* pDoc; + SwPaM* pPam; + SvStream& rInput; + +public: + LwpParser( SwDoc *pDoc, const SwPaM& rPoint, SvStream& rIn ); + ULONG CallParser(); + void readString( String &rString, int nCount ); + bool CheckValidData( UINT8 nChar ); +}; + +ULONG LwpReader::Read( SwDoc &rDoc, const String&, SwPaM &rPam, const String & ) +{ + if( !pStrm ) + return ERR_SWG_READ_ERROR; + LwpParser* aParser = new LwpParser( &rDoc, rPam, *pStrm ); + ULONG nRet = aParser->CallParser(); + + return nRet; +} + +LwpParser::LwpParser( SwDoc* rDoc, const SwPaM& rPam, SvStream& pIn ): + pDoc( rDoc ), rInput( pIn ) +{ + pPam = new SwPaM( *rPam.GetPoint() ); +} + +ULONG LwpParser::CallParser() +{ + UINT8 nDelim, nDummy, nLen, nData; + UINT16 nOpcode; + int nCount = 0; + while( !rInput.IsEof()) + { + rInput >> nDelim; + if( nDelim == 0x40 ) + { + rInput >> nDummy >> nOpcode; + switch( nOpcode ) + { + case 0xC00B: // Dictionary Word + rInput >> nLen >> nDummy; + while( nLen > 0 && !rInput.IsEof() ) + { + UINT8 nChar; + rInput >> nChar; + if( CheckValidData( nChar ) ) + pDoc-> Insert( *pPam, nChar ); + nLen--; + } + break; + + case 0x0242: // Non Dictionary word + rInput >> nData; + if( nData == 0x02 ) + { + rInput >> nLen >> nDummy; + while( nLen > 0 && !rInput.IsEof() ) + { + rInput >> nData; + if( CheckValidData( nData ) ) + pDoc->Insert( *pPam, nData ); + nLen--; + } + } + break; + } + } + } +return 0; +} + +bool LwpParser::CheckValidData( UINT8 nChar ) +{ + if( ( nChar >= 0x20 && nChar <= 0x7E ) && ( nChar != 0X40 ) ) + return true; + return false; +}