diff options
Diffstat (limited to 'src/main/cpp/util/path_platform.h')
-rw-r--r-- | src/main/cpp/util/path_platform.h | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/main/cpp/util/path_platform.h b/src/main/cpp/util/path_platform.h index 3c4671f004..e2efe097fe 100644 --- a/src/main/cpp/util/path_platform.h +++ b/src/main/cpp/util/path_platform.h @@ -77,9 +77,6 @@ std::pair<std::wstring, std::wstring> SplitPathW(const std::wstring &path); bool IsRootDirectoryW(const std::wstring &path); -bool AsWindowsPath(const std::string &path, std::string *result, - std::string *error); - // Returns a normalized form of the input `path`. // // `path` must be a relative or absolute Windows path, it may use "/" instead of @@ -95,7 +92,14 @@ bool AsWindowsPath(const std::string &path, std::string *result, // "foo". // // Visible for testing, would be static otherwise. -std::string NormalizeWindowsPath(std::string path); +template <typename char_type> +std::basic_string<char_type> NormalizeWindowsPath( + std::basic_string<char_type> path); + +template <typename char_type> +std::basic_string<char_type> NormalizeWindowsPath(const char_type *path) { + return NormalizeWindowsPath(std::basic_string<char_type>(path)); +} // Converts a UTF8-encoded `path` to a normalized, widechar Windows path. // @@ -116,8 +120,32 @@ std::string NormalizeWindowsPath(std::string path); bool AsWindowsPath(const std::string &path, std::wstring *result, std::string *error); -bool AsAbsoluteWindowsPath(const std::string &path, std::wstring *wpath, - std::string *error); +template <typename char_type> +bool AsWindowsPath(const std::basic_string<char_type> &path, + std::basic_string<char_type> *result, std::string *error); + +template <typename char_type> +bool AsWindowsPath(const char_type *path, std::basic_string<char_type> *result, + std::string *error) { + return AsWindowsPath(std::basic_string<char_type>(path), result, error); +} + +template <typename char_type> +bool AsAbsoluteWindowsPath(const std::basic_string<char_type> &path, + std::wstring *result, std::string *error); + +template <typename char_type> +bool AsAbsoluteWindowsPath(const char_type *path, std::wstring *result, + std::string *error) { + return AsAbsoluteWindowsPath(std::basic_string<char_type>(path), result, + error); +} + +// Explicit instantiate AsAbsoluteWindowsPath for char and wchar_t. +template bool AsAbsoluteWindowsPath<char>(const char *, std::wstring *, + std::string *); +template bool AsAbsoluteWindowsPath<wchar_t>(const wchar_t *, std::wstring *, + std::string *); // Same as `AsWindowsPath`, but returns a lowercase 8dot3 style shortened path. // Result will never have a UNC prefix, nor a trailing "/" or "\". |