From 6f723e9f4dd7a288c93cbb4b6724672cf5798306 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 12 Dec 2023 11:25:32 +0100 Subject: [PATCH] [winpr,crt] add InitializeConstWCharFromUtf8 --- winpr/include/winpr/string.h | 10 ++++++++++ winpr/libwinpr/crt/string.c | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/winpr/include/winpr/string.h b/winpr/include/winpr/string.h index ef2d3b630..09b253c33 100644 --- a/winpr/include/winpr/string.h +++ b/winpr/include/winpr/string.h @@ -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, diff --git a/winpr/libwinpr/crt/string.c b/winpr/libwinpr/crt/string.c index af3502a21..b1c137ac0 100644 --- a/winpr/libwinpr/crt/string.c +++ b/winpr/libwinpr/crt/string.c @@ -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; +}