diff --git a/honoka/src/skkdic.cpp b/honoka/src/skkdic.cpp index 9dde59f..641bdc6 100644 --- a/honoka/src/skkdic.cpp +++ b/honoka/src/skkdic.cpp @@ -53,17 +53,19 @@ okuri = false; continue; } - if (String(s).substr(0,2) == ";;") continue; + if (String(s).length() >= 2) + if (String(s).substr(0,2) == ";;") continue; vector sList; WideString wstr; iconv.convert(wstr,String(s)); + if (!wstr.length()) continue; uint pos = 0,count = 0; // "/"��split�� while(-1) { - if ((pos + count) >= wstr.size()) break; + if ((pos + count) >= wstr.length()) break; if (wstr.at(pos + count) == utf8_mbstowcs(String("/"))[0]) { if (count) sList.push_back(wstr.substr(pos,count)); - pos += count + 1; + pos += (count + 1); count = 0; continue; } @@ -72,7 +74,7 @@ // �ɤߤζ�������� // @todo okuri-ari wstr = WideString(); - if (!sList.size()) continue; + if (sList.size() < 2) continue; for(unsigned int i = 0;i < sList[0].length();i ++) { if (sList[0][i] != utf8_mbstowcs(String(" "))[0]) { wstr = wstr + sList[0][i]; @@ -80,20 +82,25 @@ } sList[0] = wstr; // ���Υơ������/����Ŧ�С� - vector dic; + SKKDicEntry dic; for(unsigned int i = 1;i < sList.size();i ++) { - SKKDicEntry e; - for(unsigned int j = 0;j < sList[i].size();j ++) { - if ((sList[i][j] == utf8_mbstowcs(String(";"))[0]) && ((j + 1) < sList[i].size()) && (j > 0)) { - e.kouho = sList[i].substr(0,j); - e.annotation = sList[i].substr(j + 1); + SKKDicEntryData e; + e.cache = false; + wstr = sList[i]; + /*if (!wstr.length()) continue; + for(unsigned int j = 1;j < (wstr.length() - 1);j ++) { + if (wstr.at(j) == utf8_mbstowcs(String(";"))[0]) { + e.annotation = wstr.substr(j + 1); + wstr = wstr.substr(0,j); break; } } - if (!e.annotation.length()) e.kouho = sList[i]; - dic.push_back(e); + //if (!e.annotation.length()) + */ + e.kouho = wstr; + dic.data.push_back(e); } - dic_data.insert(pair >(sList[0],dic)); + dic_data.insert(pair(sList[0],dic)); } fclose(f); } @@ -102,9 +109,40 @@ /*! \fn SKKDic::find(WideString text) */ -const vector SKKDic::find(WideString text) +const vector SKKDic::find(WideString text) { - map >::iterator it = dic_data.find(text); - if (it == dic_data.end()) return vector(); - return it->second; + map::iterator it = dic_data.find(text); + if (it == dic_data.end()) return vector(); + //return it->second.data; + vector d; + for(unsigned int i = 0;i < it->second.data.size();i ++) { + if (!it->second.data[i].cache) { + d.push_back(annotationParser(it->second.data[i].kouho)); + } else d.push_back(it->second.data[i]); + } + return d; +} + + +/*! + \fn SKKDic::annotationParser(WideString) + */ +SKKDicEntryData SKKDic::annotationParser(WideString l) +{ + SKKDicEntryData e; + e.cache = true; + if (l.length() <= 2) { + e.kouho = l; + return e; + } + for(unsigned int j = 1;j < (l.length() - 1);j ++) { + if (l.at(j) == utf8_mbstowcs(String(";"))[0]) { + e.annotation = l.substr(j + 1); + e.kouho = l.substr(0,j); + break; + } + } + if (!e.kouho.length()) e.kouho = l; + return e; + } diff --git a/honoka/src/skkdic.h b/honoka/src/skkdic.h index 6c7a4ef..106678c 100644 --- a/honoka/src/skkdic.h +++ b/honoka/src/skkdic.h @@ -38,23 +38,31 @@ /** @author TAM (Teppei Tamra) */ -class SKKDicEntry { +class SKKDicEntryData { public: + bool cache; WideString annotation; WideString kouho; }; +class SKKDicEntry { +public: + WideString line; + vector data; +}; + class SKKDic{ public: SKKDic(String file); ~SKKDic(); - const vector find(WideString text); + const vector find(WideString text); + SKKDicEntryData annotationParser(WideString l); protected: String filename; IConvert iconv; - map< WideString,vector > dic_data; + map dic_data; protected: void init(); }; diff --git a/honoka/src/skkdicconversion.cpp b/honoka/src/skkdicconversion.cpp index fbdb720..3155345 100644 --- a/honoka/src/skkdicconversion.cpp +++ b/honoka/src/skkdicconversion.cpp @@ -110,7 +110,7 @@ list.Yomi = buns[pos]; list.kouho.push_back(e); list.count = 1; - vector es = dic->find(buns[p]); + vector es = dic->find(buns[p]); for(unsigned int i = 0;i < es.size();i ++) { e.kanji = es[i].kouho; if (es[i].annotation.length()) {