Gives ANSI path to curl CURLOPT_CAINFO

This commit is contained in:
RipleyTom 2020-03-26 20:48:56 +00:00 committed by Ivan
parent 2aac46efcc
commit cd4eed0704
5 changed files with 72 additions and 3 deletions

View file

@ -1,4 +1,4 @@
#include "StrFmt.h"
#include "StrFmt.h"
#include "BEType.h"
#include "StrUtil.h"
#include "cfmt.h"
@ -14,6 +14,47 @@
#include <errno.h>
#endif
#ifdef _WIN32
std::string wchar_to_utf8(wchar_t *src)
{
std::string utf8_string;
auto tmp_size = WideCharToMultiByte(CP_UTF8, 0, src, -1, nullptr, 0, nullptr, nullptr);
utf8_string.resize(tmp_size);
WideCharToMultiByte(CP_UTF8, 0, src, -1, utf8_string.data(), tmp_size, nullptr, nullptr);
return utf8_string;
}
std::string wchar_path_to_ansi_path(const std::wstring& src)
{
std::wstring buf_short;
std::string buf_final;
// Get the short path from the wide char path(short path should only contain ansi characters)
auto tmp_size = GetShortPathNameW(src.data(), nullptr, 0);
buf_short.resize(tmp_size);
GetShortPathNameW(src.data(), buf_short.data(), tmp_size);
// Convert wide char to ansi
tmp_size = WideCharToMultiByte(CP_ACP, 0, buf_short.data(), -1, nullptr, 0, nullptr, nullptr);
buf_final.resize(tmp_size);
WideCharToMultiByte(CP_ACP, 0, buf_short.data(), -1, buf_final.data(), tmp_size, nullptr, nullptr);
return buf_final;
}
std::string utf8_path_to_ansi_path(const std::string& src)
{
std::wstring buf_wide;
// Converts the utf-8 path to wide char
auto tmp_size = MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, nullptr, 0);
buf_wide.resize(tmp_size);
MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, buf_wide.data(), tmp_size);
return wchar_path_to_ansi_path(buf_wide);
}
#endif
template <>
void fmt_class_string<std::pair<const fmt_type_info*, u64>>::format(std::string& out, u64 arg)
{