Foundation
Loading...
Searching...
No Matches
PathUtil.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cctype>
4#include <Core/Container.hpp>
5
6// Lexical path helpers; no filesystem access. Separators may be '/' or '\\'.
7// These never touch the OS, so they are safe to call from noexcept contexts.
9{
11{
12 auto pos = path.find_last_of("/\\");
13 return pos == Foundation::Core::StringView::npos ? Foundation::Core::StringView{} : path.substr(0, pos);
14}
15
17{
18 auto pos = path.find_last_of("/\\");
19 return pos == Foundation::Core::StringView::npos ? path : path.substr(pos + 1);
20}
21
23{
25 auto dot = name.find_last_of('.');
26 return (dot == Foundation::Core::StringView::npos || dot == 0) ? name : name.substr(0, dot);
27}
28
30{
31 if (dir.empty())
32 return Foundation::Core::String(file);
34 if (out.back() != '/' && out.back() != '\\')
35 out += '/';
36 out += file;
37 return out;
38}
39
40// Lowercase file extension including the leading '.', or empty if none.
41// Only the final path component is considered (a dot in a directory segment is ignored).
43{
45 auto dot = name.find_last_of('.');
46 Foundation::Core::String ext = (dot == Foundation::Core::StringView::npos || dot == 0)
48 : Foundation::Core::String(name.substr(dot));
49 for (char& c : ext)
50 c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
51 return ext;
52}
53} // namespace EditorPathUtil
Definition PathUtil.hpp:9
Foundation::Core::String LowerExtension(Foundation::Core::StringView path)
Definition PathUtil.hpp:42
Foundation::Core::StringView ParentPath(Foundation::Core::StringView path)
Definition PathUtil.hpp:10
Foundation::Core::String JoinPath(Foundation::Core::StringView dir, Foundation::Core::StringView file)
Definition PathUtil.hpp:29
Foundation::Core::StringView Stem(Foundation::Core::StringView path)
Definition PathUtil.hpp:22
Foundation::Core::StringView FileName(Foundation::Core::StringView path)
Definition PathUtil.hpp:16
std::basic_string< char, std::char_traits< char >, StlDefaultAllocator< char > > String
Alias for std::basic_string<char>, without an explicit allocator constructor.
Definition Container.hpp:120
std::basic_string_view< char > StringView
Alias for std::basic_string_view<char>
Definition Container.hpp:56