35#ifndef OPENSWMM_ENGINE_CORE_FILEIO_HPP
36#define OPENSWMM_ENGINE_CORE_FILEIO_HPP
55inline std::filesystem::path
utf8_path(
const std::string& utf8) {
57 return std::filesystem::path(
58 std::u8string(
reinterpret_cast<const char8_t*
>(utf8.data()), utf8.size()));
60 return std::filesystem::path(utf8);
86 requires std::same_as<std::remove_cvref_t<P>, std::filesystem::path>
99inline std::string
path_utf8(
const std::filesystem::path& p,
bool generic =
false) {
101 const std::u8string s =
generic ? p.generic_u8string() : p.u8string();
102 return std::string(
reinterpret_cast<const char*
>(s.data()), s.size());
106 return generic ? p.generic_string() : p.string();
120 requires(!std::same_as<std::remove_cvref_t<S>, std::filesystem::path>)
135inline std::FILE*
fopen_path(
const std::filesystem::path& p,
const char* mode) {
139 const std::wstring wmode(mode, mode + std::char_traits<char>::length(mode));
140 return ::_wfopen(p.c_str(), wmode.c_str());
142 return std::fopen(p.c_str(), mode);
155inline std::FILE*
fopen_utf8(
const std::string& utf8,
const char* mode) {
Definition AtomicOutputFile.hpp:25
std::filesystem::path utf8_path(const std::string &utf8)
Convert borrowed path bytes into an owned native filesystem path.
Definition FileIO.hpp:55
std::string path_utf8(const std::filesystem::path &p, bool generic=false)
Copy a native path into the engine byte-string representation.
Definition FileIO.hpp:99
std::FILE * fopen_utf8(const std::string &utf8, const char *mode)
Convert engine path bytes and open a C stdio stream.
Definition FileIO.hpp:155
std::FILE * fopen_path(const std::filesystem::path &p, const char *mode)
Open a borrowed native path using platform C stdio.
Definition FileIO.hpp:135