aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd
diff options
context:
space:
mode:
authorJade Lovelace <lix@jade.fyi>2024-03-17 19:14:18 -0700
committerJade Lovelace <lix@jade.fyi>2024-03-17 20:17:19 -0700
commit61e21b25576f7f3491f6a837bf59d8b44c6897a0 (patch)
tree3f62d83b3bab84afcf1011b5c2353226b84313b3 /src/libcmd
parent706cee5c493b39e25bdb0add55d2e1771dc31696 (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/libcmd')
-rw-r--r--src/libcmd/common-eval-args.cc2
-rw-r--r--src/libcmd/installables.cc12
-rw-r--r--src/libcmd/repl.cc2
3 files changed, 8 insertions, 8 deletions
diff --git a/src/libcmd/common-eval-args.cc b/src/libcmd/common-eval-args.cc
index e36bda52f..07161cba9 100644
--- a/src/libcmd/common-eval-args.cc
+++ b/src/libcmd/common-eval-args.cc
@@ -172,7 +172,7 @@ SourcePath lookupFileArg(EvalState & state, std::string_view s)
return state.rootPath(CanonPath(state.store->toRealPath(storePath)));
}
- else if (hasPrefix(s, "flake:")) {
+ else if (s.starts_with("flake:")) {
experimentalFeatureSettings.require(Xp::Flakes);
auto flakeRef = parseFlakeRef(std::string(s.substr(6)), {}, true, false);
auto storePath = flakeRef.resolve(state.store).fetchTree(state.store).first.storePath;
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
index f40136411..973db62b0 100644
--- a/src/libcmd/installables.cc
+++ b/src/libcmd/installables.cc
@@ -159,7 +159,7 @@ void MixFlakeOptions::completeFlakeInput(std::string_view prefix)
auto flakeRef = parseFlakeRefWithFragment(expandTilde(flakeRefS), absPath(".")).first;
auto flake = flake::getFlake(*evalState, flakeRef, true);
for (auto & input : flake.inputs)
- if (hasPrefix(input.first, prefix))
+ if (input.first.starts_with(prefix))
completions->add(input.first);
}
}
@@ -320,7 +320,7 @@ void completeFlakeRefWithFragment(
auto attrPath = parseAttrPath(*evalState, attrPathS);
std::string lastAttr;
- if (!attrPath.empty() && !hasSuffix(attrPathS, ".")) {
+ if (!attrPath.empty() && !attrPathS.ends_with(".")) {
lastAttr = evalState->symbols[attrPath.back()];
attrPath.pop_back();
}
@@ -329,7 +329,7 @@ void completeFlakeRefWithFragment(
if (!attr) continue;
for (auto & attr2 : (*attr)->getAttrs()) {
- if (hasPrefix(evalState->symbols[attr2], lastAttr)) {
+ if (std::string_view(evalState->symbols[attr2]).starts_with(lastAttr)) {
auto attrPath2 = (*attr)->getAttrPath(attr2);
/* Strip the attrpath prefix. */
attrPath2.erase(attrPath2.begin(), attrPath2.begin() + attrPathPrefix.size());
@@ -367,12 +367,12 @@ void completeFlakeRef(ref<Store> store, std::string_view prefix)
for (auto & registry : fetchers::getRegistries(store)) {
for (auto & entry : registry->entries) {
auto from = entry.from.to_string();
- if (!hasPrefix(prefix, "flake:") && hasPrefix(from, "flake:")) {
+ if (!prefix.starts_with("flake:") && from.starts_with("flake:")) {
std::string from2(from, 6);
- if (hasPrefix(from2, prefix))
+ if (from2.starts_with(prefix))
completions->add(from2);
} else {
- if (hasPrefix(from, prefix))
+ if (from.starts_with(prefix))
completions->add(from);
}
}
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc
index 9e5599152..f5738963e 100644
--- a/src/libcmd/repl.cc
+++ b/src/libcmd/repl.cc
@@ -272,7 +272,7 @@ StringSet NixRepl::completePrefix(const std::string & prefix)
auto dir = std::string(cur, 0, slash);
auto prefix2 = std::string(cur, slash + 1);
for (auto & entry : readDirectory(dir == "" ? "/" : dir)) {
- if (entry.name[0] != '.' && hasPrefix(entry.name, prefix2))
+ if (entry.name[0] != '.' && entry.name.starts_with(prefix2))
completions.insert(prev + dir + "/" + entry.name);
}
} catch (Error &) {