diff --git a/src/eckit/filesystem/URI.h b/src/eckit/filesystem/URI.h index 0cd9a4824..523d3e3f8 100644 --- a/src/eckit/filesystem/URI.h +++ b/src/eckit/filesystem/URI.h @@ -43,7 +43,7 @@ class URI { // Contructors URI(); - URI(const std::string& uri); + explicit URI(const std::string& uri); URI(const std::string& scheme, const PathName& path); URI(const std::string& scheme, const URI& uri); URI(const std::string& scheme, const std::string& hostname, int port); diff --git a/src/eckit/io/MultiHandle.cc b/src/eckit/io/MultiHandle.cc index 659fe5396..d634feef7 100644 --- a/src/eckit/io/MultiHandle.cc +++ b/src/eckit/io/MultiHandle.cc @@ -149,11 +149,13 @@ long MultiHandle::read1(char* buffer, long length) { } long n = (*current_)->read(buffer, length); - if (n <= 0) { + if (n < length) { (*current_)->close(); current_++; openCurrent(); - return read1(buffer, length); + if (n <= 0) { + return read1(buffer, length); + } } return n; } diff --git a/src/eckit/log/TimeStamp.cc b/src/eckit/log/TimeStamp.cc index 057d6a52a..0a2d36d20 100644 --- a/src/eckit/log/TimeStamp.cc +++ b/src/eckit/log/TimeStamp.cc @@ -9,6 +9,7 @@ */ #include +#include #include "eckit/eckit.h" @@ -27,6 +28,12 @@ TimeStamp::TimeStamp(time_t t, const std::string& format) : time_(t), format_(format) {} std::ostream& operator<<(std::ostream& s, const TimeStamp& x) { + + if (x.format_ == "hex") { + s << std::setw(16) << std::setfill('0') << std::hex << (uint64_t) x.time_; + return s; + } + char buf[80]; #if eckit_HAVE_GMTIME_R struct tm t; diff --git a/src/eckit/types/Time.cc b/src/eckit/types/Time.cc index f10eb9ba8..402253f22 100644 --- a/src/eckit/types/Time.cc +++ b/src/eckit/types/Time.cc @@ -18,6 +18,13 @@ #include "eckit/utils/Hash.h" #include "eckit/utils/Tokenizer.h" +namespace { + static thread_local std::regex digits_time_("^-?[0-9]+$"); + static thread_local std::regex float_hours_("^-?[0-9]*\\.[0-9]+$"); + static thread_local std::regex hhmmss_("^([0-9]+):([0-5]?[0-9])(:[0-5]?[0-9])?$"); + static thread_local std::regex ddhhmmss_("^-?([0-9]+[dD])?([0-9]+[hH])?([0-9]+[mM])?([0-9]+[sS])?$"); +} + namespace eckit { //---------------------------------------------------------------------------------------------------------------------- @@ -45,7 +52,7 @@ Time::Time(const std::string& s, bool extended) { long dd = 0; std::smatch m; - if (std::regex_match (s, m, std::regex("^-?[0-9]+$"))) { // only digits + if (std::regex_match (s, m, digits_time_)) { long t = std::stol(s); int sign = (s[0] == '-' ? 1 : 0); if (extended || s.length() <= 2+sign) { // cases: h, hh, (or hhh..h for step parsing) @@ -62,7 +69,7 @@ Time::Time(const std::string& s, bool extended) { } } else { - if (std::regex_match (s, m, std::regex("^-?[0-9]*\\.[0-9]+$"))) { // floating point (hours) + if (std::regex_match (s, m, float_hours_)) { long sec = std::round(std::stod(s)*3600); hh = sec/3600; sec -= hh*3600; @@ -71,7 +78,7 @@ Time::Time(const std::string& s, bool extended) { ss = sec; } else { - if (std::regex_match (s, m, std::regex("^([0-9]+):([0-5]?[0-9])(:[0-5]?[0-9])?$"))) { + if (std::regex_match (s, m, hhmmss_)) { for (int i=1; i