]> git.lyx.org Git - lyx.git/blob - src/Thesaurus.C
* GuiView.C (updateTab): do not update early if current tab has
[lyx.git] / src / Thesaurus.C
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  */
10
11 #include <config.h>
12
13 #include "Thesaurus.h"
14
15 #include "support/lstrings.h"
16
17 #include <algorithm>
18
19
20 namespace lyx {
21
22 #ifdef HAVE_LIBAIKSAURUS
23
24 using std::sort;
25 using std::string;
26
27
28 Thesaurus::Thesaurus()
29         : aik_(new Aiksaurus)
30 {}
31
32
33 Thesaurus::~Thesaurus()
34 {
35         delete aik_;
36 }
37
38
39 Thesaurus::Meanings Thesaurus::lookup(docstring const & t)
40 {
41         Meanings meanings;
42
43         // aiksaurus is for english text only, therefore it does not work
44         // with non-ascii strings.
45         // The interface of the Thesaurus class uses docstring because a
46         // non-english thesaurus is possible in theory.
47         if (!support::isAscii(t))
48                 // to_ascii() would assert
49                 return meanings;
50
51         string const text = to_ascii(t);
52         if (!aik_->find(text.c_str()))
53                 return meanings;
54
55         // weird api, but ...
56
57         int prev_meaning = -1;
58         int cur_meaning;
59         docstring meaning;
60
61         // correct, returns "" at the end
62         string ret = aik_->next(cur_meaning);
63
64         while (!ret.empty()) {
65                 if (cur_meaning != prev_meaning) {
66                         meaning = from_ascii(ret);
67                         ret = aik_->next(cur_meaning);
68                         prev_meaning = cur_meaning;
69                 } else {
70                         if (ret != text)
71                                 meanings[meaning].push_back(from_ascii(ret));
72                 }
73
74                 ret = aik_->next(cur_meaning);
75         }
76
77         for (Meanings::iterator it = meanings.begin();
78              it != meanings.end(); ++it)
79                 sort(it->second.begin(), it->second.end());
80
81         return meanings;
82 }
83
84 #else
85
86 Thesaurus::Thesaurus()
87 {
88 }
89
90
91 Thesaurus::~Thesaurus()
92 {
93 }
94
95
96 Thesaurus::Meanings Thesaurus::lookup(docstring const &)
97 {
98         return Meanings();
99 }
100
101 #endif // HAVE_LIBAIKSAURUS
102
103 // Global instance
104 Thesaurus thesaurus;
105
106
107 } // namespace lyx