Skip to content

Commit

Permalink
use string_view (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Aug 15, 2023
1 parent e07ca47 commit 206c6ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions include/ylt/thirdparty/cinatra/time_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ inline constexpr std::array<component_of_time_format, 32> get_format() {
}
} // namespace time_util

template <time_format Format = time_format::http_format>
inline std::pair<bool, std::time_t> get_timestamp(
const std::string &gmt_time_str) {
template <time_format Format = time_format::http_format, typename String>
inline std::pair<bool, std::time_t> get_timestamp(const String &gmt_time_str) {
using namespace time_util;
std::string_view sv(gmt_time_str);
int year, month, day, hour, min, sec, day_of_week;
Expand Down
5 changes: 2 additions & 3 deletions include/ylt/util/time_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
namespace ylt {
using time_format = cinatra::time_format;

template <time_format Format = time_format::http_format>
inline std::pair<bool, std::time_t> get_timestamp(
const std::string &gmt_time_str) {
template <time_format Format = time_format::http_format, typename String>
inline std::pair<bool, std::time_t> get_timestamp(const String &gmt_time_str) {
return cinatra::get_timestamp<Format>(gmt_time_str);
}

Expand Down
4 changes: 2 additions & 2 deletions src/util/tests/test_time_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int main() {
assert(ylt::get_gmt_time_str(t) == tm_str);
}

std::string utc_str = "2006-01-02T15:04:05.000Z";
constexpr std::string_view utc_str = "2006-01-02T15:04:05.000Z";
if (auto [ok, t] = ylt::get_timestamp<ylt::time_format::utc_format>(utc_str);
ok) {
std::cout << cinatra::get_gmt_time_str(
Expand All @@ -24,7 +24,7 @@ int main() {
assert(ylt::get_gmt_time_str(t) == tm_str);
}

std::string utc_str1 = "20060102T150405000Z";
std::string_view utc_str1 = "20060102T150405000Z";
if (auto [ok, t] =
ylt::get_timestamp<ylt::time_format::utc_without_punctuation_format>(
utc_str1);
Expand Down

0 comments on commit 206c6ca

Please sign in to comment.