Created
March 1, 2023 18:32
-
-
Save Andersama/37af81647412ec62c1eb31a2202fa80c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <string> | |
#include <filesystem> | |
//needs utf8-cpp! | |
void string_from(std::string& buf, const std::filesystem::path& path) | |
{ | |
// buf.clear(); | |
if constexpr (std::is_same_v<std::filesystem::path::string_type, std::string>) { | |
// buf.insert(buf.end(), path.native().data(), path.native().data() + path.native().size()); | |
// char_star(buf, path.native()); | |
buf.assign(path.native().data(), path.native().data() + path.native().size()); | |
} | |
else if (std::is_same_v<std::filesystem::path::string_type, std::wstring>) { | |
// buf = path.string();//char_star(buf, path.native()); | |
#if _WIN32 | |
buf.clear(); | |
utf8::unchecked::utf16to8( | |
path.native().data(), path.native().data() + path.native().size(), std::back_inserter(buf)); | |
#else | |
buf = path.string(); | |
#endif | |
} | |
else if (std::is_same_v<std::filesystem::path::string_type, std::u8string>) { | |
buf.assign(path.native().data(), path.native().data() + path.native().size()); | |
} | |
else if (std::is_same_v<std::filesystem::path::string_type, std::u16string>) { | |
buf.clear(); | |
utf8::unchecked::utf16to8( | |
path.native().data(), path.native().data() + path.native().size(), std::back_inserter(buf)); | |
} | |
else if (std::is_same_v<std::filesystem::path::string_type, std::u32string>) { | |
buf.clear(); | |
utf8::unchecked::utf32to8( | |
path.native().data(), path.native().data() + path.native().size(), std::back_inserter(buf)); | |
} | |
else { | |
buf = path.string(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment