diff --git a/.Rbuildignore b/.Rbuildignore
index d6a074f9c..cf0404921 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -13,6 +13,7 @@ README.Rmd
codecov.yml
.lintr
.covrignore
+^src/.clang-format$
# Temporary files
.DS_Store
diff --git a/R/RcppExports.R b/R/RcppExports.R
index 77566d09a..3271fec6f 100644
--- a/R/RcppExports.R
+++ b/R/RcppExports.R
@@ -169,22 +169,22 @@ write_xml_file <- function(xml_content, escapes) {
#'
#' @examples
#' # add single node
-#' xml_node <- "openxlsx2"
-#' xml_attr <- c(qux = "quux")
-#' # "openxlsx2"
-#' xml_attr_mod(xml_node, xml_attr)
+#' xml_node <- "openxlsx2"
+#' xml_attr <- c(qux = "quux")
+#' # "openxlsx2"
+#' xml_attr_mod(xml_node, xml_attr)
#'
#' # update node and add node
-#' xml_node <- "openxlsx2"
-#' xml_attr <- c(foo = "baz", qux = "quux")
-#' # "openxlsx2"
-#' xml_attr_mod(xml_node, xml_attr)
+#' xml_node <- "openxlsx2"
+#' xml_attr <- c(foo = "baz", qux = "quux")
+#' # "openxlsx2"
+#' xml_attr_mod(xml_node, xml_attr)
#'
#' # remove node and add node
-#' xml_node <- "openxlsx2"
-#' xml_attr <- c(foo = "", qux = "quux")
-#' # "openxlsx2"
-#' xml_attr_mod(xml_node, xml_attr)
+#' xml_node <- "openxlsx2"
+#' xml_attr <- c(foo = "", qux = "quux")
+#' # "openxlsx2"
+#' xml_attr_mod(xml_node, xml_attr)
#' @export
xml_attr_mod <- function(xml_content, xml_attributes, escapes = FALSE, declaration = FALSE, remove_empty_attr = TRUE) {
.Call(`_openxlsx2_xml_attr_mod`, xml_content, xml_attributes, escapes, declaration, remove_empty_attr)
diff --git a/man/xml_attr_mod.Rd b/man/xml_attr_mod.Rd
index d30865d2d..171c397cd 100644
--- a/man/xml_attr_mod.Rd
+++ b/man/xml_attr_mod.Rd
@@ -36,20 +36,20 @@ updated else it is added as attribute.
}
\examples{
# add single node
- xml_node <- "openxlsx2"
- xml_attr <- c(qux = "quux")
- # "openxlsx2"
- xml_attr_mod(xml_node, xml_attr)
+ xml_node <- "openxlsx2"
+ xml_attr <- c(qux = "quux")
+ # "openxlsx2"
+ xml_attr_mod(xml_node, xml_attr)
# update node and add node
- xml_node <- "openxlsx2"
- xml_attr <- c(foo = "baz", qux = "quux")
- # "openxlsx2"
- xml_attr_mod(xml_node, xml_attr)
+ xml_node <- "openxlsx2"
+ xml_attr <- c(foo = "baz", qux = "quux")
+ # "openxlsx2"
+ xml_attr_mod(xml_node, xml_attr)
# remove node and add node
- xml_node <- "openxlsx2"
- xml_attr <- c(foo = "", qux = "quux")
- # "openxlsx2"
- xml_attr_mod(xml_node, xml_attr)
+ xml_node <- "openxlsx2"
+ xml_attr <- c(foo = "", qux = "quux")
+ # "openxlsx2"
+ xml_attr_mod(xml_node, xml_attr)
}
diff --git a/src/.clang-format b/src/.clang-format
new file mode 100644
index 000000000..356c6ce16
--- /dev/null
+++ b/src/.clang-format
@@ -0,0 +1,14 @@
+IndentWidth: 2
+ContinuationIndentWidth: 2 # Control the indentation width after a line break, such as in function arguments
+ColumnLimit: 100 # Set the maximum line length to 100 characters
+BreakBeforeBraces: Attach # Keep braces on the same line as the function declaration
+BinPackParameters: false # Force each parameter to appear on its own line
+BinPackArguments: false # Force each argument in calls to appear on its own line
+AlignAfterOpenBracket: AlwaysBreak
+AlignConsecutiveAssignments: true # Align equal signs in consecutive assignments
+AlignConsecutiveDeclarations: true # Align types and variables in consecutive declarations
+AlignTrailingComments: true # Align trailing comments
+AllowShortFunctionsOnASingleLine: None # Break short functions into multiple lines
+Cpp11BracedListStyle: true # Format braced initializer lists cleanly
+PenaltyBreakBeforeFirstCallParameter: 0 # Encourage breaking after the first parameter
+
diff --git a/src/helper_functions.cpp b/src/helper_functions.cpp
index caadd5a53..e502c1dbf 100644
--- a/src/helper_functions.cpp
+++ b/src/helper_functions.cpp
@@ -16,17 +16,18 @@
//' @noRd
// [[Rcpp::export]]
bool to_long(std::string path) {
- return path.size() > R_PATH_MAX;
+ return path.size() > R_PATH_MAX;
}
// [[Rcpp::export]]
SEXP openxlsx2_type(SEXP x) {
const SEXP names = Rf_getAttrib(x, R_NamesSymbol);
- R_xlen_t ncol = Rf_length(x);
+ R_xlen_t ncol = Rf_length(x);
Rcpp::IntegerVector type(ncol);
- if (!Rf_isNull(names)) type.attr("names") = names;
+ if (!Rf_isNull(names))
+ type.attr("names") = names;
for (R_xlen_t i = 0; i < ncol; ++i) {
@@ -104,15 +105,12 @@ SEXP openxlsx2_type(SEXP x) {
type[i] = list;
break;
-
// whatever is not covered from above
default: {
type[i] = character;
break;
}
-
}
-
}
return type;
@@ -122,9 +120,9 @@ SEXP openxlsx2_type(SEXP x) {
Rcpp::IntegerVector col_to_int(Rcpp::CharacterVector x) {
// This function converts the Excel column letter to an integer
- R_xlen_t n = static_cast(x.size());
+ R_xlen_t n = static_cast(x.size());
std::unordered_map col_map;
- Rcpp::IntegerVector colNums(n);
+ Rcpp::IntegerVector colNums(n);
for (R_xlen_t i = 0; i < n; ++i) {
std::string a = Rcpp::as(x[i]);
@@ -143,8 +141,8 @@ Rcpp::IntegerVector col_to_int(Rcpp::CharacterVector x) {
} else {
// Compute the integer value and store it in the map
int col_int = cell_to_colint(a);
- col_map[a] = col_int;
- colNums[i] = col_int;
+ col_map[a] = col_int;
+ colNums[i] = col_int;
}
}
@@ -153,8 +151,8 @@ Rcpp::IntegerVector col_to_int(Rcpp::CharacterVector x) {
// [[Rcpp::export]]
Rcpp::CharacterVector ox_int_to_col(Rcpp::NumericVector x) {
- R_xlen_t n = static_cast(x.size());
- Rcpp::CharacterVector colNames(n);
+ R_xlen_t n = static_cast(x.size());
+ Rcpp::CharacterVector colNames(n);
std::unordered_map cache; // Updated key type
for (R_xlen_t i = 0; i < n; ++i) {
@@ -166,8 +164,8 @@ Rcpp::CharacterVector ox_int_to_col(Rcpp::NumericVector x) {
} else {
// Compute the column name and store it in the cache
std::string col_name = int_to_col(num);
- cache[num] = col_name;
- colNames[i] = col_name;
+ cache[num] = col_name;
+ colNames[i] = col_name;
}
}
@@ -178,48 +176,48 @@ Rcpp::CharacterVector ox_int_to_col(Rcpp::NumericVector x) {
// [[Rcpp::export]]
SEXP rbindlist(Rcpp::List x) {
- R_xlen_t nn = static_cast(x.size());
+ R_xlen_t nn = static_cast(x.size());
std::vector all_names;
// get unique names and create set
for (R_xlen_t i = 0; i < nn; ++i) {
- if (Rf_isNull(x[i])) continue;
+ if (Rf_isNull(x[i]))
+ continue;
std::vector name_i = Rcpp::as(x[i]).attr("names");
std::unique_copy(name_i.begin(), name_i.end(), std::back_inserter(all_names));
}
std::sort(all_names.begin(), all_names.end());
- std::set unique_names(std::make_move_iterator(all_names.begin()),
- std::make_move_iterator(all_names.end()));
+ std::set unique_names(
+ std::make_move_iterator(all_names.begin()), std::make_move_iterator(all_names.end()));
R_xlen_t kk = static_cast(unique_names.size());
// 1. create the list
Rcpp::List df(kk);
- for (R_xlen_t i = 0; i < kk; ++i)
- {
+ for (R_xlen_t i = 0; i < kk; ++i) {
SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn)));
}
for (R_xlen_t i = 0; i < nn; ++i) {
- if (Rf_isNull(x[i])) continue;
+ if (Rf_isNull(x[i]))
+ continue;
std::vector values = Rcpp::as>(x[i]);
- std::vector names = Rcpp::as(x[i]).attr("names");
+ std::vector names = Rcpp::as(x[i]).attr("names");
for (size_t j = 0; j < names.size(); ++j) {
- auto find_res = unique_names.find(names[j]);
- R_xlen_t mtc = std::distance(unique_names.begin(), find_res);
+ auto find_res = unique_names.find(names[j]);
+ R_xlen_t mtc = std::distance(unique_names.begin(), find_res);
Rcpp::as(df[mtc])[i] = Rcpp::String(values[j]);
}
-
}
// 3. Create a data.frame
df.attr("row.names") = Rcpp::IntegerVector::create(NA_INTEGER, nn);
- df.attr("names") = unique_names;
- df.attr("class") = "data.frame";
+ df.attr("names") = unique_names;
+ df.attr("class") = "data.frame";
return df;
}
@@ -230,18 +228,18 @@ SEXP copy(SEXP x) {
}
// [[Rcpp::export]]
-Rcpp::CharacterVector needed_cells(const std::string& range) {
+Rcpp::CharacterVector needed_cells(const std::string &range) {
std::vector cells;
// Parse the input range
std::string startCell, endCell;
- size_t colonPos = range.find(':');
+ size_t colonPos = range.find(':');
if (colonPos != std::string::npos) {
startCell = range.substr(0, colonPos);
- endCell = range.substr(colonPos + 1);
+ endCell = range.substr(colonPos + 1);
} else {
startCell = range;
- endCell = range;
+ endCell = range;
}
if (!validate_dims(startCell) || !validate_dims(endCell)) {
@@ -250,7 +248,7 @@ Rcpp::CharacterVector needed_cells(const std::string& range) {
// Extract column and row numbers from start and end cells
uint32_t startRow, endRow;
- int32_t startCol = 0, endCol = 0;
+ int32_t startCol = 0, endCol = 0;
startCol = cell_to_colint(startCell);
endCol = cell_to_colint(endCell);
@@ -272,8 +270,12 @@ Rcpp::CharacterVector needed_cells(const std::string& range) {
// provide a basic rbindlist for lists of named characters
// [[Rcpp::export]]
-SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Nullable filled, bool fill,
- Rcpp::Nullable fcols) {
+SEXP dims_to_df(
+ Rcpp::IntegerVector rows,
+ Rcpp::CharacterVector cols,
+ Rcpp::Nullable filled,
+ bool fill,
+ Rcpp::Nullable fcols) {
R_xlen_t kk = static_cast(cols.size());
R_xlen_t nn = static_cast(rows.size());
@@ -283,8 +285,7 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null
// 1. create the list
Rcpp::List df(kk);
- for (R_xlen_t i = 0; i < kk; ++i)
- {
+ for (R_xlen_t i = 0; i < kk; ++i) {
if (fill)
SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn)));
else
@@ -294,20 +295,19 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null
if (fill) {
if (has_filled) {
- std::vector flld = Rcpp::as>(filled.get());
+ std::vector flld = Rcpp::as>(filled.get());
std::unordered_set flls(flld.begin(), flld.end());
// with has_filled we always have to run this loop
for (R_xlen_t i = 0; i < kk; ++i) {
Rcpp::CharacterVector cvec = Rcpp::as(df[i]);
- std::string coli = Rcpp::as(cols[i]);
+ std::string coli = Rcpp::as(cols[i]);
for (R_xlen_t j = 0; j < nn; ++j) {
std::string cell = coli + std::to_string(rows[j]);
if (has_cell(cell, flls))
cvec[j] = cell;
}
}
-
} else { // insert cells into data frame
std::vector fcls;
@@ -319,7 +319,7 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null
if (has_fcols && std::find(fcls.begin(), fcls.end(), i) == fcls.end())
continue;
Rcpp::CharacterVector cvec = Rcpp::as(df[i]);
- std::string coli = Rcpp::as(cols[i]);
+ std::string coli = Rcpp::as(cols[i]);
for (R_xlen_t j = 0; j < nn; ++j) {
cvec[j] = coli + std::to_string(rows[j]);
}
@@ -330,8 +330,8 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null
// 3. Create a data.frame
df.attr("row.names") = rows;
- df.attr("names") = cols;
- df.attr("class") = "data.frame";
+ df.attr("names") = cols;
+ df.attr("class") = "data.frame";
return df;
}
@@ -340,11 +340,11 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null
// [[Rcpp::export]]
void long_to_wide(Rcpp::DataFrame z, Rcpp::DataFrame tt, Rcpp::DataFrame zz) {
- R_xlen_t n = static_cast(zz.nrow());
+ R_xlen_t n = static_cast(zz.nrow());
R_xlen_t col = 0, row = 0;
- Rcpp::IntegerVector cols = zz["cols"];
- Rcpp::IntegerVector rows = zz["rows"];
+ Rcpp::IntegerVector cols = zz["cols"];
+ Rcpp::IntegerVector rows = zz["rows"];
Rcpp::CharacterVector vals = zz["val"];
Rcpp::CharacterVector typs = zz["typ"];
@@ -374,25 +374,24 @@ Rcpp::LogicalVector is_charnum(Rcpp::CharacterVector x) {
// similar to dcast converts cc dataframe to z dataframe
// [[Rcpp::export]]
void wide_to_long(
- Rcpp::DataFrame z,
- std::vector vtyps,
- Rcpp::DataFrame zz,
- bool ColNames,
- int32_t start_col,
- int32_t start_row,
- Rcpp::Nullable refed,
- int32_t string_nums,
- bool na_null,
- bool na_missing,
- std::string na_strings,
- bool inline_strings,
- std::string c_cm,
- std::vector dims
-) {
-
- R_xlen_t n = static_cast(z.nrow());
- R_xlen_t m = static_cast(z.ncol());
- bool has_dims = static_cast(dims.size()) == (n * m);
+ Rcpp::DataFrame z,
+ std::vector vtyps,
+ Rcpp::DataFrame zz,
+ bool ColNames,
+ int32_t start_col,
+ int32_t start_row,
+ Rcpp::Nullable refed,
+ int32_t string_nums,
+ bool na_null,
+ bool na_missing,
+ std::string na_strings,
+ bool inline_strings,
+ std::string c_cm,
+ std::vector dims) {
+
+ R_xlen_t n = static_cast(z.nrow());
+ R_xlen_t m = static_cast(z.ncol());
+ bool has_dims = static_cast(dims.size()) == (n * m);
std::vector srows(static_cast(n));
for (size_t j = 0; j < static_cast(n); ++j) {
@@ -404,10 +403,11 @@ void wide_to_long(
scols[i] = int_to_col(static_cast(start_col) + i);
}
- bool has_refs = refed.isNotNull();
+ bool has_refs = refed.isNotNull();
std::vector ref;
- if (has_refs) ref = Rcpp::as>(refed.get());
+ if (has_refs)
+ ref = Rcpp::as>(refed.get());
int32_t in_string_nums = string_nums;
@@ -430,36 +430,35 @@ void wide_to_long(
R_xlen_t idx = 0;
- SEXP blank_sexp = Rf_mkChar("");
- SEXP array_sexp = Rf_mkChar("array");
- SEXP inlineStr_sexp = Rf_mkChar("inlineStr");
- SEXP bool_sexp = Rf_mkChar("b");
- SEXP expr_sexp = Rf_mkChar("e");
- SEXP sharedStr_sexp = Rf_mkChar("s");
- SEXP string_sexp = Rf_mkChar("str");
+ SEXP blank_sexp = Rf_mkChar("");
+ SEXP array_sexp = Rf_mkChar("array");
+ SEXP inlineStr_sexp = Rf_mkChar("inlineStr");
+ SEXP bool_sexp = Rf_mkChar("b");
+ SEXP expr_sexp = Rf_mkChar("e");
+ SEXP sharedStr_sexp = Rf_mkChar("s");
+ SEXP string_sexp = Rf_mkChar("str");
SEXP na_sexp = Rf_mkChar("#N/A");
SEXP num_sexp = Rf_mkChar("#NUM!");
SEXP value_sexp = Rf_mkChar("#VALUE!");
SEXP na_strings_sexp = Rf_mkChar(na_strings.c_str());
-
for (R_xlen_t i = 0; i < m; ++i) {
- Rcpp::CharacterVector cvec = Rcpp::as(z[i]);
- const std::string& col = scols[static_cast(i)];
- int8_t vtyp_i = static_cast(vtyps[static_cast(i)]);
+ Rcpp::CharacterVector cvec = Rcpp::as(z[i]);
+ const std::string &col = scols[static_cast(i)];
+ int8_t vtyp_i = static_cast(vtyps[static_cast(i)]);
for (R_xlen_t j = 0; j < n; ++j, ++idx) {
checkInterrupt(idx);
// if colname is provided, the first row is always a character
- int8_t vtyp = (ColNames && j == 0) ? character : vtyp_i;
- SEXP vals_sexp = STRING_ELT(cvec, j);
- const char* vals = CHAR(vals_sexp);
+ int8_t vtyp = (ColNames && j == 0) ? character : vtyp_i;
+ SEXP vals_sexp = STRING_ELT(cvec, j);
+ const char *vals = CHAR(vals_sexp);
- const std::string& row = srows[static_cast(j)];
+ const std::string &row = srows[static_cast(j)];
R_xlen_t pos = (j * m) + i;
@@ -477,8 +476,7 @@ void wide_to_long(
else
string_nums = in_string_nums;
- switch(vtyp)
- {
+ switch (vtyp) {
case currency:
case short_date:
@@ -494,7 +492,7 @@ void wide_to_long(
break;
case logical:
// v and c_t = "b"
- SET_STRING_ELT(zz_v, pos, vals_sexp);
+ SET_STRING_ELT(zz_v, pos, vals_sexp);
SET_STRING_ELT(zz_c_t, pos, bool_sexp);
break;
case factor:
@@ -504,17 +502,17 @@ void wide_to_long(
if (string_nums && is_double(vals)) {
// v
SET_STRING_ELT(zz_v, pos, vals_sexp);
- vtyp = (string_nums == 1) ? string_num : numeric;
+ vtyp = (string_nums == 1) ? string_num : numeric;
} else {
// check if we write sst or inlineStr
if (inline_strings) {
- // is and c_t = "inlineStr"
- SET_STRING_ELT(zz_c_t, pos, inlineStr_sexp);
- SET_STRING_ELT(zz_is, pos, Rf_mkChar(txt_to_is(vals, 0, 1, 1).c_str()));
- } else {
- // v and c_t = "s"
- SET_STRING_ELT(zz_c_t, pos, sharedStr_sexp);
- SET_STRING_ELT(zz_v, pos, Rf_mkChar(txt_to_si(vals, 0, 1, 1).c_str()));
+ // is and c_t = "inlineStr"
+ SET_STRING_ELT(zz_c_t, pos, inlineStr_sexp);
+ SET_STRING_ELT(zz_is, pos, Rf_mkChar(txt_to_is(vals, 0, 1, 1).c_str()));
+ } else {
+ // v and c_t = "s"
+ SET_STRING_ELT(zz_c_t, pos, sharedStr_sexp);
+ SET_STRING_ELT(zz_v, pos, Rf_mkChar(txt_to_si(vals, 0, 1, 1).c_str()));
}
}
break;
@@ -522,19 +520,19 @@ void wide_to_long(
case formula:
// f and c_t = "str";
SET_STRING_ELT(zz_c_t, pos, string_sexp);
- SET_STRING_ELT(zz_f, pos, vals_sexp);
+ SET_STRING_ELT(zz_f, pos, vals_sexp);
break;
case array_formula:
// f, f_t = "array", and f_ref
- SET_STRING_ELT(zz_f, pos, vals_sexp);
- SET_STRING_ELT(zz_f_t, pos, array_sexp);
+ SET_STRING_ELT(zz_f, pos, vals_sexp);
+ SET_STRING_ELT(zz_f_t, pos, array_sexp);
SET_STRING_ELT(zz_f_ref, pos, Rf_mkChar(ref_str.c_str()));
break;
case cm_formula:
// c_cm, f, f_t = "array", and f_ref
- SET_STRING_ELT(zz_c_cm, pos, Rf_mkChar(c_cm.c_str()));
- SET_STRING_ELT(zz_f, pos, vals_sexp);
- SET_STRING_ELT(zz_f_t, pos, array_sexp);
+ SET_STRING_ELT(zz_c_cm, pos, Rf_mkChar(c_cm.c_str()));
+ SET_STRING_ELT(zz_f, pos, vals_sexp);
+ SET_STRING_ELT(zz_f_t, pos, array_sexp);
SET_STRING_ELT(zz_f_ref, pos, Rf_mkChar(ref_str.c_str()));
break;
}
@@ -543,34 +541,34 @@ void wide_to_long(
if (na_missing) {
// v = "#N/A"
- SET_STRING_ELT(zz_v, pos, na_sexp);
+ SET_STRING_ELT(zz_v, pos, na_sexp);
SET_STRING_ELT(zz_c_t, pos, expr_sexp);
// is = "" - required only if inline_strings
// and vtyp = character || vtyp = factor
- SET_STRING_ELT(zz_is, pos, blank_sexp);
- } else {
+ SET_STRING_ELT(zz_is, pos, blank_sexp);
+ } else {
if (na_null) {
- // all three v, c_t, and is = "" - there should be nothing in this row
- SET_STRING_ELT(zz_v, pos, blank_sexp);
+ // all three v, c_t, and is = "" - there should be nothing in this
+ // row
+ SET_STRING_ELT(zz_v, pos, blank_sexp);
SET_STRING_ELT(zz_c_t, pos, blank_sexp);
- SET_STRING_ELT(zz_is, pos, blank_sexp);
+ SET_STRING_ELT(zz_is, pos, blank_sexp);
} else {
// c_t = "inlineStr" or "s"
- SET_STRING_ELT(zz_c_t, pos, inline_strings ? inlineStr_sexp : sharedStr_sexp);
+ SET_STRING_ELT(zz_c_t, pos, inline_strings ? inlineStr_sexp : sharedStr_sexp);
// for inlineStr is = na_strings else ""
- SET_STRING_ELT(zz_is, pos, inline_strings ? na_strings_sexp : blank_sexp);
+ SET_STRING_ELT(zz_is, pos, inline_strings ? na_strings_sexp : blank_sexp);
// otherwise v = na_strings else ""
- SET_STRING_ELT(zz_v, pos, !inline_strings ? na_strings_sexp : blank_sexp);
+ SET_STRING_ELT(zz_v, pos, !inline_strings ? na_strings_sexp : blank_sexp);
}
}
-
} else if (strcmp(vals, "NaN") == 0) {
// v = "#VALUE!"
- SET_STRING_ELT(zz_v, pos, value_sexp);
+ SET_STRING_ELT(zz_v, pos, value_sexp);
SET_STRING_ELT(zz_c_t, pos, expr_sexp);
} else if (strcmp(vals, "-Inf") == 0 || strcmp(vals, "Inf") == 0) {
// v = "#NUM!"
- SET_STRING_ELT(zz_v, pos, num_sexp);
+ SET_STRING_ELT(zz_v, pos, num_sexp);
SET_STRING_ELT(zz_c_t, pos, expr_sexp);
}
@@ -612,8 +610,8 @@ Rcpp::DataFrame create_char_dataframe(Rcpp::CharacterVector colnames, R_xlen_t n
// 3. Create a data.frame
df.attr("row.names") = rvec;
- df.attr("names") = colnames;
- df.attr("class") = "data.frame";
+ df.attr("names") = colnames;
+ df.attr("class") = "data.frame";
return df;
}
@@ -621,31 +619,34 @@ Rcpp::DataFrame create_char_dataframe(Rcpp::CharacterVector colnames, R_xlen_t n
// TODO styles_xml.cpp should be converted to use these functions
// [[Rcpp::export]]
-Rcpp::DataFrame read_xml2df(XPtrXML xml, std::string vec_name, std::vector vec_attrs, std::vector vec_chlds) {
+Rcpp::DataFrame read_xml2df(
+ XPtrXML xml,
+ std::string vec_name,
+ std::vector vec_attrs,
+ std::vector vec_chlds) {
std::set nam_attrs(vec_attrs.begin(), vec_attrs.end());
std::set nam_chlds(vec_chlds.begin(), vec_chlds.end());
- auto total_length = nam_attrs.size() + nam_chlds.size();
+ auto total_length = nam_attrs.size() + nam_chlds.size();
std::vector all_names(total_length);
std::copy(nam_attrs.begin(), nam_attrs.end(), all_names.begin());
- std::copy(nam_chlds.begin(), nam_chlds.end(), all_names.begin() + static_cast(nam_attrs.size()));
+ std::copy(
+ nam_chlds.begin(), nam_chlds.end(), all_names.begin() + static_cast(nam_attrs.size()));
- std::set nams(std::make_move_iterator(all_names.begin()),
- std::make_move_iterator(all_names.end()));
+ std::set nams(
+ std::make_move_iterator(all_names.begin()), std::make_move_iterator(all_names.end()));
-
- R_xlen_t nn = std::distance(xml->begin(), xml->end());
- R_xlen_t kk = static_cast(nams.size());
+ R_xlen_t nn = std::distance(xml->begin(), xml->end());
+ R_xlen_t kk = static_cast(nams.size());
uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes;
Rcpp::CharacterVector rvec(nn);
// 1. create the list
Rcpp::List df(kk);
- for (R_xlen_t i = 0; i < kk; ++i)
- {
+ for (R_xlen_t i = 0; i < kk; ++i) {
SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn)));
}
@@ -655,15 +656,15 @@ Rcpp::DataFrame read_xml2df(XPtrXML xml, std::string vec_name, std::vectorchildren(vec_name.c_str())) {
for (auto attrs : xml_node.attributes()) {
- std::string attr_name = attrs.name();
+ std::string attr_name = attrs.name();
std::string attr_value = attrs.value();
- auto find_res = nams.find(attr_name);
+ auto find_res = nams.find(attr_name);
// check if name is already known
if (nams.count(attr_name) == 0) {
Rcpp::warning("%s: not found in %s name table", attr_name, vec_name);
} else {
- R_xlen_t mtc = std::distance(nams.begin(), find_res);
+ R_xlen_t mtc = std::distance(nams.begin(), find_res);
Rcpp::as(df[mtc])[itr] = attr_value;
}
}
@@ -671,7 +672,7 @@ Rcpp::DataFrame read_xml2df(XPtrXML xml, std::string vec_name, std::vector(df[mtc])[itr] = cld_value;
}
}
rvec[itr] = std::to_string(itr);
++itr;
-
}
// 3. Create a data.frame
df.attr("row.names") = rvec;
- df.attr("names") = nams;
- df.attr("class") = "data.frame";
+ df.attr("names") = nams;
+ df.attr("class") = "data.frame";
return df;
}
-
// [[Rcpp::export]]
-Rcpp::CharacterVector write_df2xml(Rcpp::DataFrame df, std::string vec_name, std::vector vec_attrs, std::vector vec_chlds) {
+Rcpp::CharacterVector write_df2xml(
+ Rcpp::DataFrame df,
+ std::string vec_name,
+ std::vector vec_attrs,
+ std::vector vec_chlds) {
- int64_t n = df.nrow();
+ int64_t n = df.nrow();
Rcpp::CharacterVector z(n);
- uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
+ uint32_t pugi_parse_flags =
+ pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes;
// openxml 2.8.1
- std::vector attrnams = df.names();
- std::set nam_attrs(vec_attrs.begin(), vec_attrs.end());
- std::set nam_chlds(vec_chlds.begin(), vec_chlds.end());
+ std::vector attrnams = df.names();
+ std::set nam_attrs(vec_attrs.begin(), vec_attrs.end());
+ std::set nam_chlds(vec_chlds.begin(), vec_chlds.end());
for (int64_t i = 0; i < n; ++i) {
pugi::xml_document doc;
- pugi::xml_node xml_node = doc.append_child(vec_name.c_str());
+ pugi::xml_node xml_node = doc.append_child(vec_name.c_str());
for (auto j = 0; j < df.ncol(); ++j) {
@@ -737,30 +741,30 @@ Rcpp::CharacterVector write_df2xml(Rcpp::DataFrame df, std::string vec_name, std
// check if name is already known
if (nam_attrs.count(attr_j) != 0) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df[j])[i];
+ cv_s = Rcpp::as(df[j])[i];
// only write attributes where cv_s has a value
if (cv_s[0] != "") {
// Rf_PrintValue(cv_s);
- const std::string val_strl = Rcpp::as(cv_s);
+ const std::string val_strl = Rcpp::as(cv_s);
xml_node.append_attribute(attr_j.c_str()) = val_strl.c_str();
}
}
if (nam_chlds.count(attr_j) != 0) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df[j])[i];
+ cv_s = Rcpp::as(df[j])[i];
if (cv_s[0] != "") {
std::string child_i = Rcpp::as(cv_s[0]);
- pugi::xml_document xml_child;
+ pugi::xml_document xml_child;
pugi::xml_parse_result result = xml_child.load_string(child_i.c_str(), pugi_parse_flags);
- if (!result) Rcpp::stop("loading %s child node fail: %s", vec_name, cv_s);
+ if (!result)
+ Rcpp::stop("loading %s child node fail: %s", vec_name, cv_s);
xml_node.append_copy(xml_child.first_child());
-
}
}
diff --git a/src/load_workbook.cpp b/src/load_workbook.cpp
index 36bb6b054..b0ac591ed 100644
--- a/src/load_workbook.cpp
+++ b/src/load_workbook.cpp
@@ -4,7 +4,7 @@
// [[Rcpp::export]]
Rcpp::DataFrame col_to_df(XPtrXML doc) {
- std::set col_nams= {
+ std::set col_nams = {
"bestFit",
"collapsed",
"customWidth",
@@ -14,8 +14,7 @@ Rcpp::DataFrame col_to_df(XPtrXML doc) {
"outlineLevel",
"phonetic",
"style",
- "width"
- };
+ "width"};
R_xlen_t nn = std::distance(doc->begin(), doc->end());
R_xlen_t kk = static_cast(col_nams.size());
@@ -24,8 +23,7 @@ Rcpp::DataFrame col_to_df(XPtrXML doc) {
// 1. create the list
Rcpp::List df(kk);
- for (R_xlen_t i = 0; i < kk; ++i)
- {
+ for (R_xlen_t i = 0; i < kk; ++i) {
SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn)));
}
@@ -35,18 +33,17 @@ Rcpp::DataFrame col_to_df(XPtrXML doc) {
for (auto col : doc->children("col")) {
for (auto attrs : col.attributes()) {
- std::string attr_name = attrs.name();
+ std::string attr_name = attrs.name();
std::string attr_value = attrs.value();
- auto find_res = col_nams.find(attr_name);
+ auto find_res = col_nams.find(attr_name);
// check if name is already known
if (col_nams.count(attr_name) == 0) {
Rcpp::Rcout << attr_name << ": not found in col name table" << std::endl;
} else {
- R_xlen_t mtc = std::distance(col_nams.begin(), find_res);
+ R_xlen_t mtc = std::distance(col_nams.begin(), find_res);
Rcpp::as(df[mtc])[itr] = attr_value;
}
-
}
// rownames as character vectors matching to
@@ -57,33 +54,32 @@ Rcpp::DataFrame col_to_df(XPtrXML doc) {
// 3. Create a data.frame
df.attr("row.names") = rvec;
- df.attr("names") = col_nams;
- df.attr("class") = "data.frame";
+ df.attr("names") = col_nams;
+ df.attr("class") = "data.frame";
return df;
}
-
// [[Rcpp::export]]
Rcpp::CharacterVector df_to_xml(std::string name, Rcpp::DataFrame df_col) {
- auto n = df_col.nrow();
+ auto n = df_col.nrow();
Rcpp::CharacterVector z(n);
for (auto i = 0; i < n; ++i) {
- pugi::xml_document doc;
+ pugi::xml_document doc;
Rcpp::CharacterVector attrnams = df_col.names();
pugi::xml_node col = doc.append_child(name.c_str());
for (auto j = 0; j < df_col.ncol(); ++j) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df_col[j])[i];
+ cv_s = Rcpp::as(df_col[j])[i];
// only write attributes where cv_s has a value
if (cv_s[0] != "") {
// Rf_PrintValue(cv_s);
- const std::string val_strl = Rcpp::as(cv_s);
+ const std::string val_strl = Rcpp::as(cv_s);
col.append_attribute(attrnams[j]) = val_strl.c_str();
}
}
@@ -97,12 +93,11 @@ Rcpp::CharacterVector df_to_xml(std::string name, Rcpp::DataFrame df_col) {
return z;
}
-
inline Rcpp::DataFrame row_to_df(XPtrXML doc) {
auto ws = doc->child("worksheet").child("sheetData");
- std::set row_nams {
+ std::set row_nams{
"r",
"spans",
"s",
@@ -115,8 +110,7 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) {
"outlineLevel",
"ph",
"thickBot",
- "thickTop"
- };
+ "thickTop"};
R_xlen_t nn = std::distance(ws.children("row").begin(), ws.children("row").end());
R_xlen_t kk = static_cast(row_nams.size());
@@ -125,8 +119,7 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) {
// 1. create the list
Rcpp::List df(kk);
- for (R_xlen_t i = 0; i < kk; ++i)
- {
+ for (R_xlen_t i = 0; i < kk; ++i) {
SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn)));
}
@@ -137,7 +130,7 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) {
bool has_rowname = false;
for (auto attrs : row.attributes()) {
- std::string attr_name = attrs.name();
+ std::string attr_name = attrs.name();
std::string attr_value = attrs.value();
// mimic which
@@ -147,18 +140,18 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) {
if (row_nams.count(attr_name) == 0) {
Rcpp::Rcout << attr_name << ": not found in row name table" << std::endl;
} else {
- R_xlen_t mtc = std::distance(row_nams.begin(), find_res);
+ R_xlen_t mtc = std::distance(row_nams.begin(), find_res);
Rcpp::as(df[mtc])[itr] = attr_value;
- if (attr_name == "r") has_rowname = true;
+ if (attr_name == "r")
+ has_rowname = true;
}
-
}
// some files have no row name in this case, we add one
if (!has_rowname) {
- std::string attr_name = "r";
- auto find_res = row_nams.find(attr_name);
- R_xlen_t mtc = std::distance(row_nams.begin(), find_res);
+ std::string attr_name = "r";
+ auto find_res = row_nams.find(attr_name);
+ R_xlen_t mtc = std::distance(row_nams.begin(), find_res);
Rcpp::as(df[mtc])[itr] = std::to_string(itr + 1);
}
@@ -170,8 +163,8 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) {
// 3. Create a data.frame
df.attr("row.names") = rvec;
- df.attr("names") = row_nams;
- df.attr("class") = "data.frame";
+ df.attr("names") = row_nams;
+ df.attr("class") = "data.frame";
return df;
}
@@ -188,21 +181,19 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) {
std::vector xml_cols;
// we check against these
- const std::string f_str = "f";
- const std::string r_str = "r";
- const std::string s_str = "s";
- const std::string t_str = "t";
- const std::string v_str = "v";
- const std::string ca_str = "ca";
- const std::string cm_str = "cm";
- const std::string is_str = "is";
- const std::string ph_str = "ph";
- const std::string si_str = "si";
- const std::string vm_str = "vm";
+ const std::string f_str = "f";
+ const std::string r_str = "r";
+ const std::string s_str = "s";
+ const std::string t_str = "t";
+ const std::string v_str = "v";
+ const std::string ca_str = "ca";
+ const std::string cm_str = "cm";
+ const std::string is_str = "is";
+ const std::string ph_str = "ph";
+ const std::string si_str = "si";
+ const std::string vm_str = "vm";
const std::string ref_str = "ref";
-
-
/*****************************************************************************
* Row information is returned as list of lists returning as much as possible.
*
@@ -212,7 +203,7 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) {
row_attributes = row_to_df(doc);
R_xlen_t idx = 0, itr_rows = 0;
- for (auto worksheet: ws.children("row")) {
+ for (auto worksheet : ws.children("row")) {
/* ---------------------------------------------------------------------- */
/* read cval, and ctyp -------------------------------------------------- */
@@ -236,7 +227,7 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) {
bool has_colname = false;
for (auto attr : col.attributes()) {
- buffer = attr.value();
+ buffer = attr.value();
attr_name = attr.name();
if (attr_name == r_str) {
@@ -246,7 +237,7 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) {
// get col name
single_xml_col.c_r = rm_rownum(buffer);
- has_colname = true;
+ has_colname = true;
// get colnum
single_xml_col.row_r = rm_colnum(buffer);
@@ -254,28 +245,31 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) {
// if some cells of the workbook have colnames but other dont,
// this will increase itr_cols and avoid duplicates in cc
itr_cols = static_cast(uint_col_to_int(single_xml_col.c_r) - 1);
-
}
- if (attr_name == s_str) single_xml_col.c_s = buffer;
- if (attr_name == t_str) single_xml_col.c_t = buffer;
- if (attr_name == cm_str) single_xml_col.c_cm = buffer;
- if (attr_name == ph_str) single_xml_col.c_ph = buffer;
- if (attr_name == vm_str) single_xml_col.c_vm = buffer;
-
+ if (attr_name == s_str)
+ single_xml_col.c_s = buffer;
+ if (attr_name == t_str)
+ single_xml_col.c_t = buffer;
+ if (attr_name == cm_str)
+ single_xml_col.c_cm = buffer;
+ if (attr_name == ph_str)
+ single_xml_col.c_ph = buffer;
+ if (attr_name == vm_str)
+ single_xml_col.c_vm = buffer;
}
// some files have no colnames. in this case we need to add c_r and row_r
// if the file provides dimensions, they could be fixed later
if (!has_colname) {
- single_xml_col.c_r = int_to_col(itr_cols + 1);
+ single_xml_col.c_r = int_to_col(itr_cols + 1);
single_xml_col.row_r = std::to_string(itr_rows + 1);
- single_xml_col.r = single_xml_col.c_r + single_xml_col.row_r;
+ single_xml_col.r = single_xml_col.c_r + single_xml_col.row_r;
}
// val ------------------------------------------------------------------
if (nn > 0) {
- for (auto val: col.children()) {
+ for (auto val : col.children()) {
val_name = val.name();
@@ -297,21 +291,24 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) {
// * ref=
// * ca=
// * si=
- for (auto cattr : val.attributes())
- {
- buffer = cattr.value();
+ for (auto cattr : val.attributes()) {
+ buffer = cattr.value();
cattr_name = cattr.name();
- if (cattr_name == t_str) single_xml_col.f_t = buffer;
- if (cattr_name == ref_str) single_xml_col.f_ref = buffer;
- if (cattr_name == ca_str) single_xml_col.f_ca = buffer;
- if (cattr_name == si_str) single_xml_col.f_si = buffer;
+ if (cattr_name == t_str)
+ single_xml_col.f_t = buffer;
+ if (cattr_name == ref_str)
+ single_xml_col.f_ref = buffer;
+ if (cattr_name == ca_str)
+ single_xml_col.f_ca = buffer;
+ if (cattr_name == si_str)
+ single_xml_col.f_si = buffer;
}
} //
//
- if (val_name == v_str) single_xml_col.v = val.text().get();
-
+ if (val_name == v_str)
+ single_xml_col.v = val.text().get();
}
/* row is done */
@@ -322,12 +319,11 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) {
++itr_cols;
}
-
/* ---------------------------------------------------------------------- */
++itr_rows;
}
sheet_data["row_attr"] = row_attributes;
- sheet_data["cc"] = Rcpp::wrap(xml_cols);
+ sheet_data["cc"] = Rcpp::wrap(xml_cols);
}
diff --git a/src/pugi.cpp b/src/pugi.cpp
index e321fbf40..3707e68fe 100644
--- a/src/pugi.cpp
+++ b/src/pugi.cpp
@@ -1,17 +1,29 @@
#include "openxlsx2.h"
// [[Rcpp::export]]
-SEXP readXML(std::string path, bool isfile, bool escapes, bool declaration, bool whitespace, bool empty_tags, bool skip_control, bool pointer) {
-
- xmldoc *doc = new xmldoc;
+SEXP readXML(
+ std::string path,
+ bool isfile,
+ bool escapes,
+ bool declaration,
+ bool whitespace,
+ bool empty_tags,
+ bool skip_control,
+ bool pointer) {
+
+ xmldoc *doc = new xmldoc;
pugi::xml_parse_result result;
// pugi::parse_default without escapes flag
uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_eol;
- if (escapes) pugi_parse_flags |= pugi::parse_escapes;
- if (declaration) pugi_parse_flags |= pugi::parse_declaration;
- if (whitespace) pugi_parse_flags |= pugi::parse_ws_pcdata_single;
- if (!whitespace) pugi_parse_flags |= pugi::parse_trim_pcdata;
+ if (escapes)
+ pugi_parse_flags |= pugi::parse_escapes;
+ if (declaration)
+ pugi_parse_flags |= pugi::parse_declaration;
+ if (whitespace)
+ pugi_parse_flags |= pugi::parse_ws_pcdata_single;
+ if (!whitespace)
+ pugi_parse_flags |= pugi::parse_trim_pcdata;
if (isfile) {
result = doc->load_file(path.c_str(), pugi_parse_flags, pugi::encoding_utf8);
@@ -24,33 +36,39 @@ SEXP readXML(std::string path, bool isfile, bool escapes, bool declaration, bool
}
uint32_t pugi_format_flags = pugi::format_raw;
- if (!escapes) pugi_format_flags |= pugi::format_no_escapes;
- if (empty_tags) pugi_format_flags |= pugi::format_no_empty_element_tags;
- if (skip_control) pugi_format_flags |= pugi::format_skip_control_chars;
+ if (!escapes)
+ pugi_format_flags |= pugi::format_no_escapes;
+ if (empty_tags)
+ pugi_format_flags |= pugi::format_no_empty_element_tags;
+ if (skip_control)
+ pugi_format_flags |= pugi::format_skip_control_chars;
if (pointer) {
XPtrXML ptr(doc, true);
- ptr.attr("class") = Rcpp::CharacterVector::create("pugi_xml");
- ptr.attr("escapes") = escapes;
- ptr.attr("empty_tags") = empty_tags;
+ ptr.attr("class") = Rcpp::CharacterVector::create("pugi_xml");
+ ptr.attr("escapes") = escapes;
+ ptr.attr("empty_tags") = empty_tags;
ptr.attr("skip_control") = skip_control;
return ptr;
}
std::ostringstream oss;
doc->print(oss, " ", pugi_format_flags);
- return Rcpp::wrap(Rcpp::String(oss.str()));
+ return Rcpp::wrap(Rcpp::String(oss.str()));
}
-inline uint32_t pugi_format(XPtrXML doc){
- bool escapes = Rcpp::as(doc.attr("escapes"));
- bool empty_tags = Rcpp::as(doc.attr("empty_tags"));
+inline uint32_t pugi_format(XPtrXML doc) {
+ bool escapes = Rcpp::as(doc.attr("escapes"));
+ bool empty_tags = Rcpp::as(doc.attr("empty_tags"));
bool skip_control = Rcpp::as(doc.attr("skip_control"));
uint32_t pugi_format_flags = pugi::format_raw;
- if (!escapes) pugi_format_flags |= pugi::format_no_escapes;
- if (empty_tags) pugi_format_flags |= pugi::format_no_empty_element_tags;
- if (skip_control) pugi_format_flags |= pugi::format_skip_control_chars;
+ if (!escapes)
+ pugi_format_flags |= pugi::format_no_escapes;
+ if (empty_tags)
+ pugi_format_flags |= pugi::format_no_empty_element_tags;
+ if (skip_control)
+ pugi_format_flags |= pugi::format_skip_control_chars;
return pugi_format_flags;
}
@@ -58,7 +76,7 @@ inline uint32_t pugi_format(XPtrXML doc){
// [[Rcpp::export]]
Rcpp::LogicalVector is_xml(std::string str) {
- pugi::xml_document doc;
+ pugi::xml_document doc;
pugi::xml_parse_result result;
result = doc.load_string(str.c_str());
@@ -74,12 +92,11 @@ SEXP getXMLXPtrName1(XPtrXML doc) {
vec_string res;
- for (auto lvl0 : doc->children())
- {
+ for (auto lvl0 : doc->children()) {
res.push_back(lvl0.name());
}
- return Rcpp::wrap(res);
+ return Rcpp::wrap(res);
}
// [[Rcpp::export]]
@@ -87,15 +104,13 @@ SEXP getXMLXPtrName2(XPtrXML doc, std::string level1) {
vec_string res;
- for (auto lvl0 : doc->children(level1.c_str()))
- {
- for (auto lvl1 : lvl0.children())
- {
+ for (auto lvl0 : doc->children(level1.c_str())) {
+ for (auto lvl1 : lvl0.children()) {
res.push_back(lvl1.name());
}
}
- return Rcpp::wrap(res);
+ return Rcpp::wrap(res);
}
// [[Rcpp::export]]
@@ -103,58 +118,52 @@ SEXP getXMLXPtrName3(XPtrXML doc, std::string level1, std::string level2) {
vec_string res;
- for (auto lvl0 : doc->children(level1.c_str()))
- {
- for (auto lvl1 : lvl0.children())
- {
- for (auto lvl2 : lvl1.children())
- {
+ for (auto lvl0 : doc->children(level1.c_str())) {
+ for (auto lvl1 : lvl0.children()) {
+ for (auto lvl2 : lvl1.children()) {
res.push_back(lvl2.name());
}
}
}
- return Rcpp::wrap(res);
+ return Rcpp::wrap(res);
}
// [[Rcpp::export]]
SEXP getXMLXPtr0(XPtrXML doc) {
vec_string res;
- uint32_t pugi_format_flags = pugi_format(doc);
+ uint32_t pugi_format_flags = pugi_format(doc);
- for (auto worksheet : doc->children())
- {
+ for (auto worksheet : doc->children()) {
std::ostringstream oss;
worksheet.print(oss, " ", pugi_format_flags);
res.push_back(Rcpp::String(oss.str()));
}
- return Rcpp::wrap(res);
+ return Rcpp::wrap(res);
}
// [[Rcpp::export]]
SEXP getXMLXPtr1(XPtrXML doc, std::string child) {
vec_string res;
- uint32_t pugi_format_flags = pugi_format(doc);
+ uint32_t pugi_format_flags = pugi_format(doc);
- for (auto cld : doc->children(child.c_str()))
- {
+ for (auto cld : doc->children(child.c_str())) {
std::ostringstream oss;
cld.print(oss, " ", pugi_format_flags);
res.push_back(Rcpp::String(oss.str()));
}
- return Rcpp::wrap(res);
+ return Rcpp::wrap(res);
}
-
// [[Rcpp::export]]
SEXP getXMLXPtr2(XPtrXML doc, std::string level1, std::string child) {
vec_string res;
- uint32_t pugi_format_flags = pugi_format(doc);
+ uint32_t pugi_format_flags = pugi_format(doc);
for (auto lvl1 : doc->children(level1.c_str())) {
for (auto cld : lvl1.children(child.c_str())) {
@@ -164,14 +173,14 @@ SEXP getXMLXPtr2(XPtrXML doc, std::string level1, std::string child) {
}
}
- return Rcpp::wrap(res);
+ return Rcpp::wrap(res);
}
// [[Rcpp::export]]
SEXP getXMLXPtr3(XPtrXML doc, std::string level1, std::string level2, std::string child) {
vec_string res;
- uint32_t pugi_format_flags = pugi_format(doc);
+ uint32_t pugi_format_flags = pugi_format(doc);
for (auto lvl1 : doc->children(level1.c_str())) {
for (auto lvl2 : lvl1.children(level2.c_str())) {
@@ -183,7 +192,7 @@ SEXP getXMLXPtr3(XPtrXML doc, std::string level1, std::string level2, std::strin
}
}
- return Rcpp::wrap(res);
+ return Rcpp::wrap(res);
}
// level2 is wildcard. (for border only color nodes are imported.
@@ -192,7 +201,7 @@ SEXP getXMLXPtr3(XPtrXML doc, std::string level1, std::string level2, std::strin
SEXP unkgetXMLXPtr3(XPtrXML doc, std::string level1, std::string child) {
vec_string res;
- uint32_t pugi_format_flags = pugi_format(doc);
+ uint32_t pugi_format_flags = pugi_format(doc);
for (auto lvl1 : doc->children(level1.c_str())) {
for (auto lvl2 : lvl1.children()) {
@@ -204,17 +213,16 @@ SEXP unkgetXMLXPtr3(XPtrXML doc, std::string level1, std::string child) {
}
}
- return Rcpp::wrap(res);
+ return Rcpp::wrap(res);
}
// [[Rcpp::export]]
SEXP getXMLPtr1con(XPtrXML doc) {
vec_string res;
- uint32_t pugi_format_flags = pugi_format(doc);
+ uint32_t pugi_format_flags = pugi_format(doc);
- for (auto node : doc->children())
- {
+ for (auto node : doc->children()) {
for (auto cld : node.children()) {
std::ostringstream oss;
cld.print(oss, " ", pugi_format_flags);
@@ -222,7 +230,7 @@ SEXP getXMLPtr1con(XPtrXML doc) {
}
}
- return Rcpp::wrap(res);
+ return Rcpp::wrap(res);
}
// [[Rcpp::export]]
@@ -231,12 +239,11 @@ SEXP getXMLXPtr1val(XPtrXML doc, std::string child) {
// returns a single vector, not a list of vectors!
std::vector x;
- for (auto worksheet : doc->children(child.c_str()))
- {
+ for (auto worksheet : doc->children(child.c_str())) {
x.push_back(Rcpp::String(worksheet.text().get()));
}
- return Rcpp::wrap(x);
+ return Rcpp::wrap(x);
}
// [[Rcpp::export]]
@@ -252,7 +259,7 @@ SEXP getXMLXPtr2val(XPtrXML doc, std::string level1, std::string child) {
}
}
- return Rcpp::wrap(x);
+ return Rcpp::wrap(x);
}
// [[Rcpp::export]]
@@ -261,37 +268,34 @@ SEXP getXMLXPtr3val(XPtrXML doc, std::string level1, std::string level2, std::st
// returns a single vector, not a list of vectors!
std::vector x;
- for (auto worksheet : doc->child(level1.c_str()).children(level2.c_str()))
- {
+ for (auto worksheet : doc->child(level1.c_str()).children(level2.c_str())) {
for (auto col : worksheet.children(child.c_str()))
x.push_back(Rcpp::String(col.text().get()));
}
- return Rcpp::wrap(x);
+ return Rcpp::wrap(x);
}
-
// [[Rcpp::export]]
SEXP getXMLXPtr1attr(XPtrXML doc, std::string child) {
auto children = doc->children(child.c_str());
- R_xlen_t n = std::distance(children.begin(),
- children.end());
+ R_xlen_t n = std::distance(children.begin(), children.end());
// for a childless single line node the distance might be zero
- if (n == 0) n++;
+ if (n == 0)
+ n++;
Rcpp::List z(n);
auto itr = 0;
for (auto chld : children) {
- Rcpp::CharacterVector res;
+ Rcpp::CharacterVector res;
std::vector nam;
- for (auto attrs : chld.attributes())
- {
+ for (auto attrs : chld.attributes()) {
nam.push_back(Rcpp::String(attrs.name()));
res.push_back(Rcpp::String(attrs.value()));
}
@@ -309,13 +313,12 @@ SEXP getXMLXPtr1attr(XPtrXML doc, std::string child) {
// [[Rcpp::export]]
Rcpp::List getXMLXPtr2attr(XPtrXML doc, std::string level1, std::string child) {
- auto worksheet = doc->child(level1.c_str()).children(child.c_str());
- R_xlen_t n = std::distance(worksheet.begin() , worksheet.end());
+ auto worksheet = doc->child(level1.c_str()).children(child.c_str());
+ R_xlen_t n = std::distance(worksheet.begin(), worksheet.end());
Rcpp::List z(n);
auto itr = 0;
- for (auto ws : worksheet)
- {
+ for (auto ws : worksheet) {
R_xlen_t w_n = std::distance(ws.attributes_begin(), ws.attributes_end());
@@ -323,8 +326,7 @@ Rcpp::List getXMLXPtr2attr(XPtrXML doc, std::string level1, std::string child) {
Rcpp::CharacterVector nam(w_n);
auto attr_itr = 0;
- for (auto attr : ws.attributes())
- {
+ for (auto attr : ws.attributes()) {
nam[attr_itr] = Rcpp::String(attr.name());
res[attr_itr] = Rcpp::String(attr.value());
++attr_itr;
@@ -343,13 +345,12 @@ Rcpp::List getXMLXPtr2attr(XPtrXML doc, std::string level1, std::string child) {
// [[Rcpp::export]]
SEXP getXMLXPtr3attr(XPtrXML doc, std::string level1, std::string level2, std::string child) {
- auto worksheet = doc->child(level1.c_str()).child(level2.c_str()).children(child.c_str());
- R_xlen_t n = std::distance(worksheet.begin(), worksheet.end());
+ auto worksheet = doc->child(level1.c_str()).child(level2.c_str()).children(child.c_str());
+ R_xlen_t n = std::distance(worksheet.begin(), worksheet.end());
Rcpp::List z(n);
auto itr = 0;
- for (auto ws : worksheet)
- {
+ for (auto ws : worksheet) {
R_xlen_t w_n = std::distance(ws.attributes_begin(), ws.attributes_end());
@@ -357,8 +358,7 @@ SEXP getXMLXPtr3attr(XPtrXML doc, std::string level1, std::string level2, std::s
Rcpp::CharacterVector nam(w_n);
auto attr_itr = 0;
- for (auto attr : ws.attributes())
- {
+ for (auto attr : ws.attributes()) {
nam[attr_itr] = Rcpp::String(attr.name());
res[attr_itr] = Rcpp::String(attr.value());
++attr_itr;
@@ -374,7 +374,6 @@ SEXP getXMLXPtr3attr(XPtrXML doc, std::string level1, std::string level2, std::s
return z;
}
-
// [[Rcpp::export]]
SEXP printXPtr(XPtrXML doc, std::string indent, bool raw, bool attr_indent) {
@@ -385,7 +384,8 @@ SEXP printXPtr(XPtrXML doc, std::string indent, bool raw, bool attr_indent) {
pugi_format_flags &= ~pugi::format_raw;
pugi_format_flags |= pugi::format_indent;
}
- if (attr_indent) pugi_format_flags |= pugi::format_indent_attributes;
+ if (attr_indent)
+ pugi_format_flags |= pugi::format_indent_attributes;
std::ostringstream oss;
doc->print(oss, indent.c_str(), pugi_format_flags);
@@ -393,27 +393,29 @@ SEXP printXPtr(XPtrXML doc, std::string indent, bool raw, bool attr_indent) {
return Rcpp::wrap(Rcpp::String(oss.str()));
}
-
// [[Rcpp::export]]
XPtrXML write_xml_file(std::string xml_content, bool escapes) {
xmldoc *doc = new xmldoc;
// pugi::parse_default without escapes flag
- uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
- if (escapes) pugi_parse_flags |= pugi::parse_escapes;
+ uint32_t pugi_parse_flags =
+ pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
+ if (escapes)
+ pugi_parse_flags |= pugi::parse_escapes;
// load and validate node
if (xml_content != "") {
pugi::xml_parse_result result;
result = doc->load_string(xml_content.c_str(), pugi_parse_flags);
- if (!result) Rcpp::stop("Loading xml_content node failed: \n %s", xml_content);
+ if (!result)
+ Rcpp::stop("Loading xml_content node failed: \n %s", xml_content);
}
// Needs to be added after the node has been loaded and validated
- pugi::xml_node decl = doc->prepend_child(pugi::node_declaration);
- decl.append_attribute("version") = "1.0";
- decl.append_attribute("encoding") = "UTF-8";
+ pugi::xml_node decl = doc->prepend_child(pugi::node_declaration);
+ decl.append_attribute("version") = "1.0";
+ decl.append_attribute("encoding") = "UTF-8";
decl.append_attribute("standalone") = "yes";
XPtrXML ptr(doc, true);
@@ -440,49 +442,57 @@ XPtrXML write_xml_file(std::string xml_content, bool escapes) {
//'
//' @examples
//' # add single node
-//' xml_node <- "openxlsx2"
-//' xml_attr <- c(qux = "quux")
-//' # "openxlsx2"
-//' xml_attr_mod(xml_node, xml_attr)
+//' xml_node <- "openxlsx2"
+//' xml_attr <- c(qux = "quux")
+//' # "openxlsx2"
+//' xml_attr_mod(xml_node, xml_attr)
//'
//' # update node and add node
-//' xml_node <- "openxlsx2"
-//' xml_attr <- c(foo = "baz", qux = "quux")
-//' # "openxlsx2"
-//' xml_attr_mod(xml_node, xml_attr)
+//' xml_node <- "openxlsx2"
+//' xml_attr <- c(foo = "baz", qux = "quux")
+//' # "openxlsx2"
+//' xml_attr_mod(xml_node, xml_attr)
//'
//' # remove node and add node
-//' xml_node <- "openxlsx2"
-//' xml_attr <- c(foo = "", qux = "quux")
-//' # "openxlsx2"
-//' xml_attr_mod(xml_node, xml_attr)
+//' xml_node <- "openxlsx2"
+//' xml_attr <- c(foo = "", qux = "quux")
+//' # "openxlsx2"
+//' xml_attr_mod(xml_node, xml_attr)
//' @export
// [[Rcpp::export]]
-Rcpp::CharacterVector xml_attr_mod(std::string xml_content, Rcpp::CharacterVector xml_attributes,
- bool escapes = false, bool declaration = false,
- bool remove_empty_attr = true) {
-
- pugi::xml_document doc;
+Rcpp::CharacterVector xml_attr_mod(
+ std::string xml_content,
+ Rcpp::CharacterVector xml_attributes,
+ bool escapes = false,
+ bool declaration = false,
+ bool remove_empty_attr = true) {
+
+ pugi::xml_document doc;
pugi::xml_parse_result result;
- uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
- if (escapes) pugi_parse_flags |= pugi::parse_escapes;
- if (declaration) pugi_parse_flags |= pugi::parse_declaration;
+ uint32_t pugi_parse_flags =
+ pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
+ if (escapes)
+ pugi_parse_flags |= pugi::parse_escapes;
+ if (declaration)
+ pugi_parse_flags |= pugi::parse_declaration;
uint32_t pugi_format_flags = pugi::format_raw;
- if (!escapes) pugi_format_flags |= pugi::format_no_escapes;
+ if (!escapes)
+ pugi_format_flags |= pugi::format_no_escapes;
// load and validate node
if (xml_content != "") {
result = doc.load_string(xml_content.c_str(), pugi_parse_flags);
- if (!result) Rcpp::stop("Loading xml_content node failed: \n %s ", xml_content);
+ if (!result)
+ Rcpp::stop("Loading xml_content node failed: \n %s ", xml_content);
}
std::vector new_attr_nam = xml_attributes.names();
std::vector new_attr_val = Rcpp::as>(xml_attributes);
for (auto cld : doc.children()) {
- for (size_t i = 0; i < static_cast(xml_attributes.length()); ++i){
+ for (size_t i = 0; i < static_cast(xml_attributes.length()); ++i) {
// check if attribute_val is empty. if yes, remove the attribute.
// otherwise add or update the attribute
@@ -534,19 +544,24 @@ Rcpp::CharacterVector xml_attr_mod(std::string xml_content, Rcpp::CharacterVecto
//' @export
// [[Rcpp::export]]
Rcpp::CharacterVector xml_node_create(
- std::string xml_name,
- Rcpp::Nullable xml_children = R_NilValue,
- Rcpp::Nullable xml_attributes = R_NilValue,
- bool escapes = false, bool declaration = false) {
+ std::string xml_name,
+ Rcpp::Nullable xml_children = R_NilValue,
+ Rcpp::Nullable xml_attributes = R_NilValue,
+ bool escapes = false,
+ bool declaration = false) {
pugi::xml_document doc;
- uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
- if (escapes) pugi_parse_flags |= pugi::parse_escapes;
- if (declaration) pugi_parse_flags |= pugi::parse_declaration;
+ uint32_t pugi_parse_flags =
+ pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
+ if (escapes)
+ pugi_parse_flags |= pugi::parse_escapes;
+ if (declaration)
+ pugi_parse_flags |= pugi::parse_declaration;
uint32_t pugi_format_flags = pugi::format_raw;
- if (!escapes) pugi_format_flags |= pugi::format_no_escapes;
+ if (!escapes)
+ pugi_format_flags |= pugi::format_no_escapes;
pugi::xml_node cld = doc.append_child(xml_name.c_str());
@@ -559,7 +574,7 @@ Rcpp::CharacterVector xml_node_create(
std::string xml_cld = std::string(xml_child[i]);
- pugi::xml_document is_node;
+ pugi::xml_document is_node;
pugi::xml_parse_result result = is_node.load_string(xml_cld.c_str(), pugi_parse_flags);
// check if result is a valid xml_node, else append as is
@@ -580,7 +595,7 @@ Rcpp::CharacterVector xml_node_create(
std::vector new_attr_nam = xml_attr.names();
std::vector new_attr_val = Rcpp::as>(xml_attr);
- for (size_t i = 0; i < static_cast(xml_attr.length()); ++i){
+ for (size_t i = 0; i < static_cast(xml_attr.length()); ++i) {
if (!new_attr_val[i].empty())
cld.append_attribute(new_attr_nam[i].c_str()) = new_attr_val[i].c_str();
}
@@ -602,7 +617,7 @@ SEXP xml_append_child1(XPtrXML node, XPtrXML child, bool pointer) {
uint32_t pugi_format_flags = pugi_format(node);
- for (auto cld: child->children()) {
+ for (auto cld : child->children()) {
node->first_child().append_copy(cld);
}
@@ -626,7 +641,7 @@ SEXP xml_append_child2(XPtrXML node, XPtrXML child, std::string level1, bool poi
uint32_t pugi_format_flags = pugi_format(node);
- for (auto cld: child->children()) {
+ for (auto cld : child->children()) {
node->first_child().child(level1.c_str()).append_copy(cld);
}
@@ -647,11 +662,12 @@ SEXP xml_append_child2(XPtrXML node, XPtrXML child, std::string level1, bool poi
// @param pointer bool if pointer should be returned
// @export
// [[Rcpp::export]]
-SEXP xml_append_child3(XPtrXML node, XPtrXML child, std::string level1, std::string level2, bool pointer) {
+SEXP xml_append_child3(
+ XPtrXML node, XPtrXML child, std::string level1, std::string level2, bool pointer) {
uint32_t pugi_format_flags = pugi_format(node);
- for (auto cld: child->children()) {
+ for (auto cld : child->children()) {
node->first_child().child(level1.c_str()).child(level2.c_str()).append_copy(cld);
}
@@ -676,10 +692,11 @@ SEXP xml_remove_child1(XPtrXML node, std::string child, int32_t which, bool poin
uint32_t pugi_format_flags = pugi_format(node);
auto ctr = 0;
- for (pugi::xml_node cld = node->first_child().child(child.c_str()); cld; ) {
+ for (pugi::xml_node cld = node->first_child().child(child.c_str()); cld;) {
auto next = cld.next_sibling();
- if (ctr == which || which < 0) cld.parent().remove_child(cld);
- cld = next;
+ if (ctr == which || which < 0)
+ cld.parent().remove_child(cld);
+ cld = next;
++ctr;
}
@@ -700,14 +717,16 @@ SEXP xml_remove_child1(XPtrXML node, std::string child, int32_t which, bool poin
// @param escapes bool if escapes should be used
// @export
// [[Rcpp::export]]
-SEXP xml_remove_child2(XPtrXML node, std::string child, std::string level1, int32_t which, bool pointer) {
+SEXP xml_remove_child2(
+ XPtrXML node, std::string child, std::string level1, int32_t which, bool pointer) {
uint32_t pugi_format_flags = pugi_format(node);
auto ctr = 0;
- for (pugi::xml_node cld = node->first_child().child(level1.c_str()).child(child.c_str()); cld; ) {
+ for (pugi::xml_node cld = node->first_child().child(level1.c_str()).child(child.c_str()); cld;) {
auto next = cld.next_sibling();
- if (ctr == which || which < 0) cld.parent().remove_child(cld);
+ if (ctr == which || which < 0)
+ cld.parent().remove_child(cld);
cld = next;
++ctr;
}
@@ -730,14 +749,23 @@ SEXP xml_remove_child2(XPtrXML node, std::string child, std::string level1, int3
// @param escapes bool if escapes should be used
// @export
// [[Rcpp::export]]
-SEXP xml_remove_child3(XPtrXML node, std::string child, std::string level1, std::string level2, int32_t which, bool pointer) {
+SEXP xml_remove_child3(
+ XPtrXML node,
+ std::string child,
+ std::string level1,
+ std::string level2,
+ int32_t which,
+ bool pointer) {
uint32_t pugi_format_flags = pugi_format(node);
auto ctr = 0;
- for (pugi::xml_node cld = node->first_child().child(level1.c_str()).child(level2.c_str()).child(child.c_str()); cld; ) {
+ for (pugi::xml_node cld =
+ node->first_child().child(level1.c_str()).child(level2.c_str()).child(child.c_str());
+ cld;) {
auto next = cld.next_sibling();
- if (ctr == which || which < 0) cld.parent().remove_child(cld);
+ if (ctr == which || which < 0)
+ cld.parent().remove_child(cld);
cld = next;
++ctr;
}
diff --git a/src/strings_xml.cpp b/src/strings_xml.cpp
index 893ed5a0e..cd14f5dd2 100644
--- a/src/strings_xml.cpp
+++ b/src/strings_xml.cpp
@@ -6,13 +6,12 @@
SEXP xml_si_to_txt(XPtrXML doc) {
auto sst = doc->child("sst");
- auto n = std::distance(sst.begin(), sst.end());
+ auto n = std::distance(sst.begin(), sst.end());
Rcpp::CharacterVector res(Rcpp::no_init(n));
auto i = 0;
- for (auto si : doc->child("sst").children("si"))
- {
+ for (auto si : doc->child("sst").children("si")) {
// text to export
std::string text = "";
@@ -24,7 +23,7 @@ SEXP xml_si_to_txt(XPtrXML doc) {
// has r node with t node
// linebreaks and spaces are handled in the nodes
for (auto r : si.children("r")) {
- for (auto t :r.children("t")) {
+ for (auto t : r.children("t")) {
text += t.text().get();
}
}
@@ -39,7 +38,7 @@ SEXP xml_si_to_txt(XPtrXML doc) {
SEXP xml_to_txt(Rcpp::CharacterVector vec, std::string type) {
- auto n = vec.length();
+ auto n = vec.length();
Rcpp::CharacterVector res(Rcpp::no_init(n));
for (auto i = 0; i < n; ++i) {
@@ -51,15 +50,15 @@ SEXP xml_to_txt(Rcpp::CharacterVector vec, std::string type) {
continue;
}
- pugi::xml_document doc;
- pugi::xml_parse_result result = doc.load_string(tmp.c_str(), pugi::parse_default | pugi::parse_ws_pcdata | pugi::parse_escapes);
+ pugi::xml_document doc;
+ pugi::xml_parse_result result = doc.load_string(
+ tmp.c_str(), pugi::parse_default | pugi::parse_ws_pcdata | pugi::parse_escapes);
if (!result) {
Rcpp::stop(type.c_str(), " xml import unsuccessful");
}
- for (auto is : doc.children(type.c_str()))
- {
+ for (auto is : doc.children(type.c_str())) {
// text to export
std::string text = "";
@@ -76,7 +75,7 @@ SEXP xml_to_txt(Rcpp::CharacterVector vec, std::string type) {
// t (Text)
// linebreaks and spaces are handled in the nodes
for (auto r : is.children("r")) {
- for (auto t :r.children("t")) {
+ for (auto t : r.children("t")) {
text += t.text().get();
}
}
@@ -84,7 +83,6 @@ SEXP xml_to_txt(Rcpp::CharacterVector vec, std::string type) {
// push everything back
res[i] = Rcpp::String(text);
}
-
}
return res;
@@ -100,38 +98,37 @@ SEXP si_to_txt(Rcpp::CharacterVector si_vec) {
return xml_to_txt(si_vec, "si");
}
-std::string txt_to_xml(
- std::string text,
- bool no_escapes,
- bool raw,
- bool skip_control,
- std::string type
-) {
+std::string
+txt_to_xml(std::string text, bool no_escapes, bool raw, bool skip_control, std::string type) {
pugi::xml_document doc;
uint32_t pugi_format_flags = pugi::format_indent;
- if (no_escapes) pugi_format_flags |= pugi::format_no_escapes;
- if (raw) pugi_format_flags |= pugi::format_raw;
- if (skip_control) pugi_format_flags |= pugi::format_skip_control_chars;
+ if (no_escapes)
+ pugi_format_flags |= pugi::format_no_escapes;
+ if (raw)
+ pugi_format_flags |= pugi::format_raw;
+ if (skip_control)
+ pugi_format_flags |= pugi::format_skip_control_chars;
pugi::xml_node is_node = doc.append_child(type.c_str());
// txt input beginning with "", 0) == 0 || text.rfind("", 0) == 0) {
- pugi::xml_document txt_node;
- pugi::xml_parse_result result = txt_node.load_string(text.c_str(), pugi::parse_default | pugi::parse_ws_pcdata | pugi::parse_escapes);
- if (!result) Rcpp::stop("Could not parse xml in txt_to_xml()");
+ pugi::xml_document txt_node;
+ pugi::xml_parse_result result = txt_node.load_string(
+ text.c_str(), pugi::parse_default | pugi::parse_ws_pcdata | pugi::parse_escapes);
+ if (!result)
+ Rcpp::stop("Could not parse xml in txt_to_xml()");
for (auto is_n : txt_node.children())
- is_node.append_copy(is_n);
-
+ is_node.append_copy(is_n);
} else {
// text to export
pugi::xml_node t_node = is_node.append_child("t");
- if ((text.size() > 0) && (std::isspace(text.at(0)) || std::isspace(text.at(text.size()-1)))) {
+ if ((text.size() > 0) && (std::isspace(text.at(0)) || std::isspace(text.at(text.size() - 1)))) {
t_node.append_attribute("xml:space").set_value("preserve");
}
@@ -146,13 +143,13 @@ std::string txt_to_xml(
}
// [[Rcpp::export]]
-std::string txt_to_is(std::string text,
- bool no_escapes = false, bool raw = true, bool skip_control = true) {
+std::string
+txt_to_is(std::string text, bool no_escapes = false, bool raw = true, bool skip_control = true) {
return txt_to_xml(text, no_escapes, raw, skip_control, "is");
}
// [[Rcpp::export]]
-std::string txt_to_si(std::string text,
- bool no_escapes = false, bool raw = true, bool skip_control = true) {
+std::string
+txt_to_si(std::string text, bool no_escapes = false, bool raw = true, bool skip_control = true) {
return txt_to_xml(text, no_escapes, raw, skip_control, "si");
}
diff --git a/src/styles_xml.cpp b/src/styles_xml.cpp
index c87eceee1..b8b48e945 100644
--- a/src/styles_xml.cpp
+++ b/src/styles_xml.cpp
@@ -8,22 +8,22 @@ bool has_it(Rcpp::DataFrame df_xf, std::set xf_nams, R_xlen_t row)
// names as vector and set. because set is ordered, we have to change the
// order of the data frame columns as well.
std::vector df_nms = df_xf.names();
- std::set df_names(df_nms.begin(), df_nms.end());
+ std::set df_names(df_nms.begin(), df_nms.end());
std::vector xf_names(xf_nams.begin(), xf_nams.end());
Rcpp::CharacterVector sel_chr;
- Rcpp::IntegerVector sel_int;
- Rcpp::DataFrame df_tmp;
+ Rcpp::IntegerVector sel_int;
+ Rcpp::DataFrame df_tmp;
sel_chr = Rcpp::wrap(df_names);
- df_tmp = df_xf[sel_chr];
+ df_tmp = df_xf[sel_chr];
// get the position of the xf_nams in the sorted df_xf data frame
std::vector idx;
for (size_t i = 0; i < xf_names.size(); ++i) {
std::string xf_name = xf_names[i];
if (df_names.count(xf_name) > 0) {
- auto res = df_names.find(xf_name);
+ auto res = df_names.find(xf_name);
R_xlen_t mtc = std::distance(df_names.begin(), res);
idx.push_back(mtc);
}
@@ -31,7 +31,7 @@ bool has_it(Rcpp::DataFrame df_xf, std::set xf_nams, R_xlen_t row)
// get a subset of the original data frame
sel_int = Rcpp::wrap(idx);
- df_tmp = df_tmp[sel_int];
+ df_tmp = df_tmp[sel_int];
// check every column of the selected row
for (auto ii = 0; ii < df_tmp.ncol(); ++ii) {
@@ -55,7 +55,7 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) {
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.cellformat?view=openxml-2.8.1
// openxml 2.8.1
- std::set nams {
+ std::set nams{
"numFmtId",
"fontId",
"fillId",
@@ -83,8 +83,7 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) {
"extLst",
// child protection
"hidden",
- "locked"
- };
+ "locked"};
R_xlen_t nn = std::distance(xml_doc_xf->begin(), xml_doc_xf->end());
R_xlen_t kk = static_cast(nams.size());
@@ -93,8 +92,7 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) {
// 1. create the list
Rcpp::List df(kk);
- for (R_xlen_t i = 0; i < kk; ++i)
- {
+ for (R_xlen_t i = 0; i < kk; ++i) {
SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn)));
}
@@ -104,15 +102,15 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) {
for (auto xml_xf : xml_doc_xf->children("xf")) {
for (auto attrs : xml_xf.attributes()) {
- std::string attr_name = attrs.name();
+ std::string attr_name = attrs.name();
std::string attr_value = attrs.value();
- auto find_res = nams.find(attr_name);
+ auto find_res = nams.find(attr_name);
// check if name is already known
if (nams.count(attr_name) == 0) {
Rcpp::warning("%s: not found in xf name table", attr_name);
} else {
- R_xlen_t mtc = std::distance(nams.begin(), find_res);
+ R_xlen_t mtc = std::distance(nams.begin(), find_res);
Rcpp::as(df[mtc])[itr] = attr_value;
}
}
@@ -126,25 +124,25 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) {
std::string cld_name = cld.name();
// check known names
- if (cld_name == "alignment" || cld_name == "extLst" || cld_name == "protection") {
+ if (cld_name == "alignment" || cld_name == "extLst" || cld_name == "protection") {
if (cld_name == "extLst") {
- R_xlen_t mtc = std::distance(nams.begin(), nams.find(cld_name));
- uint32_t pugi_format_flags = pugi::format_raw;
+ R_xlen_t mtc = std::distance(nams.begin(), nams.find(cld_name));
+ uint32_t pugi_format_flags = pugi::format_raw;
std::ostringstream oss;
cld.print(oss, " ", pugi_format_flags);
Rcpp::as(df[mtc])[itr] = Rcpp::String(oss.str());
} else {
for (auto attrs : cld.attributes()) {
- std::string attr_name = attrs.name();
+ std::string attr_name = attrs.name();
std::string attr_value = attrs.value();
- auto find_res = nams.find(attr_name);
+ auto find_res = nams.find(attr_name);
// check if name is already known
if (nams.count(attr_name) == 0) {
Rcpp::warning("%s: not found in xf name table", attr_name);
} else {
- R_xlen_t mtc = std::distance(nams.begin(), find_res);
+ R_xlen_t mtc = std::distance(nams.begin(), find_res);
Rcpp::as(df[mtc])[itr] = attr_value;
}
}
@@ -163,18 +161,17 @@ Rcpp::DataFrame read_xf(XPtrXML xml_doc_xf) {
// 3. Create a data.frame
df.attr("row.names") = rvec;
- df.attr("names") = nams;
- df.attr("class") = "data.frame";
+ df.attr("names") = nams;
+ df.attr("class") = "data.frame";
return df;
}
-
// [[Rcpp::export]]
Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) {
- R_xlen_t n = static_cast(df_xf.nrow());
- R_xlen_t k = static_cast(df_xf.ncol());
+ R_xlen_t n = static_cast(df_xf.nrow());
+ R_xlen_t k = static_cast(df_xf.ncol());
Rcpp::CharacterVector z(n);
uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes;
@@ -194,8 +191,7 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) {
"applyNumberFormat",
"applyProtection",
"pivotButton",
- "quotePrefix"
- };
+ "quotePrefix"};
std::set xf_nams_alignment = {
"horizontal",
@@ -206,17 +202,11 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) {
"shrinkToFit",
"textRotation",
"vertical",
- "wrapText"
- };
+ "wrapText"};
- std::set xf_nams_extLst = {
- "extLst"
- };
+ std::set xf_nams_extLst = {"extLst"};
- std::set xf_nams_protection = {
- "hidden",
- "locked"
- };
+ std::set xf_nams_protection = {"hidden", "locked"};
for (R_xlen_t i = 0; i < n; ++i) {
pugi::xml_document doc;
@@ -225,7 +215,7 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) {
// check if alignment node is required
bool has_alignment = false;
- has_alignment = has_it(df_xf, xf_nams_alignment, i);
+ has_alignment = has_it(df_xf, xf_nams_alignment, i);
pugi::xml_node xf_alignment;
if (has_alignment) {
@@ -234,13 +224,13 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) {
// check if extLst node is required
bool has_extLst = false;
- has_extLst = has_it(df_xf, xf_nams_extLst, i);
+ has_extLst = has_it(df_xf, xf_nams_extLst, i);
pugi::xml_node xf_extLst;
// check if protection node is required
bool has_protection = false;
- has_protection = has_it(df_xf, xf_nams_protection, i);
+ has_protection = has_it(df_xf, xf_nams_protection, i);
pugi::xml_node xf_protection;
if (has_protection) {
@@ -252,41 +242,41 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) {
std::string attrnam = attrnams[static_cast(j)];
// not all missing in match: ergo they are
- bool is_xf = xf_nams.count(attrnam) > 0;
- bool is_alignment = xf_nams_alignment.count(attrnam) > 0;
- bool is_extLst = xf_nams_extLst.count(attrnam) > 0;
+ bool is_xf = xf_nams.count(attrnam) > 0;
+ bool is_alignment = xf_nams_alignment.count(attrnam) > 0;
+ bool is_extLst = xf_nams_extLst.count(attrnam) > 0;
bool is_protection = xf_nams_protection.count(attrnam) > 0;
//
if (is_xf) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df_xf[j])[i];
+ cv_s = Rcpp::as(df_xf[j])[i];
// only write attributes where cv_s has a value
if (cv_s[0] != "") {
// Rf_PrintValue(cv_s);
- const std::string val_strl = Rcpp::as(cv_s);
+ const std::string val_strl = Rcpp::as(cv_s);
xf.append_attribute(attrnam.c_str()) = val_strl.c_str();
}
}
if (has_alignment && is_alignment) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df_xf[j])[i];
+ cv_s = Rcpp::as(df_xf[j])[i];
if (cv_s[0] != "") {
- const std::string val_strl = Rcpp::as(cv_s);
+ const std::string val_strl = Rcpp::as(cv_s);
xf_alignment.append_attribute(attrnam.c_str()) = val_strl.c_str();
}
}
if (has_extLst && is_extLst) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df_xf[j])[i];
+ cv_s = Rcpp::as(df_xf[j])[i];
if (cv_s[0] != "") {
- const std::string val_strl = Rcpp::as(cv_s);
- pugi::xml_document tempDoc;
+ const std::string val_strl = Rcpp::as(cv_s);
+ pugi::xml_document tempDoc;
pugi::xml_parse_result tempResult = tempDoc.load_string(val_strl.c_str());
if (tempResult) {
xf.append_copy(tempDoc.first_child());
@@ -298,14 +288,13 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) {
if (has_protection && is_protection) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df_xf[j])[i];
+ cv_s = Rcpp::as(df_xf[j])[i];
if (cv_s[0] != "") {
- const std::string val_strl = Rcpp::as(cv_s);
+ const std::string val_strl = Rcpp::as(cv_s);
xf_protection.append_attribute(attrnam.c_str()) = val_strl.c_str();
}
}
-
}
std::ostringstream oss;
@@ -317,14 +306,13 @@ Rcpp::CharacterVector write_xf(Rcpp::DataFrame df_xf) {
return z;
}
-
// [[Rcpp::export]]
Rcpp::DataFrame read_font(XPtrXML xml_doc_font) {
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.font?view=openxml-2.8.1
// openxml 2.8.1
- std::set nams {
+ std::set nams{
"b",
"charset",
"color",
@@ -340,19 +328,17 @@ Rcpp::DataFrame read_font(XPtrXML xml_doc_font) {
"strike",
"sz",
"u",
- "vertAlign"
- };
+ "vertAlign"};
- R_xlen_t nn = std::distance(xml_doc_font->begin(), xml_doc_font->end());
- R_xlen_t kk = static_cast(nams.size());
+ R_xlen_t nn = std::distance(xml_doc_font->begin(), xml_doc_font->end());
+ R_xlen_t kk = static_cast(nams.size());
uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes;
Rcpp::CharacterVector rvec(nn);
// 1. create the list
Rcpp::List df(kk);
- for (R_xlen_t i = 0; i < kk; ++i)
- {
+ for (R_xlen_t i = 0; i < kk; ++i) {
SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn)));
}
@@ -363,9 +349,9 @@ Rcpp::DataFrame read_font(XPtrXML xml_doc_font) {
for (auto cld : xml_font.children()) {
- std::string name = cld.name();
- std::string value = cld.value();
- auto find_res = nams.find(name);
+ std::string name = cld.name();
+ std::string value = cld.value();
+ auto find_res = nams.find(name);
// check if name is already known
if (nams.count(name) == 0) {
@@ -375,7 +361,7 @@ Rcpp::DataFrame read_font(XPtrXML xml_doc_font) {
std::ostringstream oss;
cld.print(oss, " ", pugi_format_flags);
- R_xlen_t mtc = std::distance(nams.begin(), find_res);
+ R_xlen_t mtc = std::distance(nams.begin(), find_res);
Rcpp::as(df[mtc])[itr] = oss.str();
}
@@ -389,19 +375,19 @@ Rcpp::DataFrame read_font(XPtrXML xml_doc_font) {
// 3. Create a data.frame
df.attr("row.names") = rvec;
- df.attr("names") = nams;
- df.attr("class") = "data.frame";
+ df.attr("names") = nams;
+ df.attr("class") = "data.frame";
return df;
}
-
// [[Rcpp::export]]
Rcpp::CharacterVector write_font(Rcpp::DataFrame df_font) {
- auto n = df_font.nrow();
+ auto n = df_font.nrow();
Rcpp::CharacterVector z(n);
- uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
+ uint32_t pugi_parse_flags =
+ pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes;
for (auto i = 0; i < n; ++i) {
@@ -409,24 +395,22 @@ Rcpp::CharacterVector write_font(Rcpp::DataFrame df_font) {
pugi::xml_node font = doc.append_child("font");
-
for (auto j = 0; j < df_font.ncol(); ++j) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df_font[j])[i];
+ cv_s = Rcpp::as(df_font[j])[i];
if (cv_s[0] != "") {
std::string font_i = Rcpp::as(cv_s[0]);
- pugi::xml_document font_node;
+ pugi::xml_document font_node;
pugi::xml_parse_result result = font_node.load_string(font_i.c_str(), pugi_parse_flags);
- if (!result) Rcpp::stop("loading font node fail: %s", cv_s);
+ if (!result)
+ Rcpp::stop("loading font node fail: %s", cv_s);
font.append_copy(font_node.first_child());
-
}
-
}
std::ostringstream oss;
@@ -438,17 +422,13 @@ Rcpp::CharacterVector write_font(Rcpp::DataFrame df_font) {
return z;
}
-
// [[Rcpp::export]]
Rcpp::DataFrame read_numfmt(XPtrXML xml_doc_numfmt) {
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.numberingformat?view=openxml-2.8.1
// openxml 2.8.1
- std::set nams {
- "formatCode",
- "numFmtId"
- };
+ std::set nams{"formatCode", "numFmtId"};
R_xlen_t nn = std::distance(xml_doc_numfmt->begin(), xml_doc_numfmt->end());
R_xlen_t kk = static_cast(nams.size());
@@ -457,8 +437,7 @@ Rcpp::DataFrame read_numfmt(XPtrXML xml_doc_numfmt) {
// 1. create the list
Rcpp::List df(kk);
- for (R_xlen_t i = 0; i < kk; ++i)
- {
+ for (R_xlen_t i = 0; i < kk; ++i) {
SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn)));
}
@@ -468,15 +447,15 @@ Rcpp::DataFrame read_numfmt(XPtrXML xml_doc_numfmt) {
for (auto xml_numfmt : xml_doc_numfmt->children("numFmt")) {
for (auto attrs : xml_numfmt.attributes()) {
- std::string attr_name = attrs.name();
+ std::string attr_name = attrs.name();
std::string attr_value = attrs.value();
- auto find_res = nams.find(attr_name);
+ auto find_res = nams.find(attr_name);
// check if name is already known
if (nams.count(attr_name) == 0) {
Rcpp::warning("%s: not found in numfmt name table", attr_name);
} else {
- R_xlen_t mtc = std::distance(nams.begin(), find_res);
+ R_xlen_t mtc = std::distance(nams.begin(), find_res);
Rcpp::as(df[mtc])[itr] = attr_value;
}
}
@@ -489,34 +468,33 @@ Rcpp::DataFrame read_numfmt(XPtrXML xml_doc_numfmt) {
// 3. Create a data.frame
df.attr("row.names") = rvec;
- df.attr("names") = nams;
- df.attr("class") = "data.frame";
+ df.attr("names") = nams;
+ df.attr("class") = "data.frame";
return df;
}
-
// [[Rcpp::export]]
Rcpp::CharacterVector write_numfmt(Rcpp::DataFrame df_numfmt) {
- auto n = df_numfmt.nrow();
+ auto n = df_numfmt.nrow();
Rcpp::CharacterVector z(n);
- uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes;
+ uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes;
for (auto i = 0; i < n; ++i) {
- pugi::xml_document doc;
+ pugi::xml_document doc;
Rcpp::CharacterVector attrnams = df_numfmt.names();
pugi::xml_node numFmt = doc.append_child("numFmt");
for (auto j = 0; j < df_numfmt.ncol(); ++j) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df_numfmt[j])[i];
+ cv_s = Rcpp::as(df_numfmt[j])[i];
// only write attributes where cv_s has a value
if (cv_s[0] != "") {
// Rf_PrintValue(cv_s);
- const std::string val_strl = Rcpp::as(cv_s);
+ const std::string val_strl = Rcpp::as(cv_s);
numFmt.append_attribute(attrnams[j]) = val_strl.c_str();
}
}
@@ -536,32 +514,32 @@ Rcpp::DataFrame read_border(XPtrXML xml_doc_border) {
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.border?view=openxml-2.8.1
// openxml 2.8.1
- std::set nam_attrs {"diagonalDown", "diagonalUp", "outline"};
+ std::set nam_attrs{"diagonalDown", "diagonalUp", "outline"};
- std::set nam_chlds {"start", "end",
- "left", "right", "top", "bottom", "diagonal",
- "vertical", "horizontal"};
+ std::set nam_chlds{
+ "start", "end", "left", "right", "top", "bottom", "diagonal", "vertical", "horizontal"};
- auto total_length = nam_attrs.size() + nam_chlds.size();
+ auto total_length = nam_attrs.size() + nam_chlds.size();
std::vector all_names(total_length);
std::copy(nam_attrs.begin(), nam_attrs.end(), all_names.begin());
- std::copy(nam_chlds.begin(), nam_chlds.end(), all_names.begin() + static_cast(nam_attrs.size()));
-
- std::set nams(std::make_move_iterator(all_names.begin()),
- std::make_move_iterator(all_names.end()));
+ std::copy(
+ nam_chlds.begin(),
+ nam_chlds.end(),
+ all_names.begin() + static_cast(nam_attrs.size()));
+ std::set nams(
+ std::make_move_iterator(all_names.begin()), std::make_move_iterator(all_names.end()));
- R_xlen_t nn = std::distance(xml_doc_border->begin(), xml_doc_border->end());
- R_xlen_t kk = static_cast(nams.size());
+ R_xlen_t nn = std::distance(xml_doc_border->begin(), xml_doc_border->end());
+ R_xlen_t kk = static_cast(nams.size());
uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes;
Rcpp::CharacterVector rvec(nn);
// 1. create the list
Rcpp::List df(kk);
- for (R_xlen_t i = 0; i < kk; ++i)
- {
+ for (R_xlen_t i = 0; i < kk; ++i) {
SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(Rcpp::no_init(nn)));
}
@@ -571,15 +549,15 @@ Rcpp::DataFrame read_border(XPtrXML xml_doc_border) {
for (auto xml_border : xml_doc_border->children("border")) {
for (auto attrs : xml_border.attributes()) {
- std::string attr_name = attrs.name();
+ std::string attr_name = attrs.name();
std::string attr_value = attrs.value();
- auto find_res = nams.find(attr_name);
+ auto find_res = nams.find(attr_name);
// check if name is already known
if (nams.count(attr_name) == 0) {
Rcpp::warning("%s: not found in border name table", attr_name);
} else {
- R_xlen_t mtc = std::distance(nams.begin(), find_res);
+ R_xlen_t mtc = std::distance(nams.begin(), find_res);
Rcpp::as(df[mtc])[itr] = attr_value;
}
}
@@ -587,7 +565,7 @@ Rcpp::DataFrame read_border(XPtrXML xml_doc_border) {
for (auto cld : xml_border.children()) {
std::string cld_name = cld.name();
- auto find_res = nams.find(cld_name);
+ auto find_res = nams.find(cld_name);
// check if name is already known
if (nams.count(cld_name) == 0) {
@@ -597,7 +575,7 @@ Rcpp::DataFrame read_border(XPtrXML xml_doc_border) {
cld.print(oss, " ", pugi_format_flags);
std::string cld_value = oss.str();
- R_xlen_t mtc = std::distance(nams.begin(), find_res);
+ R_xlen_t mtc = std::distance(nams.begin(), find_res);
Rcpp::as(df[mtc])[itr] = cld_value;
}
}
@@ -605,51 +583,48 @@ Rcpp::DataFrame read_border(XPtrXML xml_doc_border) {
// rownames as character vectors matching to
rvec[itr] = std::to_string(itr);
++itr;
-
}
// 3. Create a data.frame
df.attr("row.names") = rvec;
- df.attr("names") = nams;
- df.attr("class") = "data.frame";
+ df.attr("names") = nams;
+ df.attr("class") = "data.frame";
return df;
}
-
// [[Rcpp::export]]
Rcpp::CharacterVector write_border(Rcpp::DataFrame df_border) {
- R_xlen_t n = static_cast(df_border.nrow());
- R_xlen_t k = static_cast(df_border.ncol());
+ R_xlen_t n = static_cast(df_border.nrow());
+ R_xlen_t k = static_cast(df_border.ncol());
Rcpp::CharacterVector z(n);
- uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
+ uint32_t pugi_parse_flags =
+ pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes;
-
// openxml 2.8.1
- std::vector attrnams = df_border.names();
- std::set nam_attrs = {"diagonalDown", "diagonalUp", "outline"};
- std::set nam_chlds = {"bottom", "diagonal", "end", "horizontal",
- "left", "right", "start", "top",
- "vertical"};
+ std::vector attrnams = df_border.names();
+ std::set nam_attrs = {"diagonalDown", "diagonalUp", "outline"};
+ std::set nam_chlds = {
+ "bottom", "diagonal", "end", "horizontal", "left", "right", "start", "top", "vertical"};
for (R_xlen_t i = 0; i < n; ++i) {
pugi::xml_document doc;
- pugi::xml_node border = doc.append_child("border");
+ pugi::xml_node border = doc.append_child("border");
for (R_xlen_t j = 0; j < k; ++j) {
std::string attr_j = attrnams[static_cast(j)];
// mimic which
- auto res1 = nam_attrs.find(attr_j);
+ auto res1 = nam_attrs.find(attr_j);
R_xlen_t mtc1 = std::distance(nam_attrs.begin(), res1);
std::vector idx1(static_cast(mtc1) + 1);
std::iota(idx1.begin(), idx1.end(), 0);
- auto res2 = nam_chlds.find(attr_j);
+ auto res2 = nam_chlds.find(attr_j);
R_xlen_t mtc2 = std::distance(nam_chlds.begin(), res2);
std::vector idx2(static_cast(mtc2) + 1);
@@ -658,30 +633,30 @@ Rcpp::CharacterVector write_border(Rcpp::DataFrame df_border) {
// check if name is already known
if (nam_attrs.count(attr_j) != 0) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df_border[j])[i];
+ cv_s = Rcpp::as(df_border[j])[i];
// only write attributes where cv_s has a value
if (cv_s[0] != "") {
// Rf_PrintValue(cv_s);
- const std::string val_strl = Rcpp::as(cv_s);
+ const std::string val_strl = Rcpp::as(cv_s);
border.append_attribute(attr_j.c_str()) = val_strl.c_str();
}
}
if (nam_chlds.count(attr_j) != 0) {
Rcpp::CharacterVector cv_s = "";
- cv_s = Rcpp::as(df_border[j])[i];
+ cv_s = Rcpp::as(df_border[j])[i];
if (cv_s[0] != "") {
std::string font_i = Rcpp::as