diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-02-06 16:34:23 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-02-06 16:34:23 +0100 |
| commit | d1b61b02b1a6bdaa337ff060eda3d3d5fb67827d (patch) | |
| tree | de3b1d7f7907e9fc786a1b7491b9bca9b9d296b0 /lib/nes/common/containers/path-view.cc | |
| parent | 30b4364c772114303d9045677186a53855ea5343 (diff) | |
refactor: move containers into separate directory
Diffstat (limited to 'lib/nes/common/containers/path-view.cc')
| -rw-r--r-- | lib/nes/common/containers/path-view.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/nes/common/containers/path-view.cc b/lib/nes/common/containers/path-view.cc new file mode 100644 index 0000000..c81668b --- /dev/null +++ b/lib/nes/common/containers/path-view.cc @@ -0,0 +1,51 @@ +#include "nes/common/containers/path-view.hh" +#include "nes/common/debug.hh" + +namespace nes +{ + auto path_view::iterator::operator*() const -> std::string_view + { + NES_ASSERT(current_ != nullptr && component_length_ > 0 && "invalid iterator"); + return std::string_view{ current_, component_length_ }; + } + + auto path_view::iterator::operator++() -> iterator& + { + // Move forward to next component + current_ += component_length_; + remaining_ -= component_length_; + + // Skip over '/'. + while (remaining_ > 0 && *current_ == '/') + { + current_ += 1; + remaining_ -= 1; + } + + // Scan until end of component to find its length. + component_length_ = 0; + while (component_length_ < remaining_ && current_[component_length_] != '/') + { + component_length_ += 1; + } + + return *this; + } + + auto path_view::iterator::operator++(int) -> iterator + { + auto const res = *this; + ++*this; + return res; + } + + auto path_view::begin() const -> iterator + { + return ++iterator{ path_.data(), 0, static_cast<u32>(path_.size()) }; + } + + auto path_view::end() const -> iterator + { + return iterator{ path_.data() + path_.size(), 0, 0 }; + } +} // namespace nes
\ No newline at end of file |
