xref: /php-src/ext/dom/lexbor/lexbor/dom/interfaces/text.c (revision bffab33a)
1 /*
2  * Copyright (C) 2018-2021 Alexander Borisov
3  *
4  * Author: Alexander Borisov <borisov@lexbor.com>
5  */
6 
7 #include "lexbor/dom/interfaces/text.h"
8 #include "lexbor/dom/interfaces/document.h"
9 
10 
11 lxb_dom_text_t *
lxb_dom_text_interface_create(lxb_dom_document_t * document)12 lxb_dom_text_interface_create(lxb_dom_document_t *document)
13 {
14     lxb_dom_text_t *element;
15 
16     element = lexbor_mraw_calloc(document->mraw,
17                                  sizeof(lxb_dom_text_t));
18     if (element == NULL) {
19         return NULL;
20     }
21 
22     lxb_dom_node_t *node = lxb_dom_interface_node(element);
23 
24     node->owner_document = lxb_dom_document_owner(document);
25     node->type = LXB_DOM_NODE_TYPE_TEXT;
26 
27     return element;
28 }
29 
30 lxb_dom_text_t *
lxb_dom_text_interface_clone(lxb_dom_document_t * document,const lxb_dom_text_t * text)31 lxb_dom_text_interface_clone(lxb_dom_document_t *document,
32                              const lxb_dom_text_t *text)
33 {
34     lxb_status_t status;
35     lxb_dom_text_t *new;
36 
37     new = lxb_dom_text_interface_create(document);
38     if (new == NULL) {
39         return NULL;
40     }
41 
42     status = lxb_dom_text_interface_copy(new, text);
43     if (status != LXB_STATUS_OK) {
44         return lxb_dom_text_interface_destroy(new);
45     }
46 
47     return new;
48 }
49 
50 lxb_dom_text_t *
lxb_dom_text_interface_destroy(lxb_dom_text_t * text)51 lxb_dom_text_interface_destroy(lxb_dom_text_t *text)
52 {
53     (void) lxb_dom_character_data_interface_destroy(
54                                         lxb_dom_interface_character_data(text));
55     return NULL;
56 }
57 
58 lxb_status_t
lxb_dom_text_interface_copy(lxb_dom_text_t * dst,const lxb_dom_text_t * src)59 lxb_dom_text_interface_copy(lxb_dom_text_t *dst, const lxb_dom_text_t *src)
60 {
61     return lxb_dom_character_data_interface_copy(&dst->char_data,
62                                                  &src->char_data);
63 }
64