Skip to content

Commit 054ef31

Browse files
committed
Convert node_write_file
1 parent c55f0ee commit 054ef31

File tree

5 files changed

+17
-27
lines changed

5 files changed

+17
-27
lines changed

R/RcppExports.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ xml_save_options <- function() {
2929
.Call(`_xml2_xml_save_options`)
3030
}
3131

32-
node_write_file <- function(x, path, encoding = "UTF-8", options = 1L) {
33-
invisible(.Call(`_xml2_node_write_file`, x, path, encoding, options))
34-
}
35-
3632
#' Convert between relative and absolute urls.
3733
#'
3834
#' @param x A character vector of urls relative to that base

R/xml_write.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ write_xml.xml_nodeset <- function(x, file, ..., options = "format", encoding = "
7272
if (!(is.character(file) && length(file) == 1 && nzchar(file))) {
7373
stop("`file` must be a non-zero character of length 1", call. = FALSE)
7474
}
75-
node_write_file(x[[1]]$node, file, options = options, encoding = encoding)
75+
.Call(node_write_file, x[[1]]$node, file, encoding, options)
7676
}
7777
}
7878

@@ -91,7 +91,7 @@ write_xml.xml_node <- function(x, file, ..., options = "format", encoding = "UTF
9191
if (!(is.character(file) && length(file) == 1 && nzchar(file))) {
9292
stop("`file` must be a non-zero character of length 1", call. = FALSE)
9393
}
94-
node_write_file(x$node, file, options = options, encoding = encoding)
94+
.Call(node_write_file, x$node, file, encoding, options)
9595
}
9696
}
9797

src/RcppExports.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,6 @@ BEGIN_RCPP
8686
return rcpp_result_gen;
8787
END_RCPP
8888
}
89-
// node_write_file
90-
void node_write_file(XPtrNode x, std::string path, std::string encoding, int options);
91-
RcppExport SEXP _xml2_node_write_file(SEXP xSEXP, SEXP pathSEXP, SEXP encodingSEXP, SEXP optionsSEXP) {
92-
BEGIN_RCPP
93-
Rcpp::RNGScope rcpp_rngScope_gen;
94-
Rcpp::traits::input_parameter< XPtrNode >::type x(xSEXP);
95-
Rcpp::traits::input_parameter< std::string >::type path(pathSEXP);
96-
Rcpp::traits::input_parameter< std::string >::type encoding(encodingSEXP);
97-
Rcpp::traits::input_parameter< int >::type options(optionsSEXP);
98-
node_write_file(x, path, encoding, options);
99-
return R_NilValue;
100-
END_RCPP
101-
}
10289
// url_absolute
10390
CharacterVector url_absolute(CharacterVector x, CharacterVector base);
10491
RcppExport SEXP _xml2_url_absolute(SEXP xSEXP, SEXP baseSEXP) {

src/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extern SEXP node_text(SEXP);
5757
extern SEXP node_type(SEXP);
5858
extern SEXP node_write_character(SEXP, SEXP, SEXP);
5959
extern SEXP node_write_connection(SEXP, SEXP, SEXP, SEXP);
60-
extern SEXP _xml2_node_write_file(SEXP, SEXP, SEXP, SEXP);
60+
extern SEXP node_write_file(SEXP, SEXP, SEXP, SEXP);
6161
extern SEXP _xml2_nodes_duplicated(SEXP);
6262
extern SEXP _xml2_ns_lookup(SEXP, SEXP, SEXP);
6363
extern SEXP _xml2_ns_lookup_uri(SEXP, SEXP, SEXP);
@@ -122,7 +122,7 @@ static const R_CallMethodDef CallEntries[] = {
122122
{"node_type", (DL_FUNC) &node_type, 1},
123123
{"node_write_character", (DL_FUNC) &node_write_character, 3},
124124
{"node_write_connection", (DL_FUNC) &node_write_connection, 4},
125-
{"_xml2_node_write_file", (DL_FUNC) &_xml2_node_write_file, 4},
125+
{"node_write_file", (DL_FUNC) &node_write_file, 4},
126126
{"_xml2_nodes_duplicated", (DL_FUNC) &_xml2_nodes_duplicated, 1},
127127
{"_xml2_ns_lookup", (DL_FUNC) &_xml2_ns_lookup, 3},
128128
{"_xml2_ns_lookup_uri", (DL_FUNC) &_xml2_ns_lookup_uri, 3},

src/xml2_output.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,23 @@ extern "C" SEXP doc_write_character(SEXP doc_sxp, SEXP encoding_sxp, SEXP option
149149
return out;
150150
}
151151

152-
// [[Rcpp::export]]
153-
void node_write_file(XPtrNode x, std::string path, std::string encoding = "UTF-8", int options = 1) {
152+
// [[export]]
153+
extern "C" SEXP node_write_file(SEXP node_sxp, SEXP path_sxp, SEXP encoding_sxp, SEXP options_sxp) {
154+
XPtrNode node(node_sxp);
155+
const char* path = CHAR(STRING_ELT(path_sxp, 0));
156+
const char* encoding = CHAR(STRING_ELT(encoding_sxp, 0));
157+
int options = INTEGER(options_sxp)[0];
158+
154159
xmlSaveCtxtPtr savectx = xmlSaveToFilename(
155-
path.c_str(),
156-
encoding.c_str(),
160+
path,
161+
encoding,
157162
options);
158-
xmlSaveTree(savectx, x.checked_get());
163+
xmlSaveTree(savectx, node.checked_get());
159164
if (xmlSaveClose(savectx) == -1) {
160-
stop("Error closing file");
165+
Rf_error("Error closing file");
161166
}
167+
168+
return R_NilValue;
162169
}
163170

164171
// [[export]]

0 commit comments

Comments
 (0)