mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
AK: Exclude JsonValue String APIs from the Kernel
These APIs are only used by userland, and String is OOM-infallible, so let's just ifdef it out of the Kernel.
This commit is contained in:
parent
c73ef87fc7
commit
43e5c326e2
1 changed files with 18 additions and 2 deletions
|
@ -8,9 +8,12 @@
|
||||||
|
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/String.h>
|
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
|
||||||
|
#ifndef KERNEL
|
||||||
|
# include <AK/String.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
class JsonValue {
|
class JsonValue {
|
||||||
|
@ -53,7 +56,9 @@ public:
|
||||||
#endif
|
#endif
|
||||||
JsonValue(bool);
|
JsonValue(bool);
|
||||||
JsonValue(const char*);
|
JsonValue(const char*);
|
||||||
|
#ifndef KERNEL
|
||||||
JsonValue(const String&);
|
JsonValue(const String&);
|
||||||
|
#endif
|
||||||
JsonValue(StringView);
|
JsonValue(StringView);
|
||||||
JsonValue(const JsonArray&);
|
JsonValue(const JsonArray&);
|
||||||
JsonValue(const JsonObject&);
|
JsonValue(const JsonObject&);
|
||||||
|
@ -70,6 +75,7 @@ public:
|
||||||
template<typename Builder>
|
template<typename Builder>
|
||||||
void serialize(Builder&) const;
|
void serialize(Builder&) const;
|
||||||
|
|
||||||
|
#ifndef KERNEL
|
||||||
String as_string_or(String const& alternative) const
|
String as_string_or(String const& alternative) const
|
||||||
{
|
{
|
||||||
if (is_string())
|
if (is_string())
|
||||||
|
@ -83,8 +89,12 @@ public:
|
||||||
return as_string();
|
return as_string();
|
||||||
return serialized<StringBuilder>();
|
return serialized<StringBuilder>();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int to_int(int default_value = 0) const { return to_i32(default_value); }
|
int to_int(int default_value = 0) const
|
||||||
|
{
|
||||||
|
return to_i32(default_value);
|
||||||
|
}
|
||||||
i32 to_i32(i32 default_value = 0) const { return to_number<i32>(default_value); }
|
i32 to_i32(i32 default_value = 0) const { return to_number<i32>(default_value); }
|
||||||
i64 to_i64(i64 default_value = 0) const { return to_number<i64>(default_value); }
|
i64 to_i64(i64 default_value = 0) const { return to_number<i64>(default_value); }
|
||||||
|
|
||||||
|
@ -138,11 +148,13 @@ public:
|
||||||
return m_value.as_bool;
|
return m_value.as_bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef KERNEL
|
||||||
String as_string() const
|
String as_string() const
|
||||||
{
|
{
|
||||||
VERIFY(is_string());
|
VERIFY(is_string());
|
||||||
return *m_value.as_string;
|
return *m_value.as_string;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const JsonObject& as_object() const
|
const JsonObject& as_object() const
|
||||||
{
|
{
|
||||||
|
@ -230,7 +242,9 @@ private:
|
||||||
Type m_type { Type::Null };
|
Type m_type { Type::Null };
|
||||||
|
|
||||||
union {
|
union {
|
||||||
|
#ifndef KERNEL
|
||||||
StringImpl* as_string { nullptr };
|
StringImpl* as_string { nullptr };
|
||||||
|
#endif
|
||||||
JsonArray* as_array;
|
JsonArray* as_array;
|
||||||
JsonObject* as_object;
|
JsonObject* as_object;
|
||||||
#if !defined(KERNEL)
|
#if !defined(KERNEL)
|
||||||
|
@ -244,6 +258,7 @@ private:
|
||||||
} m_value;
|
} m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef KERNEL
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<JsonValue> : Formatter<StringView> {
|
struct Formatter<JsonValue> : Formatter<StringView> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, JsonValue const& value)
|
ErrorOr<void> format(FormatBuilder& builder, JsonValue const& value)
|
||||||
|
@ -251,6 +266,7 @@ struct Formatter<JsonValue> : Formatter<StringView> {
|
||||||
return Formatter<StringView>::format(builder, value.to_string());
|
return Formatter<StringView>::format(builder, value.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue