Node.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteString.h>
  8. #include <AK/HashMap.h>
  9. #include <AK/Variant.h>
  10. #include <AK/Vector.h>
  11. #include <LibXML/FundamentalTypes.h>
  12. namespace XML {
  13. struct Attribute {
  14. Name name;
  15. ByteString value;
  16. };
  17. struct Offset {
  18. size_t offset { 0 };
  19. size_t line { 0 };
  20. size_t column { 0 };
  21. };
  22. struct Node {
  23. struct Text {
  24. StringBuilder builder;
  25. };
  26. struct Comment {
  27. ByteString text;
  28. };
  29. struct Element {
  30. Name name;
  31. HashMap<Name, ByteString> attributes;
  32. Vector<NonnullOwnPtr<Node>> children;
  33. };
  34. bool operator==(Node const&) const;
  35. Offset offset;
  36. Variant<Text, Comment, Element> content;
  37. Node* parent { nullptr };
  38. bool is_text() const { return content.has<Text>(); }
  39. Text const& as_text() const { return content.get<Text>(); }
  40. bool is_comment() const { return content.has<Comment>(); }
  41. Comment const& as_comment() const { return content.get<Comment>(); }
  42. bool is_element() const { return content.has<Element>(); }
  43. Element const& as_element() const { return content.get<Element>(); }
  44. };
  45. }