Moving from gitlab
This commit is contained in:
28
includes/FilesystemHelper.hpp
Normal file
28
includes/FilesystemHelper.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
// Safer portable conversion:
|
||||
std::string to_utf8(const std::filesystem::path& path) {
|
||||
#ifdef _WIN32
|
||||
// path.native() gives wchar_t, convert to UTF-8
|
||||
std::wstring ws = path.native();
|
||||
if (ws.empty()) return {};
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, ws.data(), int(ws.size()),
|
||||
nullptr, 0, nullptr, nullptr);
|
||||
std::string result(size_needed, 0);
|
||||
WideCharToMultiByte(CP_UTF8, 0, ws.data(), int(ws.size()), result.data(), size_needed, nullptr, nullptr);
|
||||
return result;
|
||||
#else
|
||||
return path.string(); // on POSIX this is already UTF-8-compatible
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user