diff options
author | jade <lix@jade.fyi> | 2024-03-18 12:01:39 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit@lix> | 2024-03-18 12:01:39 -0600 |
commit | 47a237f7ec594c409a7abbbfe0ff0170a9970183 (patch) | |
tree | b1300e42617d2c728a1688e066ffb6f3a252bfbd /src/libexpr | |
parent | 86a1121d16f7eeb594955e39ff4e6fcd69f1b8c5 (diff) | |
parent | 61e21b25576f7f3491f6a837bf59d8b44c6897a0 (diff) |
Merge "Delete hasPrefix and hasSuffix from the codebase" into main
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/eval-settings.cc | 4 | ||||
-rw-r--r-- | src/libexpr/eval.cc | 16 | ||||
-rw-r--r-- | src/libexpr/flake/config.cc | 2 | ||||
-rw-r--r-- | src/libexpr/flake/flakeref.cc | 2 |
4 files changed, 12 insertions, 12 deletions
diff --git a/src/libexpr/eval-settings.cc b/src/libexpr/eval-settings.cc index 89ca198d8..046ca557d 100644 --- a/src/libexpr/eval-settings.cc +++ b/src/libexpr/eval-settings.cc @@ -29,7 +29,7 @@ static Strings parseNixPath(const std::string & s) if (*p == ':') { auto prefix = std::string(start2, s.end()); - if (EvalSettings::isPseudoUrl(prefix) || hasPrefix(prefix, "flake:")) { + if (EvalSettings::isPseudoUrl(prefix) || prefix.starts_with("flake:")) { ++p; while (p != s.end() && *p != ':') ++p; } @@ -82,7 +82,7 @@ bool EvalSettings::isPseudoUrl(std::string_view s) std::string EvalSettings::resolvePseudoUrl(std::string_view url) { - if (hasPrefix(url, "channel:")) + if (url.starts_with("channel:")) return "https://nixos.org/channels/" + std::string(url.substr(8)) + "/nixexprs.tar.xz"; else return std::string(url); diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 6db1eaffe..7cf33aec4 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -484,7 +484,7 @@ SourcePath EvalState::checkSourcePath(const SourcePath & path_) */ Path abspath = canonPath(path_.path.abs()); - if (hasPrefix(abspath, corepkgsPrefix)) return CanonPath(abspath); + if (abspath.starts_with(corepkgsPrefix)) return CanonPath(abspath); for (auto & i : *allowedPaths) { if (isDirOrInDir(abspath, i)) { @@ -527,18 +527,18 @@ void EvalState::checkURI(const std::string & uri) if (uri == prefix || (uri.size() > prefix.size() && prefix.size() > 0 - && hasPrefix(uri, prefix) + && uri.starts_with(prefix) && (prefix[prefix.size() - 1] == '/' || uri[prefix.size()] == '/'))) return; /* If the URI is a path, then check it against allowedPaths as well. */ - if (hasPrefix(uri, "/")) { + if (uri.starts_with("/")) { checkSourcePath(CanonPath(uri)); return; } - if (hasPrefix(uri, "file://")) { + if (uri.starts_with("file://")) { checkSourcePath(CanonPath(std::string(uri, 7))); return; } @@ -642,7 +642,7 @@ Value * EvalState::addPrimOp(PrimOp && primOp) } auto envName = symbols.create(primOp.name); - if (hasPrefix(primOp.name, "__")) + if (primOp.name.starts_with("__")) primOp.name = primOp.name.substr(2); Value * v = allocValue(); @@ -719,7 +719,7 @@ void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & // for the top level, don't print the double underscore ones; // they are in builtins. for (auto & i : se.vars) - if (!hasPrefix(st[i.first], "__")) + if (!std::string_view(st[i.first]).starts_with("__")) std::cout << st[i.first] << " "; std::cout << ANSI_NORMAL; std::cout << std::endl; @@ -2795,7 +2795,7 @@ SourcePath EvalState::findFile(const SearchPath & searchPath, const std::string_ if (pathExists(res)) return CanonPath(canonPath(res)); } - if (hasPrefix(path, "nix/")) + if (path.starts_with("nix/")) return CanonPath(concatStrings(corepkgsPrefix, path.substr(4))); error<ThrownError>( @@ -2828,7 +2828,7 @@ std::optional<std::string> EvalState::resolveSearchPathPath(const SearchPath::Pa } } - else if (hasPrefix(value, "flake:")) { + else if (value.starts_with("flake:")) { experimentalFeatureSettings.require(Xp::Flakes); auto flakeRef = parseFlakeRef(value.substr(6), {}, true, false); debug("fetching flake search path element '%s''", value); diff --git a/src/libexpr/flake/config.cc b/src/libexpr/flake/config.cc index e89014862..b9613462a 100644 --- a/src/libexpr/flake/config.cc +++ b/src/libexpr/flake/config.cc @@ -35,7 +35,7 @@ void ConfigFile::apply() for (auto & [name, value] : settings) { - auto baseName = hasPrefix(name, "extra-") ? std::string(name, 6) : name; + auto baseName = name.starts_with("extra-") ? std::string(name, 6) : name; // FIXME: Move into libutil/config.cc. std::string valueS; diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc index e1bce90bc..1c90bfc43 100644 --- a/src/libexpr/flake/flakeref.cc +++ b/src/libexpr/flake/flakeref.cc @@ -186,7 +186,7 @@ std::pair<FlakeRef, std::string> parseFlakeRefWithFragment( } } else { - if (!hasPrefix(path, "/")) + if (!path.starts_with("/")) throw BadURL("flake reference '%s' is not an absolute path", url); auto query = decodeQuery(match[2]); path = canonPath(path + "/" + getOr(query, "dir", "")); |