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:
parent
d296001f3f
commit
3219ce3d61
3 changed files with 32 additions and 6 deletions
12
AK/Hex.cpp
12
AK/Hex.cpp
|
@ -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
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue