[winpr,crt] add InitializeConstWCharFromUtf8

This commit is contained in:
Armin Novak 2023-12-12 11:25:32 +01:00 committed by akallabeth
parent 30494d0c93
commit 6f723e9f4d
2 changed files with 18 additions and 0 deletions

View File

@ -390,6 +390,16 @@ extern "C"
*/
WINPR_API WCHAR* ConvertMszUtf8NToWCharAlloc(const char* str, size_t len, size_t* pSize);
/** \brief Helper function to initialize const WCHAR pointer from a Utf8 string
*
* \param str The Utf8 string to use for initialization
* \param buffer The WCHAR buffer used to store the converted data
* \param len The size of the buffer in number of WCHAR
*
* \return The WCHAR string (a pointer to buffer)
*/
WINPR_API const WCHAR* InitializeConstWCharFromUtf8(const char* str, WCHAR* buffer, size_t len);
#if defined(WITH_WINPR_DEPRECATED)
WINPR_API WINPR_DEPRECATED_VAR("Use ConvertUtf8ToWChar functions instead",
int ConvertToUnicode(UINT CodePage, DWORD dwFlags,

View File

@ -833,3 +833,11 @@ char* strndup(const char* src, size_t n)
return dst;
}
#endif
const WCHAR* InitializeConstWCharFromUtf8(const char* str, WCHAR* buffer, size_t len)
{
WINPR_ASSERT(str);
WINPR_ASSERT(buffer || (len == 0));
ConvertUtf8ToWChar(str, buffer, len);
return buffer;
}