Value.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibPDF/Object.h>
  7. #include <LibPDF/Value.h>
  8. namespace PDF {
  9. ByteString Value::to_byte_string(int indent) const
  10. {
  11. return visit(
  12. [&](Empty const&) -> ByteString {
  13. // Return type deduction means that we can't use implicit conversions.
  14. return "<empty>";
  15. },
  16. [&](nullptr_t const&) -> ByteString {
  17. return "null";
  18. },
  19. [&](bool const& b) -> ByteString {
  20. return b ? "true" : "false";
  21. },
  22. [&](int const& i) {
  23. return ByteString::number(i);
  24. },
  25. [&](float const& f) {
  26. return ByteString::number(f);
  27. },
  28. [&](Reference const& ref) {
  29. return ByteString::formatted("{} {} R", ref.as_ref_index(), ref.as_ref_generation_index());
  30. },
  31. [&](NonnullRefPtr<Object> const& object) {
  32. return object->to_byte_string(indent);
  33. });
  34. }
  35. }