summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibPDF
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2021-05-24 13:41:40 -0700
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-12 22:45:01 +0430
commitd654fe0e41071bd769b920c08b30f302951eb638 (patch)
treec6f9f933785af5a5a50dcb35e15ca50c36b087db /Userland/Libraries/LibPDF
parentbd9e20ef791a614deec2a7e37f3be1657f75816a (diff)
downloadserenity-d654fe0e41071bd769b920c08b30f302951eb638.zip
LibPDF: Differentiate Value's null and empty states
Diffstat (limited to 'Userland/Libraries/LibPDF')
-rw-r--r--Userland/Libraries/LibPDF/Parser.cpp2
-rw-r--r--Userland/Libraries/LibPDF/Value.cpp3
-rw-r--r--Userland/Libraries/LibPDF/Value.h12
3 files changed, 15 insertions, 2 deletions
diff --git a/Userland/Libraries/LibPDF/Parser.cpp b/Userland/Libraries/LibPDF/Parser.cpp
index 8ec0adabae..7ec53eb15c 100644
--- a/Userland/Libraries/LibPDF/Parser.cpp
+++ b/Userland/Libraries/LibPDF/Parser.cpp
@@ -268,7 +268,7 @@ Value Parser::parse_value()
if (m_reader.matches("null")) {
m_reader.move_by(4);
consume_whitespace();
- return Value();
+ return Value(Value::NullTag {});
}
if (m_reader.matches("true")) {
diff --git a/Userland/Libraries/LibPDF/Value.cpp b/Userland/Libraries/LibPDF/Value.cpp
index a254d78ea0..0248356fa6 100644
--- a/Userland/Libraries/LibPDF/Value.cpp
+++ b/Userland/Libraries/LibPDF/Value.cpp
@@ -19,6 +19,7 @@ Value& Value::operator=(const Value& other)
{
m_type = other.m_type;
switch (m_type) {
+ case Type::Empty:
case Type::Null:
break;
case Type::Bool:
@@ -45,6 +46,8 @@ Value& Value::operator=(const Value& other)
String Value::to_string(int indent) const
{
switch (m_type) {
+ case Type::Empty:
+ return "<empty>";
case Type::Null:
return "null";
case Type::Bool:
diff --git a/Userland/Libraries/LibPDF/Value.h b/Userland/Libraries/LibPDF/Value.h
index cb75a92662..f6b3b61899 100644
--- a/Userland/Libraries/LibPDF/Value.h
+++ b/Userland/Libraries/LibPDF/Value.h
@@ -23,6 +23,14 @@ public:
static constexpr auto max_ref_generation_index = (1 << 15) - 1; // 2 ^ 14 - 1
Value()
+ : m_type(Type::Empty)
+ {
+ }
+
+ struct NullTag {
+ };
+
+ Value(NullTag)
: m_type(Type::Null)
{
}
@@ -70,6 +78,7 @@ public:
Value& operator=(const Value& other);
+ [[nodiscard]] ALWAYS_INLINE bool is_empty() const { return m_type == Type::Empty; }
[[nodiscard]] ALWAYS_INLINE bool is_null() const { return m_type == Type::Null; }
[[nodiscard]] ALWAYS_INLINE bool is_bool() const { return m_type == Type::Bool; }
[[nodiscard]] ALWAYS_INLINE bool is_int() const { return m_type == Type::Int; }
@@ -124,12 +133,13 @@ public:
[[nodiscard]] ALWAYS_INLINE NonnullRefPtr<Object> as_object() const { return *m_as_object; }
- [[nodiscard]] ALWAYS_INLINE explicit operator bool() const { return !is_null(); }
+ [[nodiscard]] ALWAYS_INLINE explicit operator bool() const { return !is_empty(); }
[[nodiscard]] String to_string(int indent = 0) const;
private:
enum class Type {
+ Empty,
Null,
Bool,
Int,