diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-02-04 19:59:47 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-02-04 19:59:47 +0100 |
| commit | 9c45e9c7df1efa5bc1c8e73b6eaef4726b828d3e (patch) | |
| tree | 4be985efa8e697fd6ef5838eec69c32c40c5d4a5 /lib/nes/common/string-builder.hh | |
| parent | e791ac9a46095e0241181da89c35a7c702982c21 (diff) | |
add span type
Diffstat (limited to 'lib/nes/common/string-builder.hh')
| -rw-r--r-- | lib/nes/common/string-builder.hh | 12 |
1 files changed, 6 insertions, 6 deletions
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 <string_view> 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<char> 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<char>); /// 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_ } { } }; |
