mirror of
https://github.com/NixOS/nix
synced 2025-06-30 03:23:16 +02:00
For example, instead of doing #include "nix/store-config.hh" #include "nix/derived-path.hh" Now do #include "nix/store/config.hh" #include "nix/store/derived-path.hh" This was originally planned in the issue, and also recent requested by Eelco. Most of the change is purely mechanical. There is just one small additional issue. See how, in the example above, we took this opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`. Well, there was already a `nix/util/config.{cc,hh}`. Even though there is not a public configuration header for libutil (which also would be called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any such confusion, we renamed that to `nix/util/configuration.{cc,hh}`. Finally, note that the libflake headers already did this, so we didn't need to do anything to them. We wouldn't want to mistakenly get `nix/flake/flake/flake.hh`! Progress on #7876
55 lines
1.2 KiB
C++
55 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;
|
|
}
|
|
|
|
}
|