Merge branch 'df2console' into develop

develop
lethosor 2015-02-13 17:59:16 -05:00
commit 2d9197df50
3 changed files with 19 additions and 0 deletions

@ -1282,6 +1282,7 @@ static bool isMapLoaded() { return Core::getInstance().isMapLoaded(); }
static std::string df2utf(std::string s) { return DF2UTF(s); }
static std::string utf2df(std::string s) { return UTF2DF(s); }
static std::string df2console(std::string s) { return DF2CONSOLE(s); }
static const LuaWrapper::FunctionReg dfhack_module[] = {
WRAP(getOSType),
@ -1294,6 +1295,7 @@ static const LuaWrapper::FunctionReg dfhack_module[] = {
WRAPM(Translation, TranslateName),
WRAP(df2utf),
WRAP(utf2df),
WRAP(df2console),
{ NULL, NULL }
};

@ -347,3 +347,19 @@ std::string UTF2DF(const std::string &in)
out.resize(pos);
return out;
}
DFHACK_EXPORT std::string DF2CONSOLE(const std::string &in)
{
bool is_utf = false;
#ifdef LINUX_BUILD
std::string locale = "";
if (getenv("LANG"))
locale += getenv("LANG");
if (getenv("LC_CTYPE"))
locale += getenv("LC_CTYPE");
locale = toUpper(locale);
is_utf = (locale.find("UTF-8") != std::string::npos) ||
(locale.find("UTF8") != std::string::npos);
#endif
return is_utf ? DF2UTF(in) : in;
}

@ -348,3 +348,4 @@ DFHACK_EXPORT std::string stl_vsprintf(const char *fmt, va_list args);
// Conversion between CP437 and UTF-8
DFHACK_EXPORT std::string UTF2DF(const std::string &in);
DFHACK_EXPORT std::string DF2UTF(const std::string &in);
DFHACK_EXPORT std::string DF2CONSOLE(const std::string &in);