30 #ifndef _GLIBCXX_FS_PATH_H
31 #define _GLIBCXX_FS_PATH_H 1
33 #if __cplusplus >= 201703L
46 #include <bits/shared_ptr.h>
49 #if __cplusplus > 201703L
53 #if defined(_WIN32) && !defined(__CYGWIN__)
54 # define _GLIBCXX_FILESYSTEM_IS_WINDOWS 1
58 namespace std _GLIBCXX_VISIBILITY(default)
60 _GLIBCXX_BEGIN_NAMESPACE_VERSION
64 _GLIBCXX_BEGIN_NAMESPACE_CXX11
75 template<
typename _CharT>
76 inline constexpr
bool __is_encoded_char =
false;
78 inline constexpr
bool __is_encoded_char<char> =
true;
79 #ifdef _GLIBCXX_USE_CHAR8_T
81 inline constexpr
bool __is_encoded_char<char8_t> =
true;
83 #if _GLIBCXX_USE_WCHAR_T
85 inline constexpr
bool __is_encoded_char<wchar_t> =
true;
88 inline constexpr
bool __is_encoded_char<char16_t> =
true;
90 inline constexpr
bool __is_encoded_char<char32_t> =
true;
92 #if __cpp_concepts >= 201907L
93 template<
typename _Iter>
96 template<
typename _Iter>
101 template<>
struct __safe_iterator_traits<void*> { };
102 template<>
struct __safe_iterator_traits<const void*> { };
103 template<>
struct __safe_iterator_traits<volatile void*> { };
104 template<>
struct __safe_iterator_traits<const volatile void*> { };
107 template<
typename _Iter_traits,
typename =
void>
108 struct __is_path_iter_src
112 template<
typename _Iter_traits>
113 struct __is_path_iter_src<_Iter_traits,
114 void_t<typename _Iter_traits::value_type>>
115 : bool_constant<__is_encoded_char<typename _Iter_traits::value_type>>
118 template<
typename _Source>
119 inline constexpr
bool __is_path_src
120 = __is_path_iter_src<iterator_traits<decay_t<_Source>>>::value;
123 inline constexpr
bool __is_path_src<path> =
false;
126 inline constexpr
bool __is_path_src<volatile path> =
false;
129 inline constexpr
bool __is_path_src<void*> =
false;
132 inline constexpr
bool __is_path_src<const void*> =
false;
135 inline constexpr
bool __is_path_src<volatile void*> =
false;
138 inline constexpr
bool __is_path_src<const volatile void*> =
false;
140 template<
typename _CharT,
typename _Traits,
typename _Alloc>
141 inline constexpr
bool
142 __is_path_src<basic_string<_CharT, _Traits, _Alloc>>
143 = __is_encoded_char<_CharT>;
145 template<
typename _CharT,
typename _Traits>
146 inline constexpr
bool
147 __is_path_src<basic_string_view<_CharT, _Traits>>
148 = __is_encoded_char<_CharT>;
151 template<
typename _Tp>
152 using _Path = enable_if_t<__is_path_src<_Tp>, path>;
155 template<
typename _Iter,
typename _Tr = __safe_iterator_traits<_Iter>>
156 using _Path2 = enable_if_t<__is_path_iter_src<_Tr>::value, path>;
162 template<
typename _CharT,
typename _Traits,
typename _Alloc>
163 inline basic_string_view<_CharT, _Traits>
164 __effective_range(
const basic_string<_CharT, _Traits, _Alloc>& __source)
167 template<
typename _CharT,
typename _Traits>
168 inline const basic_string_view<_CharT, _Traits>&
169 __effective_range(
const basic_string_view<_CharT, _Traits>& __source)
172 template<
typename _Source>
174 __effective_range(
const _Source& __source)
176 if constexpr (is_pointer_v<decay_t<_Source>>)
177 return basic_string_view{&*__source};
183 =
typename iterator_traits<_Source>::value_type;
184 basic_string<value_type> __str;
185 _Source __it = __source;
186 for (value_type __ch = *__it; __ch != value_type(); __ch = *++__it)
187 __str.push_back(__ch);
193 template<
typename _Tp>
195 decltype(__detail::__effective_range(std::declval<_Tp>()))>::value_type;
200 template<
typename _Tp,
typename _Val = __value_t<_Tp>>
201 using __value_type_is_char
206 template<
typename _Tp,
typename _Val = __value_t<_Tp>>
207 using __value_type_is_char_or_char8_t
209 #ifdef _GLIBCXX_USE_CHAR8_T
210 || std::is_same_v<_Val, char8_t>
215 template<
typename _InputIterator>
217 __string_from_range(_InputIterator __first, _InputIterator __last)
221 static_assert(__is_encoded_char<_EcharT>);
223 #if __cpp_lib_concepts
224 constexpr
bool __contiguous = std::contiguous_iterator<_InputIterator>;
226 constexpr
bool __contiguous
227 = is_pointer_v<decltype(std::__niter_base(__first))>;
229 if constexpr (__contiguous)
232 const auto* __f = std::__to_address(std::__niter_base(__first));
233 const auto* __l = std::__to_address(std::__niter_base(__last));
234 return basic_string_view<_EcharT>(__f, __l - __f);
238 return basic_string<_EcharT>(__first, __last);
241 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
242 template<
typename _Tp>
244 __wstr_from_utf8(
const _Tp& __str)
246 static_assert(std::is_same_v<typename _Tp::value_type, char>);
249 std::codecvt_utf8_utf16<wchar_t> __wcvt;
250 const auto __p = __str.
data();
251 if (!__str_codecvt_in_all(__p, __p + __str.size(), __wstr, __wcvt))
252 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
253 "Cannot convert character sequence",
254 std::make_error_code(errc::illegal_byte_sequence)));
266 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
267 using value_type = wchar_t;
268 static constexpr value_type preferred_separator = L
'\\';
270 # ifdef _GLIBCXX_DOXYGEN
272 using value_type = __os_dependent__;
274 using value_type = char;
276 static constexpr value_type preferred_separator =
'/';
281 enum format :
unsigned char { native_format, generic_format, auto_format };
287 path(
const path& __p) =
default;
290 #if _GLIBCXX_USE_CXX11_ABI || _GLIBCXX_FULLY_DYNAMIC_STRING == 0
293 : _M_pathname(
std::move(__p._M_pathname)),
297 path(string_type&& __source,
format = auto_format)
298 : _M_pathname(
std::
move(__source))
299 { _M_split_cmpts(); }
301 template<
typename _Source,
302 typename _Require = __detail::_Path<_Source>>
303 path(_Source
const& __source,
format = auto_format)
304 : _M_pathname(_S_convert(__detail::__effective_range(__source)))
305 { _M_split_cmpts(); }
307 template<
typename _InputIterator,
308 typename _Require = __detail::_Path2<_InputIterator>>
309 path(_InputIterator __first, _InputIterator __last,
format = auto_format)
310 : _M_pathname(_S_convert(__first, __last))
311 { _M_split_cmpts(); }
313 template<
typename _Source,
314 typename _Require = __detail::_Path<_Source>,
315 typename _Require2 = __detail::__value_type_is_char<_Source>>
316 path(_Source
const& __src,
const locale& __loc,
format = auto_format)
317 : _M_pathname(_S_convert_loc(__detail::__effective_range(__src), __loc))
318 { _M_split_cmpts(); }
320 template<
typename _InputIterator,
321 typename _Require = __detail::_Path2<_InputIterator>,
322 typename _Req2 = __detail::__value_type_is_char<_InputIterator>>
323 path(_InputIterator __first, _InputIterator __last,
const locale& __loc,
325 : _M_pathname(_S_convert_loc(__first, __last, __loc))
326 { _M_split_cmpts(); }
332 path& operator=(
const path&);
333 path& operator=(path&&) noexcept;
334 path& operator=(string_type&& __source);
335 path& assign(string_type&& __source);
337 template<typename _Source>
338 __detail::_Path<_Source>&
339 operator=(_Source const& __source)
340 {
return *
this = path(__source); }
342 template<
typename _Source>
343 __detail::_Path<_Source>&
344 assign(_Source
const& __source)
345 {
return *
this = path(__source); }
347 template<
typename _InputIterator>
348 __detail::_Path2<_InputIterator>&
349 assign(_InputIterator __first, _InputIterator __last)
350 {
return *
this = path(__first, __last); }
354 path& operator/=(
const path& __p);
356 template<
typename _Source>
357 __detail::_Path<_Source>&
358 operator/=(_Source
const& __source)
360 _M_append(_S_convert(__detail::__effective_range(__source)));
364 template<
typename _Source>
365 __detail::_Path<_Source>&
366 append(_Source
const& __source)
368 _M_append(_S_convert(__detail::__effective_range(__source)));
372 template<
typename _InputIterator>
373 __detail::_Path2<_InputIterator>&
374 append(_InputIterator __first, _InputIterator __last)
376 _M_append(_S_convert(__first, __last));
382 path& operator+=(
const path& __x);
383 path& operator+=(
const string_type& __x);
384 path& operator+=(
const value_type* __x);
385 path& operator+=(value_type __x);
386 path& operator+=(basic_string_view<value_type> __x);
388 template<
typename _Source>
389 __detail::_Path<_Source>&
390 operator+=(_Source
const& __x) {
return concat(__x); }
392 template<
typename _CharT>
393 __detail::_Path2<_CharT*>&
394 operator+=(_CharT __x);
396 template<
typename _Source>
397 __detail::_Path<_Source>&
398 concat(_Source
const& __x)
400 _M_concat(_S_convert(__detail::__effective_range(__x)));
404 template<
typename _InputIterator>
405 __detail::_Path2<_InputIterator>&
406 concat(_InputIterator __first, _InputIterator __last)
408 _M_concat(_S_convert(__first, __last));
414 void clear() noexcept { _M_pathname.
clear(); _M_split_cmpts(); }
416 path& make_preferred();
417 path& remove_filename();
418 path& replace_filename(
const path& __replacement);
419 path& replace_extension(
const path& __replacement = path());
421 void swap(path& __rhs) noexcept;
425 const string_type& native() const noexcept {
return _M_pathname; }
426 const value_type* c_str() const noexcept {
return _M_pathname.
c_str(); }
427 operator string_type()
const {
return _M_pathname; }
429 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
430 typename _Allocator = std::allocator<_CharT>>
432 string(
const _Allocator& __a = _Allocator())
const;
435 #if _GLIBCXX_USE_WCHAR_T
438 #ifdef _GLIBCXX_USE_CHAR8_T
439 __attribute__((__abi_tag__(
"__u8")))
440 std::u8string u8string() const;
443 #endif // _GLIBCXX_USE_CHAR8_T
448 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
449 typename _Allocator = std::allocator<_CharT>>
451 generic_string(
const _Allocator& __a = _Allocator())
const;
454 #if _GLIBCXX_USE_WCHAR_T
457 #ifdef _GLIBCXX_USE_CHAR8_T
458 __attribute__((__abi_tag__(
"__u8")))
459 std::u8string generic_u8string() const;
462 #endif // _GLIBCXX_USE_CHAR8_T
468 int compare(
const path& __p)
const noexcept;
469 int compare(
const string_type& __s)
const noexcept;
470 int compare(
const value_type* __s)
const noexcept;
471 int compare(basic_string_view<value_type> __s)
const noexcept;
475 path root_name()
const;
476 path root_directory()
const;
477 path root_path()
const;
478 path relative_path()
const;
479 path parent_path()
const;
480 path filename()
const;
482 path extension()
const;
486 [[nodiscard]]
bool empty() const noexcept {
return _M_pathname.
empty(); }
487 bool has_root_name() const noexcept;
488 bool has_root_directory() const noexcept;
489 bool has_root_path() const noexcept;
490 bool has_relative_path() const noexcept;
491 bool has_parent_path() const noexcept;
492 bool has_filename() const noexcept;
493 bool has_stem() const noexcept;
494 bool has_extension() const noexcept;
495 bool is_absolute() const noexcept;
496 bool is_relative() const noexcept {
return !is_absolute(); }
499 path lexically_normal()
const;
500 path lexically_relative(
const path& base)
const;
501 path lexically_proximate(
const path& base)
const;
505 using const_iterator = iterator;
507 iterator
begin()
const;
508 iterator
end()
const;
511 template<
typename _CharT,
typename _Traits>
515 __os <<
std::quoted(__p.string<_CharT, _Traits>());
520 template<
typename _CharT,
typename _Traits>
534 {
return __lhs.compare(__rhs) == 0; }
536 #if __cpp_lib_three_way_comparison
538 friend strong_ordering
539 operator<=>(
const path& __lhs,
const path& __rhs) noexcept
540 {
return __lhs.compare(__rhs) <=> 0; }
544 {
return !(__lhs == __rhs); }
548 {
return __lhs.compare(__rhs) < 0; }
552 {
return !(__rhs < __lhs); }
556 {
return __rhs < __lhs; }
560 {
return !(__lhs < __rhs); }
566 path __result(__lhs);
572 enum class _Type : unsigned char {
573 _Multi = 0, _Root_name, _Root_dir, _Filename
579 __glibcxx_assert(__type != _Type::_Multi);
580 _M_cmpts.type(__type);
583 enum class _Split { _Stem, _Extension };
585 void _M_append(basic_string_view<value_type>);
586 void _M_concat(basic_string_view<value_type>);
588 pair<const string_type*, size_t> _M_find_extension() const noexcept;
599 _S_convert(string_type __str)
602 template<
typename _Tp>
604 _S_convert(
const _Tp& __str)
606 if constexpr (is_same_v<_Tp, string_type>)
608 else if constexpr (is_same_v<_Tp, basic_string_view<value_type>>)
610 else if constexpr (is_same_v<typename _Tp::value_type, value_type>)
611 return basic_string_view<value_type>(__str.
data(), __str.
size());
613 return _S_convert(__str.
data(), __str.
data() + __str.
size());
616 template<typename _EcharT>
618 _S_convert(const _EcharT* __first, const _EcharT* __last);
620 template<typename _Iter>
622 _S_convert(_Iter __first, _Iter __last)
623 {
return _S_convert(__detail::__string_from_range(__first, __last)); }
626 _S_convert_loc(
const char* __first,
const char* __last,
629 template<
typename _Iter>
631 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
633 const auto __s = __detail::__string_from_range(__first, __last);
634 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
637 template<
typename _Tp>
639 _S_convert_loc(
const _Tp& __s,
const std::locale& __loc)
641 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
644 template<
typename _CharT,
typename _Traits,
typename _Allocator>
645 static basic_string<_CharT, _Traits, _Allocator>
646 _S_str_convert(basic_string_view<value_type>,
const _Allocator&);
648 void _M_split_cmpts();
650 _Type _M_type() const noexcept {
return _M_cmpts.type(); }
652 string_type _M_pathname;
658 using value_type = _Cmpt;
659 using iterator = value_type*;
660 using const_iterator =
const value_type*;
664 _List(_List&&) =
default;
669 _Type type() const noexcept
670 {
return _Type(
reinterpret_cast<uintptr_t
>(_M_impl.get()) & 0x3); }
672 void type(_Type) noexcept;
674 int size() const noexcept;
675 bool empty() const noexcept;
677 void swap(_List& __l) noexcept { _M_impl.swap(__l._M_impl); }
678 int capacity() const noexcept;
679 void reserve(
int,
bool);
684 iterator begin() noexcept;
685 iterator end() noexcept;
686 const_iterator begin() const noexcept;
687 const_iterator end() const noexcept;
689 value_type& front() noexcept;
690 value_type& back() noexcept;
691 const value_type& front() const noexcept;
692 const value_type& back() const noexcept;
695 void _M_erase_from(const_iterator __pos);
700 void operator()(_Impl*)
const noexcept;
711 inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
713 size_t hash_value(
const path& __p) noexcept;
737 const path& path1()
const noexcept;
738 const path& path2()
const noexcept;
739 const char*
what() const noexcept;
743 std::__shared_ptr<const _Impl> _M_impl;
750 template<typename _InputIterator,
751 typename _Require = __detail::_Path2<_InputIterator>,
753 = __detail::__value_type_is_char_or_char8_t<_InputIterator>>
755 u8path(_InputIterator __first, _InputIterator __last)
757 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
758 if constexpr (is_same_v<_CharT, char>)
759 return path{ __detail::__wstr_from_utf8(
760 __detail::__string_from_range(__first, __last)) };
762 return path{ __first, __last };
765 return path{ __first, __last };
773 template<
typename _Source,
774 typename _Require = __detail::_Path<_Source>,
775 typename _CharT = __detail::__value_type_is_char_or_char8_t<_Source>>
779 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
780 if constexpr (is_same_v<_CharT, char>)
781 return path{ __detail::__wstr_from_utf8(
782 __detail::__effective_range(__source)) };
784 return path{ __source };
787 return path{ __source };
793 struct path::_Cmpt :
path
796 :
path(__s, __t), _M_pos(__pos) { }
798 _Cmpt() : _M_pos(-1) { }
803 template<
typename _E
charT>
805 path::_S_convert(
const _EcharT* __f,
const _EcharT* __l)
807 static_assert(__detail::__is_encoded_char<_EcharT>);
809 if constexpr (is_same_v<_EcharT, value_type>)
810 return basic_string_view<value_type>(__f, __l - __f);
811 #if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
812 else if constexpr (is_same_v<_EcharT, char8_t>)
814 return string_view(
reinterpret_cast<const char*
>(__f), __l - __f);
818 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
820 if constexpr (is_same_v<_EcharT, char>)
822 struct _UCvt :
std::codecvt<wchar_t, char, std::mbstate_t>
824 if (__str_codecvt_in_all(__f, __l, __wstr, __cvt))
827 #ifdef _GLIBCXX_USE_CHAR8_T
828 else if constexpr (is_same_v<_EcharT, char8_t>)
830 const auto __f2 =
reinterpret_cast<const char*
>(__f);
831 return __detail::__wstr_from_utf8(string_view(__f2, __l - __f));
836 struct _UCvt :
std::codecvt<_EcharT, char, std::mbstate_t>
839 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
840 return __detail::__wstr_from_utf8(__str);
843 struct _UCvt :
std::codecvt<_EcharT, char, std::mbstate_t>
846 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
849 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
850 "Cannot convert character sequence",
851 std::make_error_code(errc::illegal_byte_sequence)));
861 using difference_type = std::ptrdiff_t;
867 iterator() : _M_path(
nullptr), _M_cur(), _M_at_end() { }
876 iterator operator++(
int) {
auto __tmp = *
this; ++*
this;
return __tmp; }
879 iterator operator--(
int) {
auto __tmp = *
this; --*
this;
return __tmp; }
882 {
return __lhs._M_equals(__rhs); }
885 {
return !__lhs._M_equals(__rhs); }
890 bool _M_is_multi()
const {
return _M_path->_M_type() == _Type::_Multi; }
892 friend difference_type
895 __glibcxx_assert(__first._M_path !=
nullptr);
896 __glibcxx_assert(__first._M_path == __last._M_path);
897 if (__first._M_is_multi())
899 else if (__first._M_at_end == __last._M_at_end)
902 return __first._M_at_end ? -1 : 1;
906 __path_iter_advance(
iterator& __i, difference_type __n)
914 __glibcxx_assert(__i._M_path !=
nullptr);
915 __glibcxx_assert(__i._M_is_multi());
921 iterator(
const path* __path, path::_List::const_iterator __iter)
922 : _M_path(__path), _M_cur(__iter), _M_at_end()
926 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
932 path::_List::const_iterator _M_cur;
940 if (&__p ==
this) [[__unlikely__]]
943 _M_pathname =
std::move(__p._M_pathname);
954 path::assign(string_type&& __source)
955 {
return *
this = path(
std::move(__source)); }
958 path::operator+=(
const string_type& __x)
965 path::operator+=(
const value_type* __x)
972 path::operator+=(value_type __x)
974 _M_concat(basic_string_view<value_type>(&__x, 1));
979 path::operator+=(basic_string_view<value_type> __x)
985 template<
typename _CharT>
986 inline __detail::_Path2<_CharT*>&
987 path::operator+=(
const _CharT __x)
989 _M_concat(_S_convert(&__x, &__x + 1));
994 path::make_preferred()
996 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
997 std::replace(_M_pathname.begin(), _M_pathname.end(), L
'/',
998 preferred_separator);
1005 _M_pathname.swap(__rhs._M_pathname);
1006 _M_cmpts.swap(__rhs._M_cmpts);
1010 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1012 path::_S_str_convert(basic_string_view<value_type> __str,
1013 const _Allocator& __a)
1015 static_assert(!is_same_v<_CharT, value_type>);
1017 using _WString = basic_string<_CharT, _Traits, _Allocator>;
1019 if (__str.size() == 0)
1020 return _WString(__a);
1022 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1025 std::codecvt_utf8_utf16<value_type> __cvt;
1027 using _CharAlloc = __alloc_rebind<_Allocator, char>;
1028 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
1029 _String __u8str{_CharAlloc{__a}};
1030 const value_type* __wfirst = __str.data();
1031 const value_type* __wlast = __wfirst + __str.size();
1032 if (__str_codecvt_out_all(__wfirst, __wlast, __u8str, __cvt)) {
1033 if constexpr (is_same_v<_CharT, char>)
1037 const char* __first = __u8str.data();
1038 const char* __last = __first + __u8str.size();
1040 const value_type* __first = __str.data();
1041 const value_type* __last = __first + __str.size();
1045 #ifdef _GLIBCXX_USE_CHAR8_T
1046 if constexpr (is_same_v<_CharT, char8_t>)
1047 return _WString(__first, __last, __a);
1052 _WString __wstr(__a);
1053 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t> { } __cvt;
1054 if (__str_codecvt_in_all(__first, __last, __wstr, __cvt))
1058 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1061 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
1062 "Cannot convert character sequence",
1063 std::make_error_code(errc::illegal_byte_sequence)));
1067 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1068 inline basic_string<_CharT, _Traits, _Allocator>
1069 path::string(
const _Allocator& __a)
const
1071 if constexpr (is_same_v<_CharT, value_type>)
1072 return { _M_pathname.c_str(), _M_pathname.length(), __a };
1074 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
1078 path::string()
const {
return string<char>(); }
1080 #if _GLIBCXX_USE_WCHAR_T
1082 path::wstring()
const {
return string<wchar_t>(); }
1085 #ifdef _GLIBCXX_USE_CHAR8_T
1086 inline std::u8string
1087 path::u8string()
const {
return string<char8_t>(); }
1090 path::u8string()
const
1092 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1095 std::codecvt_utf8_utf16<value_type> __cvt;
1096 const value_type* __first = _M_pathname.data();
1097 const value_type* __last = __first + _M_pathname.size();
1098 if (__str_codecvt_out_all(__first, __last, __str, __cvt))
1100 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
1101 "Cannot convert character sequence",
1102 std::make_error_code(errc::illegal_byte_sequence)));
1107 #endif // _GLIBCXX_USE_CHAR8_T
1110 path::u16string()
const {
return string<char16_t>(); }
1113 path::u32string()
const {
return string<char32_t>(); }
1115 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1117 path::generic_string(
const _Allocator& __a)
const
1119 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1120 const value_type __slash = L
'/';
1122 const value_type __slash =
'/';
1124 using _Alloc2 =
typename allocator_traits<_Allocator>::template
1125 rebind_alloc<value_type>;
1126 basic_string<value_type, char_traits<value_type>, _Alloc2> __str(__a);
1128 if (_M_type() == _Type::_Root_dir)
1129 __str.
assign(1, __slash);
1132 __str.
reserve(_M_pathname.size());
1133 bool __add_slash =
false;
1134 for (
auto& __elem : *
this)
1136 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1137 if (__elem._M_type() == _Type::_Root_dir)
1145 __str += basic_string_view<value_type>(__elem._M_pathname);
1146 __add_slash = __elem._M_type() == _Type::_Filename;
1150 if constexpr (is_same_v<_CharT, value_type>)
1153 return _S_str_convert<_CharT, _Traits>(__str, __a);
1157 path::generic_string()
const
1158 {
return generic_string<char>(); }
1160 #if _GLIBCXX_USE_WCHAR_T
1162 path::generic_wstring()
const
1163 {
return generic_string<wchar_t>(); }
1166 #ifdef _GLIBCXX_USE_CHAR8_T
1167 inline std::u8string
1168 path::generic_u8string()
const
1169 {
return generic_string<char8_t>(); }
1172 path::generic_u8string()
const
1173 {
return generic_string(); }
1177 path::generic_u16string()
const
1178 {
return generic_string<char16_t>(); }
1181 path::generic_u32string()
const
1182 {
return generic_string<char32_t>(); }
1185 path::compare(
const string_type& __s)
const noexcept
1186 {
return compare(basic_string_view<value_type>(__s)); }
1189 path::compare(
const value_type* __s)
const noexcept
1190 {
return compare(basic_string_view<value_type>(__s)); }
1193 path::filename()
const
1197 else if (_M_type() == _Type::_Filename)
1199 else if (_M_type() == _Type::_Multi)
1201 if (_M_pathname.back() == preferred_separator)
1203 auto& __last = *--
end();
1204 if (__last._M_type() == _Type::_Filename)
1213 auto ext = _M_find_extension();
1214 if (ext.first && ext.second != 0)
1215 return path{ext.first->substr(0, ext.second)};
1220 path::extension()
const
1222 auto ext = _M_find_extension();
1224 return path{ext.first->substr(ext.second)};
1229 path::has_stem() const noexcept
1231 auto ext = _M_find_extension();
1232 return ext.first && ext.second != 0;
1236 path::has_extension() const noexcept
1238 auto ext = _M_find_extension();
1243 path::is_absolute() const noexcept
1245 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1246 return has_root_name() && has_root_directory();
1248 return has_root_directory();
1252 inline path::iterator
1255 if (_M_type() == _Type::_Multi)
1256 return iterator(
this, _M_cmpts.begin());
1257 return iterator(
this,
empty());
1260 inline path::iterator
1263 if (_M_type() == _Type::_Multi)
1264 return iterator(
this, _M_cmpts.end());
1265 return iterator(
this,
true);
1268 inline path::iterator&
1269 path::iterator::operator++()
1271 __glibcxx_assert(_M_path !=
nullptr);
1272 if (_M_path->_M_type() == _Type::_Multi)
1274 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1279 __glibcxx_assert(!_M_at_end);
1285 inline path::iterator&
1286 path::iterator::operator--()
1288 __glibcxx_assert(_M_path !=
nullptr);
1289 if (_M_path->_M_type() == _Type::_Multi)
1291 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1296 __glibcxx_assert(_M_at_end);
1302 inline path::iterator::reference
1303 path::iterator::operator*()
const
1305 __glibcxx_assert(_M_path !=
nullptr);
1306 if (_M_path->_M_type() == _Type::_Multi)
1308 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1315 path::iterator::_M_equals(iterator __rhs)
const
1317 if (_M_path != __rhs._M_path)
1319 if (_M_path ==
nullptr)
1321 if (_M_path->_M_type() == path::_Type::_Multi)
1322 return _M_cur == __rhs._M_cur;
1323 return _M_at_end == __rhs._M_at_end;
1327 _GLIBCXX_END_NAMESPACE_CXX11
1331 distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
1332 {
return __path_iter_distance(__first, __last); }
1334 template<
typename _InputIterator,
typename _Distance>
1336 advance(filesystem::path::iterator& __i, _Distance __n)
1337 { __path_iter_advance(__i,
static_cast<ptrdiff_t
>(__n)); }
1339 extern template class __shared_ptr<const filesystem::filesystem_error::_Impl>;
1341 _GLIBCXX_END_NAMESPACE_VERSION
1346 #endif // _GLIBCXX_FS_PATH_H