Skip to content

ludus::foundation::StringBuilder

Ludus Wiki · API overview · Browse API

Class

Reusable append buffer around one String.
Appends report failure explicitly and leave the contents unchanged; there are no expression templates, allocating operator+ chains or hidden copies. Clear keeps the storage for reuse. Not internally synchronized, like String.

Declared in modules/foundation/strings/include/ludus/foundation/strings/string.hpp

#include <ludus/foundation/strings/string.hpp>
class ludus::foundation::StringBuilder final

Methods

StringBuilder

explicit ludus::foundation::StringBuilder::StringBuilder(const AllocationDomain &domain=GetSystemAllocationDomain()) noexcept
Creates an empty builder whose string allocates from domain; does not allocate.
ParameterDescription
domain
Borrowed allocation domain; it must outlive the builder and any taken string.

Related types: AllocationDomain

Declared in modules/foundation/strings/include/ludus/foundation/strings/string.hpp

TryAppend

StringStatus ludus::foundation::StringBuilder::TryAppend(std::string_view value) noexcept
Appends value, as String::TryAppend; value may alias the builder's contents.

Related types: StringStatus

Declared in modules/foundation/strings/include/ludus/foundation/strings/string.hpp

TryAppendMany

StringStatus ludus::foundation::StringBuilder::TryAppendMany(std::span< const std::string_view > values) noexcept
Appends every view with one reserve and one commit, as String::TryAppendMany.

Related types: StringStatus

Declared in modules/foundation/strings/include/ludus/foundation/strings/string.hpp

TryEnsureCapacity

StringStatus ludus::foundation::StringBuilder::TryEnsureCapacity(usize capacity) noexcept
Reserves room for capacity bytes, as String::TryEnsureCapacity.

Related types: StringStatus · usize

Declared in modules/foundation/strings/include/ludus/foundation/strings/string.hpp

GetView

std::string_view ludus::foundation::StringBuilder::GetView() const &noexcept
Borrowed view of the bytes built so far; valid until the next non-const call or destruction.

Declared in modules/foundation/strings/include/ludus/foundation/strings/string.hpp

GetView

std::string_view ludus::foundation::StringBuilder::GetView() const &&=delete
Deleted so a view cannot outlive a temporary builder that is destroyed at the end of the expression.

Declared in modules/foundation/strings/include/ludus/foundation/strings/string.hpp

TakeString

String ludus::foundation::StringBuilder::TakeString() noexcept
Moves the built string out without allocating.
The result keeps the builder's domain and storage. The builder becomes empty and inline with the same domain, so growing it beyond String::kInlineCapacity allocates again.

Related types: String

Declared in modules/foundation/strings/include/ludus/foundation/strings/string.hpp

Clear

void ludus::foundation::StringBuilder::Clear() noexcept
Empties the builder and keeps its storage; never allocates or frees.

Declared in modules/foundation/strings/include/ludus/foundation/strings/string.hpp