Skip to content

Commit

Permalink
Merge pull request #103 from phprus/unix-wchar_t
Browse files Browse the repository at this point in the history
Enabled wchar_t path Source on UNIX
  • Loading branch information
gulrak authored Feb 22, 2021
2 parents 0e5f2f5 + f98478c commit bc69aa3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
7 changes: 0 additions & 7 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,12 @@ class GHC_FS_API_CLASS path

template <typename T1, typename T2 = void>
using path_type = typename std::enable_if<!std::is_same<path, T1>::value, path>::type;
#ifdef GHC_USE_WCHAR_T
template <typename T>
using path_from_string = typename std::enable_if<_is_basic_string<T>::value || std::is_same<char const*, typename std::decay<T>::type>::value || std::is_same<char*, typename std::decay<T>::type>::value ||
std::is_same<wchar_t const*, typename std::decay<T>::type>::value || std::is_same<wchar_t*, typename std::decay<T>::type>::value,
path>::type;
template <typename T>
using path_type_EcharT = typename std::enable_if<std::is_same<T, char>::value || std::is_same<T, char16_t>::value || std::is_same<T, char32_t>::value, path>::type;
#else
template <typename T>
using path_from_string = typename std::enable_if<_is_basic_string<T>::value || std::is_same<char const*, typename std::decay<T>::type>::value || std::is_same<char*, typename std::decay<T>::type>::value, path>::type;
template <typename T>
using path_type_EcharT = typename std::enable_if<std::is_same<T, char>::value || std::is_same<T, char16_t>::value || std::is_same<T, char32_t>::value || std::is_same<T, wchar_t>::value, path>::type;
#endif
// 30.10.8.4.1 constructors and destructor
path() noexcept;
path(const path& p);
Expand Down
16 changes: 10 additions & 6 deletions test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ TEST_CASE("30.10.8.4.2 path assignments", "[filesystem][path][fs.path.assign]")
REQUIRE(p1 == p3);
p3 = fs::path{"/usr/local"};
REQUIRE(p2 == p3);
p3 = fs::path{L"/usr/local"};
REQUIRE(p2 == p3);
p3.assign(L"/usr/local");
REQUIRE(p2 == p3);
#if defined(IS_WCHAR_PATH) || defined(GHC_USE_WCHAR_T)
p3 = fs::path::string_type{L"/foo/bar"};
REQUIRE(p1 == p3);
Expand Down Expand Up @@ -499,9 +503,13 @@ TEST_CASE("30.10.8.4.4 path concatenation", "[filesystem][path][fs.path.concat]"

CHECK((fs::path("foo") += "bar") == "foobar");
CHECK((fs::path("foo") += "/bar") == "foo/bar");
CHECK((fs::path("foo") += L"bar") == "foobar");
CHECK((fs::path("foo") += L"/bar") == "foo/bar");

CHECK((fs::path("foo") += 'b') == "foob");
CHECK((fs::path("foo") += '/') == "foo/");
CHECK((fs::path("foo") += L'b') == "foob");
CHECK((fs::path("foo") += L'/') == "foo/");

CHECK((fs::path("foo") += std::string("bar")) == "foobar");
CHECK((fs::path("foo") += std::string("/bar")) == "foo/bar");
Expand All @@ -514,6 +522,8 @@ TEST_CASE("30.10.8.4.4 path concatenation", "[filesystem][path][fs.path.concat]"

CHECK(fs::path("foo").concat("bar") == "foobar");
CHECK(fs::path("foo").concat("/bar") == "foo/bar");
CHECK(fs::path("foo").concat(L"bar") == "foobar");
CHECK(fs::path("foo").concat(L"/bar") == "foo/bar");
std::string bar = "bar";
CHECK(fs::path("foo").concat(bar.begin(), bar.end()) == "foobar");
#ifndef USE_STD_FS
Expand Down Expand Up @@ -2745,14 +2755,10 @@ TEST_CASE("std::string_view support", "[filesystem][fs.string_view]")
#if defined(GHC_HAS_STD_STRING_VIEW)
using namespace std::literals;
using string_view = std::string_view;
#if defined(IS_WCHAR_PATH) || defined(GHC_USE_WCHAR_T)
using wstring_view = std::wstring_view;
#endif
#elif defined(GHC_HAS_STD_EXPERIMENTAL_STRING_VIEW)
using string_view = std::experimental::string_view;
#if defined(IS_WCHAR_PATH) || defined(GHC_USE_WCHAR_T)
using wstring_view = std::experimental::wstring_view;
#endif
#endif

{
Expand All @@ -2769,7 +2775,6 @@ TEST_CASE("std::string_view support", "[filesystem][fs.string_view]")
p /= string_view("Appendix");
CHECK(p == "XYZ/Appendix");
}
#if defined(IS_WCHAR_PATH) || defined(GHC_USE_WCHAR_T)
{
std::wstring p(L"foo/bar");
wstring_view sv(p);
Expand All @@ -2779,7 +2784,6 @@ TEST_CASE("std::string_view support", "[filesystem][fs.string_view]")
CHECK(p2 == "foo");
CHECK(p2.compare(wstring_view(L"foo")) == 0);
}
#endif

#else
WARN("std::string_view specific tests are empty without std::string_view.");
Expand Down

0 comments on commit bc69aa3

Please sign in to comment.