-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutf8_path.hpp
More file actions
42 lines (34 loc) · 872 Bytes
/
Copy pathutf8_path.hpp
File metadata and controls
42 lines (34 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include "encoding.hpp"
#include <filesystem>
#include <string>
#include <system_error>
namespace acecode {
inline std::filesystem::path path_from_utf8(const std::string& text) {
#ifdef _WIN32
return std::filesystem::path(utf8_to_wide(text));
#else
return std::filesystem::path(text);
#endif
}
inline std::string path_to_utf8(const std::filesystem::path& path) {
#ifdef _WIN32
return wide_to_utf8(path.wstring());
#else
return path.string();
#endif
}
inline std::string path_to_utf8_generic(const std::filesystem::path& path) {
#ifdef _WIN32
return wide_to_utf8(path.generic_wstring());
#else
return path.generic_string();
#endif
}
inline std::string current_path_utf8() {
std::error_code ec;
auto path = std::filesystem::current_path(ec);
if (ec) return {};
return path_to_utf8(path);
}
} // namespace acecode