1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___FILESYSTEM_U8PATH_H 11 #define _LIBCPP___FILESYSTEM_U8PATH_H 12 13 #include <__availability> 14 #include <__config> 15 #include <__filesystem/path.h> 16 #include <type_traits> 17 18 #ifndef _LIBCPP_CXX03_LANG 19 20 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM 21 22 _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH 23 24 template <class _InputIt> 25 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T 26 typename enable_if<__is_pathable<_InputIt>::value, path>::type 27 u8path(_InputIt __f, _InputIt __l) { 28 static_assert( 29 #ifndef _LIBCPP_HAS_NO_CHAR8_T 30 is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value || 31 #endif 32 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value, 33 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'" 34 " or 'char8_t'"); 35 #if defined(_LIBCPP_WIN32API) 36 string __tmp(__f, __l); 37 using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>; 38 _VSTD::wstring __w; 39 __w.reserve(__tmp.size()); 40 _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size()); 41 return path(__w); 42 #else 43 return path(__f, __l); 44 #endif /* !_LIBCPP_WIN32API */ 45 } 46 47 #if defined(_LIBCPP_WIN32API) 48 template <class _InputIt> 49 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T 50 typename enable_if<__is_pathable<_InputIt>::value, path>::type 51 u8path(_InputIt __f, _NullSentinel) { 52 static_assert( 53 #ifndef _LIBCPP_HAS_NO_CHAR8_T 54 is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value || 55 #endif 56 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value, 57 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'" 58 " or 'char8_t'"); 59 string __tmp; 60 const char __sentinel = char{}; 61 for (; *__f != __sentinel; ++__f) 62 __tmp.push_back(*__f); 63 using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>; 64 _VSTD::wstring __w; 65 __w.reserve(__tmp.size()); 66 _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size()); 67 return path(__w); 68 } 69 #endif /* _LIBCPP_WIN32API */ 70 71 template <class _Source> 72 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T 73 typename enable_if<__is_pathable<_Source>::value, path>::type 74 u8path(const _Source& __s) { 75 static_assert( 76 #ifndef _LIBCPP_HAS_NO_CHAR8_T 77 is_same<typename __is_pathable<_Source>::__char_type, char8_t>::value || 78 #endif 79 is_same<typename __is_pathable<_Source>::__char_type, char>::value, 80 "u8path(Source const&) requires Source have a character type of type " 81 "'char' or 'char8_t'"); 82 #if defined(_LIBCPP_WIN32API) 83 using _Traits = __is_pathable<_Source>; 84 return u8path(_VSTD::__unwrap_iter(_Traits::__range_begin(__s)), _VSTD::__unwrap_iter(_Traits::__range_end(__s))); 85 #else 86 return path(__s); 87 #endif 88 } 89 90 _LIBCPP_AVAILABILITY_FILESYSTEM_POP 91 92 _LIBCPP_END_NAMESPACE_FILESYSTEM 93 94 #endif // _LIBCPP_CXX03_LANG 95 96 #endif // _LIBCPP___FILESYSTEM_U8PATH_H 97