Skip to content

Commit eef2c2b

Browse files
committed
refs #81, work on incomplete string_view support when using c++17
1 parent 97577f4 commit eef2c2b

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

.clang-tidy

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
Checks: -modernize-use-nodiscard
3+
...

include/ghc/filesystem.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1569,14 +1569,14 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT
15691569
return result;
15701570
}
15711571

1572-
template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 1), int>::type size = 1>
1573-
inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicodeString)
1572+
template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value && (sizeof(typename strT::value_type) == 1), int>::type size = 1>
1573+
inline std::string toUtf8(const strT& unicodeString)
15741574
{
15751575
return std::string(unicodeString.begin(), unicodeString.end());
15761576
}
15771577

1578-
template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 2), int>::type size = 2>
1579-
inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicodeString)
1578+
template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value && (sizeof(typename strT::value_type) == 2), int>::type size = 2>
1579+
inline std::string toUtf8(const strT& unicodeString)
15801580
{
15811581
std::string result;
15821582
for (auto iter = unicodeString.begin(); iter != unicodeString.end(); ++iter) {
@@ -1604,8 +1604,8 @@ inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicode
16041604
return result;
16051605
}
16061606

1607-
template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 4), int>::type size = 4>
1608-
inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicodeString)
1607+
template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value && (sizeof(typename strT::value_type) == 4), int>::type size = 4>
1608+
inline std::string toUtf8(const strT& unicodeString)
16091609
{
16101610
std::string result;
16111611
for (auto c : unicodeString) {

test/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ else()
4444
endif()
4545
ParseAndAddCatchTests(filesystem_test_wchar)
4646
endif()
47+
if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
48+
add_executable(filesystem_test_cpp17 filesystem_test.cpp catch.hpp)
49+
set_property(TARGET filesystem_test_cpp17 PROPERTY CXX_STANDARD 17)
50+
target_link_libraries(filesystem_test_cpp17 ghc_filesystem)
51+
target_compile_options(filesystem_test_cpp17 PRIVATE
52+
$<$<BOOL:${EMSCRIPTEN}>:-s DISABLE_EXCEPTION_CATCHING=0>
53+
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Werror>
54+
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Wno-psabi -Werror>
55+
$<$<CXX_COMPILER_ID:MSVC>:/WX>)
56+
if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
57+
target_compile_definitions(filesystem_test_cpp17 PRIVATE _CRT_SECURE_NO_WARNINGS)
58+
endif()
59+
if(EMSCRIPTEN)
60+
set_target_properties(filesystem_test_cpp17 PROPERTIES LINK_FLAGS "-g4 -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1")
61+
endif()
62+
ParseAndAddCatchTests(filesystem_test_cpp17)
63+
endif()
4764
endif()
4865

4966
add_executable(multifile_test multi1.cpp multi2.cpp catch.hpp)

test/filesystem_test.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,7 @@ TEST_CASE("30.10.15.39 weakly_canonical", "[filesystem][operations][fs.op.weakly
26892689
TEST_CASE("std::string_view support", "[filesystem][fs.string_view]")
26902690
{
26912691
#if __cpp_lib_string_view
2692+
using namespace std::literals;
26922693
{
26932694
std::string p("foo/bar");
26942695
std::string_view sv(p);
@@ -2698,7 +2699,11 @@ TEST_CASE("std::string_view support", "[filesystem][fs.string_view]")
26982699
CHECK(p2 == "foo");
26992700
CHECK(p2.compare(std::string_view("foo")) == 0);
27002701
}
2701-
2702+
{
2703+
auto p = fs::path{"XYZ"};
2704+
p /= "Appendix"sv;
2705+
CHECK(p == "XYZ/Appendix");
2706+
}
27022707
#if defined(IS_WCHAR_PATH) || defined(GHC_USE_WCHAR_T)
27032708
{
27042709
std::wstring p(L"foo/bar");

0 commit comments

Comments
 (0)