| 54 | } |
| 55 | |
| 56 | std::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 | |
| 88 | std::string FileRepository::uriToSourceUnitName(std::string const& _path) const |
| 89 | { |
no test coverage detected