summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2013-02-27 18:00:42 -0600
committerJordan Woyak <jordan.woyak@gmail.com>2013-02-27 18:00:42 -0600
commit0ea458b4dc9241a59fd18456c846be44694fdb7d (patch)
tree408e771cde643698796027f29d763e2eb9e20f26 /Source/Core/Common
parent9ff704f202cf4d31e00476c08d27327f12478b8a (diff)
Add functions for converting between UTF-8/16.
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/Src/StringUtil.cpp34
-rw-r--r--Source/Core/Common/Src/StringUtil.h7
2 files changed, 41 insertions, 0 deletions
diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp
index 6ef3d91a73..503c2810c3 100644
--- a/Source/Core/Common/Src/StringUtil.cpp
+++ b/Source/Core/Common/Src/StringUtil.cpp
@@ -22,6 +22,10 @@
#include "CommonPaths.h"
#include "StringUtil.h"
+#ifdef _WIN32
+#include <Windows.h>
+#endif
+
// faster than sscanf
bool AsciiToHex(const char* _szValue, u32& result)
{
@@ -375,3 +379,33 @@ std::string UriEncode(const std::string & sSrc)
delete [] pStart;
return sResult;
}
+
+#ifdef _WIN32
+
+std::string UTF16ToUTF8(const std::wstring& input)
+{
+ auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), input.size(), nullptr, 0, nullptr, nullptr);
+
+ std::string output;
+ output.resize(size);
+
+ if (size != WideCharToMultiByte(CP_UTF8, 0, input.data(), input.size(), &output[0], output.size(), nullptr, nullptr))
+ output.clear();
+
+ return output;
+}
+
+std::wstring UTF8ToUTF16(const std::string& input)
+{
+ auto const size = MultiByteToWideChar(CP_UTF8, 0, input.data(), input.size(), nullptr, 0);
+
+ std::wstring output;
+ output.resize(size);
+
+ if (size != MultiByteToWideChar(CP_UTF8, 0, input.data(), input.size(), &output[0], output.size()))
+ output.clear();
+
+ return output;
+}
+
+#endif
diff --git a/Source/Core/Common/Src/StringUtil.h b/Source/Core/Common/Src/StringUtil.h
index 102ae2d5fb..4e02ce4506 100644
--- a/Source/Core/Common/Src/StringUtil.h
+++ b/Source/Core/Common/Src/StringUtil.h
@@ -97,4 +97,11 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st
std::string UriDecode(const std::string & sSrc);
std::string UriEncode(const std::string & sSrc);
+#ifdef _WIN32
+
+std::string UTF16ToUTF8(const std::wstring& str);
+std::wstring UTF8ToUTF16(const std::string& str);
+
+#endif
+
#endif // _STRINGUTIL_H_