Commit 42798448 authored by Sylvain Thery's avatar Sylvain Thery

utility fonction of path/name extractions

parent 928f2127
......@@ -32,7 +32,7 @@ namespace CGoGN
namespace Utils
{
/**
* @brief checkFileNameExtension
* @brief check if filename has extension and add it if not
* @param filename
* @param extension (with . example ".svg")
* @return the modified (or not) filename
......@@ -44,11 +44,50 @@ inline std::string checkFileNameExtension(const std::string &filename, const std
{
if (filename[filename.size()-1]=='.')
return filename.substr(0,filename.size()-1) + extension;
return filename + extension;
}
return filename;
}
/**
* @brief extract the path from a file-name
* @param filename
* @return the path (with ending /) if there is a / (or \) in filename
*/
inline std::string extractPathFromFileName(const std::string &filename)
{
std::size_t found = filename.rfind('/');
if (found == std::string::npos)
found = filename.rfind('\\'); // welcome on NTFS ;)
if (found == std::string::npos)
return "";
return filename.substr(0,found+1);
}
/**
* @brief extract the name from a file-name
* @param filename
* @return the name of file (string behind last / (or /))
*/
inline std::string extractNameFromFileName(const std::string &filename)
{
std::size_t found = filename.rfind('/');
if (found == std::string::npos)
found = filename.rfind('\\'); // welcome on NTFS ;)
if (found == std::string::npos)
return filename;
return filename.substr(found+1);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment