Skip to content

Commit

Permalink
further simplification thanks to Boost
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Dec 6, 2016
1 parent f7285de commit 4d13361
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
@@ -1 +1 @@
comment: false
comment: false
8 changes: 7 additions & 1 deletion ChangeLog
@@ -1,7 +1,13 @@
2016-12-06 Dirk Eddelbuettel <edd@debian.org>

* src/anytime.cpp (isAtLeastGivenLengthAndAllDigits): Simplified
using Boost classification and predicate use

2016-12-05 Dirk Eddelbuettel <edd@debian.org>

* src/anytime.cpp (format): Condition only on Rcpp version
* tests/utilities.R: Call anytime:::format()

* tests/utilities.R: Call anytime:::format()

2016-12-04 Dirk Eddelbuettel <edd@debian.org>

Expand Down
12 changes: 5 additions & 7 deletions src/anytime.cpp
Expand Up @@ -24,10 +24,13 @@
#include <boost/date_time/c_local_time_adjustor.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/split.hpp>

#include <Rcpp.h>

namespace bt = boost::posix_time;
namespace ba = boost::algorithm;

static bool debug = false;

Expand Down Expand Up @@ -201,12 +204,7 @@ void stringSplitter(const std::string & in, const std::string spliton,
// yes, we could use regular expression -- but then we'd either be C++11 or would
// require an additional library with header / linking requirement (incl boost regex)
bool isAtLeastGivenLengthAndAllDigits(const std::string& s, const unsigned int n) {
bool res = s.size() >= n;
size_t i = 0;
while (res && i < n) {
res = res && s[i] >= '0' && s[i] <= '9';
i++;
}
bool res = (s.size() >= n) && ba::all(s, ba::is_digit());
if (debug) Rcpp::Rcout << "s: " << s << " len: " << s.size() << " res: " << res << std::endl;
return res;
}
Expand Down Expand Up @@ -403,7 +401,7 @@ std::vector<std::string> format(Rcpp::NumericVector x) {
std::vector<std::string> z(x.size());
for (int i=0; i<x.size(); i++) {
Rcpp::Datetime d(x[i]);
#if RCPP_DEV_VERSION >= RcppDevVersion(0,12,8,1)
#if RCPP_DEV_VERSION >= RcppDevVersion(0,12,8,2)
z[i] = d.format();
#else
z[i] = "";
Expand Down

0 comments on commit 4d13361

Please sign in to comment.