Skip to content

Commit

Permalink
refs #81, work on incomplete string_view support when using c++17
Browse files Browse the repository at this point in the history
  • Loading branch information
gulrak committed Dec 26, 2020
1 parent 97577f4 commit eef2c2b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
Checks: -modernize-use-nodiscard
...
12 changes: 6 additions & 6 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1569,14 +1569,14 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT
return result;
}

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

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

template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 4), int>::type size = 4>
inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicodeString)
template <typename strT, typename std::enable_if<path::_is_basic_string<strT>::value && (sizeof(typename strT::value_type) == 4), int>::type size = 4>
inline std::string toUtf8(const strT& unicodeString)
{
std::string result;
for (auto c : unicodeString) {
Expand Down
17 changes: 17 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ else()
endif()
ParseAndAddCatchTests(filesystem_test_wchar)
endif()
if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
add_executable(filesystem_test_cpp17 filesystem_test.cpp catch.hpp)
set_property(TARGET filesystem_test_cpp17 PROPERTY CXX_STANDARD 17)
target_link_libraries(filesystem_test_cpp17 ghc_filesystem)
target_compile_options(filesystem_test_cpp17 PRIVATE
$<$<BOOL:${EMSCRIPTEN}>:-s DISABLE_EXCEPTION_CATCHING=0>
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Werror>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Wno-psabi -Werror>
$<$<CXX_COMPILER_ID:MSVC>:/WX>)
if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
target_compile_definitions(filesystem_test_cpp17 PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
if(EMSCRIPTEN)
set_target_properties(filesystem_test_cpp17 PROPERTIES LINK_FLAGS "-g4 -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1")
endif()
ParseAndAddCatchTests(filesystem_test_cpp17)
endif()
endif()

add_executable(multifile_test multi1.cpp multi2.cpp catch.hpp)
Expand Down
7 changes: 6 additions & 1 deletion test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2689,6 +2689,7 @@ TEST_CASE("30.10.15.39 weakly_canonical", "[filesystem][operations][fs.op.weakly
TEST_CASE("std::string_view support", "[filesystem][fs.string_view]")
{
#if __cpp_lib_string_view
using namespace std::literals;
{
std::string p("foo/bar");
std::string_view sv(p);
Expand All @@ -2698,7 +2699,11 @@ TEST_CASE("std::string_view support", "[filesystem][fs.string_view]")
CHECK(p2 == "foo");
CHECK(p2.compare(std::string_view("foo")) == 0);
}

{
auto p = fs::path{"XYZ"};
p /= "Appendix"sv;
CHECK(p == "XYZ/Appendix");
}
#if defined(IS_WCHAR_PATH) || defined(GHC_USE_WCHAR_T)
{
std::wstring p(L"foo/bar");
Expand Down

0 comments on commit eef2c2b

Please sign in to comment.