2#ifndef LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_UTILS_ENCODING_UTILS_HPP_INCLUDED
3#define LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_UTILS_ENCODING_UTILS_HPP_INCLUDED
14#include <stringapiset.h>
21 inline std::string utf8_to_ansi(
const std::string& utf8) {
22 int n_len = MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, NULL, 0);
23 if (n_len == 0)
return {};
25 std::wstring wide_string(n_len + 1, L
'\0');
26 MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, &wide_string[0], n_len);
28 n_len = WideCharToMultiByte(CP_ACP, 0, wide_string.c_str(), -1, NULL, 0, NULL, NULL);
29 if (n_len == 0)
return {};
31 std::string ansi_string(n_len - 1,
'\0');
32 WideCharToMultiByte(CP_ACP, 0, wide_string.c_str(), -1, &ansi_string[0], n_len, NULL, NULL);
39 inline std::wstring utf8_to_wstring(
const std::string& utf8) {
40 int n_len = MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, NULL, 0);
41 if (n_len == 0)
return {};
42 std::wstring wide_string(n_len - 1, L
'\0');
43 MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, &wide_string[0], n_len);
50 inline std::string wstring_to_utf8(
const std::wstring& wide) {
51 int n_len = WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, NULL, 0, NULL, NULL);
52 if (n_len == 0)
return {};
53 std::string utf8(n_len - 1,
'\0');
54 WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, &utf8[0], n_len, NULL, NULL);
The primary namespace for the LogIt++ library.