diff --git a/GleeBug/GleeBug.cpp b/GleeBug/GleeBug.cpp new file mode 100644 index 0000000..e80795f --- /dev/null +++ b/GleeBug/GleeBug.cpp @@ -0,0 +1,41 @@ +#include "GleeBug.h" + +namespace GleeBug +{ + //Conversion functions taken from: http://www.nubaria.com/en/blog/?p=289 + std::string Utf16ToUtf8(const std::wstring & wstr) + { + std::string convertedString; + auto requiredSize = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr); + if(requiredSize > 0) + { + std::vector buffer(requiredSize); + WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &buffer[0], requiredSize, nullptr, nullptr); + convertedString.assign(buffer.begin(), buffer.end() - 1); + } + return convertedString; + } + + std::string Utf16ToUtf8(const wchar_t* wstr) + { + return Utf16ToUtf8(wstr ? std::wstring(wstr) : std::wstring()); + } + + std::wstring Utf8ToUtf16(const std::string & str) + { + std::wstring convertedString; + int requiredSize = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0); + if(requiredSize > 0) + { + std::vector buffer(requiredSize); + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &buffer[0], requiredSize); + convertedString.assign(buffer.begin(), buffer.end() - 1); + } + return convertedString; + } + + std::wstring Utf8ToUtf16(const char* str) + { + return Utf8ToUtf16(str ? std::string(str) : std::string()); + } +}; \ No newline at end of file diff --git a/GleeBug/GleeBug.h b/GleeBug/GleeBug.h index 27d6969..9c58ab4 100644 --- a/GleeBug/GleeBug.h +++ b/GleeBug/GleeBug.h @@ -53,6 +53,11 @@ namespace GleeBug return a.second < b.first; } }; + + std::string Utf16ToUtf8(const std::wstring & wstr); + std::string Utf16ToUtf8(const wchar_t* wstr); + std::wstring Utf8ToUtf16(const std::string & str); + std::wstring Utf8ToUtf16(const char* str); } #endif //GLEEBUG_H \ No newline at end of file diff --git a/GleeBug/GleeBug.vcxproj b/GleeBug/GleeBug.vcxproj index 03ec159..b1ecb74 100644 --- a/GleeBug/GleeBug.vcxproj +++ b/GleeBug/GleeBug.vcxproj @@ -168,6 +168,7 @@ + diff --git a/GleeBug/GleeBug.vcxproj.filters b/GleeBug/GleeBug.vcxproj.filters index e21dc23..41f6f89 100644 --- a/GleeBug/GleeBug.vcxproj.filters +++ b/GleeBug/GleeBug.vcxproj.filters @@ -83,6 +83,9 @@ Source Files\capstone_wrapper + + Source Files +