update dict
[QFreeRecite.git] / src / core / DictItem.cpp
blob994069281fc797a2940ce0fc75d0a2f4b7a9e752
1 #include "DictItem.h"
3 namespace freeRecite {
5 //Initialize the const static members of DictItem.
7 const std::string DictItem::sW("[W]");
8 const std::string DictItem::sT("[T]");
9 const std::string DictItem::sM("[M]");
10 const std::string DictItem::sE("[E]");
11 const int DictItem::offset(3);
14 bool DictItem::refer(const std::string &str) {
16 posW = str.find(DictItem::sW);
17 posT = str.find(DictItem::sT);
18 posM = str.find(DictItem::sM);
19 posE = str.find(DictItem::sE);
21 if(posW == std::string::npos
22 || posT == std::string::npos
23 || posM == std::string::npos) {
24 strItem = 0;
25 return false;
28 strItem = &str;
30 bufW = strItem->substr(posW+offset,posT-posW-offset);
31 bufT = strItem->substr(posT+offset,posM-posT-offset);
32 if(posE == std::string::npos){
33 bufM = strItem->substr(posM+offset,strItem->size()-posM-offset);
34 bufE = std::string("");
35 }else {
36 bufM = strItem->substr(posM+offset,posE-posM-offset);
37 bufE = strItem->substr(posE+offset,strItem->size()-posE-offset);
40 return true;
43 } // namespace freeRecite end