mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibCrypto: Define *BigInteger::to_base to convert big integers to String
This commit is contained in:
committed by
Linus Groh
parent
0ddc2e1f50
commit
3ad1f250e7
Notes:
sideshowbarker
2024-07-17 01:41:35 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/3ad1f250e7 Pull-request: https://github.com/SerenityOS/serenity/pull/17014 Reviewed-by: https://github.com/linusg ✅
@@ -51,16 +51,22 @@ SignedBigInteger SignedBigInteger::from_base(u16 N, StringView str)
|
||||
return { move(unsigned_data), sign };
|
||||
}
|
||||
|
||||
DeprecatedString SignedBigInteger::to_base_deprecated(u16 N) const
|
||||
ErrorOr<String> SignedBigInteger::to_base(u16 N) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
||||
if (m_sign)
|
||||
builder.append('-');
|
||||
TRY(builder.try_append('-'));
|
||||
|
||||
builder.append(m_unsigned_data.to_base_deprecated(N));
|
||||
auto unsigned_as_base = TRY(m_unsigned_data.to_base(N));
|
||||
TRY(builder.try_append(unsigned_as_base.bytes_as_string_view()));
|
||||
|
||||
return builder.to_deprecated_string();
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
DeprecatedString SignedBigInteger::to_base_deprecated(u16 N) const
|
||||
{
|
||||
return MUST(to_base(N)).to_deprecated_string();
|
||||
}
|
||||
|
||||
u64 SignedBigInteger::to_u64() const
|
||||
|
||||
Reference in New Issue
Block a user