helpers.cpp: Add getFileName(), getFileExt(), getNowTimeStr()

Origin commit data
------------------
Branch: ni/coolstream
Commit: 5d77f01b5d
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2013-08-07 (Wed, 07 Aug 2013)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
Michael Liebmann
2013-08-07 21:52:44 +02:00
parent f443e20c0f
commit 26a05097b5
2 changed files with 37 additions and 4 deletions

View File

@@ -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);