diff options
author | Jade Lovelace <lix@jade.fyi> | 2024-03-17 19:14:18 -0700 |
---|---|---|
committer | Jade Lovelace <lix@jade.fyi> | 2024-03-17 20:17:19 -0700 |
commit | 61e21b25576f7f3491f6a837bf59d8b44c6897a0 (patch) | |
tree | 3f62d83b3bab84afcf1011b5c2353226b84313b3 /src/nix | |
parent | 706cee5c493b39e25bdb0add55d2e1771dc31696 (diff) |
Delete hasPrefix and hasSuffix from the codebase
These now have equivalents in the standard lib in C++20. This change was
performed with a custom clang-tidy check which I will submit later.
Executed like so:
ninja -C build && run-clang-tidy -checks='-*,nix-*' -load=build/libnix-clang-tidy.so -p .. -fix ../tests | tee -a clang-tidy-result
Change-Id: I62679e315ff9e7ce72a40b91b79c3e9fc01b27e9
Diffstat (limited to 'src/nix')
-rw-r--r-- | src/nix/develop.cc | 2 | ||||
-rw-r--r-- | src/nix/doctor.cc | 2 | ||||
-rw-r--r-- | src/nix/flake.cc | 2 | ||||
-rw-r--r-- | src/nix/prefetch.cc | 2 | ||||
-rw-r--r-- | src/nix/upgrade-nix.cc | 4 |
5 files changed, 6 insertions, 6 deletions
diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 9ecfdef5d..b5543447e 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -448,7 +448,7 @@ struct Common : InstallableCommand, MixProfile StorePath getShellOutPath(ref<Store> store, ref<Installable> installable) { auto path = installable->getStorePath(); - if (path && hasSuffix(path->to_string(), "-env")) + if (path && path->to_string().ends_with("-env")) return *path; else { auto drvs = Installable::toDerivations(store, {installable}); diff --git a/src/nix/doctor.cc b/src/nix/doctor.cc index 1aa6831d3..531f0ad86 100644 --- a/src/nix/doctor.cc +++ b/src/nix/doctor.cc @@ -101,7 +101,7 @@ struct CmdDoctor : StoreCommand try { Path userEnv = canonPath(profileDir, true); - if (store->isStorePath(userEnv) && hasSuffix(userEnv, "user-environment")) { + if (store->isStorePath(userEnv) && userEnv.ends_with("user-environment")) { while (profileDir.find("/profiles/") == std::string::npos && isLink(profileDir)) profileDir = absPath(readLink(profileDir), dirOf(profileDir)); diff --git a/src/nix/flake.cc b/src/nix/flake.cc index bbefff87a..6b3012558 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -334,7 +334,7 @@ struct CmdFlakeCheck : FlakeCommand return name == expected || name == "_" - || (hasPrefix(name, "_") && name.substr(1) == expected); + || (name.starts_with("_") && name.substr(1) == expected); }; auto checkSystemName = [&](const std::string & system, const PosIdx pos) { diff --git a/src/nix/prefetch.cc b/src/nix/prefetch.cc index 9f2d6cc57..0104635fb 100644 --- a/src/nix/prefetch.cc +++ b/src/nix/prefetch.cc @@ -42,7 +42,7 @@ std::string resolveMirrorUrl(EvalState & state, const std::string & url) throw Error("mirror URL '%s' did not expand to anything", url); std::string mirror(state.forceString(*mirrorList->value->listElems()[0], noPos, "while evaluating the first available mirror")); - return mirror + (hasSuffix(mirror, "/") ? "" : "/") + s.substr(p + 1); + return mirror + (mirror.ends_with("/") ? "" : "/") + s.substr(p + 1); } std::tuple<StorePath, Hash> prefetchFile( diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index d238456db..af219c1b9 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -115,7 +115,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand printInfo("found Nix in '%s'", where); - if (hasPrefix(where, "/run/current-system")) + if (where.starts_with("/run/current-system")) throw Error("Nix on NixOS must be upgraded via 'nixos-rebuild'"); Path profileDir = dirOf(where); @@ -129,7 +129,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand Path userEnv = canonPath(profileDir, true); if (baseNameOf(where) != "bin" || - !hasSuffix(userEnv, "user-environment")) + !userEnv.ends_with("user-environment")) throw Error("directory '%s' does not appear to be part of a Nix profile", where); if (!store->isValidPath(store->parseStorePath(userEnv))) |