New cpp folder structure

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk
2025-07-17 22:35:52 +03:00
committed by Konstantin Pastbin
parent c9cbb64f12
commit 76ffc99abd
2390 changed files with 345 additions and 339 deletions

View File

@@ -0,0 +1,57 @@
#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