-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictinfo.cpp
78 lines (73 loc) · 3.16 KB
/
dictinfo.cpp
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
#include "dictinfo.hpp"
#include <iostream>
#include <fstream>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#ifdef WIN32
#include <QtZlib/zlib.h>
#else
#include <zlib.h>
#endif
DictInfo::DictInfo()
{
}
bool DictInfo::load(const std::string& fileName)
{
std::fstream stream(fileName, std::ios::in);
if(!stream.is_open()) {
std::cerr << "file[" << fileName << "] cannot open!" << std::endl;
return false;
}
std::string val;
while(!stream.eof()) {
std::getline(stream, val);
if(val.size() == 0) {
continue;
} else if(boost::algorithm::starts_with(val,"version=")) {
boost::algorithm::replace_first(val, "version=", "");
this->version = val;
} else if(boost::algorithm::starts_with(val,"bookname=")) {
boost::algorithm::replace_first(val, "bookname=", "");
this->bookname = val;
} else if(boost::algorithm::starts_with(val,"wordcount=")) {
boost::algorithm::replace_first(val, "wordcount=", "");
this->wordcount = boost::lexical_cast<uint32_t>(val);
} else if(boost::algorithm::starts_with(val,"synwordcount=")) {
boost::algorithm::replace_first(val, "synwordcount=", "");
this->synwordcount = boost::lexical_cast<uint32_t>(val);
} else if(boost::algorithm::starts_with(val,"idxfilesize=")) {
boost::algorithm::replace_first(val, "idxfilesize=", "");
this->idxfilesize = boost::lexical_cast<uint32_t>(val);
} else if(boost::algorithm::starts_with(val,"idxoffsetbits=")) {
boost::algorithm::replace_first(val, "idxoffsetbits=", "");
this->idxoffsetbits = boost::lexical_cast<uint32_t>(val);
} else if(boost::algorithm::starts_with(val,"sametypesequence=")) {
boost::algorithm::replace_first(val, "sametypesequence=", "");
this->sametypesequence = val;
} else if(boost::algorithm::starts_with(val,"dicttype=")) {
boost::algorithm::replace_first(val, "dicttype=", "");
this->dicttype = val;
} else if(boost::algorithm::starts_with(val,"description=")) {
boost::algorithm::replace_first(val, "description=", "");
this->description = val;
} else if(boost::algorithm::starts_with(val,"copyright=")) {
boost::algorithm::replace_first(val, "copyright=", "");
this->copyright = val;
} else if(boost::algorithm::starts_with(val,"author=")) {
boost::algorithm::replace_first(val, "author=", "");
this->author = val;
} else if(boost::algorithm::starts_with(val,"email=")) {
boost::algorithm::replace_first(val, "email=", "");
this->email = val;
} else if(boost::algorithm::starts_with(val,"website=")) {
boost::algorithm::replace_first(val, "website=", "");
this->website = val;
} else if(boost::algorithm::starts_with(val,"date=")) {
boost::algorithm::replace_first(val, "date=", "");
this->date = val;
}
}
stream.close();
return true;
}