mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:07:36 +00:00
AK: Implement string formatting for FixedStringBuffers
To ensure this happens without duplicating code, we allow forcing a StringBuilder object to only use the inline buffer, so the code in the AK/Format.cpp file doesn't need to deal with different underlying storage types (expandable or inline-fixed) at all.
This commit is contained in:
parent
b096f39e92
commit
b2fd51f561
3 changed files with 76 additions and 6 deletions
|
@ -16,11 +16,19 @@ namespace AK {
|
|||
|
||||
class StringBuilder {
|
||||
public:
|
||||
static constexpr size_t inline_capacity = 256;
|
||||
|
||||
using OutputType = DeprecatedString;
|
||||
|
||||
static ErrorOr<StringBuilder> create(size_t initial_capacity = inline_capacity);
|
||||
|
||||
explicit StringBuilder(size_t initial_capacity = inline_capacity);
|
||||
|
||||
enum class UseInlineCapacityOnly {
|
||||
Yes,
|
||||
No,
|
||||
};
|
||||
explicit StringBuilder(UseInlineCapacityOnly use_inline_capacity_only);
|
||||
~StringBuilder() = default;
|
||||
|
||||
ErrorOr<void> try_append(StringView);
|
||||
|
@ -73,9 +81,9 @@ public:
|
|||
[[nodiscard]] StringView string_view() const;
|
||||
void clear();
|
||||
|
||||
[[nodiscard]] size_t length() const { return m_buffer.size(); }
|
||||
[[nodiscard]] bool is_empty() const { return m_buffer.is_empty(); }
|
||||
void trim(size_t count) { m_buffer.resize(m_buffer.size() - count); }
|
||||
[[nodiscard]] size_t length() const;
|
||||
[[nodiscard]] bool is_empty() const;
|
||||
void trim(size_t count);
|
||||
|
||||
template<class SeparatorType, class CollectionType>
|
||||
void join(SeparatorType const& separator, CollectionType const& collection, StringView fmtstr = "{}"sv)
|
||||
|
@ -98,10 +106,10 @@ public:
|
|||
|
||||
private:
|
||||
ErrorOr<void> will_append(size_t);
|
||||
u8* data() { return m_buffer.data(); }
|
||||
u8 const* data() const { return m_buffer.data(); }
|
||||
u8* data();
|
||||
u8 const* data() const;
|
||||
|
||||
static constexpr size_t inline_capacity = 256;
|
||||
UseInlineCapacityOnly m_use_inline_capacity_only { UseInlineCapacityOnly::No };
|
||||
Detail::ByteBuffer<inline_capacity> m_buffer;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue