MCPcopy Create free account
hub / github.com/argotorg/solidity / sourceUnitNameToUri

Method sourceUnitNameToUri

libsolidity/lsp/FileRepository.cpp:56–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56std::string FileRepository::sourceUnitNameToUri(std::string const& _sourceUnitName) const
57{
58 std::regex const windowsDriveLetterPath("^[a-zA-Z]:/");
59
60 auto const ensurePathIsUnixLike = [&](std::string inputPath) -> std::string {
61 if (!regex_search(inputPath, windowsDriveLetterPath))
62 return inputPath;
63 else
64 return "/" + std::move(inputPath);
65 };
66
67 if (m_sourceUnitNamesToUri.count(_sourceUnitName))
68 {
69 solAssert(boost::starts_with(m_sourceUnitNamesToUri.at(_sourceUnitName), "file://"), "");
70 return m_sourceUnitNamesToUri.at(_sourceUnitName);
71 }
72 else if (_sourceUnitName.find("file://") == 0)
73 return _sourceUnitName;
74 else if (regex_search(_sourceUnitName, windowsDriveLetterPath))
75 return "file:///" + _sourceUnitName;
76 else if (
77 auto const resolvedPath = tryResolvePath(_sourceUnitName);
78 resolvedPath.message().empty()
79 )
80 return "file://" + ensurePathIsUnixLike(resolvedPath.get().generic_string());
81 else if (m_basePath.generic_string() != "/")
82 return "file://" + m_basePath.generic_string() + "/" + _sourceUnitName;
83 else
84 // Avoid double-/ in case base-path itself is simply a UNIX root filesystem root.
85 return "file:///" + _sourceUnitName;
86}
87
88std::string FileRepository::uriToSourceUnitName(std::string const& _path) const
89{

Callers 4

toJsonMethod · 0.80
operator()Method · 0.80
compileMethod · 0.80

Calls 5

atMethod · 0.80
countMethod · 0.45
findMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected