blob: 4fe18046218d28c9c2a8caca679fff2308d0409a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#ifndef __RTFREADER_H__
#define __RTFREADER_H__
#include <string>
#include <stack>
using std::string;
using std::wstring;
class RtfReader;
class RtfHandler
{
public:
virtual void startDocument(RtfReader* reader) = 0;
virtual void endDocument() = 0;
virtual void controlWord(const string& cw, int flags, int param) = 0;
virtual void groupStart() = 0;
virtual void groupEnd() = 0;
virtual void charData(wstring data) = 0;
static const int kAsterisk;
static const int kHasParam;
static const int kIsEncoded;
};
class RtfReader
{
public:
RtfReader();
virtual ~RtfReader();
bool parse(string fileName);
bool parse(FILE* file);
void setHandler(RtfHandler* handler)
{ m_handler = handler; }
string getParseErrors() const
{ return m_parseErrors; }
int getDepth() const
{ return m_depth; }
void setHexParse(bool parse)
{ m_parseHex = parse; }
void setUnicode(bool unicode);
protected:
RtfHandler* m_handler;
int m_depth;
bool m_parseHex;
string m_parseErrors;
// Unicode handling
bool m_parseUnicode;
typedef std::stack<int> StackInt;
StackInt m_uniEatStack;
int m_uniEat;
private:
struct RtfContext
{
FILE* file;
bool isData;
wstring data;
};
bool parseControlWord(RtfContext& cx);
bool parseHexChar(RtfContext& cx, int num);
void sendControlWord(RtfContext& cx, string cw, int flags, int param);
void sendData(RtfContext& cx, wchar_t ch);
void sendData(RtfContext& cx, wstring data);
void emptyData(RtfContext& cx);
};
#endif // __RTFREADER_H__
|