Skip to content

Commit

Permalink
tidy:1.8.19, 将Basename(const char*)移到util::fs下
Browse files Browse the repository at this point in the history
  • Loading branch information
hevake committed May 24, 2024
1 parent 0a4cdbe commit 02b60fc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
12 changes: 12 additions & 0 deletions modules/util/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ std::string Basename(const std::string &full_path)
return full_path.substr(pos + 1);
}

const char* Basename(const char *full_path)
{
const char *p_last = full_path;
if (p_last != nullptr) {
for (const char *p = full_path; *p; ++p) {
if (*p == '/')
p_last = p + 1;
}
}
return p_last;
}

/**
* 目标:
* "a" -> "."
Expand Down
1 change: 1 addition & 0 deletions modules/util/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ bool RemoveDirectory(const std::string &dir, bool is_remove_file_only = false);
* 根据路径获取文件名
*/
std::string Basename(const std::string &full_path);
const char* Basename(const char *full_path);

/**
* 根据路径获取目录名
Expand Down
19 changes: 3 additions & 16 deletions modules/util/time_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* of the source tree.
*/
#include "time_counter.h"
#include "fs.h"

#define USE_PRINTF 1

Expand All @@ -35,20 +36,6 @@ namespace util {
using namespace std;
using namespace std::chrono;

namespace {
const char* Basename(const char *full_path)
{
const char *p_last = full_path;
if (p_last != nullptr) {
for (const char *p = full_path; *p; ++p) {
if (*p == '/')
p_last = p + 1;
}
}
return p_last;
}
}

TimeCounter::TimeCounter()
: start_time_point_(steady_clock::now())
{ }
Expand Down Expand Up @@ -151,12 +138,12 @@ void FixedTimeCounter::stop()
#if USE_PRINTF
printf("TIME_COST: %8" PRIu64 ".%03" PRIu64 " us at %s() in %s:%u\n",
ns_count / 1000, ns_count % 1000,
func_name_, Basename(file_name_), line_);
func_name_, fs::Basename(file_name_), line_);
#else
cout << "TIME_COST: " << setw(8) << ns_count / 1000
<< '.' << setw(3) << setfill('0') << ns_count % 1000 << setfill(' ')
<< " us at " << func_name_ << "() in "
<< Basename(file_name_) << ':' << line_ << endl;
<< fs::Basename(file_name_) << ':' << line_ << endl;
#endif

}
Expand Down
2 changes: 1 addition & 1 deletion version.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
# TBOX版本号
TBOX_VERSION_MAJOR := 1
TBOX_VERSION_MINOR := 8
TBOX_VERSION_REVISION := 18
TBOX_VERSION_REVISION := 19

0 comments on commit 02b60fc

Please sign in to comment.