MCPcopy Create free account
hub / github.com/ElementsProject/elements / PathToString

Function PathToString

src/fs.h:112–130  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

110 * PEP-383, and CESU-8 (see https://en.wikipedia.org/wiki/UTF-8#Derivatives).
111 */
112static 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.

Callers 15

SerializeFileDBFunction · 0.85
ReadMethod · 0.85
LoadAddrmanFunction · 0.85
ReadAnchorsFunction · 0.85
TorControllerMethod · 0.85
add_onion_cbMethod · 0.85
CallRPCFunction · 0.85
CreatePidFileFunction · 0.85
LockDataDirectoryFunction · 0.85
AppInitMainFunction · 0.85
CDBWrapperMethod · 0.85

Calls

no outgoing calls

Tested by 9

SetWalletDirMethod · 0.68
BOOST_FIXTURE_TEST_CASEFunction · 0.68
GetWalletEnvFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68
BasicTestingSetupMethod · 0.68