mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-28 07:51:11 +02:00
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:
@@ -284,17 +284,17 @@ bool get_mem_usage(unsigned long &kbtotal, unsigned long &kbfree)
|
|||||||
return true;
|
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)
|
if (pos == std::string::npos)
|
||||||
return path;
|
return path;
|
||||||
return path.substr(0, pos);
|
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)
|
if (pos == std::string::npos)
|
||||||
return path;
|
return path;
|
||||||
if (path.length() == pos +1)
|
if (path.length() == pos +1)
|
||||||
@@ -302,6 +302,36 @@ std::string getBaseName(std::string &path)
|
|||||||
return path.substr(pos+1);
|
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 trim(std::string &str, const std::string &trimChars /*= " \n\r\t"*/)
|
||||||
{
|
{
|
||||||
std::string result = str.erase(str.find_last_not_of(trimChars) + 1);
|
std::string result = str.erase(str.find_last_not_of(trimChars) + 1);
|
||||||
|
@@ -38,6 +38,9 @@ bool get_mem_usage(unsigned long &total, unsigned long &free);
|
|||||||
|
|
||||||
std::string getPathName(std::string &path);
|
std::string getPathName(std::string &path);
|
||||||
std::string getBaseName(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");
|
std::string trim(std::string &str, const std::string &trimChars = " \n\r\t");
|
||||||
|
|
||||||
class CFileHelpers
|
class CFileHelpers
|
||||||
|
Reference in New Issue
Block a user