From 9c45e9c7df1efa5bc1c8e73b6eaef4726b828d3e Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Tue, 4 Feb 2025 19:59:47 +0100 Subject: add span type --- lib/nes/common/path-builder.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'lib/nes/common/path-builder.cc') diff --git a/lib/nes/common/path-builder.cc b/lib/nes/common/path-builder.cc index 67190dc..794d565 100644 --- a/lib/nes/common/path-builder.cc +++ b/lib/nes/common/path-builder.cc @@ -2,12 +2,11 @@ namespace nes { - path_builder::path_builder(char* buffer, u32 const buffer_length) + path_builder::path_builder(span const buffer) : buffer_{ buffer } - , buffer_length_{ buffer_length } { // Initialize the path to "/" if possible. - if (buffer_length > 0) { buffer_[actual_length_++] = '/'; } + if (buffer_.get_length() > 0) { buffer_[length_++] = '/'; } } auto path_builder::push(std::string_view component) -> bool @@ -18,30 +17,30 @@ namespace nes if (component.empty() || std::find(component.begin(), component.end(), '/') != component.end()) { return false; } // Check if there is enough remaining capacity for "/" - auto const add_leading_slash = actual_length_ == 0 || buffer_[actual_length_ - 1] != '/'; + auto const add_leading_slash = length_ == 0 || buffer_[length_ - 1] != '/'; auto const length = component.length() + (add_leading_slash ? 1 : 0); - if (actual_length_ + length > buffer_length_) { return false; } + if (length_ + length > buffer_.get_length()) { return false; } // Append "/" - if (add_leading_slash) { buffer_[actual_length_++] = '/'; } - for (auto i = u32{ 0 }; i < component.length(); ++i) { buffer_[actual_length_++] = component[i]; } + if (add_leading_slash) { buffer_[length_++] = '/'; } + for (auto i = u32{ 0 }; i < component.length(); ++i) { buffer_[length_++] = component[i]; } return true; } auto path_builder::pop() -> bool { - if (actual_length_ == 0 || buffer_[actual_length_ - 1] == '/') { return false; } + if (length_ == 0 || buffer_[length_ - 1] == '/') { return false; } // Find the start of the last component. - auto last_start = actual_length_ - 1; + auto last_start = length_ - 1; while (last_start > 0 && buffer_[last_start] != '/') { last_start -= 1; } // Drop the slash if we are not at the root. if (last_start == 0) { last_start += 1; } // Drop everything including the trailing slash. - actual_length_ = last_start; + length_ = last_start; return true; } } // namespace nes \ No newline at end of file -- cgit v1.3.1