From 26a05097b561f3d6f3298ce244e8c5cca893d30a Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Wed, 7 Aug 2013 21:52:44 +0200 Subject: [PATCH] helpers.cpp: Add getFileName(), getFileExt(), getNowTimeStr() Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/5d77f01b5d9916cad07c7c10ff3767f87661d389 Author: Michael Liebmann Date: 2013-08-07 (Wed, 07 Aug 2013) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/system/helpers.cpp | 38 ++++++++++++++++++++++++++++++++++---- src/system/helpers.h | 3 +++ 2 files changed, 37 insertions(+), 4 deletions(-) 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