mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:14:58 +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:
parent
ab1244a160
commit
6f6d6c654d
2 changed files with 22 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue