Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Require/src/PathUtilities.cpp
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
3
#include "PathUtilities.h"
4
5
#include <string_view>
6
7
namespace Luau::Require
8
{
9
10
PathType getPathType(std::string_view path)
11
{
12
if (path.size() >= 2 && path.substr(0, 2) == "./")
13
return PathType::RelativeToCurrent;
14
if (path.size() >= 3 && path.substr(0, 3) == "../")
15
return PathType::RelativeToParent;
16
if (path.size() >= 1 && path[0] == '@')
17
return PathType::Aliased;
18
19
return PathType::Unsupported;
20
}
21
22
std::pair<std::string_view, std::string_view> splitPath(std::string_view path)
23
{
24
size_t pos = path.find_first_of('/');
25
if (pos == std::string_view::npos)
26
return {path, {}};
27
28
return {path.substr(0, pos), path.substr(pos + 1)};
29
}
30
31
} // namespace Luau::Require
32
33