Removed codecvt

This commit is contained in:
Jack Andersen 2015-08-24 21:02:47 -10:00
parent 28ed4ba6af
commit dcb83ff908
1 changed files with 19 additions and 6 deletions

View File

@ -1,5 +1,3 @@
#include <locale>
#include <codecvt>
#include "NOD/NOD.hpp"
namespace NOD
@ -7,14 +5,29 @@ namespace NOD
std::string WideToUTF8(const std::wstring& src)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
return conv.to_bytes(src);
std::string retval;
retval.reserve(src.length());
for (wchar_t ch : src)
{
char mb[4];
int c = std::wctomb(mb, ch);
retval.append(mb, c);
}
return retval;
}
std::wstring UTF8ToWide(const std::string& src)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
return conv.from_bytes(src);
std::wstring retval;
retval.reserve(src.length());
const char* buf = src.c_str();
while (*buf)
{
wchar_t wc;
buf += std::mbtowc(&wc, buf, MB_CUR_MAX);
retval += wc;
}
return retval;
}
}