30 #ifndef _GLIBCXX_FS_PATH_H 31 #define _GLIBCXX_FS_PATH_H 1 33 #if __cplusplus >= 201703L 36 #include <type_traits> 42 #include <system_error> 47 #if defined(_WIN32) && !defined(__CYGWIN__) 48 # define _GLIBCXX_FILESYSTEM_IS_WINDOWS 1 52 namespace std _GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
58 _GLIBCXX_BEGIN_NAMESPACE_CXX11
68 template<
typename _CharT>
71 template<
typename _Iter,
72 typename _Iter_traits = std::iterator_traits<_Iter>>
73 using __is_path_iter_src
74 = __and_<__is_encoded_char<typename _Iter_traits::value_type>,
76 typename _Iter_traits::iterator_category>>;
78 template<
typename _Iter>
79 static __is_path_iter_src<_Iter>
80 __is_path_src(_Iter,
int);
82 template<
typename _CharT,
typename _Traits,
typename _Alloc>
83 static __is_encoded_char<_CharT>
84 __is_path_src(
const basic_string<_CharT, _Traits, _Alloc>&,
int);
86 template<
typename _CharT,
typename _Traits>
87 static __is_encoded_char<_CharT>
88 __is_path_src(
const basic_string_view<_CharT, _Traits>&,
int);
90 template<
typename _Unknown>
92 __is_path_src(
const _Unknown&, ...);
94 template<
typename _Tp1,
typename _Tp2>
95 struct __constructible_from;
97 template<
typename _Iter>
98 struct __constructible_from<_Iter, _Iter>
99 : __is_path_iter_src<_Iter>
102 template<
typename _Source>
103 struct __constructible_from<_Source, void>
104 : decltype(__is_path_src(std::declval<_Source>(), 0))
107 template<
typename _Tp1,
typename _Tp2 =
void>
108 using _Path =
typename 110 __constructible_from<_Tp1, _Tp2>>::value,
113 template<
typename _Source>
115 _S_range_begin(_Source __begin) {
return __begin; }
117 struct __null_terminated { };
119 template<
typename _Source>
120 static __null_terminated
121 _S_range_end(_Source) {
return {}; }
123 template<
typename _CharT,
typename _Traits,
typename _Alloc>
125 _S_range_begin(
const basic_string<_CharT, _Traits, _Alloc>& __str)
126 {
return __str.data(); }
128 template<
typename _CharT,
typename _Traits,
typename _Alloc>
130 _S_range_end(
const basic_string<_CharT, _Traits, _Alloc>& __str)
131 {
return __str.data() + __str.size(); }
133 template<
typename _CharT,
typename _Traits>
135 _S_range_begin(
const basic_string_view<_CharT, _Traits>& __str)
136 {
return __str.data(); }
138 template<
typename _CharT,
typename _Traits>
140 _S_range_end(
const basic_string_view<_CharT, _Traits>& __str)
141 {
return __str.data() + __str.size(); }
143 template<
typename _Tp,
144 typename _Iter = decltype(_S_range_begin(std::declval<_Tp>())),
145 typename _Val =
typename std::iterator_traits<_Iter>::value_type>
146 using __value_type_is_char
150 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 151 typedef wchar_t value_type;
152 static constexpr value_type preferred_separator = L
'\\';
154 typedef char value_type;
155 static constexpr value_type preferred_separator =
'/';
159 enum format { native_format, generic_format, auto_format };
165 path(
const path& __p) =
default;
167 path(path&& __p) noexcept
168 : _M_pathname(std::move(__p._M_pathname)), _M_type(__p._M_type)
174 path(string_type&& __source, format = auto_format)
175 : _M_pathname(
std::move(__source))
176 { _M_split_cmpts(); }
178 template<
typename _Source,
179 typename _Require = _Path<_Source>>
180 path(_Source
const& __source, format = auto_format)
181 : _M_pathname(_S_convert(_S_range_begin(__source),
182 _S_range_end(__source)))
183 { _M_split_cmpts(); }
185 template<
typename _InputIterator,
186 typename _Require = _Path<_InputIterator, _InputIterator>>
187 path(_InputIterator __first, _InputIterator __last, format = auto_format)
188 : _M_pathname(_S_convert(__first, __last))
189 { _M_split_cmpts(); }
191 template<
typename _Source,
192 typename _Require = _Path<_Source>,
193 typename _Require2 = __value_type_is_char<_Source>>
194 path(_Source
const& __source,
const locale& __loc, format = auto_format)
195 : _M_pathname(_S_convert_loc(_S_range_begin(__source),
196 _S_range_end(__source), __loc))
197 { _M_split_cmpts(); }
199 template<
typename _InputIterator,
200 typename _Require = _Path<_InputIterator, _InputIterator>,
201 typename _Require2 = __value_type_is_char<_InputIterator>>
202 path(_InputIterator __first, _InputIterator __last,
const locale& __loc,
203 format = auto_format)
204 : _M_pathname(_S_convert_loc(__first, __last, __loc))
205 { _M_split_cmpts(); }
211 path& operator=(
const path& __p) =
default;
212 path& operator=(path&& __p) noexcept;
213 path& operator=(string_type&& __source);
214 path& assign(string_type&& __source);
216 template<
typename _Source>
218 operator=(_Source
const& __source)
219 {
return *
this = path(__source); }
221 template<
typename _Source>
223 assign(_Source
const& __source)
224 {
return *
this = path(__source); }
226 template<
typename _InputIterator>
227 _Path<_InputIterator, _InputIterator>&
228 assign(_InputIterator __first, _InputIterator __last)
229 {
return *
this = path(__first, __last); }
233 path& operator/=(
const path& __p)
235 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 236 if (__p.is_absolute()
237 || (__p.has_root_name() && __p.root_name() != root_name()))
241 string_type __pathname;
242 if (__p.has_root_directory())
243 __pathname = root_name().native();
244 else if (has_filename() || (!has_root_directory() && is_absolute()))
245 __pathname = _M_pathname + preferred_separator;
246 __pathname += __p.relative_path().native();
247 _M_pathname.swap(__pathname);
252 if (__p.is_absolute())
256 if (has_filename() || (_M_type == _Type::_Root_name))
257 _M_pathname += preferred_separator;
258 _M_pathname += __p.native();
265 template <
class _Source>
267 operator/=(_Source
const& __source)
268 {
return _M_append(path(__source)); }
270 template<
typename _Source>
272 append(_Source
const& __source)
273 {
return _M_append(path(__source)); }
275 template<
typename _InputIterator>
276 _Path<_InputIterator, _InputIterator>&
277 append(_InputIterator __first, _InputIterator __last)
278 {
return _M_append(path(__first, __last)); }
282 path& operator+=(
const path& __x);
283 path& operator+=(
const string_type& __x);
284 path& operator+=(
const value_type* __x);
285 path& operator+=(value_type __x);
286 path& operator+=(basic_string_view<value_type> __x);
288 template<
typename _Source>
290 operator+=(_Source
const& __x) {
return concat(__x); }
292 template<
typename _CharT>
293 _Path<_CharT*, _CharT*>&
294 operator+=(_CharT __x);
296 template<
typename _Source>
298 concat(_Source
const& __x)
299 {
return *
this += _S_convert(_S_range_begin(__x), _S_range_end(__x)); }
301 template<
typename _InputIterator>
302 _Path<_InputIterator, _InputIterator>&
303 concat(_InputIterator __first, _InputIterator __last)
304 {
return *
this += _S_convert(__first, __last); }
308 void clear() noexcept { _M_pathname.clear(); _M_split_cmpts(); }
310 path& make_preferred();
311 path& remove_filename();
312 path& replace_filename(
const path& __replacement);
313 path& replace_extension(
const path& __replacement = path());
315 void swap(path& __rhs) noexcept;
319 const string_type& native() const noexcept {
return _M_pathname; }
320 const value_type* c_str() const noexcept {
return _M_pathname.c_str(); }
321 operator string_type()
const {
return _M_pathname; }
323 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
324 typename _Allocator = std::allocator<_CharT>>
326 string(
const _Allocator& __a = _Allocator())
const;
329 #if _GLIBCXX_USE_WCHAR_T 337 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
338 typename _Allocator = std::allocator<_CharT>>
340 generic_string(
const _Allocator& __a = _Allocator())
const;
343 #if _GLIBCXX_USE_WCHAR_T 352 int compare(
const path& __p)
const noexcept;
353 int compare(
const string_type& __s)
const;
354 int compare(
const value_type* __s)
const;
355 int compare(
const basic_string_view<value_type> __s)
const;
359 path root_name()
const;
360 path root_directory()
const;
361 path root_path()
const;
362 path relative_path()
const;
363 path parent_path()
const;
364 path filename()
const;
366 path extension()
const;
370 [[nodiscard]]
bool empty() const noexcept {
return _M_pathname.empty(); }
371 bool has_root_name()
const;
372 bool has_root_directory()
const;
373 bool has_root_path()
const;
374 bool has_relative_path()
const;
375 bool has_parent_path()
const;
376 bool has_filename()
const;
377 bool has_stem()
const;
378 bool has_extension()
const;
379 bool is_absolute()
const {
return has_root_directory(); }
380 bool is_relative()
const {
return !is_absolute(); }
383 path lexically_normal()
const;
384 path lexically_relative(
const path& base)
const;
385 path lexically_proximate(
const path& base)
const;
389 typedef iterator const_iterator;
391 iterator
begin()
const;
392 iterator
end()
const;
395 enum class _Type : unsigned char {
396 _Multi, _Root_name, _Root_dir, _Filename
399 path(string_type __str, _Type __type) : _M_pathname(__str), _M_type(__type)
401 __glibcxx_assert(_M_type != _Type::_Multi);
404 enum class _Split { _Stem, _Extension };
409 if (__p.is_absolute())
410 operator=(std::move(__p));
411 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 412 else if (__p.has_root_name() && __p.root_name() != root_name())
413 operator=(std::move(__p));
416 operator/=(const_cast<const path&>(__p));
420 pair<const string_type*, size_t> _M_find_extension()
const;
422 template<
typename _CharT>
426 _S_convert(value_type* __src, __null_terminated)
427 {
return string_type(__src); }
430 _S_convert(
const value_type* __src, __null_terminated)
431 {
return string_type(__src); }
433 template<
typename _Iter>
435 _S_convert(_Iter __first, _Iter __last)
437 using __value_type =
typename std::iterator_traits<_Iter>::value_type;
438 return _Cvt<typename remove_cv<__value_type>::type>::
439 _S_convert(__first, __last);
442 template<
typename _InputIterator>
444 _S_convert(_InputIterator __src, __null_terminated)
446 using _Tp =
typename std::iterator_traits<_InputIterator>::value_type;
448 for (; *__src != _Tp{}; ++__src)
454 _S_convert_loc(
const char* __first,
const char* __last,
457 template<
typename _Iter>
459 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
462 return _S_convert_loc(__str.data(), __str.data()+__str.size(), __loc);
465 template<
typename _InputIterator>
467 _S_convert_loc(_InputIterator __src, __null_terminated,
471 while (*__src !=
'\0')
473 return _S_convert_loc(__tmp.
data(), __tmp.
data()+__tmp.
size(), __loc);
476 template<
typename _CharT,
typename _Traits,
typename _Allocator>
477 static basic_string<_CharT, _Traits, _Allocator>
478 _S_str_convert(
const string_type&,
const _Allocator& __a);
480 bool _S_is_dir_sep(value_type __ch)
482 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 483 return __ch == L
'/' || __ch == preferred_separator;
489 void _M_split_cmpts();
491 void _M_add_root_name(
size_t __n);
492 void _M_add_root_dir(
size_t __pos);
493 void _M_add_filename(
size_t __pos,
size_t __n);
495 string_type _M_pathname;
498 using _List = _GLIBCXX_STD_C::vector<_Cmpt>;
500 _Type _M_type = _Type::_Multi;
505 {
using value_type = char; };
509 {
using value_type = wchar_t; };
513 {
using value_type = char16_t; };
517 {
using value_type = char32_t; };
519 template<
typename _Tp>
520 struct path::__is_encoded_char<const _Tp> : __is_encoded_char<_Tp> { };
522 inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
527 inline bool operator<(
const path& __lhs,
const path& __rhs) noexcept
528 {
return __lhs.compare(__rhs) < 0; }
531 inline bool operator<=(
const path& __lhs,
const path& __rhs) noexcept
532 {
return !(__rhs < __lhs); }
535 inline bool operator>(
const path& __lhs,
const path& __rhs) noexcept
536 {
return __rhs < __lhs; }
539 inline bool operator>=(
const path& __lhs,
const path& __rhs) noexcept
540 {
return !(__lhs < __rhs); }
543 inline bool operator==(
const path& __lhs,
const path& __rhs) noexcept
544 {
return __lhs.compare(__rhs) == 0; }
547 inline bool operator!=(
const path& __lhs,
const path& __rhs) noexcept
548 {
return !(__lhs == __rhs); }
551 inline path
operator/(
const path& __lhs,
const path& __rhs)
552 {
return path(__lhs) /= __rhs; }
555 template<
typename _CharT,
typename _Traits>
556 basic_ostream<_CharT, _Traits>&
557 operator<<(basic_ostream<_CharT, _Traits>& __os,
const path& __p)
559 auto __tmp = __p.string<_CharT, _Traits>();
560 using __quoted_string
562 __os << __quoted_string{__tmp,
'"',
'\\'};
567 template<
typename _CharT,
typename _Traits>
568 basic_istream<_CharT, _Traits>&
569 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
571 basic_string<_CharT, _Traits> __tmp;
572 using __quoted_string
574 if (__is >> __quoted_string{ __tmp,
'"',
'\\' })
575 __p = std::move(__tmp);
579 template<
typename _Source>
581 u8path(
const _Source& __source)
584 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 586 return std::filesystem::u8path(__u8str.begin(), __u8str.end());
588 return path{ __source };
592 template<
typename _InputIterator>
594 u8path(_InputIterator __first, _InputIterator __last)
597 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 598 codecvt_utf8<value_type> __cvt;
600 if (__str_codecvt_in(__first, __last, __tmp, __cvt))
601 return path{ __tmp };
605 return path{ __first, __last };
612 filesystem_error(
const string& __what_arg, error_code __ec)
613 : system_error(__ec, __what_arg) { }
615 filesystem_error(
const string& __what_arg,
const path& __p1,
617 : system_error(__ec, __what_arg), _M_path1(__p1) { }
619 filesystem_error(
const string& __what_arg,
const path& __p1,
620 const path& __p2, error_code __ec)
621 : system_error(__ec, __what_arg), _M_path1(__p1), _M_path2(__p2)
626 const path& path1() const noexcept {
return _M_path1; }
627 const path& path2() const noexcept {
return _M_path2; }
628 const char* what() const noexcept {
return _M_what.c_str(); }
638 struct path::_Cmpt : path
640 _Cmpt(string_type __s, _Type __t,
size_t __pos)
641 : path(
std::move(__s), __t), _M_pos(__pos) { }
643 _Cmpt() : _M_pos(-1) { }
650 struct path::_Cvt<path::value_type>
652 template<
typename _Iter>
654 _S_convert(_Iter __first, _Iter __last)
655 {
return string_type{__first, __last}; }
658 template<
typename _CharT>
661 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 663 _S_wconvert(
const char* __f,
const char* __l,
true_type)
666 const auto& __cvt = std::use_facet<_Cvt>(
std::locale{});
668 if (__str_codecvt_in(__f, __l, __wstr, __cvt))
670 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
671 "Cannot convert character sequence",
672 std::make_error_code(errc::illegal_byte_sequence)));
676 _S_wconvert(
const _CharT* __f,
const _CharT* __l,
false_type)
678 std::codecvt_utf8<_CharT> __cvt;
680 if (__str_codecvt_out(__f, __l, __str, __cvt))
682 const char* __f2 = __str.
data();
683 const char* __l2 = __f2 + __str.
size();
684 std::codecvt_utf8<wchar_t> __wcvt;
686 if (__str_codecvt_in(__f2, __l2, __wstr, __wcvt))
689 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
690 "Cannot convert character sequence",
691 std::make_error_code(errc::illegal_byte_sequence)));
695 _S_convert(
const _CharT* __f,
const _CharT* __l)
697 return _S_wconvert(__f, __l, is_same<_CharT, char>{});
701 _S_convert(
const _CharT* __f,
const _CharT* __l)
703 std::codecvt_utf8<_CharT> __cvt;
705 if (__str_codecvt_out(__f, __l, __str, __cvt))
707 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
708 "Cannot convert character sequence",
709 std::make_error_code(errc::illegal_byte_sequence)));
714 _S_convert(_CharT* __f, _CharT* __l)
716 return _S_convert(const_cast<const _CharT*>(__f),
717 const_cast<const _CharT*>(__l));
720 template<
typename _Iter>
722 _S_convert(_Iter __first, _Iter __last)
725 return _S_convert(__str.
data(), __str.
data() + __str.
size());
728 template<
typename _Iter,
typename _Cont>
730 _S_convert(__gnu_cxx::__normal_iterator<_Iter, _Cont> __first,
731 __gnu_cxx::__normal_iterator<_Iter, _Cont> __last)
732 {
return _S_convert(__first.base(), __last.base()); }
739 using difference_type = std::ptrdiff_t;
740 using value_type = path;
741 using reference =
const path&;
742 using pointer =
const path*;
745 iterator() : _M_path(nullptr), _M_cur(), _M_at_end() { }
747 iterator(
const iterator&) =
default;
748 iterator& operator=(
const iterator&) =
default;
753 iterator& operator++();
754 iterator operator++(
int) {
auto __tmp = *
this; ++*
this;
return __tmp; }
756 iterator& operator--();
757 iterator operator--(
int) {
auto __tmp = *
this; --*
this;
return __tmp; }
759 friend bool operator==(
const iterator& __lhs,
const iterator& __rhs)
760 {
return __lhs._M_equals(__rhs); }
762 friend bool operator!=(
const iterator& __lhs,
const iterator& __rhs)
763 {
return !__lhs._M_equals(__rhs); }
768 iterator(
const path* __path, path::_List::const_iterator __iter)
769 : _M_path(__path), _M_cur(__iter), _M_at_end()
772 iterator(
const path* __path,
bool __at_end)
773 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
776 bool _M_equals(iterator)
const;
779 path::_List::const_iterator _M_cur;
785 path::operator=(path&& __p) noexcept
787 _M_pathname = std::move(__p._M_pathname);
788 _M_cmpts = std::move(__p._M_cmpts);
789 _M_type = __p._M_type;
795 path::operator=(string_type&& __source)
796 {
return *
this = path(std::move(__source)); }
799 path::assign(string_type&& __source)
800 {
return *
this = path(std::move(__source)); }
803 path::operator+=(
const path& __p)
805 return operator+=(__p.native());
809 path::operator+=(
const string_type& __x)
817 path::operator+=(
const value_type* __x)
825 path::operator+=(value_type __x)
833 path::operator+=(basic_string_view<value_type> __x)
835 _M_pathname.append(__x.data(), __x.size());
840 template<
typename _CharT>
841 inline path::_Path<_CharT*, _CharT*>&
842 path::operator+=(_CharT __x)
845 return concat(__addr, __addr + 1);
849 path::make_preferred()
851 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 852 std::replace(_M_pathname.begin(), _M_pathname.end(), L
'/',
853 preferred_separator);
858 inline void path::swap(path& __rhs) noexcept
860 _M_pathname.swap(__rhs._M_pathname);
861 _M_cmpts.swap(__rhs._M_cmpts);
862 std::swap(_M_type, __rhs._M_type);
865 template<
typename _CharT,
typename _Traits,
typename _Allocator>
867 path::_S_str_convert(
const string_type& __str,
const _Allocator& __a)
869 if (__str.size() == 0)
872 const value_type* __first = __str.data();
873 const value_type* __last = __first + __str.size();
875 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 876 using _CharAlloc = __alloc_rebind<_Allocator, char>;
877 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
878 using _WString = basic_string<_CharT, _Traits, _Allocator>;
881 codecvt_utf8<value_type> __cvt;
882 _String __u8str{_CharAlloc{__a}};
883 if (__str_codecvt_out(__first, __last, __u8str, __cvt))
885 if constexpr (is_same_v<_CharT, char>)
891 codecvt_utf8<_CharT> __cvt;
892 const char* __f = __u8str.
data();
893 const char* __l = __f + __u8str.size();
894 if (__str_codecvt_in(__f, __l, __wstr, __cvt))
899 codecvt_utf8<_CharT> __cvt;
900 basic_string<_CharT, _Traits, _Allocator> __wstr{__a};
901 if (__str_codecvt_in(__first, __last, __wstr, __cvt))
904 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
905 "Cannot convert character sequence",
906 std::make_error_code(errc::illegal_byte_sequence)));
909 template<
typename _CharT,
typename _Traits,
typename _Allocator>
910 inline basic_string<_CharT, _Traits, _Allocator>
913 if constexpr (is_same_v<_CharT, value_type>)
914 #if _GLIBCXX_USE_CXX11_ABI 915 return { _M_pathname, __a };
917 return { _M_pathname, string_type::size_type(0), __a };
920 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
926 #if _GLIBCXX_USE_WCHAR_T 932 path::u8string()
const 934 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 937 codecvt_utf8<value_type> __cvt;
938 const value_type* __first = _M_pathname.
data();
939 const value_type* __last = __first + _M_pathname.size();
940 if (__str_codecvt_out(__first, __last, __str, __cvt))
942 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
943 "Cannot convert character sequence",
944 std::make_error_code(errc::illegal_byte_sequence)));
956 template<
typename _CharT,
typename _Traits,
typename _Allocator>
958 path::generic_string(
const _Allocator& __a)
const 960 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 961 const value_type __slash = L
'/';
963 const value_type __slash =
'/';
965 string_type __str(__a);
967 if (_M_type == _Type::_Root_dir)
971 __str.
reserve(_M_pathname.size());
972 bool __add_slash =
false;
973 for (
auto& __elem : *
this)
977 __str += __elem._M_pathname;
978 __add_slash = __elem._M_type == _Type::_Filename;
982 if constexpr (is_same_v<_CharT, value_type>)
985 return _S_str_convert<_CharT, _Traits>(__str, __a);
989 path::generic_string()
const 990 {
return generic_string<char>(); }
992 #if _GLIBCXX_USE_WCHAR_T 994 path::generic_wstring()
const 995 {
return generic_string<wchar_t>(); }
999 path::generic_u8string()
const 1000 {
return generic_string(); }
1003 path::generic_u16string()
const 1004 {
return generic_string<char16_t>(); }
1007 path::generic_u32string()
const 1008 {
return generic_string<char32_t>(); }
1011 path::compare(
const string_type& __s)
const {
return compare(path(__s)); }
1014 path::compare(
const value_type* __s)
const {
return compare(path(__s)); }
1017 path::compare(basic_string_view<value_type> __s)
const 1018 {
return compare(path(__s)); }
1021 path::filename()
const 1025 else if (_M_type == _Type::_Filename)
1027 else if (_M_type == _Type::_Multi)
1029 if (_M_pathname.back() == preferred_separator)
1031 auto& __last = *--
end();
1032 if (__last._M_type == _Type::_Filename)
1041 auto ext = _M_find_extension();
1042 if (ext.first && ext.second != 0)
1043 return path{ext.first->substr(0, ext.second)};
1048 path::extension()
const 1050 auto ext = _M_find_extension();
1051 if (ext.first && ext.second != string_type::npos)
1052 return path{ext.first->substr(ext.second)};
1057 path::has_stem()
const 1059 auto ext = _M_find_extension();
1060 return ext.first && ext.second != 0;
1064 path::has_extension()
const 1066 auto ext = _M_find_extension();
1067 return ext.first && ext.second != string_type::npos;
1070 inline path::iterator
1073 if (_M_type == _Type::_Multi)
1074 return iterator(
this, _M_cmpts.begin());
1075 return iterator(
this,
false);
1078 inline path::iterator
1081 if (_M_type == _Type::_Multi)
1082 return iterator(
this, _M_cmpts.end());
1083 return iterator(
this,
true);
1086 inline path::iterator&
1087 path::iterator::operator++()
1089 __glibcxx_assert(_M_path !=
nullptr);
1090 if (_M_path->_M_type == _Type::_Multi)
1092 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1097 __glibcxx_assert(!_M_at_end);
1103 inline path::iterator&
1104 path::iterator::operator--()
1106 __glibcxx_assert(_M_path !=
nullptr);
1107 if (_M_path->_M_type == _Type::_Multi)
1109 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1114 __glibcxx_assert(_M_at_end);
1120 inline path::iterator::reference
1121 path::iterator::operator*()
const 1123 __glibcxx_assert(_M_path !=
nullptr);
1124 if (_M_path->_M_type == _Type::_Multi)
1126 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1133 path::iterator::_M_equals(iterator __rhs)
const 1135 if (_M_path != __rhs._M_path)
1137 if (_M_path ==
nullptr)
1139 if (_M_path->_M_type == path::_Type::_Multi)
1140 return _M_cur == __rhs._M_cur;
1141 return _M_at_end == __rhs._M_at_end;
1145 _GLIBCXX_END_NAMESPACE_CXX11
1148 _GLIBCXX_END_NAMESPACE_VERSION
1153 #endif // _GLIBCXX_FS_PATH_H size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
basic_string< char32_t > u32string
A string of char32_t.
Define a member typedef type only if a boolean constant is true.
Thrown to indicate error code of underlying system.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
basic_string< char > string
A string of char.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
void replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__old_value, const _Tp &__new_value)
Replace each occurrence of one value in a sequence with another value.
void push_back(_CharT __c)
Append a single character.
const _CharT * data() const noexcept
Return const pointer to contents.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
basic_string< char16_t > u16string
A string of char16_t.
Class codecvt<wchar_t, char, mbstate_t> specialization.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
size_t hash_value(const path &__p) noexcept
Compare paths.
ISO C++ entities toplevel namespace is std.
static const locale & classic()
Return reference to the C locale.
Bidirectional iterators support a superset of forward iterator operations.
path u8path(const _Source &__source)
Compare paths.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
Struct for delimited strings.
complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
basic_string< wchar_t > wstring
A string of wchar_t.
Container class for localization functionality.The locale class is first a class wrapper for C librar...
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.