1 /*
2  * Copyright (C) 2018-2021 Alexander Borisov
3  *
4  * Author: Alexander Borisov <borisov@lexbor.com>
5  */
6 
7 #ifndef LEXBOR_DOM_DOCUMENT_TYPE_H
8 #define LEXBOR_DOM_DOCUMENT_TYPE_H
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include "lexbor/core/str.h"
15 
16 #include "lexbor/dom/interfaces/document.h"
17 #include "lexbor/dom/interfaces/node.h"
18 #include "lexbor/dom/interfaces/attr.h"
19 #include "lexbor/dom/interfaces/document_type.h"
20 
21 
22 struct lxb_dom_document_type {
23     lxb_dom_node_t    node;
24 
25     lxb_dom_attr_id_t name;
26     lexbor_str_t      public_id;
27     lexbor_str_t      system_id;
28 };
29 
30 
31 LXB_API lxb_dom_document_type_t *
32 lxb_dom_document_type_interface_create(lxb_dom_document_t *document);
33 
34 LXB_API lxb_dom_document_type_t *
35 lxb_dom_document_type_interface_clone(lxb_dom_document_t *document,
36                                       const lxb_dom_document_type_t *dtype);
37 
38 LXB_API lxb_dom_document_type_t *
39 lxb_dom_document_type_interface_destroy(lxb_dom_document_type_t *document_type);
40 
41 
42 /*
43  * Inline functions
44  */
45 lxb_inline const lxb_char_t *
lxb_dom_document_type_name(lxb_dom_document_type_t * doc_type,size_t * len)46 lxb_dom_document_type_name(lxb_dom_document_type_t *doc_type, size_t *len)
47 {
48     const lxb_dom_attr_data_t *data;
49 
50     static const lxb_char_t lxb_empty[] = "";
51 
52     data = lxb_dom_attr_data_by_id(doc_type->node.owner_document->attrs,
53                                    doc_type->name);
54     if (data == NULL || doc_type->name == LXB_DOM_ATTR__UNDEF) {
55         if (len != NULL) {
56             *len = 0;
57         }
58 
59         return lxb_empty;
60     }
61 
62     if (len != NULL) {
63         *len = data->entry.length;
64     }
65 
66     return lexbor_hash_entry_str(&data->entry);
67 }
68 
69 lxb_inline const lxb_char_t *
lxb_dom_document_type_public_id(lxb_dom_document_type_t * doc_type,size_t * len)70 lxb_dom_document_type_public_id(lxb_dom_document_type_t *doc_type, size_t *len)
71 {
72     if (len != NULL) {
73         *len = doc_type->public_id.length;
74     }
75 
76     return doc_type->public_id.data;
77 }
78 
79 lxb_inline const lxb_char_t *
lxb_dom_document_type_system_id(lxb_dom_document_type_t * doc_type,size_t * len)80 lxb_dom_document_type_system_id(lxb_dom_document_type_t *doc_type, size_t *len)
81 {
82     if (len != NULL) {
83         *len = doc_type->system_id.length;
84     }
85 
86     return doc_type->system_id.data;
87 }
88 
89 /*
90  * No inline functions for ABI.
91  */
92 LXB_API const lxb_char_t *
93 lxb_dom_document_type_name_noi(lxb_dom_document_type_t *doc_type, size_t *len);
94 
95 LXB_API const lxb_char_t *
96 lxb_dom_document_type_public_id_noi(lxb_dom_document_type_t *doc_type,
97                                     size_t *len);
98 
99 LXB_API const lxb_char_t *
100 lxb_dom_document_type_system_id_noi(lxb_dom_document_type_t *doc_type,
101                                     size_t *len);
102 
103 
104 #ifdef __cplusplus
105 } /* extern "C" */
106 #endif
107 
108 #endif /* LEXBOR_DOM_DOCUMENT_TYPE_H */
109