20namespace openvpn::wstring {
28inline std::wstring from_utf8(
const std::string &
str)
33 const int str_size =
static_cast<int>(
str.size());
34 const auto reqSize = ::MultiByteToWideChar(CP_UTF8, 0,
str.data(), str_size,
nullptr, 0);
36 throw std::runtime_error(
"MultiByteToWideChar(1) failed with code: [" + std::to_string(::GetLastError()) +
"]");
37 wStr.resize(reqSize, L
'\0');
38 if (::MultiByteToWideChar(CP_UTF8, 0,
str.data(), str_size, wStr.data(), reqSize) == 0)
39 throw std::runtime_error(
"MultiByteToWideChar(2) failed with code: [" + std::to_string(::GetLastError()) +
"]");
49inline std::string to_utf8(
const std::wstring &wstr)
54 const int wstr_size =
static_cast<int>(wstr.size());
55 const auto reqSize = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size,
nullptr, 0,
nullptr,
nullptr);
57 throw std::runtime_error(
"WideCharToMultiByte(1) failed with code: [" + std::to_string(::GetLastError()) +
"]");
58 str.resize(reqSize,
'\0');
59 if (::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size,
str.data(), reqSize,
nullptr,
nullptr) == 0)
60 throw std::runtime_error(
"WideCharToMultiByte(2) failed with code: [" + std::to_string(::GetLastError()) +
"]");
75inline std::wstring pack_string_vector(
const std::vector<std::string> &strvec)
79 return std::wstring(2, L
'\0');
82 for (
auto &s : strvec)
os<< "Session Name: "<< tbc-> session_name<< '\n';os<< "Layer: "<< tbc-> layer str()<< '\n'