Replace string_view with string
In datatypes.cpp function to_timestamp() the istringstream needs a string, so passing a string_view around is pointless.
This commit is contained in:
parent
8ca23eb221
commit
1cb40fd5ba
6 changed files with 17 additions and 23 deletions
|
@ -30,7 +30,7 @@ Header to_header (const nap::HttpResponse& resp) {
|
|||
Header ret;
|
||||
for (const auto& entry : resp.header) {
|
||||
if (entry.first == "Date")
|
||||
ret.date = from_header_timestamp(entry.second);
|
||||
ret.date = from_header_timestamp(std::string(entry.second));
|
||||
else if (entry.first == "X-RateLimit-Limit")
|
||||
ret.rate_limit = int_conv<decltype(ret.rate_limit)>(entry.second);
|
||||
else if (entry.first == "X-RateLimit-Remaining")
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
#include "date/date.h"
|
||||
|
||||
namespace oro {
|
||||
Timestamp& Timestamp::operator= (const std::string& str) {
|
||||
ts = from_json_timestamp(str);
|
||||
Timestamp& Timestamp::operator= (std::string&& str) {
|
||||
ts = from_json_timestamp(std::move(str));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace oro {
|
|||
typedef std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds> timestamp_t;
|
||||
|
||||
struct Timestamp {
|
||||
Timestamp& operator= (const std::string& str);
|
||||
Timestamp& operator= (std::string&& str);
|
||||
operator timestamp_t() const { return ts; }
|
||||
|
||||
timestamp_t ts;
|
||||
|
|
|
@ -32,8 +32,8 @@ namespace {
|
|||
}
|
||||
};
|
||||
|
||||
Timestamp to_timestamp (const char* fmt, std::string_view str) {
|
||||
std::istringstream iss{std::string(str)};
|
||||
Timestamp to_timestamp (const char* fmt, std::string&& str) {
|
||||
std::istringstream iss{std::move(str)};
|
||||
Timestamp ts;
|
||||
date::from_stream(iss, fmt, ts.ts);
|
||||
return ts;
|
||||
|
@ -45,29 +45,25 @@ namespace {
|
|||
//For formatting modifiers see:
|
||||
//https://howardhinnant.github.io/date/date.html#from_stream_formatting
|
||||
|
||||
Timestamp from_json_timestamp (const std::string& str) {
|
||||
Timestamp from_json_timestamp (std::string&& str) {
|
||||
if (not str.empty() and str.back() == 'Z') {
|
||||
//date has this format: 2020-06-19T22:40:51Z
|
||||
return to_timestamp("%FT%TZ", str);
|
||||
return to_timestamp("%FT%TZ", std::move(str));
|
||||
}
|
||||
else {
|
||||
//date has this format: 2020-06-19T22:33:36.855672+00:00
|
||||
return to_timestamp("%FT%T%Ez", str);
|
||||
return to_timestamp("%FT%T%Ez", std::move(str));
|
||||
}
|
||||
}
|
||||
|
||||
Timestamp from_header_timestamp (const std::string& str) {
|
||||
return from_header_timestamp(std::string_view(str));
|
||||
}
|
||||
|
||||
Timestamp from_header_timestamp (std::string_view str) {
|
||||
Timestamp from_header_timestamp (std::string&& str) {
|
||||
UniqueLocale loc(std::setlocale(LC_TIME, "POSIX"));
|
||||
//date has this format: Fri, 19 Jun 2020 22:33:43 GMT
|
||||
return to_timestamp("%a, %d %b %Y %T %Z", str);
|
||||
return to_timestamp("%a, %d %b %Y %T %Z", std::move(str));
|
||||
}
|
||||
|
||||
Timestamp from_sqlite_timestamp (const std::string& str) {
|
||||
return to_timestamp("%F %T", str);
|
||||
Timestamp from_sqlite_timestamp (std::string&& str) {
|
||||
return to_timestamp("%F %T", std::move(str));
|
||||
}
|
||||
|
||||
std::string to_sqlite_string (const oro::Timestamp& ts) {
|
||||
|
|
|
@ -19,13 +19,11 @@
|
|||
|
||||
#include "oro/datatypes.hpp"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace oro {
|
||||
Timestamp from_json_timestamp (const std::string& str);
|
||||
Timestamp from_header_timestamp (std::string_view str);
|
||||
Timestamp from_header_timestamp (const std::string& str);
|
||||
Timestamp from_sqlite_timestamp (const std::string& str);
|
||||
Timestamp from_json_timestamp (std::string&& str);
|
||||
Timestamp from_header_timestamp (std::string&& str);
|
||||
Timestamp from_sqlite_timestamp (std::string&& str);
|
||||
std::string to_sqlite_string (const Timestamp& ts);
|
||||
std::string to_iso8601_string (const Timestamp& ts);
|
||||
} //namespace oro
|
||||
|
|
|
@ -556,7 +556,7 @@ Timestamp OriginsDBSQLite::next_access_time (DBOperation op) const {
|
|||
if (not info)
|
||||
throw std::runtime_error("Query returned no value for access.operation " + to_string(static_cast<int>(op)));
|
||||
|
||||
return from_sqlite_timestamp(*info);
|
||||
return from_sqlite_timestamp(std::move(*info));
|
||||
}
|
||||
|
||||
} //namespace oro
|
||||
|
|
Loading…
Reference in a new issue