mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibJS: Add a fallible ThrowableStringBuilder::appendff
This commit is contained in:
parent
7163e4d456
commit
519a1cd23d
1 changed files with 14 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Format.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
|
@ -25,6 +26,19 @@ public:
|
||||||
ThrowCompletionOr<void> append_code_point(u32 value);
|
ThrowCompletionOr<void> append_code_point(u32 value);
|
||||||
ThrowCompletionOr<String> to_string() const;
|
ThrowCompletionOr<String> to_string() const;
|
||||||
|
|
||||||
|
template<typename... Parameters>
|
||||||
|
ThrowCompletionOr<void> appendff(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
||||||
|
{
|
||||||
|
AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::No, Parameters...> variadic_format_params { parameters... };
|
||||||
|
|
||||||
|
if (vformat(*this, fmtstr.view(), variadic_format_params).is_error()) {
|
||||||
|
// The size returned here is a bit of an estimate, as we don't know what the final formatted string length would be.
|
||||||
|
return m_vm.throw_completion<InternalError>(ErrorType::NotEnoughMemoryToAllocate, length() + fmtstr.view().length());
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
using AK::StringBuilder::is_empty;
|
using AK::StringBuilder::is_empty;
|
||||||
using AK::StringBuilder::string_view;
|
using AK::StringBuilder::string_view;
|
||||||
using AK::StringBuilder::trim;
|
using AK::StringBuilder::trim;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue