console encoding patch
This commit is contained in:
@@ -22,6 +22,10 @@
|
||||
#include "pistack.h"
|
||||
#include "piobject.h"
|
||||
#include "pistring_std.h"
|
||||
#ifdef HAS_LOCALE
|
||||
# include <locale>
|
||||
# include <codecvt>
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
# include <windows.h>
|
||||
# include <wingdi.h>
|
||||
@@ -147,6 +151,9 @@ PRIVATE_DEFINITION_START(PICout)
|
||||
static WORD dattr;
|
||||
static DWORD smode;
|
||||
#endif
|
||||
#ifdef HAS_LOCALE
|
||||
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> utf8conv;
|
||||
#endif
|
||||
PRIVATE_DEFINITION_END(PICout)
|
||||
|
||||
#ifdef WINDOWS
|
||||
@@ -539,8 +546,13 @@ PICout & PICout::writePIString(const PIString & s) {
|
||||
if (buffer_) {
|
||||
buffer_->append(s);
|
||||
} else {
|
||||
|
||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) {
|
||||
#ifdef HAS_LOCALE
|
||||
std::cout << PRIVATE->utf8conv.to_bytes((char16_t*)&(const_cast<PIString&>(s).front()), (char16_t*)&(const_cast<PIString&>(s).front()) + s.size());
|
||||
#else
|
||||
for (PIChar c: s) std::wcout.put(c.toWChar());
|
||||
#endif
|
||||
}
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__().append(s);
|
||||
}
|
||||
|
||||
@@ -152,12 +152,15 @@ PIInit::PIInit() {
|
||||
}
|
||||
# endif //WINDOWS
|
||||
# ifdef HAS_LOCALE
|
||||
//cout << "has locale" << endl;
|
||||
//std::cout << "has locale" << std::endl;
|
||||
if (currentLocale_t != 0) {
|
||||
freelocale(currentLocale_t);
|
||||
currentLocale_t = 0;
|
||||
}
|
||||
currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, ""), 0);
|
||||
//std::ios_base::sync_with_stdio(false);
|
||||
//std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> );
|
||||
//std::wcout.imbue(utf8);
|
||||
# else //HAS_LOCALE
|
||||
setlocale(LC_ALL, "");
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
@@ -212,9 +215,6 @@ PIInit::PIInit() {
|
||||
if (gethostname(cbuff, 1023) == 0) {
|
||||
sinfo->hostname = cbuff;
|
||||
}
|
||||
// std::ios_base::sync_with_stdio(false);
|
||||
// std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> );
|
||||
// std::wcout.imbue(utf8);
|
||||
#ifdef WINDOWS
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
|
||||
Reference in New Issue
Block a user