From 24d06bb1c9d54c74286bd8637fdc653bfdbb13d5 Mon Sep 17 00:00:00 2001 From: Vladimir Perminov Date: Mon, 17 Aug 2015 23:04:05 +0300 Subject: [PATCH] More use StringUtf8ToWideChar and PlatformStringFromString --- cocos/platform/winrt/CCFileUtilsWinRT.cpp | 2 +- cocos/platform/winrt/InputEvent.cpp | 5 +--- cocos/ui/UIEditBox/UIEditBoxImpl-winrt.cpp | 32 ++-------------------- cocos/ui/UIEditBox/UIEditBoxImpl-winrt.h | 3 -- 4 files changed, 5 insertions(+), 37 deletions(-) diff --git a/cocos/platform/winrt/CCFileUtilsWinRT.cpp b/cocos/platform/winrt/CCFileUtilsWinRT.cpp index a792c2a203..e6ceec1d90 100644 --- a/cocos/platform/winrt/CCFileUtilsWinRT.cpp +++ b/cocos/platform/winrt/CCFileUtilsWinRT.cpp @@ -153,7 +153,7 @@ bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const bool CCFileUtilsWinRT::isDirectoryExistInternal(const std::string& dirPath) const { WIN32_FILE_ATTRIBUTE_DATA wfad; - std::wstring wdirPath(dirPath.begin(), dirPath.end()); + std::wstring wdirPath = StringUtf8ToWideChar(dirPath); if (GetFileAttributesEx(wdirPath.c_str(), GetFileExInfoStandard, &wfad)) { return true; diff --git a/cocos/platform/winrt/InputEvent.cpp b/cocos/platform/winrt/InputEvent.cpp index defe52f4c7..068c7e38b1 100644 --- a/cocos/platform/winrt/InputEvent.cpp +++ b/cocos/platform/winrt/InputEvent.cpp @@ -84,10 +84,7 @@ void KeyboardEvent::execute() { case Cocos2dKeyEvent::Text: { - std::wstring w(m_text.Get()->Data()); - std::u16string s16(w.begin(),w.end()); - std::string utf8String; - StringUtils::UTF16ToUTF8(s16, utf8String); + std::string utf8String = PlatformStringToString(m_text.Get()); IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), utf8String.size()); break; } diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.cpp b/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.cpp index ca5f713e19..ff0eb88361 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.cpp +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.cpp @@ -354,7 +354,7 @@ void UIEditBoxImplWinrt::openKeyboard() Windows::Foundation::EventHandler^ receiveHandler = ref new Windows::Foundation::EventHandler( [this](Platform::Object^ sender, Platform::String^ arg) { - setText(PlatformStringTostring(arg).c_str()); + setText(PlatformStringToString(arg).c_str()); if (_delegate != NULL) { _delegate->editBoxTextChanged(_editBox, getText()); _delegate->editBoxEditingDidEnd(_editBox); @@ -362,10 +362,10 @@ void UIEditBoxImplWinrt::openKeyboard() } }); - m_editBoxWinrt = ref new EditBoxWinRT(stringToPlatformString(placeHolder), stringToPlatformString(getText()), m_nMaxLength, m_eEditBoxInputMode, m_eEditBoxInputFlag, receiveHandler); + m_editBoxWinrt = ref new EditBoxWinRT(PlatformStringFromString(placeHolder), PlatformStringFromString(getText()), m_nMaxLength, m_eEditBoxInputMode, m_eEditBoxInputFlag, receiveHandler); } - m_editBoxWinrt->OpenXamlEditBox(stringToPlatformString(getText())); + m_editBoxWinrt->OpenXamlEditBox(PlatformStringFromString(getText())); } bool UIEditBoxImplWinrt::initWithSize( const Size& size ) @@ -570,32 +570,6 @@ void UIEditBoxImplWinrt::onEnter( void ) } -Platform::String^ UIEditBoxImplWinrt::stringToPlatformString( std::string strSrc ) -{ - // to wide char - int nStrLen = MultiByteToWideChar(CP_UTF8, 0, strSrc.c_str(), -1, NULL, 0); - wchar_t* pWStr = new wchar_t[nStrLen + 1]; - memset(pWStr, 0, nStrLen + 1); - MultiByteToWideChar(CP_UTF8, 0, strSrc.c_str(), -1, pWStr, nStrLen); - Platform::String^ strDst = ref new Platform::String(pWStr); - delete[] pWStr; - return strDst; -} - -std::string UIEditBoxImplWinrt::PlatformStringTostring( Platform::String^ strSrc ) -{ - const wchar_t* pWStr = strSrc->Data(); - int nStrLen = WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, NULL, 0, NULL, NULL); - char* pStr = new char[nStrLen + 1]; - memset(pStr, 0, nStrLen + 1); - WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, pStr, nStrLen, NULL, NULL); ; - - std::string strDst = std::string(pStr); - - delete[] pStr; - return strDst; -} - } NS_CC_END diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.h b/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.h index 3dce2b6cb9..840aa25282 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.h +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.h @@ -116,9 +116,6 @@ namespace ui { virtual void closeKeyboard(); virtual void onEnter(void); private: - Platform::String^ stringToPlatformString(std::string strSrc); - std::string PlatformStringTostring(Platform::String^ strSrc); - private: EditBoxWinRT^ m_editBoxWinrt;