From b0b0a91729abc5fc6b1479214c293c283135b2dc Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 24 Aug 2023 13:58:55 +0200 Subject: [PATCH] unicode: add variants for zero-terminated input Signed-off-by: Simon Rozman --- include/stdex/unicode.hpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/stdex/unicode.hpp b/include/stdex/unicode.hpp index fd981b100..08866c95d 100644 --- a/include/stdex/unicode.hpp +++ b/include/stdex/unicode.hpp @@ -132,6 +132,23 @@ namespace stdex strcpy(dst, src.data(), src.size(), charset); } + /// + /// Convert string to Unicode string (UTF-16 on Windows) + /// + /// \param[in] src String. Must be zero-terminated. + /// \param[in] charset Charset (stdex::charset_id::default - system default) + /// + /// \return Unicode string + /// + inline std::wstring str2wstr( + _In_z_ const char* src, + _In_ charset_id charset = charset_id::default) + { + std::wstring dst; + strcat(dst, src, SIZE_MAX, charset); + return dst; + } + /// /// Convert string to Unicode string (UTF-16 on Windows) /// @@ -266,6 +283,23 @@ namespace stdex strcpy(dst, src.data(), src.size(), charset); } + /// + /// Convert Unicode string (UTF-16 on Windows) to string + /// + /// \param[in] src Unicode string. Must be zero-terminated. + /// \param[in] charset Charset (stdex::charset_id::default - system default) + /// + /// \return String + /// + inline std::string wstr2str( + _In_z_ const wchar_t* src, + _In_ charset_id charset = charset_id::default) + { + std::string dst; + strcat(dst, src, SIZE_MAX, charset); + return dst; + } + /// /// Convert Unicode string (UTF-16 on Windows) to string ///