Skip to content

Commit 6f723e9

Browse files
Armin Novakakallabeth
authored andcommitted
[winpr,crt] add InitializeConstWCharFromUtf8
1 parent 30494d0 commit 6f723e9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

winpr/include/winpr/string.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,16 @@ extern "C"
390390
*/
391391
WINPR_API WCHAR* ConvertMszUtf8NToWCharAlloc(const char* str, size_t len, size_t* pSize);
392392

393+
/** \brief Helper function to initialize const WCHAR pointer from a Utf8 string
394+
*
395+
* \param str The Utf8 string to use for initialization
396+
* \param buffer The WCHAR buffer used to store the converted data
397+
* \param len The size of the buffer in number of WCHAR
398+
*
399+
* \return The WCHAR string (a pointer to buffer)
400+
*/
401+
WINPR_API const WCHAR* InitializeConstWCharFromUtf8(const char* str, WCHAR* buffer, size_t len);
402+
393403
#if defined(WITH_WINPR_DEPRECATED)
394404
WINPR_API WINPR_DEPRECATED_VAR("Use ConvertUtf8ToWChar functions instead",
395405
int ConvertToUnicode(UINT CodePage, DWORD dwFlags,

winpr/libwinpr/crt/string.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,11 @@ char* strndup(const char* src, size_t n)
833833
return dst;
834834
}
835835
#endif
836+
837+
const WCHAR* InitializeConstWCharFromUtf8(const char* str, WCHAR* buffer, size_t len)
838+
{
839+
WINPR_ASSERT(str);
840+
WINPR_ASSERT(buffer || (len == 0));
841+
ConvertUtf8ToWChar(str, buffer, len);
842+
return buffer;
843+
}

0 commit comments

Comments
 (0)