diff --git a/include/of_path.h b/include/of_path.h index 2a012c8..a003148 100644 --- a/include/of_path.h +++ b/include/of_path.h @@ -19,6 +19,7 @@ public: static ofString get_full(const ofString& path, const ofString& sub_file_path); static bool exist(const ofString& path); static bool write(const ofString& path, const char* data, int len); + static ofString to_full(const ofString& path); }; }; // namespace ofen #endif \ No newline at end of file diff --git a/include/of_str.h b/include/of_str.h index f31b6f1..0a6698a 100644 --- a/include/of_str.h +++ b/include/of_str.h @@ -10,11 +10,12 @@ class COfStr public: COfStr(); ~COfStr(); + public: static ofString replace(const ofString& str, const ofString& from, const ofString& to); static std::vector split(const ofString& input, const ofString& delimiter); + static ofString trim(const ofString& input); }; }; // namespace ofen - #endif \ No newline at end of file diff --git a/include/of_util.h b/include/of_util.h index f072b2d..e85d023 100644 --- a/include/of_util.h +++ b/include/of_util.h @@ -38,6 +38,14 @@ private: template std::shared_ptr OfSingleton::instance = nullptr; template std::once_flag OfSingleton::init_flag; +class OfUtil { +public: + OfUtil(); + ~OfUtil(); +public: + static ofString now_time(); +}; + class CMutBuffer { public: diff --git a/src/of_path.cpp b/src/of_path.cpp index 55d3298..9ad65b4 100644 --- a/src/of_path.cpp +++ b/src/of_path.cpp @@ -1,7 +1,7 @@ #include "of_path.h" +#include "of_str.h" #include #include -#include "of_str.h" #ifdef _WIN32 #include @@ -139,4 +139,21 @@ bool COfPath::write(const ofString& path, const char* data, int len) return true; } +ofString COfPath::to_full(const ofString& path) +{ + fs::path base; + if (fs::path(path).is_relative()) { + base = fs::current_path(); + base.append(path); + } else { + base = fs::path(path); + } + fs::path ret = fs::absolute(base); +#ifdef UNICODE_OFSTR + return ofString(ret.wstring()); +#else + return ofString(ret.string()); +#endif +} + } // namespace ofen diff --git a/src/of_str.cpp b/src/of_str.cpp index fea283e..470abe4 100644 --- a/src/of_str.cpp +++ b/src/of_str.cpp @@ -31,4 +31,13 @@ std::vector COfStr::split(const ofString& input, const ofString& delim result.push_back(input.substr(prev)); return result; } +ofString COfStr::trim(const ofString& input) +{ + size_t start = input.find_first_not_of(" \t\n\r\f\v"); + if (start == std::string::npos) { + return ""; + } + size_t end = input.find_last_not_of(" \t\n\r\f\v"); + return input.substr(start, end - start + 1); +} } // namespace ofen diff --git a/src/of_util.cpp b/src/of_util.cpp index 5ca54ad..f5bbdc5 100644 --- a/src/of_util.cpp +++ b/src/of_util.cpp @@ -1,4 +1,7 @@ #include "of_util.h" +#include +#include +#include namespace ofen { void CMutBuffer::push(const char* data, int len) @@ -43,4 +46,24 @@ void CMutBuffer::clear() std::lock_guard lock(mutex_); buffer_.clear(); } +OfUtil::OfUtil() +{ +} +OfUtil::~OfUtil() +{ +} +ofString OfUtil::now_time() +{ + auto now = std::chrono::system_clock::now(); + auto time_t_now = std::chrono::system_clock::to_time_t(now); + std::tm tm_now; +#if defined(_WIN32) || defined(_WIN64) + localtime_s(&tm_now, &time_t_now); +#else + localtime_r(&time_t_now, &tm_now); +#endif + std::ostringstream oss; + oss << std::put_time(&tm_now, "%Y-%m-%d %H:%M:%S"); + return oss.str(); +} } // namespace ofen