Repo created
This commit is contained in:
parent
4af19165ec
commit
68073add76
12458 changed files with 12350765 additions and 2 deletions
60
libs/base/file_name_utils.hpp
Normal file
60
libs/base/file_name_utils.hpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "base/assert.hpp"
|
||||
|
||||
namespace base
|
||||
{
|
||||
/// Remove extension from file name.
|
||||
void GetNameWithoutExt(std::string & name);
|
||||
std::string FilenameWithoutExt(std::string name);
|
||||
/// @return File extension with the dot or empty std::string if no extension found.
|
||||
std::string GetFileExtension(std::string const & name);
|
||||
|
||||
/// Get file name from full path.
|
||||
void GetNameFromFullPath(std::string & name);
|
||||
|
||||
std::string FileNameFromFullPath(std::string path);
|
||||
|
||||
/// Get file name from full path without extension.
|
||||
std::string GetNameFromFullPathWithoutExt(std::string path);
|
||||
|
||||
/// Returns all but last components of the path. After dropping the last
|
||||
/// component, all trailing slashes are removed, unless the result is a
|
||||
/// root directory. If the argument is a single component, returns ".".
|
||||
std::string GetDirectory(std::string const & path);
|
||||
|
||||
/// Get native folder separator for the platform.
|
||||
std::string::value_type GetNativeSeparator();
|
||||
|
||||
/// Add the terminating slash to the folder path std::string if it's not already there.
|
||||
std::string AddSlashIfNeeded(std::string const & path);
|
||||
|
||||
namespace impl
|
||||
{
|
||||
inline std::string JoinPath(std::string const & file)
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
std::string JoinPath(std::string const & folder, Args &&... args)
|
||||
{
|
||||
if (folder.empty())
|
||||
return {};
|
||||
|
||||
return AddSlashIfNeeded(folder) + impl::JoinPath(std::forward<Args>(args)...);
|
||||
}
|
||||
} // namespace impl
|
||||
|
||||
/// Create full path from some folder using native folders separator.
|
||||
template <typename... Args>
|
||||
std::string JoinPath(std::string const & dir, std::string const & fileOrDir, Args &&... args)
|
||||
{
|
||||
ASSERT(!dir.empty(), ("JoinPath dir is empty"));
|
||||
ASSERT(!fileOrDir.empty(), ("JoinPath fileOrDir is empty"));
|
||||
return impl::JoinPath(dir, fileOrDir, std::forward<Args>(args)...);
|
||||
}
|
||||
} // namespace base
|
||||
Loading…
Add table
Add a link
Reference in a new issue