Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cpp11 #405

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5b11a52
`use_cpp11()`
mgirlich Sep 4, 2023
1fd06ac
Use cpp11 register mechanism
mgirlich Sep 4, 2023
48ab979
Migrate `xml2_url.cpp`
mgirlich Sep 4, 2023
992cd01
Replace `extern "C"` by `cpp11::sexp`
mgirlich Sep 4, 2023
44eddbe
Remove unused `R_ReadConnection()`
mgirlich Sep 4, 2023
66f4c60
Remove unnecessary `R_GetConnection()`
mgirlich Sep 4, 2023
cd54aed
Migrate `xml2_output.cpp`
mgirlich Sep 4, 2023
e351747
Convert `xml2_doc.cpp`
mgirlich Sep 4, 2023
60ae697
Convert `xml2_schema.cpp`
mgirlich Sep 4, 2023
ae3a6ec
Convert `xml2_path.cpp`
mgirlich Sep 4, 2023
33d6c7e
Fix compilation issues
mgirlich Sep 4, 2023
8029c30
Minor things
mgirlich Sep 4, 2023
33561d8
As `as_cpp<int>()`
mgirlich Nov 2, 2023
10f3f75
Use `R_xlen_t` for `size()` method
mgirlich Nov 2, 2023
d43f4bf
Use cpp11 raws with memcpy
mgirlich Nov 2, 2023
ea377a9
Check for empty vectors as well
mgirlich Nov 2, 2023
51cbbaf
Merge commit '005b78659c2271a03ed016f13df0d32f8b1e66e5'
mgirlich Nov 2, 2023
31e7555
Fix ambiguous initializer
mgirlich Nov 2, 2023
b7ff753
More cpp11 i `xml2_xpath.cpp`
mgirlich Nov 2, 2023
50489ac
Minor changes
mgirlich Nov 2, 2023
6f0e353
Use cpp11 in `xml2_utils.h`
mgirlich Nov 2, 2023
0352dfa
Merge commit 'e088a1c892e97436fdd3263c6cfc6df61e47a365'
mgirlich Nov 2, 2023
2539195
Use cpp11 in `xml2_node.cpp`
mgirlich Nov 3, 2023
b65e011
Fix compilation issues
mgirlich Nov 3, 2023
f73bb41
Use cpp11 in namespace and connection
mgirlich Nov 3, 2023
2e85921
Remove cpp wrapper macro
mgirlich Nov 3, 2023
01c41e7
Some more cleanup
mgirlich Nov 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge commit 'e088a1c892e97436fdd3263c6cfc6df61e47a365'
  • Loading branch information
mgirlich committed Nov 2, 2023
commit 0352dfae84b1e4391d0e21a0afa5c0d827cc1b04
28 changes: 14 additions & 14 deletions R/cpp11.R
Original file line number Diff line number Diff line change
@@ -64,24 +64,24 @@ ns_lookup <- function(doc_sxp, node_sxp, prefix_sxp) {
.Call(`_xml2_ns_lookup`, doc_sxp, node_sxp, prefix_sxp)
}

node_name <- function(node_sxp, nsMap) {
.Call(`_xml2_node_name`, node_sxp, nsMap)
node_name <- function(x, nsMap) {
.Call(`_xml2_node_name`, x, nsMap)
}

node_set_name <- function(node_sxp, value) {
.Call(`_xml2_node_set_name`, node_sxp, value)
}

node_text <- function(node_sxp) {
.Call(`_xml2_node_text`, node_sxp)
node_text <- function(x) {
.Call(`_xml2_node_text`, x)
}

node_attr <- function(node_sxp, name_sxp, missing_sxp, nsMap_sxp) {
.Call(`_xml2_node_attr`, node_sxp, name_sxp, missing_sxp, nsMap_sxp)
node_attr <- function(x, name_sxp, missing_sxp, nsMap_sxp) {
.Call(`_xml2_node_attr`, x, name_sxp, missing_sxp, nsMap_sxp)
}

node_attrs <- function(node_sxp, nsMap_sxp) {
.Call(`_xml2_node_attrs`, node_sxp, nsMap_sxp)
node_attrs <- function(x, nsMap_sxp) {
.Call(`_xml2_node_attrs`, x, nsMap_sxp)
}

node_set_attr <- function(node_sxp, name_sxp, value, nsMap) {
@@ -96,8 +96,8 @@ node_children <- function(node_sxp, only_node_sxp) {
.Call(`_xml2_node_children`, node_sxp, only_node_sxp)
}

node_length <- function(node_sxp, only_node_sxp) {
.Call(`_xml2_node_length`, node_sxp, only_node_sxp)
node_length <- function(x, only_node_sxp) {
.Call(`_xml2_node_length`, x, only_node_sxp)
}

node_has_children <- function(node_sxp, only_node_sxp) {
@@ -116,16 +116,16 @@ node_parent <- function(node_sxp) {
.Call(`_xml2_node_parent`, node_sxp)
}

node_path <- function(node_sxp) {
.Call(`_xml2_node_path`, node_sxp)
node_path <- function(x) {
.Call(`_xml2_node_path`, x)
}

nodes_duplicated <- function(nodes) {
.Call(`_xml2_nodes_duplicated`, nodes)
}

node_type <- function(node_sxp) {
.Call(`_xml2_node_type`, node_sxp)
node_type <- function(x) {
.Call(`_xml2_node_type`, x)
}

node_copy <- function(node_sxp) {
43 changes: 2 additions & 41 deletions R/xml_attr.R
Original file line number Diff line number Diff line change
@@ -60,31 +60,7 @@
#' xml_attrs(doc) <- c("b:id" = "one", "f:id" = "two", "id" = "three")
#' xml_set_attrs(doc, c("b:id" = "one", "f:id" = "two", "id" = "three"))
xml_attr <- function(x, attr, ns = character(), default = NA_character_) {
UseMethod("xml_attr")
}

#' @export
xml_attr.xml_missing <- function(x, attr, ns = character(), default = NA_character_) {
default
}

#' @export
xml_attr.xml_node <- function(x, attr, ns = character(),
default = NA_character_) {
node_attr(x$node, attr, as.character(default), ns)
}

#' @export
xml_attr.xml_nodeset <- function(x, attr, ns = character(),
default = NA_character_) {
vapply(
x,
xml_attr,
attr = attr,
default = default,
ns = ns,
FUN.VALUE = character(1)
)
node_attr(x, attr, as.character(default), ns)
}

#' @export
@@ -96,22 +72,7 @@ xml_has_attr <- function(x, attr, ns = character()) {
#' @export
#' @rdname xml_attr
xml_attrs <- function(x, ns = character()) {
UseMethod("xml_attrs")
}

#' @export
xml_attrs.xml_missing <- function(x, ns = character()) {
NA_character_
}

#' @export
xml_attrs.xml_node <- function(x, ns = character()) {
node_attrs(x$node, nsMap_sxp = ns)
}

#' @export
xml_attrs.xml_nodeset <- function(x, ns = character()) {
lapply(x, xml_attrs, ns = ns)
node_attrs(x, nsMap_sxp = ns)
}

#' @param value character vector of new value.
21 changes: 1 addition & 20 deletions R/xml_children.R
Original file line number Diff line number Diff line change
@@ -100,26 +100,7 @@ xml_parent.xml_nodeset <- function(x) {
#' @export
#' @rdname xml_children
xml_length <- function(x, only_elements = TRUE) {
UseMethod("xml_length")
}

#' @export
xml_length.xml_missing <- function(x, only_elements = TRUE) {
0L
}

#' @export
xml_length.xml_node <- function(x, only_elements = TRUE) {
node_length(x$node, only_elements)
}

#' @export
xml_length.xml_nodeset <- function(x, only_elements = TRUE) {
if (length(x) == 0) {
return(0L)
}

vapply(x, xml_length, only_elements = only_elements, FUN.VALUE = integer(1))
node_length(x, only_elements)
}

#' @export
17 changes: 1 addition & 16 deletions R/xml_name.R
Original file line number Diff line number Diff line change
@@ -18,22 +18,7 @@
#' z <- xml_children(y)
#' xml_name(xml_children(y))
xml_name <- function(x, ns = character()) {
UseMethod("xml_name")
}

#' @export
xml_name.xml_missing <- function(x, ns = character()) {
NA_character_
}

#' @export
xml_name.xml_nodeset <- function(x, ns = character()) {
vapply(x, xml_name, ns = ns, FUN.VALUE = character(1))
}

#' @export
xml_name.xml_node <- function(x, ns = character()) {
node_name(x$node, ns)
node_name(x, ns)
}

#' Modify the (tag) name of an element
17 changes: 1 addition & 16 deletions R/xml_path.R
Original file line number Diff line number Diff line change
@@ -10,20 +10,5 @@
#' x <- read_xml("<foo><bar><baz /></bar><baz /></foo>")
#' xml_path(xml_find_all(x, ".//baz"))
xml_path <- function(x) {
UseMethod("xml_path")
}

#' @export
xml_path.xml_missing <- function(x) {
NA_character_
}

#' @export
xml_path.xml_node <- function(x) {
node_path(x$node)
}

#' @export
xml_path.xml_nodeset <- function(x) {
vapply(x, xml_path, FUN.VALUE = character(1))
node_path(x)
}
12 changes: 1 addition & 11 deletions R/xml_text.R
Original file line number Diff line number Diff line change
@@ -22,17 +22,7 @@
#' xml_integer(xml_find_all(x, "//@x"))
#' @export
xml_text <- function(x, trim = FALSE) {
UseMethod("xml_text")
}

#' @export
xml_text.xml_missing <- function(x, trim = FALSE) {
NA_character_
}

#' @export
xml_text.xml_node <- function(x, trim = FALSE) {
res <- node_text(x$node)
res <- node_text(x)
if (isTRUE(trim)) {
res <- trim_text(res)
}
17 changes: 1 addition & 16 deletions R/xml_type.R
Original file line number Diff line number Diff line change
@@ -7,22 +7,7 @@
#' xml_type(x)
#' xml_type(xml_contents(x))
xml_type <- function(x) {
UseMethod("xml_type")
}

#' @export
xml_type.xml_missing <- function(x) {
NA_character_
}

#' @export
xml_type.xml_node <- function(x) {
xmlElementType[node_type(x$node)]
}

#' @export
xml_type.xml_nodeset <- function(x) {
types <- vapply(x, function(x) node_type(x$node), integer(1))
types <- node_type(x)
xmlElementType[types]
}

Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.