浏览代码

LibXML: Add helpers for extracting node contents if its type is known

Dan Klishch 1 年之前
父节点
当前提交
b40ab55830
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      Userland/Libraries/LibXML/DOM/Node.h

+ 9 - 0
Userland/Libraries/LibXML/DOM/Node.h

@@ -36,5 +36,14 @@ struct Node {
 
     Variant<Text, Comment, Element> content;
     Node* parent { nullptr };
+
+    bool is_text() const { return content.has<Text>(); }
+    Text const& as_text() const { return content.get<Text>(); }
+
+    bool is_comment() const { return content.has<Comment>(); }
+    Comment const& as_comment() const { return content.get<Comment>(); }
+
+    bool is_element() const { return content.has<Element>(); }
+    Element const& as_element() const { return content.get<Element>(); }
 };
 }