Skip to content

Commit

Permalink
replace std::regex which might cause issues on certain operating systems
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Sep 10, 2024
1 parent dd19b3c commit bab35f1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/write_file.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

#include "openxlsx.h"
#include <regex>


//' @import Rcpp
Expand Down Expand Up @@ -161,6 +160,19 @@ SEXP buildMatrixNumeric(CharacterVector v, IntegerVector rowInd, IntegerVector c
}


// from openxlsx2:
// similar to is.numeric(x)
// returns true if string can be written as numeric and is not Inf
// @param x a string input
bool is_double(std::string x) {
char *endp;
double res;
res = R_strtod(x.c_str(), &endp);
if (isBlankString(endp) && std::isfinite(res)) {
return 1;
}
return 0;
}


// [[Rcpp::export]]
Expand Down Expand Up @@ -232,7 +244,7 @@ SEXP buildMatrixMixed(CharacterVector v,
try{
// Some values are incorrectly detected as dates. This regex determines if they are numerics.
// If so, they are converted to Dates.
if (std::regex_match( dt_str, std::regex( ( "((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?" ) ) )) {
if (is_double(dt_str)) {
datetmp[ri] = as<Rcpp::Date>(cTD(dt_str));
} else {
datetmp[ri] = Rcpp::Date(atoi(dt_str.substr(5,2).c_str()), atoi(dt_str.substr(8,2).c_str()), atoi(dt_str.substr(0,4).c_str()) );
Expand Down

0 comments on commit bab35f1

Please sign in to comment.