Add df2console() wrapper

Closes #522
develop
lethosor 2015-02-13 17:56:29 -05:00
parent 3f9d3dc110
commit a8a8fc43ef
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);