1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:57:44 +00:00

AK: Return KString instead of String from encode_hex in the Kernel

This let's us propagate allocation errors from this API.
This commit is contained in:
Idan Horowitz 2022-02-15 23:25:25 +02:00 committed by Andreas Kling
parent d296001f3f
commit 3219ce3d61
3 changed files with 32 additions and 6 deletions

View file

@ -35,6 +35,17 @@ ErrorOr<ByteBuffer> decode_hex(StringView input)
return { move(output) };
}
#ifdef KERNEL
ErrorOr<NonnullOwnPtr<Kernel::KString>> encode_hex(const ReadonlyBytes input)
{
StringBuilder output(input.size() * 2);
for (auto ch : input)
TRY(output.try_appendff("{:02x}", ch));
return Kernel::KString::try_create(output.string_view());
}
#else
String encode_hex(const ReadonlyBytes input)
{
StringBuilder output(input.size() * 2);
@ -44,5 +55,6 @@ String encode_hex(const ReadonlyBytes input)
return output.build();
}
#endif
}