2021-04-30 18:23:17 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibPDF/Object.h>
|
|
|
|
|
#include <LibPDF/Value.h>
|
|
|
|
|
|
|
|
|
|
namespace PDF {
|
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString Value::to_byte_string(int indent) const
|
2021-04-30 18:23:17 -07:00
|
|
|
{
|
2021-09-19 20:56:05 +02:00
|
|
|
return visit(
|
2023-12-16 17:49:34 +03:30
|
|
|
[&](Empty const&) -> ByteString {
|
2021-09-19 20:56:05 +02:00
|
|
|
// Return type deduction means that we can't use implicit conversions.
|
|
|
|
|
return "<empty>";
|
|
|
|
|
},
|
2023-12-16 17:49:34 +03:30
|
|
|
[&](nullptr_t const&) -> ByteString {
|
2021-09-19 20:56:05 +02:00
|
|
|
return "null";
|
|
|
|
|
},
|
2023-12-16 17:49:34 +03:30
|
|
|
[&](bool const& b) -> ByteString {
|
2021-09-19 20:56:05 +02:00
|
|
|
return b ? "true" : "false";
|
|
|
|
|
},
|
|
|
|
|
[&](int const& i) {
|
2023-12-16 17:49:34 +03:30
|
|
|
return ByteString::number(i);
|
2021-09-19 20:56:05 +02:00
|
|
|
},
|
|
|
|
|
[&](float const& f) {
|
2023-12-16 17:49:34 +03:30
|
|
|
return ByteString::number(f);
|
2021-09-19 20:56:05 +02:00
|
|
|
},
|
|
|
|
|
[&](Reference const& ref) {
|
2023-12-16 17:49:34 +03:30
|
|
|
return ByteString::formatted("{} {} R", ref.as_ref_index(), ref.as_ref_generation_index());
|
2021-09-19 20:56:05 +02:00
|
|
|
},
|
|
|
|
|
[&](NonnullRefPtr<Object> const& object) {
|
2023-12-16 17:49:34 +03:30
|
|
|
return object->to_byte_string(indent);
|
2021-09-19 20:56:05 +02:00
|
|
|
});
|
2021-04-30 18:23:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|