php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
interface.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2021 Alexander Borisov
3 *
4 * Author: Alexander Borisov <borisov@lexbor.com>
5 */
6
7#include "lexbor/core/mraw.h"
8
11
13
14#define LXB_HTML_INTERFACE_RES_CONSTRUCTORS
15#define LXB_HTML_INTERFACE_RES_DESTRUCTOR
17
18
19static lxb_dom_element_t *
20lxb_html_interface_clone_element(lxb_dom_document_t *document,
21 const lxb_dom_element_t *element);
22
23
26 lxb_ns_id_t ns)
27{
28 lxb_dom_node_t *node;
29
30 if (tag_id >= LXB_TAG__LAST_ENTRY) {
31 if (ns == LXB_NS_HTML) {
33
35 node = lxb_dom_interface_node(unel);
36 }
37 else if (ns == LXB_NS_SVG) {
38 /* TODO: For this need implement SVGElement */
39 lxb_dom_element_t *domel;
40
42 node = lxb_dom_interface_node(domel);
43 }
44 else {
45 lxb_dom_element_t *domel;
46
48 node = lxb_dom_interface_node(domel);
49 }
50 }
51 else {
52 node = lxb_html_interface_res_constructors[tag_id][ns](document);
53 }
54
55 if (node == NULL) {
56 return NULL;
57 }
58
59 node->local_name = tag_id;
60 node->ns = ns;
61
62 return node;
63}
64
67 const lxb_dom_interface_t *intrfc)
68{
69 const lxb_dom_node_t *node = intrfc;
70
71 if (document == NULL) {
72 document = node->owner_document;
73 }
74
75 switch (node->type) {
77 return lxb_html_interface_clone_element(document, intrfc);
78
80 return lxb_dom_text_interface_clone(document, intrfc);
81
84 intrfc);
86 return lxb_dom_comment_interface_clone(document, intrfc);
87
89 return lxb_dom_document_interface_clone(document, intrfc);
90
92 return lxb_dom_document_type_interface_clone(document, intrfc);
93
94 default:
95 return lxb_dom_node_interface_clone(document, node, false);
96 }
97}
98
99static lxb_dom_element_t *
100lxb_html_interface_clone_element(lxb_dom_document_t *document,
101 const lxb_dom_element_t *element)
102{
104 const lxb_dom_node_t *node = lxb_dom_interface_node(element);
105
107 node->local_name, node->ns);
108 if (new == NULL) {
109 return NULL;
110 }
111
112 if (lxb_dom_element_interface_copy(new, element) != LXB_STATUS_OK) {
114 }
115
116 return new;
117}
118
121{
122 if (intrfc == NULL) {
123 return NULL;
124 }
125
126 lxb_dom_node_t *node = intrfc;
127
128 switch (node->type) {
134 if (node->local_name >= LXB_TAG__LAST_ENTRY) {
135 if (node->ns == LXB_NS_HTML) {
137 }
138 else if (node->ns == LXB_NS_SVG) {
139 /* TODO: For this need implement SVGElement */
141 }
142 else {
144 }
145 }
146 else {
147 return lxb_html_interface_res_destructor[node->local_name][node->ns](intrfc);
148 }
149
151 return lxb_dom_attr_interface_destroy(intrfc);
152
155
158
161
162 default:
163 return NULL;
164 }
165}
lxb_dom_cdata_section_t * lxb_dom_cdata_section_interface_destroy(lxb_dom_cdata_section_t *cdata_section)
@ LXB_STATUS_OK
Definition base.h:49
lxb_dom_document_fragment_t * lxb_dom_document_fragment_interface_destroy(lxb_dom_document_fragment_t *document_fragment)
lxb_dom_document_type_t * lxb_dom_document_type_interface_clone(lxb_dom_document_t *document, const lxb_dom_document_type_t *dtype)
struct lxb_dom_document lxb_dom_document_t
Definition interface.h:41
#define lxb_dom_interface_node(obj)
Definition interface.h:31
struct lxb_dom_node lxb_dom_node_t
Definition interface.h:38
void lxb_dom_interface_t
Definition interface.h:51
struct lxb_dom_element lxb_dom_element_t
Definition interface.h:39
@ LXB_DOM_NODE_TYPE_COMMENT
Definition node.h:32
@ LXB_DOM_NODE_TYPE_CDATA_SECTION
Definition node.h:28
@ LXB_DOM_NODE_TYPE_PROCESSING_INSTRUCTION
Definition node.h:31
@ LXB_DOM_NODE_TYPE_DOCUMENT
Definition node.h:33
@ LXB_DOM_NODE_TYPE_DOCUMENT_FRAGMENT
Definition node.h:35
@ LXB_DOM_NODE_TYPE_DOCUMENT_TYPE
Definition node.h:34
@ LXB_DOM_NODE_TYPE_ATTRIBUTE
Definition node.h:26
@ LXB_DOM_NODE_TYPE_ELEMENT
Definition node.h:25
@ LXB_DOM_NODE_TYPE_TEXT
Definition node.h:27
lxb_dom_interface_t * lxb_html_interface_clone(lxb_dom_document_t *document, const lxb_dom_interface_t *intrfc)
Definition interface.c:66
lxb_dom_interface_t * lxb_html_interface_destroy(lxb_dom_interface_t *intrfc)
Definition interface.c:120
lxb_dom_interface_t * lxb_html_interface_create(lxb_html_document_t *document, lxb_tag_id_t tag_id, lxb_ns_id_t ns)
Definition interface.c:25
#define NULL
Definition gdcache.h:45
struct lxb_html_unknown_element lxb_html_unknown_element_t
Definition interface.h:165
struct lxb_html_document lxb_html_document_t
Definition interface.h:95
lxb_dom_attr_t * lxb_dom_attr_interface_destroy(lxb_dom_attr_t *attr)
Definition attr.c:109
lxb_dom_comment_t * lxb_dom_comment_interface_clone(lxb_dom_document_t *document, const lxb_dom_comment_t *text)
Definition comment.c:31
lxb_dom_document_t * lxb_dom_document_interface_clone(lxb_dom_document_t *document, const lxb_dom_document_t *doc)
Definition document.c:35
lxb_status_t lxb_dom_element_interface_copy(lxb_dom_element_t *dst, const lxb_dom_element_t *src)
Definition element.c:89
lxb_dom_element_t * lxb_dom_element_interface_create(lxb_dom_document_t *document)
Definition element.c:33
lxb_dom_element_t * lxb_dom_element_interface_destroy(lxb_dom_element_t *element)
Definition element.c:70
lxb_dom_node_t * lxb_dom_node_interface_clone(lxb_dom_document_t *document, const lxb_dom_node_t *node, bool is_attr)
Definition node.c:106
lxb_dom_text_t * lxb_dom_text_interface_clone(lxb_dom_document_t *document, const lxb_dom_text_t *text)
Definition text.c:31
uintptr_t lxb_ns_id_t
Definition const.h:20
@ LXB_NS_SVG
Definition const.h:28
@ LXB_NS_HTML
Definition const.h:26
lxb_dom_processing_instruction_t * lxb_dom_processing_instruction_interface_clone(lxb_dom_document_t *document, const lxb_dom_processing_instruction_t *pinstr)
lxb_dom_processing_instruction_t * lxb_dom_processing_instruction_interface_destroy(lxb_dom_processing_instruction_t *processing_instruction)
uintptr_t ns
Definition node.h:48
lxb_dom_document_t * owner_document
Definition node.h:50
lxb_dom_node_type_t type
Definition node.h:59
uintptr_t local_name
Definition node.h:46
lxb_dom_document_t dom_document
Definition document.h:58
@ LXB_TAG__LAST_ENTRY
Definition const.h:220
uintptr_t lxb_tag_id_t
Definition const.h:21
lxb_html_unknown_element_t * lxb_html_unknown_element_interface_destroy(lxb_html_unknown_element_t *unknown_element)
lxb_html_unknown_element_t * lxb_html_unknown_element_interface_create(lxb_html_document_t *document)