1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-21 17:59:36 +01:00
nix/src/libexpr/search-path.cc
Graham Christensen e4f62e4608 Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter,
* It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files
* Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose,

Let's rip the bandaid off?

Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
2025-07-18 12:47:27 -04:00

50 lines
1.2 KiB
C++

#include "nix/expr/search-path.hh"
namespace nix {
std::optional<std::string_view> LookupPath::Prefix::suffixIfPotentialMatch(std::string_view path) const
{
auto n = s.size();
/* Non-empty prefix and suffix must be separated by a /, or the
prefix is not a valid path prefix. */
bool needSeparator = n > 0 && n < path.size();
if (needSeparator && path[n] != '/') {
return std::nullopt;
}
/* Prefix must be prefix of this path. */
if (path.compare(0, n, s) != 0) {
return std::nullopt;
}
/* Skip next path separator. */
return {path.substr(needSeparator ? n + 1 : n)};
}
LookupPath::Elem LookupPath::Elem::parse(std::string_view rawElem)
{
size_t pos = rawElem.find('=');
return LookupPath::Elem{
.prefix =
Prefix{
.s = pos == std::string::npos ? std::string{""} : std::string{rawElem.substr(0, pos)},
},
.path =
Path{
.s = std::string{rawElem.substr(pos + 1)},
},
};
}
LookupPath LookupPath::parse(const Strings & rawElems)
{
LookupPath res;
for (auto & rawElem : rawElems)
res.elements.emplace_back(LookupPath::Elem::parse(rawElem));
return res;
}
} // namespace nix