View | Details | Raw Unified | Return to issue 11215
Collapse All | Expand All

(-) (+87 lines)
Added Link Here
1
#include <doc.hxx>
2
#include <shellio.hxx>
3
#include <fltini.hxx>
4
#include <swtypes.hxx>
5
#include <pam.hxx>
6
#include <swerror.h>
7
8
class LwpParser
9
{
10
    SwDoc* pDoc;   
11
    SwPaM* pPam;
12
    SvStream& rInput;
13
    
14
public:
15
    LwpParser( SwDoc *pDoc, const SwPaM& rPoint, SvStream& rIn );
16
    ULONG CallParser();
17
    void readString( String &rString, int nCount );	
18
    bool CheckValidData( UINT8 nChar );
19
};
20
21
ULONG LwpReader::Read( SwDoc &rDoc, const String&, SwPaM &rPam, const String & )
22
{
23
    if( !pStrm )
24
        return ERR_SWG_READ_ERROR;
25
    LwpParser* aParser = new LwpParser( &rDoc, rPam, *pStrm );
26
    ULONG nRet = aParser->CallParser();
27
28
    return nRet;
29
}
30
31
LwpParser::LwpParser( SwDoc* rDoc, const SwPaM& rPam, SvStream& pIn ):
32
	pDoc( rDoc ), rInput( pIn )
33
{
34
	pPam = new SwPaM( *rPam.GetPoint() );
35
}
36
37
ULONG LwpParser::CallParser()
38
{
39
    UINT8 nDelim, nDummy, nLen, nData;
40
    UINT16 nOpcode;
41
    int nCount = 0;
42
    while( !rInput.IsEof())
43
    {
44
	rInput >> nDelim;
45
	if( nDelim == 0x40 )
46
	{
47
	    rInput >> nDummy >> nOpcode;
48
	    switch( nOpcode )
49
	    {
50
		case 0xC00B:  // Dictionary Word
51
		    rInput >> nLen >> nDummy;
52
		    while( nLen > 0 && !rInput.IsEof() )
53
		    {
54
			UINT8 nChar;
55
			rInput >> nChar;
56
			if( CheckValidData( nChar ) )
57
			    pDoc-> Insert( *pPam, nChar ); 	
58
			nLen--;
59
		    }
60
		    break;
61
		
62
		case 0x0242:  // Non Dictionary word
63
			rInput >> nData;
64
			if( nData == 0x02 )
65
			{ 
66
			    rInput >> nLen >> nDummy;
67
			    while( nLen > 0 && !rInput.IsEof() )
68
			    {
69
				rInput >> nData;
70
				if( CheckValidData( nData ) )
71
				    pDoc->Insert( *pPam, nData );
72
				nLen--;
73
			    }
74
			}
75
			break;
76
	    }
77
	}   
78
    }   
79
return 0;
80
}            
81
82
bool LwpParser::CheckValidData( UINT8 nChar )
83
{
84
    if( ( nChar >= 0x20 && nChar <= 0x7E ) && ( nChar != 0X40 ) )
85
        return  true;
86
    return false;				   
87
} 

Return to issue 11215