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"
25 using namespace lyx::support;
29 FileName PersonalWordList::dictfile() const
31 string fname = "pwl_" + lang_ + ".dict";
32 return FileName(addName(package().user_support().absFileName(),fname));
36 docstring_list::const_iterator PersonalWordList::begin() const
38 return words_.begin();
42 docstring_list::const_iterator PersonalWordList::end() const
48 void PersonalWordList::load()
50 FileName fn = dictfile();
51 LYXERR(Debug::FILES, "load personal dictionary from: " << fn);
52 ifstream ifs(fn.toFilesystemEncoding().c_str());
54 dirty(!words_.empty());
58 if (line == header()) {
61 if (!line.empty() && !(line[0] == '#')) {
62 docstring const word = from_utf8(line);
66 LYXERR(Debug::FILES, "valid dictionary file found: " << words_.size() << " items.");
68 LYXERR(Debug::FILES, "invalid dictionary file found: header is \"" << line << "\".");
75 void PersonalWordList::save()
79 FileName fn = dictfile();
80 LYXERR(Debug::FILES, "save personal dictionary at: " << fn);
81 ofstream ofs(fn.toFilesystemEncoding().c_str());
82 docstring_list::iterator it = words_.begin();
83 docstring_list::const_iterator et = words_.end();
85 ofs << header() << "\n";
86 for (; it != et; ++it) {
87 ofs << to_utf8(*it) << "\n";
89 LYXERR(Debug::FILES, "count of saved items: " << words_.size());
93 bool PersonalWordList::equalwords(docstring const & w1, docstring const & w2) const
99 bool PersonalWordList::exists(docstring const & word) const
101 docstring_list::const_iterator it = words_.begin();
102 docstring_list::const_iterator et = words_.end();
103 for (; it != et; ++it) {
104 if (equalwords(word,*it))
111 void PersonalWordList::insert(docstring const & word)
115 words_.push_back(word);
120 void PersonalWordList::remove(docstring const & word)
122 docstring_list::iterator it = words_.begin();
123 docstring_list::const_iterator et = words_.end();
124 for (; it != et; ++it) {
125 if (equalwords(word,*it)) {