Skip to content

Commit 1fd06ac

Browse files
committed
Use cpp11 register mechanism
1 parent 5b11a52 commit 1fd06ac

36 files changed

+952
-298
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ SystemRequirements: libxml2: libxml2-dev (deb), libxml2-devel (rpm)
4242
Collate:
4343
'S4.R'
4444
'as_list.R'
45+
'cpp11.R'
4546
'xml_parse.R'
4647
'as_xml_document.R'
4748
'classes.R'

R/as_xml_document.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ as_xml_document.list <- function(x, ...) {
4646

4747
add_node <- function(x, parent, tag = NULL) {
4848
if (is.atomic(x)) {
49-
return(.Call(node_new_text, parent$node, as.character(x)))
49+
return(node_new_text(parent$node, as.character(x)))
5050
}
5151
if (!is.null(tag)) {
5252
parent <- xml_add_child(parent, tag)

R/cpp11.R

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
# Generated by cpp11: do not edit by hand
2+
3+
read_connection_ <- function(con_sxp, read_size_sxp) {
4+
.Call(`_xml2_read_connection_`, con_sxp, read_size_sxp)
5+
}
6+
7+
xml_parse_options_ <- function() {
8+
.Call(`_xml2_xml_parse_options_`)
9+
}
10+
11+
doc_parse_file <- function(path_sxp, encoding_sxp, as_html_sxp, options_sxp) {
12+
.Call(`_xml2_doc_parse_file`, path_sxp, encoding_sxp, as_html_sxp, options_sxp)
13+
}
14+
15+
doc_parse_raw <- function(x, encoding_sxp, base_url_sxp, as_html_sxp, options_sxp) {
16+
.Call(`_xml2_doc_parse_raw`, x, encoding_sxp, base_url_sxp, as_html_sxp, options_sxp)
17+
}
18+
19+
doc_root <- function(x) {
20+
.Call(`_xml2_doc_root`, x)
21+
}
22+
23+
doc_has_root <- function(x_sxp) {
24+
.Call(`_xml2_doc_has_root`, x_sxp)
25+
}
26+
27+
doc_url <- function(doc_sxp) {
28+
.Call(`_xml2_doc_url`, doc_sxp)
29+
}
30+
31+
doc_new <- function(version_sxp, encoding_sxp) {
32+
.Call(`_xml2_doc_new`, version_sxp, encoding_sxp)
33+
}
34+
35+
doc_set_root <- function(doc_sxp, root_sxp) {
36+
.Call(`_xml2_doc_set_root`, doc_sxp, root_sxp)
37+
}
38+
39+
doc_is_html <- function(doc_sxp) {
40+
.Call(`_xml2_doc_is_html`, doc_sxp)
41+
}
42+
43+
init_libxml2 <- function() {
44+
.Call(`_xml2_init_libxml2`)
45+
}
46+
47+
libxml2_version_ <- function() {
48+
.Call(`_xml2_libxml2_version_`)
49+
}
50+
51+
unique_ns <- function(ns) {
52+
.Call(`_xml2_unique_ns`, ns)
53+
}
54+
55+
doc_namespaces <- function(doc_sxp) {
56+
.Call(`_xml2_doc_namespaces`, doc_sxp)
57+
}
58+
59+
ns_lookup_uri <- function(doc_sxp, node_sxp, uri_sxp) {
60+
.Call(`_xml2_ns_lookup_uri`, doc_sxp, node_sxp, uri_sxp)
61+
}
62+
63+
ns_lookup <- function(doc_sxp, node_sxp, prefix_sxp) {
64+
.Call(`_xml2_ns_lookup`, doc_sxp, node_sxp, prefix_sxp)
65+
}
66+
67+
node_name <- function(node_sxp, nsMap) {
68+
.Call(`_xml2_node_name`, node_sxp, nsMap)
69+
}
70+
71+
node_set_name <- function(node_sxp, value) {
72+
.Call(`_xml2_node_set_name`, node_sxp, value)
73+
}
74+
75+
node_text <- function(node_sxp) {
76+
.Call(`_xml2_node_text`, node_sxp)
77+
}
78+
79+
node_attr <- function(node_sxp, name_sxp, missing_sxp, nsMap_sxp) {
80+
.Call(`_xml2_node_attr`, node_sxp, name_sxp, missing_sxp, nsMap_sxp)
81+
}
82+
83+
node_attrs <- function(node_sxp, nsMap_sxp) {
84+
.Call(`_xml2_node_attrs`, node_sxp, nsMap_sxp)
85+
}
86+
87+
node_set_attr <- function(node_sxp, name_sxp, value, nsMap) {
88+
.Call(`_xml2_node_set_attr`, node_sxp, name_sxp, value, nsMap)
89+
}
90+
91+
node_remove_attr <- function(node_sxp, name_sxp, nsMap) {
92+
.Call(`_xml2_node_remove_attr`, node_sxp, name_sxp, nsMap)
93+
}
94+
95+
node_children <- function(node_sxp, only_node_sxp) {
96+
.Call(`_xml2_node_children`, node_sxp, only_node_sxp)
97+
}
98+
99+
node_length <- function(node_sxp, only_node_sxp) {
100+
.Call(`_xml2_node_length`, node_sxp, only_node_sxp)
101+
}
102+
103+
node_has_children <- function(node_sxp, only_node_sxp) {
104+
.Call(`_xml2_node_has_children`, node_sxp, only_node_sxp)
105+
}
106+
107+
node_parents <- function(node_sxp) {
108+
.Call(`_xml2_node_parents`, node_sxp)
109+
}
110+
111+
node_siblings <- function(node_sxp, only_node_sxp) {
112+
.Call(`_xml2_node_siblings`, node_sxp, only_node_sxp)
113+
}
114+
115+
node_parent <- function(node_sxp) {
116+
.Call(`_xml2_node_parent`, node_sxp)
117+
}
118+
119+
node_path <- function(node_sxp) {
120+
.Call(`_xml2_node_path`, node_sxp)
121+
}
122+
123+
nodes_duplicated <- function(nodes) {
124+
.Call(`_xml2_nodes_duplicated`, nodes)
125+
}
126+
127+
node_type <- function(node_sxp) {
128+
.Call(`_xml2_node_type`, node_sxp)
129+
}
130+
131+
node_copy <- function(node_sxp) {
132+
.Call(`_xml2_node_copy`, node_sxp)
133+
}
134+
135+
node_set_content <- function(node_sxp, content) {
136+
.Call(`_xml2_node_set_content`, node_sxp, content)
137+
}
138+
139+
node_append_content <- function(node_sxp, content) {
140+
.Call(`_xml2_node_append_content`, node_sxp, content)
141+
}
142+
143+
node_new_text <- function(node_sxp, content) {
144+
.Call(`_xml2_node_new_text`, node_sxp, content)
145+
}
146+
147+
node_append_child <- function(parent_sxp, cur_sxp) {
148+
.Call(`_xml2_node_append_child`, parent_sxp, cur_sxp)
149+
}
150+
151+
node_prepend_child <- function(parent_sxp, cur_sxp) {
152+
.Call(`_xml2_node_prepend_child`, parent_sxp, cur_sxp)
153+
}
154+
155+
node_prepend_sibling <- function(cur_sxp, elem_sxp) {
156+
.Call(`_xml2_node_prepend_sibling`, cur_sxp, elem_sxp)
157+
}
158+
159+
node_append_sibling <- function(cur_sxp, elem_sxp) {
160+
.Call(`_xml2_node_append_sibling`, cur_sxp, elem_sxp)
161+
}
162+
163+
node_replace <- function(old_sxp, cur_sxp) {
164+
.Call(`_xml2_node_replace`, old_sxp, cur_sxp)
165+
}
166+
167+
node_remove <- function(node_sxp, free_sxp) {
168+
.Call(`_xml2_node_remove`, node_sxp, free_sxp)
169+
}
170+
171+
node_new <- function(name) {
172+
.Call(`_xml2_node_new`, name)
173+
}
174+
175+
node_cdata_new <- function(doc_sxp, content_sxp) {
176+
.Call(`_xml2_node_cdata_new`, doc_sxp, content_sxp)
177+
}
178+
179+
node_comment_new <- function(content) {
180+
.Call(`_xml2_node_comment_new`, content)
181+
}
182+
183+
node_new_ns <- function(name, ns_sxp) {
184+
.Call(`_xml2_node_new_ns`, name, ns_sxp)
185+
}
186+
187+
node_set_namespace_uri <- function(doc_sxp, node_sxp, uri) {
188+
.Call(`_xml2_node_set_namespace_uri`, doc_sxp, node_sxp, uri)
189+
}
190+
191+
node_set_namespace_prefix <- function(doc_sxp, node_sxp, prefix_sxp) {
192+
.Call(`_xml2_node_set_namespace_prefix`, doc_sxp, node_sxp, prefix_sxp)
193+
}
194+
195+
node_new_dtd <- function(doc_sxp, name_sxp, eid_sxp, sid_sxp) {
196+
.Call(`_xml2_node_new_dtd`, doc_sxp, name_sxp, eid_sxp, sid_sxp)
197+
}
198+
199+
xml_save_options_ <- function() {
200+
.Call(`_xml2_xml_save_options_`)
201+
}
202+
203+
doc_write_file <- function(doc_sxp, path_sxp, encoding_sxp, options_sxp) {
204+
.Call(`_xml2_doc_write_file`, doc_sxp, path_sxp, encoding_sxp, options_sxp)
205+
}
206+
207+
doc_write_connection <- function(doc_sxp, connection, encoding_sxp, options_sxp) {
208+
.Call(`_xml2_doc_write_connection`, doc_sxp, connection, encoding_sxp, options_sxp)
209+
}
210+
211+
doc_write_character <- function(doc_sxp, encoding_sxp, options_sxp) {
212+
.Call(`_xml2_doc_write_character`, doc_sxp, encoding_sxp, options_sxp)
213+
}
214+
215+
node_write_file <- function(node_sxp, path_sxp, encoding_sxp, options_sxp) {
216+
.Call(`_xml2_node_write_file`, node_sxp, path_sxp, encoding_sxp, options_sxp)
217+
}
218+
219+
node_write_connection <- function(node_sxp, connection, encoding_sxp, options_sxp) {
220+
.Call(`_xml2_node_write_connection`, node_sxp, connection, encoding_sxp, options_sxp)
221+
}
222+
223+
node_write_character <- function(node_sxp, encoding_sxp, options_sxp) {
224+
.Call(`_xml2_node_write_character`, node_sxp, encoding_sxp, options_sxp)
225+
}
226+
227+
doc_validate <- function(doc_sxp, schema_sxp) {
228+
.Call(`_xml2_doc_validate`, doc_sxp, schema_sxp)
229+
}
230+
231+
url_absolute_ <- function(x_sxp, base_sxp) {
232+
.Call(`_xml2_url_absolute_`, x_sxp, base_sxp)
233+
}
234+
235+
url_relative_ <- function(x_sxp, base_sxp) {
236+
.Call(`_xml2_url_relative_`, x_sxp, base_sxp)
237+
}
238+
239+
url_parse_ <- function(x_sxp) {
240+
.Call(`_xml2_url_parse_`, x_sxp)
241+
}
242+
243+
url_escape_ <- function(x_sxp, reserved_sxp) {
244+
.Call(`_xml2_url_escape_`, x_sxp, reserved_sxp)
245+
}
246+
247+
url_unescape_ <- function(x_sxp) {
248+
.Call(`_xml2_url_unescape_`, x_sxp)
249+
}
250+
251+
xpath_search <- function(node_sxp, doc_sxp, xpath_sxp, nsMap_sxp, num_results_sxp) {
252+
.Call(`_xml2_xpath_search`, node_sxp, doc_sxp, xpath_sxp, nsMap_sxp, num_results_sxp)
253+
}

R/init.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
.onLoad <- function(lib, pkg) {
2-
.Call(init_libxml2)
2+
init_libxml2()
33
}
44

55
libxml2_version <- function() {
6-
as.numeric_version(.Call(libxml2_version_))
6+
as.numeric_version(libxml2_version_())
77
}
88

99
xml_parse_options <- function() {
10-
.Call(xml_parse_options_)
10+
xml_parse_options_()
1111
}
1212

1313
xml_save_options <- function() {
14-
.Call(xml_save_options_)
14+
xml_save_options_()
1515
}

R/xml_attr.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ xml_attr.xml_missing <- function(x, attr, ns = character(), default = NA_charact
7171
#' @export
7272
xml_attr.xml_node <- function(x, attr, ns = character(),
7373
default = NA_character_) {
74-
.Call(node_attr, x$node, attr, as.character(default), ns)
74+
node_attr(x$node, attr, as.character(default), ns)
7575
}
7676

7777
#' @export
@@ -106,7 +106,7 @@ xml_attrs.xml_missing <- function(x, ns = character()) {
106106

107107
#' @export
108108
xml_attrs.xml_node <- function(x, ns = character()) {
109-
.Call(node_attrs, x$node, nsMap = ns)
109+
node_attrs(x$node, nsMap_sxp = ns)
110110
}
111111

112112
#' @export
@@ -124,10 +124,10 @@ xml_attrs.xml_nodeset <- function(x, ns = character()) {
124124
#' @export
125125
`xml_attr<-.xml_node` <- function(x, attr, ns = character(), value) {
126126
if (is.null(value)) {
127-
.Call(node_remove_attr, x$node, attr, ns)
127+
node_remove_attr(x$node, attr, ns)
128128
} else {
129129
value <- as.character(value)
130-
.Call(node_set_attr, x$node, attr, value, ns)
130+
node_set_attr(x$node, attr, value, ns)
131131
}
132132
x
133133
}

R/xml_children.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#' xml_child(x, 2)
3939
#' xml_child(x, "baz")
4040
xml_children <- function(x) {
41-
nodeset_apply(x, function(x) .Call(node_children, x, TRUE))
41+
nodeset_apply(x, function(x) node_children(x, TRUE))
4242
}
4343

4444
#' @export
@@ -60,19 +60,19 @@ xml_child <- function(x, search = 1, ns = xml_ns(x)) {
6060
#' @export
6161
#' @rdname xml_children
6262
xml_contents <- function(x) {
63-
nodeset_apply(x, function(x) .Call(node_children, x, FALSE))
63+
nodeset_apply(x, function(x) node_children(x, FALSE))
6464
}
6565

6666
#' @export
6767
#' @rdname xml_children
6868
xml_parents <- function(x) {
69-
nodeset_apply(x, function(x) .Call(node_parents, x))
69+
nodeset_apply(x, function(x) node_parents(x))
7070
}
7171

7272
#' @export
7373
#' @rdname xml_children
7474
xml_siblings <- function(x) {
75-
nodeset_apply(x, function(x) .Call(node_siblings, x, TRUE))
75+
nodeset_apply(x, function(x) node_siblings(x, TRUE))
7676
}
7777

7878
#' @export
@@ -88,12 +88,12 @@ xml_parent.xml_missing <- function(x) {
8888

8989
#' @export
9090
xml_parent.xml_node <- function(x) {
91-
xml_node(.Call(node_parent, x$node), x$doc)
91+
xml_node(node_parent(x$node), x$doc)
9292
}
9393

9494
#' @export
9595
xml_parent.xml_nodeset <- function(x) {
96-
nodeset_apply(x, function(x) .Call(node_parent, x))
96+
nodeset_apply(x, function(x) node_parent(x))
9797
}
9898

9999

@@ -110,7 +110,7 @@ xml_length.xml_missing <- function(x, only_elements = TRUE) {
110110

111111
#' @export
112112
xml_length.xml_node <- function(x, only_elements = TRUE) {
113-
.Call(node_length, x$node, only_elements)
113+
node_length(x$node, only_elements)
114114
}
115115

116116
#' @export
@@ -134,7 +134,7 @@ xml_root <- function(x) {
134134
return(xml_root(x[[1]]))
135135
}
136136
}
137-
if (!.Call(doc_has_root, x$doc)) {
137+
if (!doc_has_root(x$doc)) {
138138
xml_missing()
139139
} else {
140140
xml_document(x$doc)

0 commit comments

Comments
 (0)