mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
AK: Implement Stream::format(fmtstr, args...)
Based on `out()` and `vout()` from AK/Format.h. As opposed to those, this propagates errors. As `Core::File` extends `AK::Stream`, this allows formatted printing directly on `Core::File`s.
This commit is contained in:
committed by
Andreas Kling
parent
ab1244a160
commit
6f6d6c654d
@@ -8,6 +8,7 @@
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Stream.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
@@ -97,6 +98,16 @@ ErrorOr<void> Stream::write_until_depleted(ReadonlyBytes buffer)
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> Stream::format_impl(StringView fmtstr, TypeErasedFormatParams& parameters)
|
||||
{
|
||||
StringBuilder builder;
|
||||
TRY(vformat(builder, fmtstr, parameters));
|
||||
|
||||
auto const string = builder.string_view();
|
||||
TRY(write_until_depleted(string.bytes()));
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<size_t> SeekableStream::tell() const
|
||||
{
|
||||
// Seek with 0 and SEEK_CUR does not modify anything despite the const_cast,
|
||||
|
||||
Reference in New Issue
Block a user