- Coding style

- Move local functions closer to where they are used.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39296 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2011-07-14 08:47:56 +00:00
parent bf92e48ada
commit dba4f28b62

View File

@ -28,7 +28,6 @@
using namespace std;
using namespace lyx::support;
namespace lyx {
Languages languages;
@ -194,57 +193,14 @@ bool Language::read(Lexer & lex)
}
namespace {
bool readTranslations(Lexer & lex, Language::TranslationMap & trans)
{
while (lex.isOK()) {
if (lex.checkFor("End"))
break;
if (!lex.next(true))
return false;
string const key = lex.getString();
if (!lex.next(true))
return false;
docstring const val = lex.getDocString();
trans[key] = val;
}
return true;
}
enum Match{NoMatch, ApproximateMatch, ExactMatch};
Match match(string const & code, Language const & lang)
{
// we need to mimic gettext: code can be a two-letter code, which
// should match all variants, e.g. "de" should match "de_DE",
// "de_AT" etc.
// special case for chinese:
// simplified => code == "zh_CN", langcode == "zh_CN"
// traditional => code == "zh_TW", langcode == "zh_CN"
string const variety = lang.variety();
string const langcode = variety.empty() ?
lang.code() : lang.code() + '_' + variety;
string const name = lang.lang();
if ((code == langcode && name != "chinese-traditional") ||
(code == "zh_TW" && name == "chinese-traditional"))
return ExactMatch;
if ((code.size() == 2 && langcode.size() > 2 &&
code + '_' == langcode.substr(0, 3)))
return ApproximateMatch;
return NoMatch;
}
}
void Language::readLayoutTranslations(Language::TranslationMap const & trans, bool replace)
{
TranslationMap::const_iterator const end = trans.end();
for (TranslationMap::const_iterator it = trans.begin(); it != end; ++it)
if (replace ||
layoutTranslations_.find(it->first) == layoutTranslations_.end())
for (TranslationMap::const_iterator it = trans.begin(); it != end; ++it) {
if (replace
|| layoutTranslations_.find(it->first) == layoutTranslations_.end())
layoutTranslations_[it->first] = it->second;
}
}
@ -294,6 +250,56 @@ void Languages::read(FileName const & filename)
}
namespace {
bool readTranslations(Lexer & lex, Language::TranslationMap & trans)
{
while (lex.isOK()) {
if (lex.checkFor("End"))
break;
if (!lex.next(true))
return false;
string const key = lex.getString();
if (!lex.next(true))
return false;
docstring const val = lex.getDocString();
trans[key] = val;
}
return true;
}
enum Match {
NoMatch,
ApproximateMatch,
ExactMatch
};
Match match(string const & code, Language const & lang)
{
// we need to mimic gettext: code can be a two-letter code, which
// should match all variants, e.g. "de" should match "de_DE",
// "de_AT" etc.
// special case for chinese:
// simplified => code == "zh_CN", langcode == "zh_CN"
// traditional => code == "zh_TW", langcode == "zh_CN"
string const variety = lang.variety();
string const langcode = variety.empty() ?
lang.code() : lang.code() + '_' + variety;
string const name = lang.lang();
if ((code == langcode && name != "chinese-traditional")
|| (code == "zh_TW" && name == "chinese-traditional"))
return ExactMatch;
if ((code.size() == 2) && (langcode.size() > 2)
&& (code + '_' == langcode.substr(0, 3)))
return ApproximateMatch;
return NoMatch;
}
}
void Languages::readLayoutTranslations(support::FileName const & filename)
{
Lexer lex;