from 1.18 branch: When creating initial config directory (1st exec), initialize specific unac_except_trans for some languages: de, se/no/dk/fi + fix mixup of language and country codes

This commit is contained in:
Jean-Francois Dockes
2012-11-01 11:27:50 +01:00
parent ee7d0f2ee7
commit 04c19b33d5
5 changed files with 87 additions and 56 deletions
+60
View File
@@ -33,11 +33,14 @@
#include <string>
#include <iostream>
#include <list>
#include <tr1/unordered_map>
using std::tr1::unordered_map;
using namespace std;
#include "smallut.h"
#include "utf8iter.h"
#include "hldata.h"
#include "cstr.h"
int stringicmp(const string & s1, const string& s2)
{
@@ -1097,6 +1100,63 @@ void HighlightData::append(const HighlightData& hl)
}
}
static const char *vlang_to_code[] = {
"be", "cp1251",
"bg", "cp1251",
"cs", "iso-8859-2",
"el", "iso-8859-7",
"he", "iso-8859-8",
"hr", "iso-8859-2",
"hu", "iso-8859-2",
"ja", "eucjp",
"kk", "pt154",
"ko", "euckr",
"lt", "iso-8859-13",
"lv", "iso-8859-13",
"pl", "iso-8859-2",
"rs", "iso-8859-2",
"ro", "iso-8859-2",
"ru", "koi8-r",
"sk", "iso-8859-2",
"sl", "iso-8859-2",
"sr", "iso-8859-2",
"th", "iso-8859-11",
"tr", "iso-8859-9",
"uk", "koi8-u",
};
string langtocode(const string& lang)
{
static unordered_map<string, string> lang_to_code;
if (lang_to_code.empty()) {
for (unsigned int i = 0;
i < sizeof(vlang_to_code) / sizeof(char *); i += 2) {
lang_to_code[vlang_to_code[i]] = vlang_to_code[i+1];
}
}
unordered_map<string,string>::const_iterator it =
lang_to_code.find(lang);
// Use cp1252 by default...
if (it == lang_to_code.end())
return cstr_cp1252;
return it->second;
}
string localelang()
{
const char *lang = getenv("LANG");
if (lang == 0 || *lang == 0 || !strcmp(lang, "C") || !strcmp(lang, "POSIX"))
return "en";
string locale(lang);
string::size_type under = locale.find_first_of("_");
if (under == string::npos)
return locale;
return locale.substr(0, under);
}
#else // TEST_SMALLUT
#include <string>
+5
View File
@@ -53,6 +53,11 @@ extern string stringtolower(const string& io);
// Is one string the end part of the other ?
extern int stringisuffcmp(const string& s1, const string& s2);
// Divine language from locale
extern std::string localelang();
// Divine 8bit charset from language
extern std::string langtocode(const string& lang);
// Compare charset names, removing the more common spelling variations
extern bool samecharset(const string &cs1, const string &cs2);