1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:37:36 +00:00

LibPDF: Propagate errors in Parser and Document

This commit is contained in:
Matthew Olsson 2022-03-05 17:30:55 -07:00 committed by Andreas Kling
parent 7e1c823725
commit 73cf8205b4
16 changed files with 472 additions and 420 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2021-2022, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2021, Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -30,10 +30,12 @@ public:
[[nodiscard]] ALWAYS_INLINE String const& string() const { return m_string; }
[[nodiscard]] ALWAYS_INLINE bool is_binary() const { return m_is_binary; }
ALWAYS_INLINE bool is_string() const override { return true; }
ALWAYS_INLINE const char* type_name() const override { return "string"; }
const char* type_name() const override { return "string"; }
String to_string(int indent) const override;
protected:
bool is_string() const override { return true; }
private:
String m_string;
bool m_is_binary;
@ -50,10 +52,12 @@ public:
[[nodiscard]] ALWAYS_INLINE FlyString const& name() const { return m_name; }
ALWAYS_INLINE bool is_name() const override { return true; }
ALWAYS_INLINE const char* type_name() const override { return "name"; }
const char* type_name() const override { return "name"; }
String to_string(int indent) const override;
protected:
bool is_name() const override { return true; }
private:
FlyString m_name;
};
@ -76,20 +80,20 @@ public:
ALWAYS_INLINE Value const& operator[](size_t index) const { return at(index); }
ALWAYS_INLINE Value const& at(size_t index) const { return m_elements[index]; }
NonnullRefPtr<Object> get_object_at(Document*, size_t index) const;
#define DEFINE_INDEXER(class_name, snake_name) \
NonnullRefPtr<class_name> get_##snake_name##_at(Document*, size_t index) const;
PDFErrorOr<NonnullRefPtr<class_name>> get_##snake_name##_at(Document*, size_t index) const;
ENUMERATE_OBJECT_TYPES(DEFINE_INDEXER)
#undef DEFINE_INDEXER
ALWAYS_INLINE bool is_array() const override
const char* type_name() const override
{
return true;
return "array";
}
ALWAYS_INLINE const char* type_name() const override { return "array"; }
String to_string(int indent) const override;
protected:
bool is_array() const override { return true; }
private:
Vector<Value> m_elements;
};
@ -117,20 +121,22 @@ public:
return value.value();
}
NonnullRefPtr<Object> get_object(Document*, FlyString const& key) const;
PDFErrorOr<NonnullRefPtr<Object>> get_object(Document*, FlyString const& key) const;
#define DEFINE_GETTER(class_name, snake_name) \
NonnullRefPtr<class_name> get_##snake_name(Document*, FlyString const& key) const;
PDFErrorOr<NonnullRefPtr<class_name>> get_##snake_name(Document*, FlyString const& key) const;
ENUMERATE_OBJECT_TYPES(DEFINE_GETTER)
#undef DEFINE_GETTER
ALWAYS_INLINE bool is_dict() const override
const char* type_name() const override
{
return true;
return "dict";
}
ALWAYS_INLINE const char* type_name() const override { return "dict"; }
String to_string(int indent) const override;
protected:
bool is_dict() const override { return true; }
private:
HashMap<FlyString, Value> m_map;
};
@ -147,10 +153,12 @@ public:
[[nodiscard]] ALWAYS_INLINE NonnullRefPtr<DictObject> dict() const { return m_dict; }
[[nodiscard]] virtual ReadonlyBytes bytes() const = 0;
ALWAYS_INLINE bool is_stream() const override { return true; }
ALWAYS_INLINE const char* type_name() const override { return "stream"; }
const char* type_name() const override { return "stream"; }
String to_string(int indent) const override;
protected:
bool is_stream() const override { return true; }
private:
NonnullRefPtr<DictObject> m_dict;
};
@ -201,10 +209,12 @@ public:
[[nodiscard]] ALWAYS_INLINE u32 index() const { return m_index; }
[[nodiscard]] ALWAYS_INLINE Value const& value() const { return m_value; }
ALWAYS_INLINE bool is_indirect_value() const override { return true; }
ALWAYS_INLINE const char* type_name() const override { return "indirect_object"; }
const char* type_name() const override { return "indirect_object"; }
String to_string(int indent) const override;
protected:
bool is_indirect_value() const override { return true; }
private:
u32 m_index;
Value m_value;