Skip to content

Commit

Permalink
Make find_slash_and_platform private
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Oct 12, 2023
1 parent c6cde29 commit 9dbf9d9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
7 changes: 0 additions & 7 deletions libmamba/include/mamba/specs/conda_url.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,5 @@ namespace mamba::specs
/** A functional equivalent to ``CondaURL::append_path``. */
auto operator/(const CondaURL& url, std::string_view subpath) -> CondaURL;
auto operator/(CondaURL&& url, std::string_view subpath) -> CondaURL;

namespace detail
{
/** Find the location of "/os-arch"-like subsring. */
[[nodiscard]] auto find_slash_and_platform(std::string_view path)
-> std::tuple<std::size_t, std::size_t, std::optional<Platform>>;
}
}
#endif
12 changes: 10 additions & 2 deletions libmamba/src/specs/channel_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@
//
// The full license is in the file LICENSE, distributed with this software.

#include <optional>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>

#include <fmt/format.h>

#include "mamba/fs/filesystem.hpp"
#include "mamba/specs/archive.hpp"
#include "mamba/specs/channel_spec.hpp"
#include "mamba/specs/conda_url.hpp"
#include "mamba/specs/platform.hpp"
#include "mamba/util/path_manip.hpp"
#include "mamba/util/string.hpp"
#include "mamba/util/url_manip.hpp"

namespace mamba::specs
{
// Defined in conda_url.cpp
[[nodiscard]] auto find_slash_and_platform(std::string_view path)
-> std::tuple<std::size_t, std::size_t, std::optional<Platform>>;

namespace
{
using dynamic_platform_set = ChannelSpec::dynamic_platform_set;
Expand Down Expand Up @@ -45,7 +53,7 @@ namespace mamba::specs
{
static constexpr auto npos = std::string_view::npos;

auto [start, len, plat] = detail::find_slash_and_platform(str);
auto [start, len, plat] = find_slash_and_platform(str);
if (plat.has_value())
{
const auto end = (len == npos) ? str.size() : start + len;
Expand Down
60 changes: 31 additions & 29 deletions libmamba/src/specs/conda_url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@

namespace mamba::specs
{
/**
* Find the location of "/os-arch"-like subsring.
*
* Not a static function, it is needed in "channel_spec.cpp".
*/
auto find_slash_and_platform(std::string_view path)
-> std::tuple<std::size_t, std::size_t, std::optional<Platform>>
{
static constexpr auto npos = std::string_view::npos;

auto start = std::size_t(0);
auto end = path.find('/', start + 1);
while (start != npos)
{
assert(start < end);
const auto count = (end == npos) ? npos : end - start;
const auto count_minus_1 = (end == npos) ? npos : end - start - 1;
if (auto plat = platform_parse(path.substr(start + 1, count_minus_1)))
{
return { start, count, plat };
}
start = end;
end = path.find('/', start + 1);
}
return { npos, 0, std::nullopt };
}

namespace
{
[[nodiscard]] auto is_token_char(char c) -> bool
Expand Down Expand Up @@ -229,7 +256,7 @@ namespace mamba::specs
{
const auto& l_path = path(Decode::no);
assert(!l_path.empty() && (l_path.front() == '/'));
const auto [pos, count, plat] = detail::find_slash_and_platform(l_path);
const auto [pos, count, plat] = find_slash_and_platform(l_path);
return plat;
}

Expand All @@ -239,7 +266,7 @@ namespace mamba::specs

const auto& l_path = path(Decode::no);
assert(!l_path.empty() && (l_path.front() == '/'));
const auto [pos, len, plat] = detail::find_slash_and_platform(l_path);
const auto [pos, len, plat] = find_slash_and_platform(l_path);
if (!plat.has_value())
{
return "";
Expand All @@ -254,7 +281,7 @@ namespace mamba::specs
static constexpr auto npos = std::string_view::npos;

assert(!path(Decode::no).empty() && (path(Decode::no).front() == '/'));
const auto [pos, len, plat] = detail::find_slash_and_platform(path(Decode::no));
const auto [pos, len, plat] = find_slash_and_platform(path(Decode::no));
if (!plat.has_value())
{
throw std::invalid_argument(
Expand Down Expand Up @@ -285,7 +312,7 @@ namespace mamba::specs
auto CondaURL::clear_platform() -> bool
{
assert(!path(Decode::no).empty() && (path(Decode::no).front() == '/'));
const auto [pos, count, plat] = detail::find_slash_and_platform(path(Decode::no));
const auto [pos, count, plat] = find_slash_and_platform(path(Decode::no));
if (!plat.has_value())
{
return false;
Expand Down Expand Up @@ -482,29 +509,4 @@ namespace mamba::specs
url.append_path(subpath);
return std::move(url);
}

namespace detail
{
auto find_slash_and_platform(std::string_view path)
-> std::tuple<std::size_t, std::size_t, std::optional<Platform>>
{
static constexpr auto npos = std::string_view::npos;

auto start = std::size_t(0);
auto end = path.find('/', start + 1);
while (start != npos)
{
assert(start < end);
const auto count = (end == npos) ? npos : end - start;
const auto count_minus_1 = (end == npos) ? npos : end - start - 1;
if (auto plat = platform_parse(path.substr(start + 1, count_minus_1)))
{
return { start, count, plat };
}
start = end;
end = path.find('/', start + 1);
}
return { npos, 0, std::nullopt };
}
}
}

0 comments on commit 9dbf9d9

Please sign in to comment.