diff --git a/src/core/string_builder.cpp b/src/core/string_builder.cpp index 3144656e4c..6ded799c30 100644 --- a/src/core/string_builder.cpp +++ b/src/core/string_builder.cpp @@ -113,13 +113,13 @@ void BaseStringBuilder::PutChar(char c) void BaseStringBuilder::PutUtf8(char32_t c) { auto [buf, len] = EncodeUtf8(c); - this->PutBuffer(buf, len); + this->PutBuffer({buf, len}); } /** * Append buffer. */ -void StringBuilder::PutBuffer(const char *str, size_type len) +void StringBuilder::PutBuffer(std::span str) { - this->dest->append(str, len); + this->dest->append(str.data(), str.size()); } diff --git a/src/core/string_builder.hpp b/src/core/string_builder.hpp index c6058bab05..24247c0c4a 100644 --- a/src/core/string_builder.hpp +++ b/src/core/string_builder.hpp @@ -26,17 +26,12 @@ public: /** * Append buffer. */ - virtual void PutBuffer(const char *str, size_type len) = 0; - - /** - * Append span. - */ - void PutBuffer(std::span str) { this->PutBuffer(str.data(), str.size()); } + virtual void PutBuffer(std::span str) = 0; /** * Append string. */ - void Put(std::string_view str) { this->PutBuffer(str.data(), str.size()); } + void Put(std::string_view str) { this->PutBuffer(str); } void PutUint8(uint8_t value); void PutSint8(int8_t value); @@ -60,7 +55,7 @@ public: auto result = std::to_chars(buf.data(), buf.data() + buf.size(), value, base); if (result.ec != std::errc{}) return; size_type len = result.ptr - buf.data(); - this->PutBuffer(buf.data(), len); + this->PutBuffer({buf.data(), len}); } }; @@ -93,8 +88,7 @@ public: */ [[nodiscard]] std::string &GetString() noexcept { return *dest; } - using BaseStringBuilder::PutBuffer; - void PutBuffer(const char *str, size_type len) override; + void PutBuffer(std::span str) override; /** * Append string. diff --git a/src/core/string_inplace.cpp b/src/core/string_inplace.cpp index 248fe8d130..1c3a5c8485 100644 --- a/src/core/string_inplace.cpp +++ b/src/core/string_inplace.cpp @@ -32,12 +32,12 @@ /** * Append buffer. */ -void InPlaceBuilder::PutBuffer(const char *str, size_type len) +void InPlaceBuilder::PutBuffer(std::span str) { auto unused = this->GetBytesUnused(); - if (len > unused) NOT_REACHED(); - std::copy(str, str + len, this->dest.data() + this->position); - this->position += len; + if (str.size() > unused) NOT_REACHED(); + std::ranges::copy(str, this->dest.data() + this->position); + this->position += str.size(); } /** diff --git a/src/core/string_inplace.hpp b/src/core/string_inplace.hpp index eaf16752b0..5b97735291 100644 --- a/src/core/string_inplace.hpp +++ b/src/core/string_inplace.hpp @@ -47,8 +47,7 @@ public: [[nodiscard]] bool AnyBytesUnused() const noexcept; [[nodiscard]] size_type GetBytesUnused() const noexcept; - using BaseStringBuilder::PutBuffer; - void PutBuffer(const char *str, size_type len) override; + void PutBuffer(std::span str) override; /** * Implementation of std::back_insert_iterator for non-growing destination buffer.