5 #include "ConfigHolder.h"
15 std::string dictName
= configHolder
.dictFile().c_str();
16 std::ifstream
ifs(dictName
.c_str());
22 std::getline(ifs
,lineStr
);
23 if( dictItem
.refer(lineStr
) )
24 dict
[dictItem
.getW()] = lineStr
;
27 ifsgdic
= new std::ifstream("/usr/share/FreeRecite/freeRecite.dict");
28 if(!ifsgdic
->is_open())
34 bool Dict::lookUp(const std::string
&word
) {
35 //Find in local dictionary.
36 std::map
<std::string
,std::string
>::iterator itr
= dict
.find(word
);
37 if( itr
!= dict
.end() ) {
38 dictItem
.refer(itr
->second
);
42 //Find in global dictionary.
43 return findInGlobl(word
);
46 bool Dict::findInGlobl(const std::string
&swatch
) {
48 ifsgdic
->seekg(0,std::ios::end
);
49 int length
= ifsgdic
->tellg();
54 while(after
-before
>1) {
55 ifsgdic
->seekg((after
+before
)/2);
56 ifsgdic
->ignore(std::numeric_limits
<int>::max(),'\n');
57 current
= ifsgdic
->tellg();
58 getline(*ifsgdic
,line
);
59 if(!dictItem
.refer(line
))
61 if(swatch
> dictItem
.getW())
62 before
= (after
+before
)/2;
63 else if(swatch
< dictItem
.getW())
64 after
= (after
+before
)/2;
65 else if( swatch
== dictItem
.getW() )
70 getline(*ifsgdic
,line
);
71 if(swatch
== dictItem
.getW())
77 bool Dict::modify(const std::string
&item
) {
78 static DictItem itemAdd
;
80 if(!itemAdd
.refer(item
)){
84 dict
[itemAdd
.getW()] = item
;
92 std::ofstream
ofs(configHolder
.dictFile().c_str());
96 std::map
<std::string
,std::string
>::const_iterator itr
= dict
.begin();
97 while(itr
!= dict
.end()) {
101 ofs
<< itr
->second
<< std::endl
;
107 const std::string
&Dict::phonetics() const {
108 static std::string __phonetics
;
110 for(unsigned i
= 0; i
< dictItem
.getT().size(); ++i
) {
111 switch(dictItem
.getT().at(i
)) {
149 __phonetics
+= dictItem
.getT().at(i
);
155 //This is a global variable.
158 } //namespace freeRecite end