MCPcopy Create free account
hub / github.com/dirkvranckaert/AndroidDecompiler / convertToMultiByte

Method convertToMultiByte

astyle/src/ASLocalizer.cpp:309–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307}
308
309string Translation::convertToMultiByte(const wstring &wideStr) const
310// Convert wchar_t to a multibyte string using the currently assigned locale.
311// Return an empty string if an error occurs.
312{
313 static bool msgDisplayed = false;
314 // get length of the output excluding the NULL and validate the parameters
315 size_t mbLen = wcstombs(NULL, wideStr.c_str(), 0);
316 if (mbLen == string::npos)
317 {
318 if (!msgDisplayed)
319 {
320 fprintf(stderr, "\n%s\n\n", "Cannot convert to multi-byte string, reverting to English");
321 msgDisplayed = true;
322 }
323 return "";
324 }
325 // convert the characters
326 char* mbStr = new(nothrow) char[mbLen + 1];
327 if (mbStr == NULL)
328 {
329 if (!msgDisplayed)
330 {
331 fprintf(stderr, "\n%s\n\n", "Bad memory alloc for multi-byte string, reverting to English");
332 msgDisplayed = true;
333 }
334 return "";
335 }
336 wcstombs(mbStr, wideStr.c_str(), mbLen + 1);
337 // return the string
338 string mbTranslation = mbStr;
339 delete [] mbStr;
340 return mbTranslation;
341}
342
343size_t Translation::getTranslationVectorSize() const
344// Return the translation vector size. Used for testing.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected