10#if defined _WIN32 || defined WINCE
11#define LITEFX_CODECVT_USE_WIN32
25 template <
typename TStrings,
typename Value =
typename TStrings::value_type>
28 std::ostringstream stream;
30 auto beg = std::begin(elements);
31 auto end = std::end(elements);
35 std::copy(beg, std::prev(end), std::ostream_iterator<Value>(stream, delimiter.c_str()));
52#if defined LITEFX_CODECVT_USE_WIN32
56 const auto size = ::MultiByteToWideChar(CP_UTF8, 0, utf8.data(),
static_cast<int>(utf8.size()),
nullptr, 0);
59 throw std::runtime_error(
"Unable to convert string to UTF-16: " + std::to_string(size));
62 ::MultiByteToWideChar(CP_UTF8, 0, utf8.data(),
static_cast<int>(utf8.size()), result.data(), size);
66 std::wstring_convert<std::codecvt_utf8_utf16<WCHAR>> conv;
67 return conv.from_bytes(utf8);
78#if defined LITEFX_CODECVT_USE_WIN32
82 const auto size = ::WideCharToMultiByte(CP_UTF8, 0, utf16.data(),
static_cast<int>(utf16.size()),
nullptr, 0,
nullptr,
nullptr);
85 throw std::runtime_error(
"Unable to convert string to UTF-8: " + std::to_string(size));
88 ::WideCharToMultiByte(CP_UTF8, 0, utf16.data(),
static_cast<int>(utf16.size()), result.data(), size,
nullptr,
nullptr);
92 std::wstring_convert<std::codecvt_utf8_utf16<WCHAR>> conv;
93 return conv.to_bytes(utf16);
98#undef LITEFX_CODECVT_USE_WIN32
std::string String
Definition: string.hpp:19
String Narrow(WStringView utf16)
Converts an UTF-16 multi-byte encoded string into an UTF-8 representation.
Definition: string.hpp:76
WString Widen(StringView utf8)
Converts an UTF-8 single-byte encoded string into an UTF-16 representation.
Definition: string.hpp:50
std::wstring_view WStringView
Definition: string.hpp:22
std::wstring WString
Definition: string.hpp:20
std::string_view StringView
Definition: string.hpp:21
String Join(const TStrings &elements, const String &delimiter="")
Definition: string.hpp:26