diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index f36bbbd5b..d084d1c8a 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -284,17 +284,17 @@ bool get_mem_usage(unsigned long &kbtotal, unsigned long &kbfree) return true; } -std::string getPathName(std::string &path) +std::string _getPathName(std::string &path, std::string sep) { - size_t pos = path.find_last_of("/"); + size_t pos = path.find_last_of(sep); if (pos == std::string::npos) return path; return path.substr(0, pos); } -std::string getBaseName(std::string &path) +std::string _getBaseName(std::string &path, std::string sep) { - size_t pos = path.find_last_of("/"); + size_t pos = path.find_last_of(sep); if (pos == std::string::npos) return path; if (path.length() == pos +1) @@ -302,6 +302,36 @@ std::string getBaseName(std::string &path) return path.substr(pos+1); } +std::string getPathName(std::string &path) +{ + return _getPathName(path, "/"); +} + +std::string getBaseName(std::string &path) +{ + return _getBaseName(path, "/"); +} + +std::string getFileName(std::string &file) +{ + return _getPathName(file, "."); +} + +std::string getFileExt(std::string &file) +{ + return _getBaseName(file, "."); +} + + +std::string getNowTimeStr(const char* format) +{ + char tmpStr[256]; + struct timeval tv; + gettimeofday(&tv, NULL); + strftime(tmpStr, sizeof(tmpStr), format, localtime(&tv.tv_sec)); + return (std::string)tmpStr; +} + std::string trim(std::string &str, const std::string &trimChars /*= " \n\r\t"*/) { std::string result = str.erase(str.find_last_not_of(trimChars) + 1); diff --git a/src/system/helpers.h b/src/system/helpers.h index 70db9525b..bab8204eb 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -38,6 +38,9 @@ bool get_mem_usage(unsigned long &total, unsigned long &free); std::string getPathName(std::string &path); std::string getBaseName(std::string &path); +std::string getFileName(std::string &file); +std::string getFileExt(std::string &file); +std::string getNowTimeStr(const char* format); std::string trim(std::string &str, const std::string &trimChars = " \n\r\t"); class CFileHelpers