diff options
Diffstat (limited to 'matlab/src/IceMatlab/Util.cpp')
-rw-r--r-- | matlab/src/IceMatlab/Util.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/matlab/src/IceMatlab/Util.cpp b/matlab/src/IceMatlab/Util.cpp index 854f8594acb..6259061d7e7 100644 --- a/matlab/src/IceMatlab/Util.cpp +++ b/matlab/src/IceMatlab/Util.cpp @@ -58,27 +58,34 @@ getMajorMinor(mxArray* p, Ice::Byte& major, Ice::Byte& minor) mxArray* IceMatlab::createStringFromUTF8(const string& s) { + if(s.empty()) + { + return mxCreateString(""); + } + else + { #ifdef _MSC_VER - // - // Workaround for Visual Studio bug that causes a link error when using char16_t. - // - wstring utf16 = wstring_convert<codecvt_utf8_utf16<wchar_t>, wchar_t>{}.from_bytes(s.data()); + // + // Workaround for Visual Studio bug that causes a link error when using char16_t. + // + wstring utf16 = wstring_convert<codecvt_utf8_utf16<wchar_t>, wchar_t>{}.from_bytes(s.data()); #else - u16string utf16 = wstring_convert<codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(s.data()); + u16string utf16 = wstring_convert<codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(s.data()); #endif - mwSize dims[2] = { 1, static_cast<mwSize>(utf16.size()) }; - auto r = mxCreateCharArray(2, dims); - auto buf = mxGetChars(r); - int i = 0; + mwSize dims[2] = { 1, static_cast<mwSize>(utf16.size()) }; + auto r = mxCreateCharArray(2, dims); + auto buf = mxGetChars(r); + int i = 0; #ifdef _MSC_VER - for(wchar_t c : utf16) + for(wchar_t c : utf16) #else - for(char16_t c : utf16) + for(char16_t c : utf16) #endif - { - buf[i++] = static_cast<mxChar>(c); + { + buf[i++] = static_cast<mxChar>(c); + } + return r; } - return r; } string |