1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-20 19:02:41 +01:00

Codechange: use std::span over char* for writing the buffers

This commit is contained in:
Rubidium
2025-05-04 11:10:32 +02:00
committed by rubidium42
parent 6817f52d9b
commit 4255a94779
4 changed files with 12 additions and 19 deletions

View File

@@ -26,17 +26,12 @@ public:
/**
* Append buffer.
*/
virtual void PutBuffer(const char *str, size_type len) = 0;
/**
* Append span.
*/
void PutBuffer(std::span<const char> str) { this->PutBuffer(str.data(), str.size()); }
virtual void PutBuffer(std::span<const char> 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<const char> str) override;
/**
* Append string.