diff --git a/gucc/include/gucc/string_utils.hpp b/gucc/include/gucc/string_utils.hpp index c678586..7a68166 100644 --- a/gucc/include/gucc/string_utils.hpp +++ b/gucc/include/gucc/string_utils.hpp @@ -2,33 +2,11 @@ #define STRING_UTILS_HPP #include // for transform +#include // for same_as +#include // for ranges::* #include // for string #include // for string_view -#include -#include // for vector - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wold-style-cast" -#pragma clang diagnostic ignored "-Wsign-conversion" -#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 -#include - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#pragma GCC diagnostic pop -#endif +#include // for vector namespace gucc::utils { @@ -65,14 +43,14 @@ auto join(const std::vector& lines, std::string_view delim = "\n") /// @return A range view representing the split lines. constexpr auto make_split_view(std::string_view str, char delim = '\n') noexcept { constexpr auto functor = [](auto&& rng) { - return std::string_view(&*rng.begin(), static_cast(ranges::distance(rng))); + return std::string_view(&*rng.begin(), static_cast(std::ranges::distance(rng))); }; constexpr auto second = [](auto&& rng) { return rng != ""; }; return str - | ranges::views::split(delim) - | ranges::views::transform(functor) - | ranges::views::filter(second); + | std::ranges::views::split(delim) + | std::ranges::views::transform(functor) + | std::ranges::views::filter(second); } template @@ -85,14 +63,14 @@ constexpr auto contains(string_findable auto const& str, std::string_view needle return str.contains(needle); } -template -constexpr auto index_viewable_range(R&& rng, ranges::range_difference_t n) noexcept { - return ranges::next(ranges::begin(rng), n); +template +constexpr auto index_viewable_range(R&& rng, std::ranges::range_difference_t n) noexcept { + return std::ranges::next(std::ranges::begin(rng), n); } -template +template constexpr auto size_viewable_range(R&& rng) noexcept { - return ranges::distance(ranges::begin(rng), ranges::end(rng)); + return std::ranges::distance(std::ranges::begin(rng), std::ranges::end(rng)); } } // namespace gucc::utils diff --git a/gucc/src/string_utils.cpp b/gucc/src/string_utils.cpp index e5188db..d8b71f2 100644 --- a/gucc/src/string_utils.cpp +++ b/gucc/src/string_utils.cpp @@ -1,46 +1,27 @@ #include "gucc/string_utils.hpp" -#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 "-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::utils { auto make_multiline(std::string_view str, bool reverse, char delim) noexcept -> std::vector { std::vector lines{}; - ranges::for_each(utils::make_split_view(str, delim), [&](auto&& rng) { lines.emplace_back(rng); }); + std::ranges::for_each(utils::make_split_view(str, delim), [&](auto&& rng) { lines.emplace_back(rng); }); if (reverse) { - ranges::reverse(lines); + std::ranges::reverse(lines); } return lines; } auto make_multiline_view(std::string_view str, bool reverse, char delim) noexcept -> std::vector { std::vector lines{}; - ranges::for_each(utils::make_split_view(str, delim), [&](auto&& rng) { lines.emplace_back(rng); }); + std::ranges::for_each(utils::make_split_view(str, delim), [&](auto&& rng) { lines.emplace_back(rng); }); if (reverse) { - ranges::reverse(lines); + std::ranges::reverse(lines); } return lines; } auto make_multiline(const std::vector& multiline, bool reverse, std::string_view delim) noexcept -> std::string { + // TODO(vnepogodin): refactor with our join std::string res{}; for (const auto& line : multiline) { res += line; @@ -48,14 +29,14 @@ auto make_multiline(const std::vector& multiline, bool reverse, std } if (reverse) { - ranges::reverse(res); + std::ranges::reverse(res); } return res; } auto join(const std::vector& lines, std::string_view delim) noexcept -> std::string { - return lines | ranges::views::join(delim) | ranges::to(); + return lines | std::ranges::views::join_with(delim) | std::ranges::to(); } } // namespace gucc::utils