// Copyright (c) 2023, QuantStack and Mamba Contributors // // Distributed under the terms of the BSD 3-Clause License. // // The full license is in the file LICENSE, distributed with this software. #ifndef MAMBA_SPECS_ARCHIVE_HPP #define MAMBA_SPECS_ARCHIVE_HPP #include #include #include #include "mamba/core/mamba_fs.hpp" namespace mamba::specs { inline static constexpr auto ARCHIVE_EXTENSIONS = std::array{ std::string_view(".tar.bz2"), std::string_view(".conda"), }; /** Detect if the package path has one of the known archive extension. */ template , bool> = true> [[nodiscard]] auto has_archive_extension(const Str& path) -> bool; [[nodiscard]] auto has_archive_extension(std::string_view path) -> bool; [[nodiscard]] auto has_archive_extension(const fs::u8path& path) -> bool; /** Remove the known archive extension from the package path if present. */ template , bool> = true> [[nodiscard]] auto strip_archive_extension(const Str& path) -> std::string_view; [[nodiscard]] auto strip_archive_extension(std::string_view path) -> std::string_view; [[nodiscard]] auto strip_archive_extension(fs::u8path path) -> fs::u8path; /******************** * Implementation * ********************/ template , bool>> [[nodiscard]] auto has_archive_extension(const Str& path) -> bool { return has_archive_extension(std::string_view(path)); } template , bool>> [[nodiscard]] auto strip_archive_extension(const Str& path) -> std::string_view { return strip_archive_extension(std::string_view(path)); } } #endif