Consider the case where there is not any layout name.
[lyx.git] / src / Thesaurus.C
blob562bd748835c6109a6d8c69a6e5f551f6be848fa
1 /**
2  * \file Thesaurus.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
11 #include <config.h>
13 #include "Thesaurus.h"
15 #include <algorithm>
16 #include <string>
18 using std::string;
20 #ifdef HAVE_LIBAIKSAURUS
22 using std::sort;
25 Thesaurus::Thesaurus()
26         : aik_(new Aiksaurus)
30 Thesaurus::~Thesaurus()
32         delete aik_;
36 Thesaurus::Meanings Thesaurus::lookup(string const & text)
38         Meanings meanings;
40         if (!aik_->find(text.c_str()))
41                 return meanings;
43         // weird api, but ...
45         int prev_meaning = -1;
46         int cur_meaning;
47         string meaning;
49         // correct, returns "" at the end
50         string ret = aik_->next(cur_meaning);
52         while (!ret.empty()) {
53                 if (cur_meaning != prev_meaning) {
54                         meaning = ret;
55                         ret = aik_->next(cur_meaning);
56                         prev_meaning = cur_meaning;
57                 } else {
58                         if (ret != text) {
59                                 meanings[meaning].push_back(ret);
60                         }
61                 }
63                 ret = aik_->next(cur_meaning);
64         }
66         for (Meanings::iterator it = meanings.begin();
67                 it != meanings.end(); ++it) {
68                         sort(it->second.begin(), it->second.end());
69         }
71         return meanings;
74 #else
76 Thesaurus::Thesaurus()
81 Thesaurus::~Thesaurus()
86 Thesaurus::Meanings Thesaurus::lookup(string const &)
88         return Meanings();
91 #endif // HAVE_LIBAIKSAURUS
93 // Global instance
94 Thesaurus thesaurus;