* Convert path object to a byte string. On POSIX, paths natively are byte * strings, so this is trivial. On Windows, paths natively are Unicode, so an * encoding step is necessary. The inverse of \ref PathToString is \ref * PathFromString. The strings returned and parsed by these functions can be * used to call POSIX APIs, and for roundtrip conversion, logging, and * debugging. * * Because
| 110 | * PEP-383, and CESU-8 (see https://en.wikipedia.org/wiki/UTF-8#Derivatives). |
| 111 | */ |
| 112 | static inline std::string PathToString(const path& path) |
| 113 | { |
| 114 | // Implementation note: On Windows, the std::filesystem::path(string) |
| 115 | // constructor and std::filesystem::path::string() method are not safe to |
| 116 | // use here, because these methods encode the path using C++'s narrow |
| 117 | // multibyte encoding, which on Windows corresponds to the current "code |
| 118 | // page", which is unpredictable and typically not able to represent all |
| 119 | // valid paths. So std::filesystem::path::u8string() and |
| 120 | // std::filesystem::u8path() functions are used instead on Windows. On |
| 121 | // POSIX, u8string/u8path functions are not safe to use because paths are |
| 122 | // not always valid UTF-8, so plain string methods which do not transform |
| 123 | // the path there are used. |
| 124 | #ifdef WIN32 |
| 125 | return path.u8string(); |
| 126 | #else |
| 127 | static_assert(std::is_same<path::string_type, std::string>::value, "PathToString not implemented on this platform"); |
| 128 | return path.std::filesystem::path::string(); |
| 129 | #endif |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Convert byte string to path object. Inverse of \ref PathToString. |
no outgoing calls