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/libfetchers | |
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/libfetchers')
-rw-r--r-- | src/libfetchers/git.cc | 6 | ||||
-rw-r--r-- | src/libfetchers/mercurial.cc | 4 | ||||
-rw-r--r-- | src/libfetchers/registry.cc | 2 | ||||
-rw-r--r-- | src/libfetchers/tarball.cc | 8 |
4 files changed, 10 insertions, 10 deletions
diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 1689155b3..48e1bd6e3 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -223,7 +223,7 @@ std::pair<StorePath, Input> fetchFromWorkdir(ref<Store> store, Input & input, co Path actualPath(absPath(workdir)); PathFilter filter = [&](const Path & p) -> bool { - assert(hasPrefix(p, actualPath)); + assert(p.starts_with(actualPath)); std::string file(p, actualPath.size() + 1); auto st = lstat(p); @@ -231,7 +231,7 @@ std::pair<StorePath, Input> fetchFromWorkdir(ref<Store> store, Input & input, co if (S_ISDIR(st.st_mode)) { auto prefix = file + "/"; auto i = files.lower_bound(prefix); - return i != files.end() && hasPrefix(*i, prefix); + return i != files.end() && (*i).starts_with(prefix); } return files.count(file); @@ -267,7 +267,7 @@ struct GitInputScheme : InputScheme url.scheme != "git+file") return {}; auto url2(url); - if (hasPrefix(url2.scheme, "git+")) url2.scheme = std::string(url2.scheme, 4); + if (url2.scheme.starts_with("git+")) url2.scheme = std::string(url2.scheme, 4); url2.query.clear(); Attrs attrs; diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index 51fd1ed42..a70403660 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -181,7 +181,7 @@ struct MercurialInputScheme : InputScheme Path actualPath(absPath(actualUrl)); PathFilter filter = [&](const Path & p) -> bool { - assert(hasPrefix(p, actualPath)); + assert(p.starts_with(actualPath)); std::string file(p, actualPath.size() + 1); auto st = lstat(p); @@ -189,7 +189,7 @@ struct MercurialInputScheme : InputScheme if (S_ISDIR(st.st_mode)) { auto prefix = file + "/"; auto i = files.lower_bound(prefix); - return i != files.end() && hasPrefix(*i, prefix); + return i != files.end() && (*i).starts_with(prefix); } return files.count(file); diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc index 43c03beec..da92273d6 100644 --- a/src/libfetchers/registry.cc +++ b/src/libfetchers/registry.cc @@ -157,7 +157,7 @@ static std::shared_ptr<Registry> getGlobalRegistry(ref<Store> store) return std::make_shared<Registry>(Registry::Global); // empty registry } - if (!hasPrefix(path, "/")) { + if (!path.starts_with("/")) { auto storePath = downloadFile(store, path, "flake-registry.json", false).storePath; if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>()) store2->addPermRoot(storePath, getCacheDir() + "/nix/flake-registry.json"); diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index e3a41e75e..68cb0ca40 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -188,10 +188,10 @@ struct CurlInputScheme : InputScheme const bool hasTarballExtension(std::string_view path) const { - return hasSuffix(path, ".zip") || hasSuffix(path, ".tar") - || hasSuffix(path, ".tgz") || hasSuffix(path, ".tar.gz") - || hasSuffix(path, ".tar.xz") || hasSuffix(path, ".tar.bz2") - || hasSuffix(path, ".tar.zst"); + return path.ends_with(".zip") || path.ends_with(".tar") + || path.ends_with(".tgz") || path.ends_with(".tar.gz") + || path.ends_with(".tar.xz") || path.ends_with(".tar.bz2") + || path.ends_with(".tar.zst"); } virtual bool isValidURL(const ParsedURL & url, bool requireTree) const = 0; |