Removed codecvt

This commit is contained in:
Jack Andersen 2015-08-24 21:02:10 -10:00
parent eb6f3237db
commit 199b8e7c32
3 changed files with 21 additions and 8 deletions

2
hecl/extern/Athena vendored

@ -1 +1 @@
Subproject commit 92898661cc318e2de2934e58607e8349a0d10d13
Subproject commit 66cb6c982e8824fa887807bf8ba42376b301478b

@ -1 +1 @@
Subproject commit 34f2f028a9e0c12b6827e93f7043339fecd84b75
Subproject commit 154b84413050cdb03f281c42861b9af6eaef7d14

View File

@ -1,20 +1,33 @@
#include "HECL/HECL.hpp"
#include <locale>
#include <codecvt>
namespace HECL
{
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;
}
}