From a16d04fb53d834ae9311737de9a204fd05cce3fa Mon Sep 17 00:00:00 2001 From: Vladimir Perminov Date: Sun, 16 Aug 2015 13:08:00 +0300 Subject: [PATCH] CCUtf8ToUnicode and CCUnicodeToUtf8 deprecated --- cocos/platform/winrt/CCWinRTUtils.cpp | 36 +++++++++++++++++++++++++++ cocos/platform/winrt/CCWinRTUtils.h | 3 ++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/cocos/platform/winrt/CCWinRTUtils.cpp b/cocos/platform/winrt/CCWinRTUtils.cpp index fe3eb998e9..1d5fccf481 100644 --- a/cocos/platform/winrt/CCWinRTUtils.cpp +++ b/cocos/platform/winrt/CCWinRTUtils.cpp @@ -47,6 +47,42 @@ using namespace Windows::Storage::Pickers; using namespace Windows::Storage::Streams; using namespace Windows::Networking::Connectivity; + +CC_DEPRECATED_ATTRIBUTE std::wstring CC_DLL CCUtf8ToUnicode(const char * pszUtf8Str, unsigned len /*= -1*/) +{ + if (len == -1) + { + return StringUtf8ToWideChar(pszUtf8Str); + } + else + { + std::wstring ret; + do + { + if (!pszUtf8Str || !len) break; + + // get UTF16 string length + int wLen = MultiByteToWideChar(CP_UTF8, 0, pszUtf8Str, len, 0, 0); + if (0 == wLen || 0xFFFD == wLen) break; + + // convert string + wchar_t * pwszStr = new wchar_t[wLen + 1]; + if (!pwszStr) break; + pwszStr[wLen] = 0; + MultiByteToWideChar(CP_UTF8, 0, pszUtf8Str, len, pwszStr, wLen + 1); + ret = pwszStr; + CC_SAFE_DELETE_ARRAY(pwszStr); + } while (0); + return ret; + } +} + +CC_DEPRECATED_ATTRIBUTE std::string CC_DLL CCUnicodeToUtf8(const wchar_t* pwszStr) +{ + return StringWideCharToUtf8(pwszStr); +} + + std::wstring StringUtf8ToWideChar(const std::string& strUtf8) { std::wstring ret; diff --git a/cocos/platform/winrt/CCWinRTUtils.h b/cocos/platform/winrt/CCWinRTUtils.h index e370133b7b..acce13da13 100644 --- a/cocos/platform/winrt/CCWinRTUtils.h +++ b/cocos/platform/winrt/CCWinRTUtils.h @@ -38,7 +38,8 @@ NS_CC_BEGIN - +CC_DEPRECATED_ATTRIBUTE std::wstring CC_DLL CCUtf8ToUnicode(const char * pszUtf8Str, unsigned len = -1); +CC_DEPRECATED_ATTRIBUTE std::string CC_DLL CCUnicodeToUtf8(const wchar_t* pwszStr); std::wstring CC_DLL StringUtf8ToWideChar(const std::string& strUtf8); std::string CC_DLL StringWideCharToUtf8(const std::wstring& strWideChar);