2 * \file PersonalWordList.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "PersonalWordList.h"
15 #include "support/debug.h"
16 #include "support/docstring_list.h"
17 #include "support/filetools.h"
18 #include "support/Package.h"
19 #include "support/FileName.h"
20 #include "support/lstrings.h"
21 #include "support/os.h"
27 using namespace lyx::support;
28 using namespace lyx::support::os;
32 FileName PersonalWordList::dictfile() const
34 string fname = "pwl_" + lang_ + ".dict";
35 return FileName(addName(package().user_support().absFileName(),fname));
39 docstring_list::const_iterator PersonalWordList::begin() const
41 return words_.begin();
45 docstring_list::const_iterator PersonalWordList::end() const
51 void PersonalWordList::load()
53 FileName fn = dictfile();
54 LYXERR(Debug::FILES, "load personal dictionary from: " << fn);
55 ifstream ifs(fn.toFilesystemEncoding().c_str());
57 dirty(words_.size() > 0);
61 if (line == header()) {
64 if (!line.empty() && !(line[0] == '#')) {
65 docstring const word = from_utf8(line);
69 LYXERR(Debug::FILES, "valid dictionary file found: " << words_.size() << " items.");
71 LYXERR(Debug::FILES, "invalid dictionary file found: header is \"" << line << "\".");
78 void PersonalWordList::save()
82 FileName fn = dictfile();
83 LYXERR(Debug::FILES, "save personal dictionary at: " << fn);
84 ofstream ofs(fn.toFilesystemEncoding().c_str());
85 docstring_list::iterator it = words_.begin();
86 docstring_list::const_iterator et = words_.end();
88 ofs << header() << "\n";
89 for (; it != et; ++it) {
90 ofs << to_utf8(*it) << "\n";
92 LYXERR(Debug::FILES, "count of saved items: " << words_.size());
96 bool PersonalWordList::equalwords(docstring const & w1, docstring const & w2) const
102 bool PersonalWordList::exists(docstring const & word) const
104 docstring_list::const_iterator it = words_.begin();
105 docstring_list::const_iterator et = words_.end();
106 for (; it != et; ++it) {
107 if (equalwords(word,*it))
114 void PersonalWordList::insert(docstring const & word)
118 words_.push_back(word);
123 void PersonalWordList::remove(docstring const & word)
125 docstring_list::iterator it = words_.begin();
126 docstring_list::const_iterator et = words_.end();
127 for (; it != et; ++it) {
128 if (equalwords(word,*it)) {