1#ifndef MSTL_CORE_ITERATOR_PATH_ITERATOR_HPP__
2#define MSTL_CORE_ITERATOR_PATH_ITERATOR_HPP__
3#include "../string/string.hpp"
4#include "../file/file_constants.hpp"
9 using value_type = string_view;
10 using reference = value_type;
12 using iterator_category = forward_iterator_tag;
16 const string* p_ =
nullptr;
23 const size_t sz = p_->size();
24 const size_t pos = start_;
26#ifdef MSTL_PLATFORM_WINDOWS__
27 if (pos == 0 && sz > 1 && (*p_)[1] ==
':') {
28 current_part_ = p_->substr(0, 2);
30 while (start_ < sz && ((*p_)[start_] ==
'/' || (*p_)[start_] ==
'\\'))
38 const size_t sep_pos = p_->find_first_of(FILE_SPLITER, pos);
39 if (sep_pos == string::npos) {
40 current_part_ = p_->substr(pos);
43 current_part_ = p_->substr(pos, sep_pos - pos);
49 path_iterator() noexcept = default;
51 explicit path_iterator(const
string* path, const
size_t pos = 0) noexcept
52 : p_(path), start_(pos), done_(false) {
53 if (!p_ || p_->empty() || start_ >= p_->size()) {
60 reference operator *() const noexcept {
61 return current_part_.view();
64 path_iterator& operator ++() {
65 if (done_)
return *
this;
67 if (start_ >= p_->size()) {
76 path_iterator operator ++(
int) {
77 path_iterator tmp = *
this;
82 MSTL_NODISCARD
bool operator ==(
const path_iterator& b)
const noexcept {
83 if (done_ && b.done_)
return true;
84 if (p_ != b.p_)
return false;
85 return start_ == b.start_;
88 MSTL_NODISCARD
bool operator !=(
const path_iterator& b)
const noexcept {
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL