Skip to content

Commit

Permalink
Make strf_time take a string_view as format string
Browse files Browse the repository at this point in the history
  • Loading branch information
imwints committed Sep 19, 2023
1 parent 39364d9 commit 3640f01
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/btop_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ namespace Draw {
}

bool update_clock(bool force) {
const auto& clock_format = Config::getS("clock_format");
const std::string_view clock_format = Config::getS("clock_format");
if (not Cpu::shown or clock_format.empty()) {
if (clock_format.empty() and not Global::clock.empty()) Global::clock.clear();
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/btop_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ namespace Logger {
using namespace Tools;
std::mutex log_mtx{};
bool first = true;
const string tdf = "%Y/%m/%d (%T) | ";

size_t loglevel;
fs::path logfile;
constexpr const std::string_view tdf = "%Y/%m/%d (%T) | ";

//* Wrapper for lowering priviliges if using SUID bit and currently isn't using real userid
class lose_priv {
Expand Down
14 changes: 8 additions & 6 deletions src/btop_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ tab-size = 4

#include <cmath>
#include <codecvt>
#include <iostream>
#include <fstream>
#include <ctime>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <iostream>
#include <ranges>
#include <sstream>
#include <string>
#include <string_view>
#include <utility>

#include <unistd.h>
#include <termios.h>
Expand Down Expand Up @@ -473,11 +475,11 @@ namespace Tools {
return new_str;
}

string strf_time(const string& strf) {
string strf_time(const std::string_view strf) {
auto in_time_t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm bt {};
std::stringstream ss;
ss << std::put_time(localtime_r(&in_time_t, &bt), strf.c_str());
ss << std::put_time(localtime_r(&in_time_t, &bt), strf.data());
return ss.str();
}

Expand Down
3 changes: 2 additions & 1 deletion src/btop_tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tab-size = 4
#include <ranges>
#include <regex>
#include <string>
#include <string_view>
#include <thread>
#include <tuple>
#include <vector>
Expand Down Expand Up @@ -297,7 +298,7 @@ namespace Tools {
std::string operator*(const string& str, int64_t n);

//* Return current time in <strf> format
string strf_time(const string& strf);
string strf_time(const std::string_view strf);

string hostname();
string username();
Expand Down

0 comments on commit 3640f01

Please sign in to comment.