7#include "../macros.hpp"
8#include "win32_error_intf.hpp"
13#include <stringapiset.h>
15hi_export_module(hikogui.win32 : stringapiset);
17hi_export
namespace hi {
inline namespace v1 {
26[[nodiscard]]
inline std::expected<std::string, win32_error>
win32_WideCharToMultiByte(std::wstring_view s,
unsigned int code_page = CP_UTF8, uint32_t flags = 0) noexcept
33 auto s_len =
static_cast<int>(
static_cast<unsigned int>(s.size()));
34 auto r_len = ::WideCharToMultiByte(code_page, flags, s.data(), s_len,
nullptr, 0,
nullptr,
nullptr);
39 auto r =
std::string(
static_cast<size_t>(
static_cast<std::make_signed_t<size_t>
>(r_len)),
'\0');
40 r.resize_and_overwrite(r_len, [&](
char *p,
size_t count) {
41 return ::WideCharToMultiByte(code_page, flags, s.data(), s_len, p,
static_cast<int>(count),
nullptr,
nullptr);
58[[nodiscard]]
inline std::expected<std::wstring, win32_error>
win32_MultiByteToWideChar(std::string_view s,
unsigned int code_page = CP_UTF8, uint32_t flags = 0) noexcept
65 auto s_len =
static_cast<int>(
static_cast<unsigned int>(s.size()));
66 auto r_len = ::MultiByteToWideChar(code_page, flags, s.data(), s_len,
nullptr, 0);
72 r.resize_and_overwrite(r_len, [&](
wchar_t *p,
size_t count) {
73 return ::MultiByteToWideChar(code_page, flags, s.data(), s_len, p,
static_cast<int>(count));
92[[nodiscard]]
inline std::expected<std::vector<std::string>, win32_error>
win32_MultiSZToStringVector(
wchar_t const *first,
wchar_t const *last)
noexcept
96 while (first != last) {
97 auto it_zero =
std::find(first, last,
wchar_t{0});
98 if (it_zero == last) {
103 auto const ws = std::wstring_view{first,
static_cast<std::size_t>(it_zero - first)};
The HikoGUI namespace.
Definition array_generic.hpp:20
std::expected< std::string, win32_error > win32_WideCharToMultiByte(std::wstring_view s, unsigned int code_page=CP_UTF8, uint32_t flags=0) noexcept
Convert a win32-API compatible std::wstring to a multi-byte std::string.
Definition stringapiset.hpp:26
std::expected< std::vector< std::string >, win32_error > win32_MultiSZToStringVector(wchar_t const *first, wchar_t const *last) noexcept
Convert a win32 zero terminated list of zero terminated strings.
Definition stringapiset.hpp:92
std::expected< std::wstring, win32_error > win32_MultiByteToWideChar(std::string_view s, unsigned int code_page=CP_UTF8, uint32_t flags=0) noexcept
Convert a win32-API compatible std::wstring to a multi-byte std::string.
Definition stringapiset.hpp:58
DOXYGEN BUG.
Definition algorithm_misc.hpp:20