mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 17:15:34 +00:00
Make path helpers constexpr and noexcept
This commit is contained in:
parent
7e1ecfc0ee
commit
8cc744997f
1 changed files with 8 additions and 8 deletions
|
@ -1,18 +1,18 @@
|
|||
#ifndef OPENMW_COMPONENTS_MISC_PATHHELPERS_H
|
||||
#define OPENMW_COMPONENTS_MISC_PATHHELPERS_H
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
inline size_t findExtension(std::string_view file)
|
||||
inline constexpr std::size_t findExtension(std::string_view file) noexcept
|
||||
{
|
||||
return file.find_last_of('.');
|
||||
}
|
||||
|
||||
inline std::string_view getFileExtension(std::string_view file)
|
||||
inline constexpr std::string_view getFileExtension(std::string_view file) noexcept
|
||||
{
|
||||
if (auto extPos = findExtension(file); extPos != std::string::npos)
|
||||
if (auto extPos = findExtension(file); extPos != std::string_view::npos)
|
||||
{
|
||||
file.remove_prefix(extPos + 1);
|
||||
return file;
|
||||
|
@ -20,9 +20,9 @@ namespace Misc
|
|||
return {};
|
||||
}
|
||||
|
||||
inline std::string_view getFileName(std::string_view path)
|
||||
inline constexpr std::string_view getFileName(std::string_view path) noexcept
|
||||
{
|
||||
if (auto namePos = path.find_last_of("/\\"); namePos != std::string::npos)
|
||||
if (auto namePos = path.find_last_of("/\\"); namePos != std::string_view::npos)
|
||||
{
|
||||
path.remove_prefix(namePos + 1);
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ namespace Misc
|
|||
return path;
|
||||
}
|
||||
|
||||
inline std::string_view stemFile(std::string_view path)
|
||||
inline constexpr std::string_view stemFile(std::string_view path) noexcept
|
||||
{
|
||||
path = getFileName(path);
|
||||
|
||||
if (auto extPos = path.find_last_of("."); extPos != std::string::npos)
|
||||
if (auto extPos = path.find_last_of('.'); extPos != std::string_view::npos)
|
||||
{
|
||||
path.remove_suffix(path.size() - extPos);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue