Skip to content

Commit e30422a

Browse files
committed
improve 3
1 parent 8a7613b commit e30422a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Dictionary.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -629,20 +629,24 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
629629
// タブで分割する。
630630
std::vector<XGStringW> fields;
631631
mstr_split(fields, line, L"\t");
632-
633632
if (fields.empty())
634633
continue;
635634

635+
// 単語を正規化する。
636636
auto strWord = XgNormalizeString(fields[0]);
637637
auto strNormalized = XgNormalizeString(strWord);
638638

639+
// 正規化された単語が見つかったか?
639640
auto it = word_to_hint_map.find(strNormalized);
640641
if (it != word_to_hint_map.end()) {
642+
// 見つかったら、フィールドを更新。
641643
if (fields.size() >= 2)
642644
fields[1] = it->second;
643645
else
644646
fields.push_back(it->second);
647+
// 写像から削除。
645648
word_to_hint_map.erase(it);
649+
// 必要なら変更する。
646650
auto strNew = mstr_join(fields, L"\t");
647651
if (line != strNew) {
648652
line = strNew;
@@ -651,6 +655,7 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
651655
}
652656
}
653657

658+
// 辞書になかった単語を追記する。
654659
for (auto& pair : word_to_hint_map) {
655660
XGStringW line = XgNormalizeStringEx(pair.first, TRUE, TRUE);
656661
line += L'\t';
@@ -660,7 +665,7 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
660665
bNoChange = FALSE;
661666
}
662667

663-
if (bNoChange) {
668+
if (bNoChange) { // 変更なし。
664669
XgCenterMessageBoxW(hwnd, XgLoadStringDx1(IDS_NOCHANGE),
665670
XgLoadStringDx2(IDS_APPNAME), MB_ICONINFORMATION);
666671
return FALSE;
@@ -678,14 +683,15 @@ BOOL XgUpdateDictionaryUsingClues(HWND hwnd, const XGStringW& dict_name)
678683

679684
fprintf(fp, "\xEF\xBB\xBF"); // UTF-8 BOM
680685

686+
// 一行ずつ書き込む。
681687
for (auto& line : lines) {
682688
auto psz = XgUnicodeToUtf8(line).c_str();
683689
if (!*psz)
684690
continue;
685691
fprintf(fp, "%s\n", psz);
686692
}
687693

688-
fclose(fp);
694+
fclose(fp); // ちゃんとファイルを閉じようね。
689695

690696
// 成功メッセージ。
691697
StringCchPrintfW(szText, _countof(szText), XgLoadStringDx1(IDS_UPDATEDICTOK),

0 commit comments

Comments
 (0)