mirror of
https://github.com/google/benchmark.git
synced 2025-02-21 16:50:14 +08:00
Eliminate usage of deprecated API in sysinfo.cc (#1474)
* Eliminate usage of deprecated API in sysinfo.cc The `std::wstring_convert` is deprecated in C++17. Since this code is in the windows branch, we could use the win32 API (MultiByteToWideChar) * ran clang-format
This commit is contained in:
parent
ff629d847c
commit
db55c89f31
@ -417,11 +417,19 @@ std::string GetSystemName() {
|
|||||||
#ifndef UNICODE
|
#ifndef UNICODE
|
||||||
str = std::string(hostname, DWCOUNT);
|
str = std::string(hostname, DWCOUNT);
|
||||||
#else
|
#else
|
||||||
// Using wstring_convert, Is deprecated in C++17
|
std::vector<wchar_t> converted;
|
||||||
using convert_type = std::codecvt_utf8<wchar_t>;
|
// Find the length first.
|
||||||
std::wstring_convert<convert_type, wchar_t> converter;
|
int len = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, hostname,
|
||||||
std::wstring wStr(hostname, DWCOUNT);
|
DWCOUNT, converted.begin(), 0);
|
||||||
str = converter.to_bytes(wStr);
|
// TODO: Report error from GetLastError()?
|
||||||
|
if (len == 0) return std::string("");
|
||||||
|
converted.reserve(len + 1);
|
||||||
|
|
||||||
|
len = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, hostname, DWCOUNT,
|
||||||
|
converted.begin(), converted.size());
|
||||||
|
// TODO: Report error from GetLastError()?
|
||||||
|
if (len == 0) return std::string("");
|
||||||
|
str = std::string(converted.data());
|
||||||
#endif
|
#endif
|
||||||
return str;
|
return str;
|
||||||
#else // defined(BENCHMARK_OS_WINDOWS)
|
#else // defined(BENCHMARK_OS_WINDOWS)
|
||||||
|
Loading…
Reference in New Issue
Block a user