2021-09-11 13:49:47 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_MISC_PATHHELPERS_H
|
|
|
|
#define OPENMW_COMPONENTS_MISC_PATHHELPERS_H
|
|
|
|
|
2024-05-02 23:28:38 +00:00
|
|
|
#include <string_view>
|
2021-09-11 13:49:47 +00:00
|
|
|
|
|
|
|
namespace Misc
|
|
|
|
{
|
2024-05-02 23:28:38 +00:00
|
|
|
inline constexpr std::size_t findExtension(std::string_view file) noexcept
|
2022-08-31 20:02:19 +00:00
|
|
|
{
|
|
|
|
return file.find_last_of('.');
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:28:38 +00:00
|
|
|
inline constexpr std::string_view getFileExtension(std::string_view file) noexcept
|
2021-09-11 13:49:47 +00:00
|
|
|
{
|
2024-05-02 23:28:38 +00:00
|
|
|
if (auto extPos = findExtension(file); extPos != std::string_view::npos)
|
2021-09-11 13:49:47 +00:00
|
|
|
{
|
|
|
|
file.remove_prefix(extPos + 1);
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
2022-07-17 13:54:06 +00:00
|
|
|
|
2024-05-02 23:28:38 +00:00
|
|
|
inline constexpr std::string_view getFileName(std::string_view path) noexcept
|
2022-07-17 13:54:06 +00:00
|
|
|
{
|
2024-05-02 23:28:38 +00:00
|
|
|
if (auto namePos = path.find_last_of("/\\"); namePos != std::string_view::npos)
|
2022-07-17 13:54:06 +00:00
|
|
|
{
|
|
|
|
path.remove_prefix(namePos + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:28:38 +00:00
|
|
|
inline constexpr std::string_view stemFile(std::string_view path) noexcept
|
2022-07-17 13:54:06 +00:00
|
|
|
{
|
|
|
|
path = getFileName(path);
|
|
|
|
|
2024-05-02 23:28:38 +00:00
|
|
|
if (auto extPos = path.find_last_of('.'); extPos != std::string_view::npos)
|
2022-07-17 13:54:06 +00:00
|
|
|
{
|
|
|
|
path.remove_suffix(path.size() - extPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
2021-09-11 13:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|