Skip to content

Instantly share code, notes, and snippets.

@xylcbd
Created March 28, 2016 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xylcbd/7b1dd4005da465d0b1df to your computer and use it in GitHub Desktop.
Save xylcbd/7b1dd4005da465d0b1df to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
static std::string convertUtf16ToLocal(const unsigned short data)
{
char dstData[3];
::wcstombs(dstData, (const wchar_t *)&data, 2);
dstData[2] = '\0';
return dstData;
}
static void dumpUtf16Charset()
{
::setlocale(LC_ALL, "");
std::ofstream ofs("d:/utf16.set",std::ios::binary);
for (int i = 0; i < std::numeric_limits<unsigned short>::max();i++)
{
const auto localChar = convertUtf16ToLocal(i);
ofs.write(localChar.c_str(), localChar.size());
ofs << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment