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/string-builder.hh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/nes/common/string-builder.hh') diff --git a/lib/nes/common/string-builder.hh b/lib/nes/common/string-builder.hh index e0bc673..256c267 100644 --- a/lib/nes/common/string-builder.hh +++ b/lib/nes/common/string-builder.hh @@ -1,6 +1,7 @@ #pragma once #include "nes/common/types.hh" +#include "nes/common/span.hh" #include namespace nes @@ -16,9 +17,8 @@ namespace nes /// Builds a string into a fixed-length buffer. class string_builder { - char* buffer_{ nullptr }; - u32 buffer_length_{ 0 }; - u32 actual_length_{ 0 }; + span buffer_; + u32 length_{ 0 }; bool is_good_{ true }; enum class format_arg_type @@ -60,10 +60,10 @@ namespace nes }; public: - explicit string_builder(char* buffer, u32 buffer_length); + explicit string_builder(span); /// Get the resulting string. - auto get_result() const -> std::string_view { return std::string_view{ buffer_, actual_length_ }; } + auto get_result() const -> std::string_view { return std::string_view{ buffer_.get_data(), length_ }; } /// Returns false after an invalid format string or buffer overflow. auto is_good() const -> bool { return is_good_; } @@ -104,7 +104,7 @@ namespace nes public: explicit string_buffer() - : string_builder{ buffer_, Capacity } + : string_builder{ buffer_ } { } }; -- cgit v1.3.1