summaryrefslogtreecommitdiff
path: root/src/rtfparser.h
blob: f28150e474e410356f0db27b4279eba13b504948 (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
77
78
79
80
// RtfReader.h: interface for the RtfReader class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_RTFREADER_H__2C77784F_5333_4E16_B0E0_B56E211C2D82__INCLUDED_)
#define AFX_RTFREADER_H__2C77784F_5333_4E16_B0E0_B56E211C2D82__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <mystring.h>
#include <stack>
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 // !defined(AFX_RTFREADER_H__2C77784F_5333_4E16_B0E0_B56E211C2D82__INCLUDED_)