mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add float support for JsonValue and JsonObjectSerializer
This commit is contained in:
parent
ae1cd4b448
commit
73ade62d4f
Notes:
sideshowbarker
2024-07-17 17:46:31 +09:00
Author: https://github.com/MichielVrins Commit: https://github.com/SerenityOS/serenity/commit/73ade62d4f Pull-request: https://github.com/SerenityOS/serenity/pull/12793 Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/drunderscore Reviewed-by: https://github.com/linusg
2 changed files with 13 additions and 3 deletions
|
@ -170,6 +170,16 @@ public:
|
|||
}
|
||||
|
||||
#ifndef KERNEL
|
||||
ErrorOr<void> add(StringView key, float value)
|
||||
{
|
||||
TRY(begin_item(key));
|
||||
if constexpr (IsLegacyBuilder<Builder>)
|
||||
TRY(m_builder.try_appendff("{}", value));
|
||||
else
|
||||
TRY(m_builder.appendff("{}", value));
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> add(StringView key, double value)
|
||||
{
|
||||
TRY(begin_item(key));
|
||||
|
|
|
@ -101,12 +101,12 @@ public:
|
|||
unsigned to_uint(unsigned default_value = 0) const { return to_u32(default_value); }
|
||||
u32 to_u32(u32 default_value = 0) const { return to_number<u32>(default_value); }
|
||||
u64 to_u64(u64 default_value = 0) const { return to_number<u64>(default_value); }
|
||||
|
||||
#if !defined(KERNEL)
|
||||
double to_double(double default_value = 0) const
|
||||
float to_float(float default_value = 0) const
|
||||
{
|
||||
return to_number<double>(default_value);
|
||||
return to_number<float>(default_value);
|
||||
}
|
||||
double to_double(double default_value = 0) const { return to_number<double>(default_value); }
|
||||
#endif
|
||||
|
||||
FlatPtr to_addr(FlatPtr default_value = 0) const
|
||||
|
|
Loading…
Reference in a new issue