131 // Owner must free the return value. |
131 // Owner must free the return value. |
132 MultibyteString PlatformString::WideStringToMultibyteString(const wchar_t* value) { |
132 MultibyteString PlatformString::WideStringToMultibyteString(const wchar_t* value) { |
133 MultibyteString result; |
133 MultibyteString result; |
134 size_t count = 0; |
134 size_t count = 0; |
135 |
135 |
|
136 if (value == NULL) { |
|
137 return result; |
|
138 } |
|
139 |
136 #ifdef WINDOWS |
140 #ifdef WINDOWS |
137 wcstombs_s(&count, NULL, 0, value, 0); |
141 count = WideCharToMultiByte(CP_UTF8, 0, value, -1, NULL, 0, NULL, NULL); |
138 |
142 |
139 if (count > 0) { |
143 if (count > 0) { |
140 result.data = new char[count + 1]; |
144 result.data = new char[count + 1]; |
141 wcstombs_s(&result.length, result.data, count, value, count); |
145 result.length = WideCharToMultiByte(CP_UTF8, 0, value, -1, result.data, (int)count, NULL, NULL); |
142 |
|
143 #endif //WINDOWS |
146 #endif //WINDOWS |
|
147 |
144 #ifdef POSIX |
148 #ifdef POSIX |
145 count = wcstombs(NULL, value, 0); |
149 count = wcstombs(NULL, value, 0); |
146 |
150 |
147 if (count > 0) { |
151 if (count > 0) { |
148 result.data = new char[count + 1]; |
152 result.data = new char[count + 1]; |
158 // Owner must free the return value. |
162 // Owner must free the return value. |
159 WideString PlatformString::MultibyteStringToWideString(const char* value) { |
163 WideString PlatformString::MultibyteStringToWideString(const char* value) { |
160 WideString result; |
164 WideString result; |
161 size_t count = 0; |
165 size_t count = 0; |
162 |
166 |
|
167 if (value == NULL) { |
|
168 return result; |
|
169 } |
|
170 |
163 #ifdef WINDOWS |
171 #ifdef WINDOWS |
164 mbstowcs_s(&count, NULL, 0, value, _TRUNCATE); |
172 mbstowcs_s(&count, NULL, 0, value, _TRUNCATE); |
165 |
173 |
166 if (count > 0) { |
174 if (count > 0) { |
167 result.data = new wchar_t[count + 1]; |
175 result.data = new wchar_t[count + 1]; |