From c32faf3dfadacd9ff225eb23b04c8cb761a02fb7 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sat, 13 Jul 2024 03:12:21 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20gucc:=20use=20std=20ranges=20fro?= =?UTF-8?q?m=20C++23=20in=20pacmanconf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gucc/src/pacmanconf_repo.cpp | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/gucc/src/pacmanconf_repo.cpp b/gucc/src/pacmanconf_repo.cpp index 1e55c97..ef4f4a6 100644 --- a/gucc/src/pacmanconf_repo.cpp +++ b/gucc/src/pacmanconf_repo.cpp @@ -3,32 +3,12 @@ #include "gucc/string_utils.hpp" #include // for ofstream +#include // for ranges::* #include // for string #include // for vector #include -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wold-style-cast" -#elif defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wnull-dereference" -#pragma GCC diagnostic ignored "-Wuseless-cast" -#pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - -#include -#include -#include -#include - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - namespace gucc::detail::pacmanconf { bool push_repos_front(std::string_view file_path, std::string_view value) noexcept { @@ -40,15 +20,15 @@ bool push_repos_front(std::string_view file_path, std::string_view value) noexce auto file_split_view = utils::make_split_view(file_content); // Find the insertion point (using ranges for iteration) - auto insertion_point_it = ranges::find_if( + auto insertion_point_it = std::ranges::find_if( file_split_view, [](auto&& rng) { - auto&& line = std::string_view(&*rng.begin(), static_cast(ranges::distance(rng))); + auto&& line = std::string_view(&*rng.begin(), static_cast(std::ranges::distance(rng))); return !line.empty() && !line.starts_with('#') && line.starts_with('[') && !line.starts_with("[options]"); }); // Handle case where insertion point is not found - if (insertion_point_it == ranges::end(file_split_view)) { + if (insertion_point_it == std::ranges::end(file_split_view)) { // No suitable insertion point found spdlog::error("[PACMANCONFREPO] Could not find a suitable insertion point in {}", file_path); return false; @@ -73,12 +53,12 @@ auto get_repo_list(std::string_view file_path) noexcept -> std::vector(ranges::distance(rng))); + return file_content | std::ranges::views::split('\n') + | std::ranges::views::filter([](auto&& rng) { + auto&& line = std::string_view(&*rng.begin(), static_cast(std::ranges::distance(rng))); return !line.empty() && !line.starts_with('#') && line.starts_with('[') && !line.starts_with("[options]"); }) - | ranges::to>(); + | std::ranges::to>(); } } // namespace gucc::detail::pacmanconf