mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Clean up Language.cpp
Use range-base for loops everywhere. Rename languagelist to languagelist_, since it is private.
This commit is contained in:
parent
bf88ad495c
commit
b8b5ed8b31
@ -288,11 +288,10 @@ bool Language::read(Lexer & lex)
|
|||||||
|
|
||||||
void Language::readLayoutTranslations(Language::TranslationMap const & trans, bool replace)
|
void Language::readLayoutTranslations(Language::TranslationMap const & trans, bool replace)
|
||||||
{
|
{
|
||||||
TranslationMap::const_iterator const end = trans.end();
|
for (auto const & t : trans) {
|
||||||
for (TranslationMap::const_iterator it = trans.begin(); it != end; ++it) {
|
|
||||||
if (replace
|
if (replace
|
||||||
|| layoutTranslations_.find(it->first) == layoutTranslations_.end())
|
|| layoutTranslations_.find(t.first) == layoutTranslations_.end())
|
||||||
layoutTranslations_[it->first] = it->second;
|
layoutTranslations_[t.first] = t.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,13 +329,13 @@ void Languages::read(FileName const & filename)
|
|||||||
static const Language ignore_lang = l;
|
static const Language ignore_lang = l;
|
||||||
ignore_language = &ignore_lang;
|
ignore_language = &ignore_lang;
|
||||||
} else
|
} else
|
||||||
languagelist[l.lang()] = l;
|
languagelist_[l.lang()] = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
default_language = getLanguage("english");
|
default_language = getLanguage("english");
|
||||||
if (!default_language) {
|
if (!default_language) {
|
||||||
LYXERR0("Default language \"english\" not found!");
|
LYXERR0("Default language \"english\" not found!");
|
||||||
default_language = &(*languagelist.begin()).second;
|
default_language = &(*languagelist_.begin()).second;
|
||||||
LYXERR0("Using \"" << default_language->lang() << "\" instead!");
|
LYXERR0("Using \"" << default_language->lang() << "\" instead!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,17 +398,15 @@ Match match(string const & code, Language const & lang)
|
|||||||
|
|
||||||
Language const * Languages::getFromCode(string const & code) const
|
Language const * Languages::getFromCode(string const & code) const
|
||||||
{
|
{
|
||||||
LanguageList::const_iterator const lbeg = languagelist.begin();
|
|
||||||
LanguageList::const_iterator const lend = languagelist.end();
|
|
||||||
// Try for exact match first
|
// Try for exact match first
|
||||||
for (LanguageList::const_iterator lit = lbeg; lit != lend; ++lit) {
|
for (auto const & l : languagelist_) {
|
||||||
if (match(code, lit->second) == ExactMatch)
|
if (match(code, l.second) == ExactMatch)
|
||||||
return &lit->second;
|
return &l.second;
|
||||||
}
|
}
|
||||||
// If not found, look for lang prefix (without country) instead
|
// If not found, look for lang prefix (without country) instead
|
||||||
for (LanguageList::const_iterator lit = lbeg; lit != lend; ++lit) {
|
for (auto const & l : languagelist_) {
|
||||||
if (match(code, lit->second) == ApproximateMatch)
|
if (match(code, l.second) == ApproximateMatch)
|
||||||
return &lit->second;
|
return &l.second;
|
||||||
}
|
}
|
||||||
LYXERR0("Unknown language `" + code + "'");
|
LYXERR0("Unknown language `" + code + "'");
|
||||||
return 0;
|
return 0;
|
||||||
@ -423,10 +420,7 @@ void Languages::readLayoutTranslations(support::FileName const & filename)
|
|||||||
lex.setContext("Languages::read");
|
lex.setContext("Languages::read");
|
||||||
|
|
||||||
// 1) read all translations (exact and approximate matches) into trans
|
// 1) read all translations (exact and approximate matches) into trans
|
||||||
typedef std::map<string, Language::TranslationMap> TransMap;
|
std::map<string, Language::TranslationMap> trans;
|
||||||
TransMap trans;
|
|
||||||
LanguageList::iterator const lbeg = languagelist.begin();
|
|
||||||
LanguageList::iterator const lend = languagelist.end();
|
|
||||||
while (lex.isOK()) {
|
while (lex.isOK()) {
|
||||||
if (!lex.checkFor("Translation")) {
|
if (!lex.checkFor("Translation")) {
|
||||||
if (lex.isOK())
|
if (lex.isOK())
|
||||||
@ -450,15 +444,12 @@ void Languages::readLayoutTranslations(support::FileName const & filename)
|
|||||||
|
|
||||||
// 2) merge all translations into the languages
|
// 2) merge all translations into the languages
|
||||||
// exact translations overwrite approximate ones
|
// exact translations overwrite approximate ones
|
||||||
TransMap::const_iterator const tbeg = trans.begin();
|
for (auto & tr : trans) {
|
||||||
TransMap::const_iterator const tend = trans.end();
|
for (auto & lang : languagelist_) {
|
||||||
for (TransMap::const_iterator tit = tbeg; tit != tend; ++tit) {
|
Match const m = match(tr.first, lang.second);
|
||||||
for (LanguageList::iterator lit = lbeg; lit != lend; ++lit) {
|
|
||||||
Match const m = match(tit->first, lit->second);
|
|
||||||
if (m == NoMatch)
|
if (m == NoMatch)
|
||||||
continue;
|
continue;
|
||||||
lit->second.readLayoutTranslations(tit->second,
|
lang.second.readLayoutTranslations(tr.second, m == ExactMatch);
|
||||||
m == ExactMatch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,8 +462,8 @@ Language const * Languages::getLanguage(string const & language) const
|
|||||||
return reset_language;
|
return reset_language;
|
||||||
if (language == "ignore")
|
if (language == "ignore")
|
||||||
return ignore_language;
|
return ignore_language;
|
||||||
const_iterator it = languagelist.find(language);
|
const_iterator it = languagelist_.find(language);
|
||||||
return it == languagelist.end() ? reset_language : &it->second;
|
return it == languagelist_.end() ? reset_language : &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,15 +174,15 @@ public:
|
|||||||
///
|
///
|
||||||
Language const * getLanguage(std::string const & language) const;
|
Language const * getLanguage(std::string const & language) const;
|
||||||
///
|
///
|
||||||
size_type size() const { return languagelist.size(); }
|
size_type size() const { return languagelist_.size(); }
|
||||||
///
|
///
|
||||||
const_iterator begin() const { return languagelist.begin(); }
|
const_iterator begin() const { return languagelist_.begin(); }
|
||||||
///
|
///
|
||||||
const_iterator end() const { return languagelist.end(); }
|
const_iterator end() const { return languagelist_.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
LanguageList languagelist;
|
LanguageList languagelist_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Global singleton instance.
|
/// Global singleton instance.
|
||||||
|
Loading…
Reference in New Issue
Block a user