]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/frnt_lang.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / frnt_lang.C
1 /**
2  * \file frnt_lang.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13
14 #include "frnt_lang.h"
15 #include "gettext.h"
16 #include "language.h"
17
18 #include <algorithm>
19
20
21 using std::string;
22 using std::vector;
23
24
25 namespace lyx {
26 namespace frontend {
27
28 namespace {
29
30 class Sorter
31         : public std::binary_function<LanguagePair,
32                                       LanguagePair, bool>
33 {
34 public:
35         bool operator()(LanguagePair const & lhs,
36                         LanguagePair const & rhs) const {
37                 return lhs.first < rhs.first;
38         }
39 };
40
41 } // namespace anon
42
43
44 vector<LanguagePair> const getLanguageData(bool character_dlg)
45 {
46         vector<LanguagePair>::size_type const size = character_dlg ?
47                 languages.size() + 2 : languages.size();
48
49         vector<LanguagePair> langs(size);
50
51         if (character_dlg) {
52                 langs[0].first = _("No change");
53                 langs[0].second = "ignore";
54                 langs[1].first = _("Reset");
55                 langs[1].second = "reset";
56         }
57
58         vector<string>::size_type i = character_dlg ? 2 : 0;
59         for (Languages::const_iterator cit = languages.begin();
60              cit != languages.end(); ++cit) {
61                 langs[i].first  = _(cit->second.display());
62                 langs[i].second = cit->second.lang();
63                 ++i;
64         }
65
66         // Don't sort "ignore" and "reset"
67         vector<LanguagePair>::iterator begin = character_dlg ?
68                 langs.begin() + 2 : langs.begin();
69
70         std::sort(begin, langs.end(), Sorter());
71
72         return langs;
73 }
74
75 } // namespace frontend
76 } // namespace lyx