2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___FILESYSTEM_U8PATH_H
11 #define _LIBCPP___FILESYSTEM_U8PATH_H
13 #include <__algorithm/unwrap_iter.h>
15 #include <__filesystem/path.h>
18 // Only required on Windows for __widen_from_utf8, and included conservatively
19 // because it requires support for localization.
20 #if defined(_LIBCPP_WIN32API)
24 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25 # pragma GCC system_header
28 #if _LIBCPP_STD_VER >= 17
30 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
32 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
34 template <class _InputIt
, __enable_if_t
<__is_pathable
<_InputIt
>::value
, int> = 0>
35 _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path
u8path(_InputIt __f
, _InputIt __l
) {
37 # if _LIBCPP_HAS_CHAR8_T
38 is_same
<typename __is_pathable
<_InputIt
>::__char_type
, char8_t
>::value
||
40 is_same
<typename __is_pathable
<_InputIt
>::__char_type
, char>::value
,
41 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
43 # if defined(_LIBCPP_WIN32API)
44 string
__tmp(__f
, __l
);
45 using _CVT
= __widen_from_utf8
<sizeof(wchar_t) * __CHAR_BIT__
>;
47 __w
.reserve(__tmp
.size());
48 _CVT()(back_inserter(__w
), __tmp
.data(), __tmp
.data() + __tmp
.size());
51 return path(__f
, __l
);
52 # endif /* !_LIBCPP_WIN32API */
55 # if defined(_LIBCPP_WIN32API)
56 template <class _InputIt
, __enable_if_t
<__is_pathable
<_InputIt
>::value
, int> = 0>
57 _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path
u8path(_InputIt __f
, _NullSentinel
) {
59 # if _LIBCPP_HAS_CHAR8_T
60 is_same
<typename __is_pathable
<_InputIt
>::__char_type
, char8_t
>::value
||
62 is_same
<typename __is_pathable
<_InputIt
>::__char_type
, char>::value
,
63 "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
66 const char __sentinel
= char{};
67 for (; *__f
!= __sentinel
; ++__f
)
68 __tmp
.push_back(*__f
);
69 using _CVT
= __widen_from_utf8
<sizeof(wchar_t) * __CHAR_BIT__
>;
71 __w
.reserve(__tmp
.size());
72 _CVT()(back_inserter(__w
), __tmp
.data(), __tmp
.data() + __tmp
.size());
75 # endif /* _LIBCPP_WIN32API */
77 template <class _Source
, __enable_if_t
<__is_pathable
<_Source
>::value
, int> = 0>
78 _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path
u8path(const _Source
& __s
) {
80 # if _LIBCPP_HAS_CHAR8_T
81 is_same
<typename __is_pathable
<_Source
>::__char_type
, char8_t
>::value
||
83 is_same
<typename __is_pathable
<_Source
>::__char_type
, char>::value
,
84 "u8path(Source const&) requires Source have a character type of type "
85 "'char' or 'char8_t'");
86 # if defined(_LIBCPP_WIN32API)
87 using _Traits
= __is_pathable
<_Source
>;
88 return u8path(std::__unwrap_iter(_Traits::__range_begin(__s
)), std::__unwrap_iter(_Traits::__range_end(__s
)));
94 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
96 _LIBCPP_END_NAMESPACE_FILESYSTEM
98 #endif // _LIBCPP_STD_VER >= 17
100 #endif // _LIBCPP___FILESYSTEM_U8PATH_H