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 PersonalWordListPart::dictfile() const
31 string fext = is_includes_ ? ".dict" : ".excl";
32 string fname = "pwl_" + lang_ + fext;
33 return FileName(addName(package().user_support().absFileName(),fname));
37 docstring_list::const_iterator PersonalWordListPart::begin() const
39 return words_.begin();
43 docstring_list::const_iterator PersonalWordListPart::end() const
49 void PersonalWordListPart::load()
51 FileName fn = dictfile();
52 LYXERR(Debug::FILES, "load personal dictionary from: " << fn);
53 ifstream ifs(fn.toFilesystemEncoding().c_str());
55 dirty(!words_.empty());
59 if (line == header()) {
62 if (!line.empty() && !(line[0] == '#')) {
63 docstring const word = from_utf8(line);
67 LYXERR(Debug::FILES, "valid dictionary file found: " << words_.size() << " items.");
69 LYXERR(Debug::FILES, "invalid dictionary file found: header is \"" << line << "\".");
76 void PersonalWordListPart::save()
80 FileName fn = dictfile();
81 LYXERR(Debug::FILES, "save personal dictionary at: " << fn);
82 ofstream ofs(fn.toFilesystemEncoding().c_str());
83 docstring_list::iterator it = words_.begin();
84 docstring_list::const_iterator et = words_.end();
86 ofs << header() << "\n";
87 for (; it != et; ++it) {
88 ofs << to_utf8(*it) << "\n";
90 LYXERR(Debug::FILES, "count of saved items: " << words_.size());
94 bool PersonalWordListPart::equalwords(docstring const & w1, docstring const & w2) const
100 bool PersonalWordListPart::exists(docstring const & word) const
102 docstring_list::const_iterator it = words_.begin();
103 docstring_list::const_iterator et = words_.end();
104 for (; it != et; ++it) {
105 if (equalwords(word,*it))
112 void PersonalWordListPart::insert(docstring const & word)
116 words_.push_back(word);
121 void PersonalWordListPart::remove(docstring const & word)
123 docstring_list::iterator it = words_.begin();
124 docstring_list::const_iterator et = words_.end();
125 for (; it != et; ++it) {
126 if (equalwords(word,*it)) {