-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRtfReader.cpp
More file actions
51 lines (46 loc) · 1.08 KB
/
RtfReader.cpp
File metadata and controls
51 lines (46 loc) · 1.08 KB
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
#include <sstream>
#include "RtfReader.h"
#include "cpp/text.h"
using namespace std;
bool RtfReader::RtfStream2TextString(string &outstring, istream &instream)
{
using namespace format;
try
{
// "{\r" at the beginning, the RTF file is considered
char head[3] = { 0 };
instream.read(head, sizeof(head));
if (head[0] != '{' || head[1] != '\\' || head[2] != 'r')
{
return false;
}
instream.seekg(0, ios::beg);
utils::stream_logger log(cerr, true, true, true);
utils::stream_source src(instream);
std::stringstream stream;
RtfReader::text proc(stream);
parsers::rtf parser(src, proc, log);
outstring = stream.str();
}
catch (...)
{
return false;
}
return true;
}
bool RtfReader::RtfString2TextString(string &outstring, const string &instring)
{
std::stringstream instream(instring);
return RtfStream2TextString(outstring, instream);
}
bool RtfReader::RtfFile2TextString(string &outstring, const char * filename)
{
ifstream file(filename);
if (file.is_open())
{
bool ret = RtfStream2TextString(outstring, file);
file.close();
return ret;
}
return false;
}