Move util_string to utility library (#2739)

This commit is contained in:
Antoine Prouvost 2023-08-11 13:32:15 +02:00 committed by GitHub
parent 3e4b1dab0c
commit 03e34174dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
62 changed files with 508 additions and 472 deletions

View File

@ -118,6 +118,8 @@ endforeach()
set(LIBMAMBA_SOURCES
longpath.manifest
${LIBMAMBA_SOURCE_DIR}/version.cpp
# C++ utility library
${LIBMAMBA_SOURCE_DIR}/util/string.cpp
# C++ wrapping of libsolv
${LIBMAMBA_SOURCE_DIR}/solv-cpp/queue.cpp
${LIBMAMBA_SOURCE_DIR}/solv-cpp/pool.cpp
@ -172,7 +174,6 @@ set(LIBMAMBA_SOURCES
${LIBMAMBA_SOURCE_DIR}/core/package_download.cpp
${LIBMAMBA_SOURCE_DIR}/core/util.cpp
${LIBMAMBA_SOURCE_DIR}/core/fsutil.cpp
${LIBMAMBA_SOURCE_DIR}/core/util_string.cpp
${LIBMAMBA_SOURCE_DIR}/core/util_os.cpp
${LIBMAMBA_SOURCE_DIR}/core/validate.cpp
${LIBMAMBA_SOURCE_DIR}/core/virtual_packages.cpp
@ -213,6 +214,7 @@ set(LIBMAMBA_PUBLIC_HEADERS
${LIBMAMBA_INCLUDE_DIR}/mamba/util/flat_bool_expr_tree.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/graph.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/iterator.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/util/string.hpp
# Implementation of version and matching specs
${LIBMAMBA_INCLUDE_DIR}/mamba/specs/platform.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/specs/version.hpp
@ -259,7 +261,6 @@ set(LIBMAMBA_PUBLIC_HEADERS
${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_os.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_random.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_scope.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_string.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/validate.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/virtual_packages.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/env_lockfile.hpp

View File

@ -10,10 +10,6 @@
#include <string>
#include <vector>
#include "mamba/core/mamba_fs.hpp"
#include "mamba/core/util_string.hpp"
namespace mamba
{
class ChannelContext;

View File

@ -22,7 +22,7 @@
#include "mamba/util/compare.hpp"
namespace mamba
namespace mamba::util
{
/**
* Return the string if the pointer is not null, otherwise a pointer to an empty string.

View File

@ -11,7 +11,7 @@
#include "mamba/core/repo.hpp"
#include "mamba/core/subdirdata.hpp"
#include "mamba/core/thread_utils.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -153,7 +153,7 @@ namespace mamba
auto& subdir = subdirs[i];
if (!subdir.loaded())
{
if (!ctx.offline && ends_with(subdir.name(), "/noarch"))
if (!ctx.offline && util::ends_with(subdir.name(), "/noarch"))
{
error_list.push_back(mamba_error(
"Subdir " + subdir.name() + " not loaded!",

View File

@ -12,7 +12,7 @@
#include "mamba/core/mamba_fs.hpp"
#include "mamba/core/package_cache.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#include "../core/progress_bar_impl.hpp"
@ -75,9 +75,9 @@ namespace mamba
{
for (auto& p : fs::directory_iterator(pkg_cache->path()))
{
if (p.exists() && ends_with(p.path().string(), ".lock")
&& (fs::exists(rstrip(p.path().string(), ".lock"))
|| (rstrip(p.path().filename().string(), ".lock")
if (p.exists() && util::ends_with(p.path().string(), ".lock")
&& (fs::exists(util::rstrip(p.path().string(), ".lock"))
|| (util::rstrip(p.path().filename().string(), ".lock")
== p.path().parent_path().filename())))
{
try
@ -98,7 +98,7 @@ namespace mamba
{
for (auto& p : fs::recursive_directory_iterator(pkg_cache->path() / "cache"))
{
if (p.exists() && ends_with(p.path().string(), ".lock"))
if (p.exists() && util::ends_with(p.path().string(), ".lock"))
{
try
{
@ -145,7 +145,7 @@ namespace mamba
{
for (auto& pkg : fs::directory_iterator(env / "conda-meta"))
{
if (ends_with(pkg.path().string(), ".json"))
if (util::ends_with(pkg.path().string(), ".json"))
{
std::string pkg_name = pkg.path().filename().string();
installed_pkgs.insert(pkg_name.substr(0, pkg_name.size() - 5));
@ -171,14 +171,17 @@ namespace mamba
for (auto* pkg_cache : caches.writable_caches())
{
std::string header_line = concat("Package cache folder: ", pkg_cache->path().string());
std::string header_line = util::concat(
"Package cache folder: ",
pkg_cache->path().string()
);
std::vector<std::vector<printers::FormattedString>> rows;
for (auto& p : fs::directory_iterator(pkg_cache->path()))
{
std::string fname = p.path().filename().string();
if (!p.is_directory()
&& (ends_with(p.path().string(), ".tar.bz2")
|| ends_with(p.path().string(), ".conda")))
&& (util::ends_with(p.path().string(), ".tar.bz2")
|| util::ends_with(p.path().string(), ".conda")))
{
res.push_back(p.path());
rows.push_back({ p.path().filename().string(), get_file_size(p.file_size()) });
@ -245,7 +248,10 @@ namespace mamba
for (auto* pkg_cache : caches.writable_caches())
{
std::string header_line = concat("Package cache folder: ", pkg_cache->path().string());
std::string header_line = util::concat(
"Package cache folder: ",
pkg_cache->path().string()
);
std::vector<std::vector<printers::FormattedString>> rows;
for (auto& p : fs::directory_iterator(pkg_cache->path()))
{

View File

@ -14,12 +14,12 @@
#include <spdlog/spdlog.h>
#include "mamba/api/configuration.hpp"
#include "mamba/api/info.hpp"
#include "mamba/api/install.hpp"
#include "mamba/core/environment.hpp"
#include "mamba/core/fsutil.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/package_download.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -199,7 +199,7 @@ namespace mamba
{
if (names.empty())
{
p_impl->m_env_var_names = { "MAMBA_" + to_upper(p_impl->m_name) };
p_impl->m_env_var_names = { "MAMBA_" + util::to_upper(p_impl->m_name) };
}
else
{
@ -575,7 +575,7 @@ namespace mamba
#endif
if (!prefix.empty())
{
prefix = rstrip(fs::weakly_canonical(env::expand_user(prefix)).string(), sep);
prefix = util::rstrip(fs::weakly_canonical(env::expand_user(prefix)).string(), sep);
}
if ((prefix == root_prefix) && config.at("create_base").value<bool>())
@ -929,7 +929,8 @@ namespace mamba
{
const auto filename = fs::u8path(file).filename();
return filename == ".condarc" || filename == "condarc" || filename == ".mambarc"
|| filename == "mambarc" || ends_with(file, ".yml") || ends_with(file, ".yaml");
|| filename == "mambarc" || util::ends_with(file, ".yml")
|| util::ends_with(file, ".yaml");
}
bool is_config_file(const fs::u8path& path)
@ -1928,7 +1929,7 @@ namespace mamba
{
if (at(n).locked())
{
LOG_ERROR << "Circular import: " << join("->", locks) << "->" << n;
LOG_ERROR << "Circular import: " << util::join("->", locks) << "->" << n;
throw std::runtime_error("Circular import detected in configuration. Aborting.");
}
add_to_loading_sequence(seq, n, locks);

View File

@ -9,8 +9,8 @@
#include "mamba/core/channel.hpp"
#include "mamba/core/context.hpp"
#include "mamba/core/environment.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/virtual_packages.hpp"
#include "mamba/util/string.hpp"
extern "C"
@ -149,7 +149,8 @@ namespace mamba
std::vector<std::string> virtual_pkgs;
for (auto pkg : get_virtual_packages())
{
virtual_pkgs.push_back(concat(pkg.name, "=", pkg.version, "=", pkg.build_string));
virtual_pkgs.push_back(util::concat(pkg.name, "=", pkg.version, "=", pkg.build_string)
);
}
items.push_back({ "virtual packages", virtual_pkgs });

View File

@ -25,8 +25,8 @@
#include "mamba/core/package_cache.hpp"
#include "mamba/core/pinning.hpp"
#include "mamba/core/transaction.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/core/virtual_packages.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -173,18 +173,18 @@ namespace mamba
};
const auto& ctx = Context::instance();
if (starts_with(ctx.platform, "win"))
if (util::starts_with(ctx.platform, "win"))
{
vals["win"] = true;
}
else
{
vals["unix"] = true;
if (starts_with(ctx.platform, "linux"))
if (util::starts_with(ctx.platform, "linux"))
{
vals["linux"] = true;
}
else if (starts_with(ctx.platform, "osx"))
else if (util::starts_with(ctx.platform, "osx"))
{
vals["osx"] = true;
}
@ -196,7 +196,7 @@ namespace mamba
{
bool eval_selector(const std::string& selector)
{
if (!(starts_with(selector, "sel(") && selector[selector.size() - 1] == ')'))
if (!(util::starts_with(selector, "sel(") && selector[selector.size() - 1] == ')'))
{
throw std::runtime_error(
"Couldn't parse selector. Needs to start with sel( and end with )"
@ -260,7 +260,7 @@ namespace mamba
for (const auto& map_el : *it)
{
std::string key = map_el.first.as<std::string>();
if (starts_with(key, "sel("))
if (util::starts_with(key, "sel("))
{
bool selected = detail::eval_selector(key);
if (selected)
@ -346,7 +346,7 @@ namespace mamba
std::vector<MatchSpec> ms_result;
for (auto& u : urls)
{
if (strip(u).size() == 0)
if (util::strip(u).size() == 0)
{
continue;
}
@ -546,7 +546,7 @@ namespace mamba
{
pinned_str.push_back(" - " + ms.conda_build_form() + "\n");
}
Console::instance().print("\nPinned packages:\n" + join("", pinned_str));
Console::instance().print("\nPinned packages:\n" + util::join("", pinned_str));
}
// FRAGILE this must be called after pins be before jobs in current ``MPool``
@ -750,7 +750,7 @@ namespace mamba
{
detail::create_target_directory(prefix);
Console::instance().print(join(
Console::instance().print(util::join(
"",
std::vector<std::string>({ "Empty environment created at prefix: ", prefix.string() })
));
@ -791,7 +791,7 @@ namespace mamba
// read specs from file :)
if (is_env_lockfile_name(file))
{
if (starts_with(file, "http"))
if (util::starts_with(file, "http"))
{
Context::instance().env_lockfile = file;
}
@ -846,12 +846,12 @@ namespace mamba
const std::vector<std::string> file_contents = read_lines(file);
if (file_contents.size() == 0)
{
throw std::runtime_error(concat("Got an empty file: ", file));
throw std::runtime_error(util::concat("Got an empty file: ", file));
}
for (std::size_t i = 0; i < file_contents.size(); ++i)
{
auto& line = file_contents[i];
if (starts_with(line, "@EXPLICIT"))
if (util::starts_with(line, "@EXPLICIT"))
{
// this is an explicit env
// we can check if the platform is correct with the previous line
@ -861,7 +861,7 @@ namespace mamba
for (std::size_t j = 0; j < i; ++j)
{
platform = file_contents[j];
if (starts_with(platform, "# platform: "))
if (util::starts_with(platform, "# platform: "))
{
platform = platform.substr(12);
break;
@ -875,7 +875,7 @@ namespace mamba
f != file_contents.end();
++f)
{
std::string_view spec = strip((*f));
std::string_view spec = util::strip((*f));
if (!spec.empty() && spec[0] != '#')
{
explicit_specs.push_back(*f);

View File

@ -13,7 +13,7 @@
#include "mamba/core/package_cache.hpp"
#include "mamba/core/prefix_data.hpp"
#include "mamba/core/repo.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -144,7 +144,7 @@ namespace mamba
case QueryResultFormat::kRECURSIVETABLE:
res.sort("name").table(
std::cout,
{ "Name", "Version", "Build", concat("Depends:", query), "Channel" }
{ "Name", "Version", "Build", util::concat("Depends:", query), "Channel" }
);
}
if (res.empty() && format != QueryResultFormat::kJSON)

View File

@ -11,8 +11,8 @@
#include "mamba/core/context.hpp"
#include "mamba/core/pinning.hpp"
#include "mamba/core/transaction.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/core/virtual_packages.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -103,7 +103,7 @@ namespace mamba
{
pinned_str.push_back(" - " + ms.conda_build_form() + "\n");
}
Console::instance().print("\nPinned packages:\n" + join("", pinned_str));
Console::instance().print("\nPinned packages:\n" + util::join("", pinned_str));
}
// FRAGILE this must be called after pins be before jobs in current ``MPool``

View File

@ -10,7 +10,7 @@
#include "mamba/core/output.hpp"
#include "mamba/core/shell_init.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -84,7 +84,7 @@ namespace mamba
fin >> j;
for (auto it = j.begin(); it != j.end(); ++it)
{
env_vars[to_upper(it.key())] = it.value();
env_vars[util::to_upper(it.key())] = it.value();
}
}
catch (nlohmann::json::exception& error)
@ -113,7 +113,7 @@ namespace mamba
<< "will overwrite those from packages";
LOG_WARNING << "Variable " << it.key() << " duplicated";
}
env_vars[to_upper(it.key())] = it.value();
env_vars[util::to_upper(it.key())] = it.value();
}
}
}
@ -190,13 +190,13 @@ namespace mamba
// TODO there may be more missing here.
}
auto conda_stacked_env = join(";", prompt_stack);
auto conda_stacked_env = util::join(";", prompt_stack);
std::string prompt = Context::instance().env_prompt;
replace_all(prompt, "{default_env}", conda_default_env);
replace_all(prompt, "{stacked_env}", conda_stacked_env);
replace_all(prompt, "{prefix}", prefix.string());
replace_all(prompt, "{name}", prefix.stem().string());
util::replace_all(prompt, "{default_env}", conda_default_env);
util::replace_all(prompt, "{stacked_env}", conda_stacked_env);
util::replace_all(prompt, "{prefix}", prefix.string());
util::replace_all(prompt, "{name}", prefix.stem().string());
return prompt;
}
else
@ -239,7 +239,7 @@ namespace mamba
std::vector<fs::u8path> path;
if (m_env.find("PATH") != m_env.end())
{
auto strings = split(m_env["PATH"], env::pathsep());
auto strings = util::split(m_env["PATH"], env::pathsep());
for (auto& s : strings)
{
path.push_back(s);
@ -280,7 +280,7 @@ namespace mamba
bool no_condabin = std::none_of(
path_list.begin(),
path_list.end(),
[](const fs::u8path& s) { return ends_with(s.string(), "condabin"); }
[](const fs::u8path& s) { return util::ends_with(s.string(), "condabin"); }
);
if (no_condabin)
{
@ -295,7 +295,7 @@ namespace mamba
final_path.insert(final_path.end(), path_list.begin(), path_list.end());
final_path.erase(std::unique(final_path.begin(), final_path.end()), final_path.end());
std::string result = join(env::pathsep(), final_path).string();
std::string result = util::join(env::pathsep(), final_path).string();
return result;
}
@ -338,7 +338,7 @@ namespace mamba
// remove duplicates
final_path.erase(std::unique(final_path.begin(), final_path.end()), final_path.end());
std::string result = join(env::pathsep(), final_path).string();
std::string result = util::join(env::pathsep(), final_path).string();
return result;
}
else
@ -347,7 +347,7 @@ namespace mamba
std::unique(current_path.begin(), current_path.end()),
current_path.end()
);
std::string result = join(env::pathsep(), current_path).string();
std::string result = util::join(env::pathsep(), current_path).string();
return result;
}
}
@ -373,11 +373,11 @@ namespace mamba
{
if (v == "")
{
envt.unset_vars.push_back(to_upper(k));
envt.unset_vars.push_back(util::to_upper(k));
}
else
{
envt.export_vars.push_back({ to_upper(k), v });
envt.export_vars.push_back({ util::to_upper(k), v });
}
}
}
@ -387,7 +387,7 @@ namespace mamba
int conda_shlvl = 0;
if (m_env.find("CONDA_SHLVL") != m_env.end())
{
std::string env_shlvl(strip(m_env["CONDA_SHLVL"]));
std::string env_shlvl(util::strip(m_env["CONDA_SHLVL"]));
conda_shlvl = std::stoi(env_shlvl);
}
@ -555,7 +555,7 @@ namespace mamba
int old_conda_shlvl = 0, new_conda_shlvl;
if (m_env.find("CONDA_SHLVL") != m_env.end())
{
std::string env_shlvl(strip(m_env["CONDA_SHLVL"]));
std::string env_shlvl(util::strip(m_env["CONDA_SHLVL"]));
old_conda_shlvl = std::stoi(env_shlvl);
}
if (m_env.find("CONDA_PREFIX") != m_env.end())
@ -616,7 +616,7 @@ namespace mamba
if (clobbering_env_vars.size())
{
LOG_WARNING << "WARNING: overwriting environment variables set in the machine";
LOG_WARNING << "Overwriting variables: " << join(",", clobbering_env_vars);
LOG_WARNING << "Overwriting variables: " << util::join(",", clobbering_env_vars);
}
std::string new_path = add_prefix_to_path(prefix, old_conda_shlvl);
@ -816,12 +816,12 @@ namespace mamba
auto current_prompt_modifier = env::get("CONDA_PROMPT_MODIFIER");
if (current_prompt_modifier)
{
replace_all(ps1, current_prompt_modifier.value(), "");
util::replace_all(ps1, current_prompt_modifier.value(), "");
}
// Because we're using single-quotes to set shell variables, we need to handle
// the proper escaping of single quotes that are already part of the string.
// Best solution appears to be https://stackoverflow.com/a/1250279
replace_all(ps1, "'", "'\"'\"'");
util::replace_all(ps1, "'", "'\"'\"'");
return { "PS1", conda_prompt_modifier + ps1 };
}
@ -929,12 +929,12 @@ namespace mamba
auto current_prompt_modifier = env::get("CONDA_PROMPT_MODIFIER");
if (current_prompt_modifier)
{
replace_all(prompt, current_prompt_modifier.value(), "");
util::replace_all(prompt, current_prompt_modifier.value(), "");
}
// Because we're using single-quotes to set shell variables, we need to handle
// the proper escaping of single quotes that are already part of the string.
// Best solution appears to be https://stackoverflow.com/a/1250279
replace_all(prompt, "'", "'\"'\"'");
util::replace_all(prompt, "'", "'\"'\"'");
return { "prompt", conda_prompt_modifier + prompt };
}

View File

@ -16,12 +16,11 @@
#include "mamba/core/channel.hpp"
#include "mamba/core/context.hpp"
#include "mamba/core/environment.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/package_cache.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/core/validate.hpp"
#include "mamba/util/string.hpp"
namespace mamba
@ -77,7 +76,7 @@ namespace mamba
if (extension != "")
{
auto sp = rsplit(cleaned_url, "/", 1);
auto sp = util::rsplit(cleaned_url, "/", 1);
cleaned_url = sp[0];
package_name = sp[1] + extension;
}
@ -127,7 +126,7 @@ namespace mamba
const std::string& path
)
{
std::string spath = std::string(rstrip(path, "/"));
std::string spath = std::string(util::rstrip(path, "/"));
std::string url = URLHandler()
.set_scheme(scheme)
.set_host(host)
@ -140,7 +139,13 @@ namespace mamba
{
URLHandler handler;
handler.set_host(host).set_port(port);
return channel_configuration(std::string(rstrip(handler.url(), "/")), "", scheme, "", "");
return channel_configuration(
std::string(util::rstrip(handler.url(), "/")),
"",
scheme,
"",
""
);
}
// Case 2: migrated_custom_channels not implemented yet
@ -152,9 +157,9 @@ namespace mamba
{
const Channel& channel = ca.second;
std::string test_url = join_url(channel.location(), channel.name());
if (vector_is_prefix(split(test_url, "/"), split(url, "/")))
if (vector_is_prefix(util::split(test_url, "/"), util::split(url, "/")))
{
auto subname = std::string(strip(url.replace(0u, test_url.size(), ""), "/"));
auto subname = std::string(util::strip(url.replace(0u, test_url.size(), ""), "/"));
return channel_configuration(
channel.location(),
@ -168,9 +173,9 @@ namespace mamba
// Case 5: channel_alias match
const Channel& ca = channel_context.get_channel_alias();
if (ca.location() != "" && starts_with(url, ca.location()))
if (ca.location() != "" && util::starts_with(url, ca.location()))
{
auto name = std::string(strip(url.replace(0u, ca.location().size(), ""), "/"));
auto name = std::string(util::strip(url.replace(0u, ca.location().size(), ""), "/"));
return channel_configuration(
ca.location(),
name,
@ -183,14 +188,14 @@ namespace mamba
// Case 6: not-otherwise-specified file://-type urls
if (host == "")
{
auto sp = rsplit(url, "/", 1);
auto sp = util::rsplit(url, "/", 1);
return channel_configuration(sp[0].size() ? sp[0] : "/", sp[1], "file", "", "");
}
// Case 7: fallback, channel_location = host:port and channel_name = path
spath = lstrip(spath, "/");
spath = util::lstrip(spath, "/");
std::string location = URLHandler().set_host(host).set_port(port).url();
return channel_configuration(std::string(strip(location, "/")), spath, scheme, "", "");
return channel_configuration(std::string(util::strip(location, "/")), spath, scheme, "", "");
}
std::vector<std::string> take_platforms(std::string& value)
@ -311,7 +316,7 @@ namespace mamba
if (p_repo_checker == nullptr)
{
p_repo_checker = std::make_unique<validation::RepoChecker>(
rsplit(base_url(), "/", 1).front(),
util::rsplit(base_url(), "/", 1).front(),
Context::instance().prefix_params.root_prefix / "etc" / "trusted-repos"
/ cache_name_from_url(base_url()),
caches.first_writable_path() / "cache" / cache_name_from_url(base_url())
@ -432,7 +437,8 @@ namespace mamba
}
else if (name == "")
{
if (channel_alias.location() != "" && starts_with(location, channel_alias.location()))
if (channel_alias.location() != ""
&& util::starts_with(location, channel_alias.location()))
{
name = location;
name.replace(0u, channel_alias.location().size(), "");
@ -442,14 +448,14 @@ namespace mamba
{
std::string full_url = concat_scheme_url(scheme, location);
URLHandler parser(full_url);
location = rstrip(
location = util::rstrip(
URLHandler().set_host(parser.host()).set_port(parser.port()).url(),
"/"
);
name = lstrip(parser.path(), "/");
name = util::lstrip(parser.path(), "/");
}
}
name = name != "" ? strip(name, "/") : strip(channel_url, "/");
name = name != "" ? util::strip(name, "/") : util::strip(channel_url, "/");
return Channel(
scheme,
location,
@ -497,11 +503,11 @@ namespace mamba
{
std::string tmp_stripped = name;
const auto& custom_channels = get_custom_channels();
auto it_end = custom_channels.end();
const auto it_end = custom_channels.end();
auto it = custom_channels.find(tmp_stripped);
while (it == it_end)
{
size_t pos = tmp_stripped.rfind("/");
const auto pos = tmp_stripped.rfind("/");
if (pos == std::string::npos)
{
break;
@ -524,7 +530,7 @@ namespace mamba
if (combined_name != name)
{
// Find common string between `name` and `combined_name`
auto common_str = get_common_parts(combined_name, name, "/");
auto common_str = util::get_common_parts(combined_name, name, "/");
// Combine names properly
if (common_str.empty())
{
@ -744,7 +750,7 @@ namespace mamba
for (const auto& [n, p] : context_custom_channels)
{
std::string url = p;
if (!starts_with(url, "http"))
if (!util::starts_with(url, "http"))
{
url = path_to_url(url);
}

View File

@ -20,7 +20,7 @@
#include "mamba/core/url.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -193,7 +193,7 @@ namespace mamba
}
for (const auto& entry : fs::directory_iterator(px))
{
if (ends_with(entry.path().filename().string(), ".token"))
if (util::ends_with(entry.path().filename().string(), ".token"))
{
found_tokens.push_back(entry.path());
std::string token_url = decode_url(entry.path().filename().string());
@ -246,7 +246,7 @@ namespace mamba
auto pass = decode_base64(el["password"].get<std::string>());
if (pass)
{
info.value = concat(user, ":", pass.value());
info.value = util::concat(user, ":", pass.value());
LOG_INFO << "Found credentials for user " << user << " for host "
<< host << " in ~/.mamba/auth/authentication.json";
}

View File

@ -10,8 +10,7 @@
#include "mamba/core/env_lockfile.hpp"
#include "mamba/core/mamba_fs.hpp"
#include "mamba/core/match_spec.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -252,6 +251,6 @@ namespace mamba
bool is_env_lockfile_name(std::string_view filename)
{
return ends_with(filename, "-lock.yml") || ends_with(filename, "-lock.yaml");
return util::ends_with(filename, "-lock.yml") || util::ends_with(filename, "-lock.yaml");
}
}

View File

@ -6,7 +6,7 @@
#include "mamba/core/environment.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#ifdef _WIN32
#include <mutex>
@ -126,7 +126,7 @@ namespace mamba
if (env_path)
{
std::string path = env_path.value();
const auto parts = split(path, pathsep());
const auto parts = util::split(path, pathsep());
const std::vector<fs::u8path> search_paths(parts.begin(), parts.end());
return which(exe, search_paths);
}
@ -212,7 +212,7 @@ namespace mamba
std::string_view s = current;
auto pos = s.find("=");
assert(pos != std::string_view::npos);
std::string key = to_upper(s.substr(0, pos));
std::string key = util::to_upper(s.substr(0, pos));
if (!key.empty())
{
std::string_view value = (pos != s.npos) ? s.substr(pos + 1) : "";
@ -247,7 +247,7 @@ namespace mamba
std::string maybe_home = env::get("USERPROFILE").value_or("");
if (maybe_home.empty())
{
maybe_home = concat(
maybe_home = util::concat(
env::get("HOMEDRIVE").value_or(""),
env::get("HOMEPATH").value_or("")
);
@ -328,7 +328,7 @@ namespace mamba
{
auto p = path.string();
auto home = home_directory().string();
if (starts_with(p, home))
if (util::starts_with(p, home))
{
p.replace(0, home.size(), "~");
}

View File

@ -13,8 +13,7 @@
#include "mamba/core/output.hpp"
#include "mamba/core/thread_utils.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/version.hpp"
#include "mamba/util/string.hpp"
#include "compression.hpp"
#include "curl.hpp"
@ -197,20 +196,20 @@ namespace mamba
m_curl_handle->set_opt(CURLOPT_HEADERFUNCTION, &DownloadTarget::header_callback);
m_curl_handle->set_opt(CURLOPT_HEADERDATA, this);
if (ends_with(url, ".json.zst"))
if (util::ends_with(url, ".json.zst"))
{
m_zstd_stream = std::make_unique<ZstdStream>(&DownloadTarget::write_callback, this);
if (ends_with(m_filename, ".zst"))
if (util::ends_with(m_filename, ".zst"))
{
m_filename = m_filename.substr(0, m_filename.size() - 4);
}
m_curl_handle->set_opt(CURLOPT_WRITEFUNCTION, ZstdStream::write_callback);
m_curl_handle->set_opt(CURLOPT_WRITEDATA, m_zstd_stream.get());
}
else if (ends_with(url, ".json.bz2"))
else if (util::ends_with(url, ".json.bz2"))
{
m_bzip2_stream = std::make_unique<Bzip2Stream>(&DownloadTarget::write_callback, this);
if (ends_with(m_filename, ".bz2"))
if (util::ends_with(m_filename, ".bz2"))
{
m_filename = m_filename.substr(0, m_filename.size() - 4);
}
@ -223,7 +222,7 @@ namespace mamba
m_curl_handle->set_opt(CURLOPT_WRITEDATA, this);
}
if (ends_with(url, ".json"))
if (util::ends_with(url, ".json"))
{
// accept all encodings supported by the libcurl build
m_curl_handle->set_opt(CURLOPT_ACCEPT_ENCODING, "");
@ -272,7 +271,7 @@ namespace mamba
return m_retries < size_t(Context::instance().remote_fetch_params.max_retries)
&& (m_http_status == 413 || m_http_status == 429 || m_http_status >= 500)
&& !starts_with(m_url, "file://");
&& !util::starts_with(m_url, "file://");
}
bool DownloadTarget::retry()
@ -357,7 +356,7 @@ namespace mamba
value = header.substr(colon_idx, (header_end > colon_idx) ? header_end - colon_idx : 0);
// http headers are case insensitive!
std::string lkey = to_lower(key);
std::string lkey = util::to_lower(key);
if (lkey == "etag")
{
s->m_etag = value;

View File

@ -14,7 +14,7 @@
#include "mamba/core/output.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_scope.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba::path
{
@ -22,7 +22,7 @@ namespace mamba::path
{
std::string path = p.string();
return path[0] == '~'
|| starts_with(env::expand_user(path).string(), env::expand_user("~").string());
|| util::starts_with(env::expand_user(path).string(), env::expand_user("~").string());
}
// TODO more error handling

View File

@ -11,7 +11,7 @@
#include "mamba/core/history.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -100,8 +100,8 @@ namespace mamba
return false;
}
std::string key(strip(line.substr(1, colon_idx - 1)));
std::string value(strip(line.substr(colon_idx + 1)));
std::string key(util::strip(line.substr(1, colon_idx - 1)));
std::string value(util::strip(line.substr(colon_idx + 1)));
if (key == "conda version")
{
@ -111,7 +111,7 @@ namespace mamba
{
req.cmd = value;
}
else if (ends_with(key, " specs"))
else if (util::ends_with(key, " specs"))
{
std::string action = key.substr(0, key.find_first_of(" "));
// small parser for pythonic lists

View File

@ -20,8 +20,8 @@
#include "mamba/core/output.hpp"
#include "mamba/core/transaction_context.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/core/validate.hpp"
#include "mamba/util/string.hpp"
#if _WIN32
#include "../data/conda_exe.hpp"
@ -33,7 +33,7 @@ namespace mamba
void python_entry_point_template(std::ostream& out, const python_entry_point_parsed& p)
{
auto import_name = split(p.func, ".")[0];
auto import_name = util::split(p.func, ".")[0];
out << "# -*- coding: utf-8 -*-\n";
out << "import re\n";
out << "import sys\n\n";
@ -69,28 +69,28 @@ namespace mamba
if (py_ver[0] == '2')
{
// make `.pyc` file in same directory
return concat(py_path.string(), 'c');
return util::concat(py_path.string(), 'c');
}
else
{
auto directory = py_path.parent_path();
auto py_file_stem = py_path.stem();
std::string py_ver_nodot = py_ver;
replace_all(py_ver_nodot, ".", "");
util::replace_all(py_ver_nodot, ".", "");
return directory / fs::u8path("__pycache__")
/ concat(py_file_stem.string(), ".cpython-", py_ver_nodot, ".pyc");
/ util::concat(py_file_stem.string(), ".cpython-", py_ver_nodot, ".pyc");
}
}
python_entry_point_parsed parse_entry_point(const std::string& ep_def)
{
// def looks like: "wheel = wheel.cli:main"
auto cmd_mod_func = rsplit(ep_def, ":", 1);
auto command_module = rsplit(cmd_mod_func[0], "=", 1);
auto cmd_mod_func = util::rsplit(ep_def, ":", 1);
auto command_module = util::rsplit(cmd_mod_func[0], "=", 1);
python_entry_point_parsed result;
result.command = strip(command_module[0]);
result.module = strip(command_module[1]);
result.func = strip(cmd_mod_func[1]);
result.command = util::strip(command_module[0]);
result.module = util::strip(command_module[1]);
result.func = util::strip(cmd_mod_func[1]);
return result;
}
@ -108,7 +108,7 @@ namespace mamba
{
fs::u8path shebang_path = match[2].str();
LOG_INFO << "New shebang path " << shebang_path;
return concat("#!/usr/bin/env ", shebang_path.filename().string(), match[3].str());
return util::concat("#!/usr/bin/env ", shebang_path.filename().string(), match[3].str());
}
else
{
@ -213,7 +213,7 @@ namespace mamba
}
else
{
return concat(pad, str, pad);
return util::concat(pad, str, pad);
}
}
@ -221,7 +221,7 @@ namespace mamba
{
#ifdef _WIN32
std::string path_copy = path;
replace_all(path_copy, "\\", "\\\\");
util::replace_all(path_copy, "\\", "\\\\");
return path_copy;
#else
return path;
@ -318,12 +318,12 @@ namespace mamba
if (on_win)
{
path = prefix / get_bin_directory_short_path()
/ concat(".", pkg_info.name, "-", action, ".bat");
/ util::concat(".", pkg_info.name, "-", action, ".bat");
}
else
{
path = prefix / get_bin_directory_short_path()
/ concat(".", pkg_info.name, "-", action, ".sh");
/ util::concat(".", pkg_info.name, "-", action, ".sh");
}
if (!fs::exists(path))
@ -411,9 +411,9 @@ namespace mamba
envmap["PKG_BUILDNUM"] = std::to_string(pkg_info.build_number);
std::string PATH = env::get("PATH").value_or("");
envmap["PATH"] = concat(path.parent_path().string(), env::pathsep(), PATH);
envmap["PATH"] = util::concat(path.parent_path().string(), env::pathsep(), PATH);
std::string cargs = join(" ", command_args);
std::string cargs = util::join(" ", command_args);
LOG_DEBUG << "For " << pkg_info.name << " at " << envmap["PREFIX"]
<< ", executing script: $ " << cargs;
LOG_TRACE << "Calling " << cargs;
@ -614,7 +614,7 @@ namespace mamba
// and copy the file
std::string new_prefix = m_context->relocate_prefix.string();
#ifdef _WIN32
replace_all(new_prefix, "\\", "/");
util::replace_all(new_prefix, "\\", "/");
#endif
LOG_TRACE << "Copying file & replace prefix " << src << " -> " << dst;
// TODO windows does something else here
@ -623,7 +623,7 @@ namespace mamba
if (path_data.file_mode != FileMode::BINARY)
{
buffer = read_contents(src, std::ios::in | std::ios::binary);
replace_all(buffer, path_data.prefix_placeholder, new_prefix);
util::replace_all(buffer, path_data.prefix_placeholder, new_prefix);
if constexpr (!on_win) // only on non-windows platforms
{
@ -682,7 +682,7 @@ namespace mamba
if (!shebang.empty() && !launcher.empty())
{
replace_all(shebang, path_data.prefix_placeholder, new_prefix);
util::replace_all(shebang, path_data.prefix_placeholder, new_prefix);
std::ofstream fo = open_ofstream(dst, std::ios::out | std::ios::binary);
fo << launcher << shebang << (buffer.c_str() + arc_pos);
fo.close();
@ -711,7 +711,7 @@ namespace mamba
++end;
}
std::string replacement = concat(new_prefix, suffix, padding);
std::string replacement = util::concat(new_prefix, suffix, padding);
buffer.replace(pos, end - pos, replacement);
pos = buffer.find(path_data.prefix_placeholder, pos + new_prefix.size());
@ -1082,7 +1082,7 @@ namespace mamba
{
LOG_WARNING << "[" << f_name
<< "] The following files were already present in the environment:\n- "
<< join("\n- ", m_clobber_warnings);
<< util::join("\n- ", m_clobber_warnings);
}
return true;

View File

@ -8,7 +8,7 @@
#include <string>
#include "mamba/core/mamba_fs.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace fs
{
@ -20,7 +20,7 @@ namespace fs
auto native_string = path.native();
static constexpr auto platform_separator = L"\\";
static constexpr auto other_separator = L"/";
mamba::replace_all(native_string, other_separator, platform_separator);
mamba::util::replace_all(native_string, other_separator, platform_separator);
path = std::move(native_string);
return path;
}

View File

@ -11,14 +11,14 @@
#include "mamba/core/match_spec.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
std::vector<std::string> parse_legacy_dist(std::string dist_str)
{
dist_str = strip_package_extension(dist_str).string();
auto split_str = rsplit(dist_str, "-", 2);
auto split_str = util::rsplit(dist_str, "-", 2);
if (split_str.size() != 3)
{
LOG_ERROR << "dist_str " << dist_str << " did not split into a correct version info.";
@ -39,7 +39,7 @@ namespace mamba
if (pos == s.npos || pos == 0)
{
std::string tmp = s;
replace_all(tmp, " ", "");
util::replace_all(tmp, " ", "");
return { tmp, "" };
}
else
@ -52,15 +52,15 @@ namespace mamba
if (d == '=' || d == '!' || d == '|' || d == ',' || d == '<' || d == '>' || d == '~')
{
std::string tmp = s;
replace_all(tmp, " ", "");
util::replace_all(tmp, " ", "");
return { tmp, "" };
}
}
// c is either ' ' or pm1 is none of the forbidden chars
std::string v = s.substr(0, pos), b = s.substr(pos + 1);
replace_all(v, " ", "");
replace_all(b, " ", "");
util::replace_all(v, " ", "");
util::replace_all(b, " ", "");
return { v, b };
}
}
@ -75,7 +75,7 @@ namespace mamba
{
spec_str = spec_str.substr(0, idx);
}
spec_str = strip(spec_str);
spec_str = util::strip(spec_str);
if (is_package_file(spec_str))
{
@ -155,7 +155,7 @@ namespace mamba
);
}
auto m5 = rsplit(spec_str, ":", 2);
auto m5 = util::rsplit(spec_str, ":", 2);
auto m5_len = m5.size();
std::string channel_str;
if (m5_len == 3)
@ -201,7 +201,7 @@ namespace mamba
if (std::regex_match(spec_str, vb_match, version_build_re))
{
name = vb_match[1].str();
version = strip(vb_match[2].str());
version = util::strip(vb_match[2].str());
if (name.size() == 0)
{
throw std::runtime_error("Invalid spec, no package name found: " + spec_str);
@ -223,8 +223,8 @@ namespace mamba
);
}
version = std::string(strip(version));
auto [pv, pb] = parse_version_and_build(std::string(strip(version)));
version = std::string(util::strip(version));
auto [pv, pb] = parse_version_and_build(std::string(util::strip(version)));
version = pv;
build_string = pb;
@ -242,7 +242,7 @@ namespace mamba
{
if (build_string.empty() && version.back() != '*')
{
version = concat(version, "*");
version = util::concat(version, "*");
}
else
{
@ -356,20 +356,20 @@ namespace mamba
{
if (is_complex_relation(version))
{
formatted_brackets.push_back(concat("version='", version, "'"));
formatted_brackets.push_back(util::concat("version='", version, "'"));
}
else if (starts_with(version, "!=") || starts_with(version, "~="))
else if (util::starts_with(version, "!=") || util::starts_with(version, "~="))
{
if (!build_string.empty())
{
formatted_brackets.push_back(concat("version='", version, "'"));
formatted_brackets.push_back(util::concat("version='", version, "'"));
}
else
{
res << " " << version;
}
}
else if (ends_with(version, ".*"))
else if (util::ends_with(version, ".*"))
{
res << "=" + version.substr(0, version.size() - 2);
}
@ -379,7 +379,7 @@ namespace mamba
{
res << "=*";
}
else if (starts_with(version, "="))
else if (util::starts_with(version, "="))
{
res << version.substr(0, version.size() - 1);
}
@ -388,7 +388,7 @@ namespace mamba
res << "=" + version.substr(0, version.size() - 1);
}
}
else if (starts_with(version, "=="))
else if (util::starts_with(version, "=="))
{
res << version;
version_exact = true;
@ -404,11 +404,11 @@ namespace mamba
{
if (is_complex_relation(build_string))
{
formatted_brackets.push_back(concat("build='", build_string, "'"));
formatted_brackets.push_back(util::concat("build='", build_string, "'"));
}
else if (build_string.find("*") != build_string.npos)
{
formatted_brackets.push_back(concat("build=", build_string));
formatted_brackets.push_back(util::concat("build=", build_string));
}
else if (version_exact)
{
@ -416,7 +416,7 @@ namespace mamba
}
else
{
formatted_brackets.push_back(concat("build=", build_string));
formatted_brackets.push_back(util::concat("build=", build_string));
}
}
@ -437,11 +437,11 @@ namespace mamba
if (brackets.at(key).find_first_of("= ,") != std::string::npos)
{
// need quoting
formatted_brackets.push_back(concat(key, "='", brackets.at(key), "'"));
formatted_brackets.push_back(util::concat(key, "='", brackets.at(key), "'"));
}
else
{
formatted_brackets.push_back(concat(key, "=", brackets.at(key)));
formatted_brackets.push_back(util::concat(key, "=", brackets.at(key)));
}
}
}
@ -458,7 +458,7 @@ namespace mamba
if (formatted_brackets.size())
{
res << "[" << join(",", formatted_brackets) << "]";
res << "[" << util::join(",", formatted_brackets) << "]";
}
return res.str();
}

View File

@ -14,7 +14,7 @@
#include "mamba/core/context.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/transaction_context.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
@ -141,9 +141,11 @@ namespace mamba
hres = pPersistFile->Save(filename.wstring().c_str(), true);
if (FAILED(hres))
{
throw std::runtime_error(
concat("Failed to create shortcut: ", filename.string(), std::to_string(hres))
);
throw std::runtime_error(util::concat(
"Failed to create shortcut: ",
filename.string(),
std::to_string(hres)
));
}
}
catch (const std::runtime_error& e)
@ -229,26 +231,26 @@ namespace mamba
std::string distribution_name = root_prefix.filename().string();
if (distribution_name.size() > 1)
{
distribution_name[0] = to_upper(distribution_name[0]);
distribution_name[0] = util::to_upper(distribution_name[0]);
}
auto to_forward_slash = [](const fs::u8path& p)
{
std::string ps = p.string();
replace_all(ps, "\\", "/");
util::replace_all(ps, "\\", "/");
return ps;
};
auto platform_split = split(ctx.platform, "-");
auto platform_split = util::split(ctx.platform, "-");
std::string platform_bitness;
if (platform_split.size() >= 2)
{
platform_bitness = concat("(", platform_split.back(), "-bit)");
platform_bitness = util::concat("(", platform_split.back(), "-bit)");
}
if (py_ver.size())
{
py_ver = split(py_ver, ".")[0];
py_ver = util::split(py_ver, ".")[0];
}
std::map<std::string, std::string> vars = {
@ -268,7 +270,7 @@ namespace mamba
for (auto& [key, val] : vars)
{
replace_all(text, key, val);
util::replace_all(text, key, val);
}
}
@ -291,7 +293,7 @@ namespace mamba
if (e_name.size())
{
name_suffix = concat(" (", e_name, ")");
name_suffix = util::concat(" (", e_name, ")");
}
#ifdef _WIN32
@ -353,7 +355,7 @@ namespace mamba
for (auto& item : j["menu_items"])
{
std::string name = item["name"];
std::string full_name = concat(name, name_suffix);
std::string full_name = util::concat(name, name_suffix);
std::vector<std::string> arguments;
fs::u8path script;
@ -361,14 +363,14 @@ namespace mamba
{
script = root_pyw;
arguments = cwp_pyw_args;
auto tmp = split(item["pywscript"], " ");
auto tmp = util::split(item["pywscript"], " ");
std::copy(tmp.begin(), tmp.end(), back_inserter(arguments));
}
else if (item.contains("pyscript"))
{
script = root_py;
arguments = cwp_py_args;
auto tmp = split(item["pyscript"], " ");
auto tmp = util::split(item["pyscript"], " ");
std::copy(tmp.begin(), tmp.end(), back_inserter(arguments));
}
else if (item.contains("webbrowser"))
@ -380,13 +382,13 @@ namespace mamba
{
script = root_py;
arguments = { cwp_path.string(), target_prefix.string() };
auto tmp = split(item["script"], " ");
auto tmp = util::split(item["script"], " ");
std::copy(tmp.begin(), tmp.end(), back_inserter(arguments));
extend_script_args(item, arguments);
}
else if (item.contains("system"))
{
auto tmp = split(item["system"], " ");
auto tmp = util::split(item["system"], " ");
script = tmp[0];
if (tmp.size() > 1)
{
@ -406,13 +408,13 @@ namespace mamba
if (remove == false)
{
std::string argstring;
std::string lscript = to_lower(script.string());
std::string lscript = util::to_lower(script.string());
for (auto& arg : arguments)
{
if (arg.size() >= 1 && arg[0] != '/')
{
mamba::replace_all(arg, "/", "\\");
util::replace_all(arg, "/", "\\");
}
}
@ -421,7 +423,8 @@ namespace mamba
{
if (arguments.size() > 1)
{
if (to_upper(arguments[0]) == "/K" || to_upper(arguments[0]) == "/C")
if (util::to_upper(arguments[0]) == "/K"
|| util::to_upper(arguments[0]) == "/C")
{
}
}

View File

@ -26,7 +26,7 @@
#include "mamba/core/thread_utils.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#include "progress_bar_impl.hpp"
@ -38,11 +38,11 @@ namespace mamba
// TODO maybe add some caching...
split_scheme_auth_token(full_url, remaining_url, scheme, auth, token);
if (starts_with(remaining_url, "conda.anaconda.org/"))
if (util::starts_with(remaining_url, "conda.anaconda.org/"))
{
return remaining_url.substr(19, std::string::npos).data();
}
if (starts_with(remaining_url, "repo.anaconda.com/"))
if (util::starts_with(remaining_url, "repo.anaconda.com/"))
{
return remaining_url.substr(18, std::string::npos).data();
}
@ -383,7 +383,7 @@ namespace mamba
std::string response;
std::getline(input_stream, response);
#ifdef _WIN32
response = strip(response);
response = util::strip(response);
#endif
if (response.size() == 0)
{

View File

@ -22,7 +22,7 @@
#include "mamba/core/package_handling.hpp"
#include "mamba/core/progress_bar.hpp"
#include "mamba/core/thread_utils.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#include "progress_bar_impl.hpp"
@ -208,11 +208,11 @@ namespace mamba
try
{
std::string fn = m_filename;
if (ends_with(fn, ".tar.bz2"))
if (util::ends_with(fn, ".tar.bz2"))
{
fn = fn.substr(0, fn.size() - 8);
}
else if (ends_with(fn, ".conda"))
else if (util::ends_with(fn, ".conda"))
{
fn = fn.substr(0, fn.size() - 6);
}

View File

@ -17,8 +17,8 @@
#include "mamba/core/package_paths.hpp"
#include "mamba/core/thread_utils.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/core/validate.hpp"
#include "mamba/util/string.hpp"
#include "nlohmann/json.hpp"
@ -211,7 +211,7 @@ namespace mamba
int zip_order(const fs::u8path& path)
{
// sort info-...tar.zst file last in zip folder"
int init_order = starts_with(path.filename().string(), "info-");
int init_order = util::starts_with(path.filename().string(), "info-");
// sort metadata.json first in zip folder
if (path.filename().string() == "metadata.json")
{
@ -348,15 +348,21 @@ namespace mamba
scoped_archive_read disk = scoped_archive_read::read_disk();
if (archive_read_disk_set_behavior(disk, 0) < ARCHIVE_OK)
{
throw std::runtime_error(concat("libarchive error: ", archive_error_string(disk)));
throw std::runtime_error(
util::concat("libarchive error: ", archive_error_string(disk))
);
}
if (archive_read_disk_open(disk, p.c_str()) < ARCHIVE_OK)
{
throw std::runtime_error(concat("libarchive error: ", archive_error_string(disk)));
throw std::runtime_error(
util::concat("libarchive error: ", archive_error_string(disk))
);
}
if (archive_read_next_header2(disk, entry) < ARCHIVE_OK)
{
throw std::runtime_error(concat("libarchive error: ", archive_error_string(disk)));
throw std::runtime_error(
util::concat("libarchive error: ", archive_error_string(disk))
);
}
// clean out UID and GID
@ -367,11 +373,13 @@ namespace mamba
if (archive_read_disk_descend(disk) < ARCHIVE_OK)
{
throw std::runtime_error(concat("libarchive error: ", archive_error_string(disk)));
throw std::runtime_error(
util::concat("libarchive error: ", archive_error_string(disk))
);
}
if (archive_write_header(a, entry) < ARCHIVE_OK)
{
throw std::runtime_error(concat("libarchive error: ", archive_error_string(a)));
throw std::runtime_error(util::concat("libarchive error: ", archive_error_string(a)));
}
@ -394,7 +402,7 @@ namespace mamba
}
else if (r < ARCHIVE_OK)
{
throw std::runtime_error(concat("libarchive error: ", archive_error_string(a)));
throw std::runtime_error(util::concat("libarchive error: ", archive_error_string(a)));
}
}
@ -410,7 +418,7 @@ namespace mamba
)
{
fs::u8path out_file_abs = fs::absolute(out_file);
if (ends_with(out_file.string(), ".tar.bz2"))
if (util::ends_with(out_file.string(), ".tar.bz2"))
{
create_archive(
directory,
@ -421,12 +429,12 @@ namespace mamba
[](const fs::u8path&) { return false; }
);
}
else if (ends_with(out_file.string(), ".conda"))
else if (util::ends_with(out_file.string(), ".conda"))
{
TemporaryDirectory tdir;
create_archive(
directory,
tdir.path() / concat("info-", out_file.stem().string(), ".tar.zst"),
tdir.path() / util::concat("info-", out_file.stem().string(), ".tar.zst"),
zstd,
compression_level,
compression_threads,
@ -437,7 +445,7 @@ namespace mamba
);
create_archive(
directory,
tdir.path() / concat("pkg-", out_file.stem().string(), ".tar.zst"),
tdir.path() / util::concat("pkg-", out_file.stem().string(), ".tar.zst"),
zstd,
compression_level,
compression_threads,
@ -696,11 +704,11 @@ namespace mamba
static fs::u8path extract_dest_dir(const fs::u8path& file)
{
if (ends_with(file.string(), ".tar.bz2"))
if (util::ends_with(file.string(), ".tar.bz2"))
{
return file.string().substr(0, file.string().size() - 8);
}
else if (ends_with(file.string(), ".conda"))
else if (util::ends_with(file.string(), ".conda"))
{
return file.string().substr(0, file.string().size() - 6);
}
@ -713,11 +721,11 @@ namespace mamba
static std::mutex extract_mutex;
std::lock_guard<std::mutex> lock(extract_mutex);
if (ends_with(file.string(), ".tar.bz2"))
if (util::ends_with(file.string(), ".tar.bz2"))
{
extract_archive(file, dest);
}
else if (ends_with(file.string(), ".conda"))
else if (util::ends_with(file.string(), ".conda"))
{
extract_conda(file, dest);
}
@ -748,7 +756,7 @@ namespace mamba
}
std::string out, err;
LOG_DEBUG << "Running subprocess extraction '" << join(" ", args) << "'";
LOG_DEBUG << "Running subprocess extraction '" << util::join(" ", args) << "'";
auto [status, ec] = reproc::run(
args,
reproc::options{},
@ -770,11 +778,11 @@ namespace mamba
{
TemporaryDirectory extract_dir;
if (ends_with(pkg_file.string(), ".tar.bz2"))
if (util::ends_with(pkg_file.string(), ".tar.bz2"))
{
extract_archive(pkg_file, extract_dir);
}
else if (ends_with(pkg_file.string(), ".conda"))
else if (util::ends_with(pkg_file.string(), ".conda"))
{
extract_conda(pkg_file, extract_dir);
}

View File

@ -13,7 +13,7 @@
#include <fmt/format.h>
#include "mamba/core/package_info.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -118,7 +118,7 @@ namespace mamba
if (std::string feat = j.value("track_features", ""); !feat.empty())
{
// Split empty string would have an empty element
track_features = split(feat, ",");
track_features = util::split(feat, ",");
}
// add the noarch type if we know it (only known for installed packages)
@ -277,12 +277,12 @@ namespace mamba
std::string PackageInfo::str() const
{
return concat(name, "-", version, "-", build_string);
return util::concat(name, "-", version, "-", build_string);
}
std::string PackageInfo::long_str() const
{
// TODO channel contains subdir right now?!
return concat(channel, "::", name, "-", version, "-", build_string);
return util::concat(channel, "::", name, "-", version, "-", build_string);
}
} // namespace mamba

View File

@ -9,7 +9,7 @@
#include <string>
#include "mamba/core/package_paths.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -33,12 +33,14 @@ namespace mamba
{
// TODO: make sure that strings that are quoted are still split correctly
// e.g. when a file path contains a space...
auto s = split(l, " ");
auto s = util::split(l, " ");
if (s.size() == 1)
{
res[s[0]] = PrefixFileParse{ concat(PREFIX_PLACEHOLDER_1, PREFIX_PLACEHOLDER_2),
"text",
s[0] };
res[s[0]] = PrefixFileParse{
util::concat(PREFIX_PLACEHOLDER_1, PREFIX_PLACEHOLDER_2),
"text",
s[0],
};
}
else if (s.size() == 3)
{
@ -46,7 +48,7 @@ namespace mamba
}
else
{
throw std::runtime_error(concat("Could not parse ", path.string()));
throw std::runtime_error(util::concat("Could not parse ", path.string()));
}
}
return res;

View File

@ -8,7 +8,7 @@
#include "mamba/core/output.hpp"
#include "mamba/core/pinning.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
@ -37,8 +37,8 @@ namespace mamba
}
}
std::vector<std::string> elems = split(py_version, ".");
std::string py_pin = concat("python ", elems[0], ".", elems[1], ".*");
std::vector<std::string> elems = util::split(py_version, ".");
std::string py_pin = util::concat("python ", elems[0], ".", elems[1], ".*");
LOG_DEBUG << "Pinning Python to '" << py_pin << "'";
return py_pin;
}

View File

@ -22,9 +22,7 @@ extern "C" // Incomplete header
#include "mamba/core/match_spec.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/pool.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/cast.hpp"
#include "mamba/util/compare.hpp"
#include "mamba/util/string.hpp"
#include "solv-cpp/pool.hpp"
#include "solv-cpp/queue.hpp"
@ -165,15 +163,15 @@ namespace mamba
// Example candidate_repo_url: https://.../conda-forge/linux-64
// example needle_spec: conda-forge/osx-64::xtensor
std::string needle_channel = split(needle_spec, ":", 1)[0];
if (!contains(needle_channel, "/"))
std::string needle_channel = util::split(needle_spec, ":", 1)[0];
if (!util::contains(needle_channel, "/"))
{
// Subdir not specified, so any subdir is fine
return true;
}
std::string needle_subdir = rsplit(needle_channel, "/", 1)[1];
std::string needle_subdir = util::rsplit(needle_channel, "/", 1)[1];
std::string candidate_repo_subdir = rsplit(candidate_repo_url, "/", 1)[1];
std::string candidate_repo_subdir = util::rsplit(candidate_repo_url, "/", 1)[1];
if (candidate_repo_subdir == needle_subdir)
{

View File

@ -13,8 +13,8 @@
#include "mamba/core/output.hpp"
#include "mamba/core/prefix_data.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/graph.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -54,7 +54,7 @@ namespace mamba
{
for (auto& p : fs::directory_iterator(conda_meta_dir))
{
if (ends_with(p.path().string(), ".json"))
if (util::ends_with(p.path().string(), ".json"))
{
load_single_record(p.path());
}

View File

@ -20,7 +20,7 @@
#include "mamba/core/package_info.hpp"
#include "mamba/core/query.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#include "solv-cpp/queue.hpp"
namespace mamba
@ -88,7 +88,7 @@ namespace mamba
if (it == not_found.end())
{
auto dep_id = dep_graph.add_node(
PackageInfo(concat(name, " >>> NOT FOUND <<<"))
PackageInfo(util::concat(name, " >>> NOT FOUND <<<"))
);
dep_graph.add_edge(parent, dep_id);
not_found.insert(std::make_pair(name, dep_id));
@ -416,7 +416,7 @@ namespace mamba
/** Remove potential subdir from channel name (not url!). */
auto cut_subdir(std::string_view str) -> std::string
{
return split(str, "/", 1).front(); // Has at least one element
return util::split(str, "/", 1).front(); // Has at least one element
}
}
@ -440,7 +440,7 @@ namespace mamba
}
else
{
auto sfmt = split(f, ":", 1);
auto sfmt = util::split(f, ":", 1);
headers.push_back(sfmt[0]);
cmds.push_back(sfmt[0]);
args.push_back(sfmt[1]);
@ -474,7 +474,7 @@ namespace mamba
std::string depends_qualifier;
for (const auto& dep : pkg.depends)
{
if (starts_with(dep, args[i]))
if (util::starts_with(dep, args[i]))
{
depends_qualifier = dep;
break;

View File

@ -27,7 +27,7 @@
#include "mamba/core/run.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_random.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#ifndef _WIN32
extern "C"
@ -345,7 +345,7 @@ namespace mamba
{
if (e.find_first_of("=") != std::string::npos)
{
auto split_e = split(e, "=", 1);
auto split_e = util::split(e, "=", 1);
env_map[split_e[0]] = split_e[1];
}
else

View File

@ -19,10 +19,8 @@
#include <fmt/format.h>
#include <fmt/ostream.h>
#include "mamba/core/output.hpp"
#include "mamba/core/package_info.hpp"
#include "mamba/core/satisfiability_error.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -582,7 +580,7 @@ namespace mamba
{
if (invoke_name(*it) != invoke_name(*first))
{
throw std::invalid_argument(concat(
throw std::invalid_argument(util::concat(
"iterator contains different names (",
invoke_name(*first),
", ",
@ -661,7 +659,7 @@ namespace mamba
{
versions.erase(std::unique(versions.begin(), versions.end()), versions.end());
}
return { join_trunc(versions, sep, etc, threshold), versions.size() };
return { util::join_trunc(versions, sep, etc, threshold), versions.size() };
}
template <typename T, typename A>
@ -684,7 +682,7 @@ namespace mamba
{
builds.erase(std::unique(builds.begin(), builds.end()), builds.end());
}
return { join_trunc(builds, sep, etc, threshold), builds.size() };
return { util::join_trunc(builds, sep, etc, threshold), builds.size() };
}
template <typename T, typename A>
@ -714,7 +712,7 @@ namespace mamba
versions_builds.end()
);
}
return { join_trunc(versions_builds, sep, etc, threshold), versions_builds.size() };
return { util::join_trunc(versions_builds, sep, etc, threshold), versions_builds.size() };
}
template <typename T, typename A>
@ -1264,7 +1262,7 @@ namespace mamba
// We show the build string in pkg_dep and not pkg_list because hand written build
// string are more likely to contain vital information about the variant.
auto [vers_builds_trunc, size] = edges.versions_and_build_strings_trunc();
if (strip(vers_builds_trunc).empty())
if (util::strip(vers_builds_trunc).empty())
{
write(fmt::format(style, "{}", edges.name()));
}
@ -1403,7 +1401,7 @@ namespace mamba
write(", which");
}
// Virtual package
if (starts_with(node.name(), "__"))
if (util::starts_with(node.name(), "__"))
{
write(" is missing on the system");
}

View File

@ -25,7 +25,7 @@
#include "mamba/core/shell_init.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -49,45 +49,45 @@ namespace mamba
LOG_DEBUG << "Guessing shell. Parent process name: " << parent_process_name;
std::string parent_process_name_lower = to_lower(parent_process_name);
std::string parent_process_name_lower = util::to_lower(parent_process_name);
if (contains(parent_process_name_lower, "bash"))
if (util::contains(parent_process_name_lower, "bash"))
{
return "bash";
}
if (contains(parent_process_name_lower, "zsh"))
if (util::contains(parent_process_name_lower, "zsh"))
{
return "zsh";
}
if (contains(parent_process_name_lower, "csh"))
if (util::contains(parent_process_name_lower, "csh"))
{
return "csh";
}
if (contains(parent_process_name_lower, "dash"))
if (util::contains(parent_process_name_lower, "dash"))
{
return "dash";
}
// xonsh in unix, Python in macOS
if (contains(parent_process_name_lower, "python"))
if (util::contains(parent_process_name_lower, "python"))
{
Console::stream() << "Your parent process name is " << parent_process_name
<< ".\nIf your shell is xonsh, please use \"-s xonsh\".";
}
if (contains(parent_process_name_lower, "xonsh"))
if (util::contains(parent_process_name_lower, "xonsh"))
{
return "xonsh";
}
if (contains(parent_process_name_lower, "cmd.exe"))
if (util::contains(parent_process_name_lower, "cmd.exe"))
{
return "cmd.exe";
}
if (contains(parent_process_name_lower, "powershell")
|| contains(parent_process_name_lower, "pwsh"))
if (util::contains(parent_process_name_lower, "powershell")
|| util::contains(parent_process_name_lower, "pwsh"))
{
return "powershell";
}
if (contains(parent_process_name_lower, "fish"))
if (util::contains(parent_process_name_lower, "fish"))
{
return "fish";
}
@ -159,7 +159,7 @@ namespace mamba
}
else
{
replace_all(new_value, replace_str, hook_string);
util::replace_all(new_value, replace_str, hook_string);
}
// set modified registry key
@ -192,20 +192,20 @@ namespace mamba
std::wstring segment;
std::vector<std::wstring> autorun_list;
autorun_list = split(std::wstring_view(prev_value), std::wstring_view(L"&"));
autorun_list = util::split(std::wstring_view(prev_value), std::wstring_view(L"&"));
// remove the mamba hook from the autorun list
autorun_list.erase(
std::remove_if(
autorun_list.begin(),
autorun_list.end(),
[&hook_string](const std::wstring& s) { return strip(s) == hook_string; }
[&hook_string](const std::wstring& s) { return util::strip(s) == hook_string; }
),
autorun_list.end()
);
// join the list back into a string
std::wstring new_value = join(L" & ", autorun_list);
std::wstring new_value = util::join(L" & ", autorun_list);
// set modified registry key
if (new_value != prev_value)
@ -238,7 +238,7 @@ namespace mamba
*/
fs::u8path bash;
fs::u8path parent_process_name = get_process_name_by_pid(getppid());
if (contains(parent_process_name.filename().string(), "bash"))
if (util::contains(parent_process_name.filename().string(), "bash"))
{
bash = parent_process_name;
}
@ -268,7 +268,7 @@ namespace mamba
{
throw std::runtime_error(ec.message());
}
return std::string(strip(out));
return std::string(util::strip(out));
}
catch (...)
{
@ -531,19 +531,19 @@ namespace mamba
if (shell == "zsh" || shell == "bash" || shell == "posix")
{
std::string contents = data_micromamba_sh;
replace_all(contents, "$MAMBA_EXE", exe.string());
util::replace_all(contents, "$MAMBA_EXE", exe.string());
return contents;
}
else if (shell == "csh")
{
std::string contents = data_micromamba_csh;
replace_all(contents, "$MAMBA_EXE", exe.string());
util::replace_all(contents, "$MAMBA_EXE", exe.string());
return contents;
}
else if (shell == "xonsh")
{
std::string contents = data_mamba_xsh;
replace_all(contents, "$MAMBA_EXE", exe.string());
util::replace_all(contents, "$MAMBA_EXE", exe.string());
return contents;
}
else if (shell == "powershell")
@ -569,7 +569,7 @@ namespace mamba
else if (shell == "fish")
{
std::string contents = data_mamba_fish;
replace_all(contents, "$MAMBA_EXE", exe.string());
util::replace_all(contents, "$MAMBA_EXE", exe.string());
return contents;
}
return "";
@ -591,12 +591,12 @@ namespace mamba
std::ofstream mamba_bat_f = open_ofstream(root_prefix / "condabin" / "micromamba.bat");
std::string mamba_bat_contents(data_micromamba_bat);
replace_all(
util::replace_all(
mamba_bat_contents,
std::string("__MAMBA_INSERT_ROOT_PREFIX__"),
"@SET \"MAMBA_ROOT_PREFIX=" + root_prefix.string() + "\""
);
replace_all(
util::replace_all(
mamba_bat_contents,
std::string("__MAMBA_INSERT_MAMBA_EXE__"),
"@SET \"MAMBA_EXE=" + exe.string() + "\""
@ -610,12 +610,12 @@ namespace mamba
std::string activate_bat_contents(data_activate_bat);
replace_all(
util::replace_all(
activate_bat_contents,
std::string("__MAMBA_INSERT_ROOT_PREFIX__"),
"@SET \"MAMBA_ROOT_PREFIX=" + root_prefix.string() + "\""
);
replace_all(
util::replace_all(
activate_bat_contents,
std::string("__MAMBA_INSERT_MAMBA_EXE__"),
"@SET \"MAMBA_EXE=" + exe.string() + "\""
@ -631,7 +631,7 @@ namespace mamba
scripts_activate_bat_f << activate_bat_contents;
std::string hook_content = data_mamba_hook_bat;
replace_all(
util::replace_all(
hook_content,
std::string("__MAMBA_INSERT_MAMBA_EXE__"),
"@SET \"MAMBA_EXE=" + exe.string() + "\""
@ -952,7 +952,7 @@ namespace mamba
return;
}
if (strip(profile_content).empty())
if (util::strip(profile_content).empty())
{
fs::remove(profile_path);
LOG_INFO << "Removed " << profile_path << " file because it's empty.";
@ -997,7 +997,7 @@ namespace mamba
{
throw std::runtime_error(ec.message());
}
return std::string(strip(out));
return std::string(util::strip(out));
}
catch (const std::exception& ex)
{

View File

@ -11,7 +11,7 @@
#include "mamba/core/package_cache.hpp"
#include "mamba/core/subdirdata.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#include "progress_bar_impl.hpp"
@ -333,7 +333,7 @@ namespace mamba
, m_progress_bar()
, m_loaded(false)
, m_download_complete(false)
, m_repodata_url(concat(url, "/", repodata_fn))
, m_repodata_url(util::concat(url, "/", repodata_fn))
, m_name(join_url(channel.canonical_name(), platform))
, m_is_noarch(platform == "noarch")
, p_channel(&channel)
@ -443,7 +443,7 @@ namespace mamba
bool MSubdirData::forbid_cache()
{
return starts_with(m_repodata_url, "file://");
return util::starts_with(m_repodata_url, "file://");
}
void MSubdirData::finalize_checks()
@ -462,7 +462,7 @@ namespace mamba
m_progress_bar_check.mark_as_completed();
}
if (ends_with(target.get_url(), ".zst"))
if (util::ends_with(target.get_url(), ".zst"))
{
this->m_metadata.has_zst = { target.get_http_status() == 200, utc_time_now() };
}
@ -909,7 +909,7 @@ namespace mamba
{
using return_type = expected_t<MRepo>;
RepoMetadata meta{
/* .url= */ rsplit(m_metadata.url, "/", 1).front(),
/* .url= */ util::rsplit(m_metadata.url, "/", 1).front(),
/* .etag= */ m_metadata.etag,
/* .mod= */ m_metadata.mod,
/* .pip_added= */ Context::instance().add_pip_as_python_dependency,

View File

@ -30,8 +30,8 @@ extern "C" // Incomplete header
#include "mamba/core/pool.hpp"
#include "mamba/core/thread_utils.hpp"
#include "mamba/core/transaction.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/flat_set.hpp"
#include "mamba/util/string.hpp"
#include "solv-cpp/pool.hpp"
#include "solv-cpp/queue.hpp"
#include "solv-cpp/repo.hpp"
@ -309,8 +309,9 @@ namespace mamba
if (!not_found.empty())
{
LOG_ERROR << "Could not find packages to remove:" + join("", not_found) << std::endl;
throw std::runtime_error("Could not find packages to remove:" + join("", not_found));
LOG_ERROR << "Could not find packages to remove:" + util::join("", not_found)
<< std::endl;
throw std::runtime_error("Could not find packages to remove:" + util::join("", not_found));
}
// TODO why is this only using the last job?
@ -1269,7 +1270,7 @@ namespace mamba
specs_to_install.reserve(urls.size());
for (auto& raw_url : urls)
{
std::string_view url = strip(raw_url);
std::string_view url = util::strip(raw_url);
if (url.empty())
{
continue;
@ -1282,7 +1283,7 @@ namespace mamba
if (hash_idx != std::string::npos)
{
std::string_view hash = url.substr(hash_idx + 1);
if (starts_with(hash, "sha256:"))
if (util::starts_with(hash, "sha256:"))
{
ms.brackets["sha256"] = hash.substr(7);
}

View File

@ -12,7 +12,7 @@
#include "mamba/core/environment.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/transaction_context.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
extern const char data_compile_pyc_py[];
@ -25,13 +25,13 @@ namespace mamba
std::string compute_short_python_version(const std::string& long_version)
{
auto sv = split(long_version, ".");
auto sv = util::split(long_version, ".");
if (sv.size() < 2)
{
LOG_ERROR << "Could not compute short python version from " << long_version;
return long_version;
}
return concat(sv[0], '.', sv[1]);
return util::concat(sv[0], '.', sv[1]);
}
// supply short python version, e.g. 2.7, 3.5...
@ -40,7 +40,7 @@ namespace mamba
#ifdef _WIN32
return "python.exe";
#else
return fs::u8path("bin") / concat("python", python_version);
return fs::u8path("bin") / util::concat("python", python_version);
#endif
}
@ -54,7 +54,7 @@ namespace mamba
#ifdef _WIN32
return fs::u8path("Lib") / "site-packages";
#else
return fs::u8path("lib") / concat("python", python_version) / "site-packages";
return fs::u8path("lib") / util::concat("python", python_version) / "site-packages";
#endif
}
@ -72,13 +72,13 @@ namespace mamba
const fs::u8path& target_site_packages_short_path
)
{
if (starts_with(source_short_path, "site-packages/"))
if (util::starts_with(source_short_path, "site-packages/"))
{
// replace `site_packages/` with prefix/site_packages
return target_site_packages_short_path
/ source_short_path.substr(14, source_short_path.size() - 14);
}
else if (starts_with(source_short_path, "python-scripts/"))
else if (util::starts_with(source_short_path, "python-scripts/"))
{
return get_bin_directory_short_path()
/ source_short_path.substr(15, source_short_path.size() - 15);
@ -195,7 +195,7 @@ namespace mamba
complete_python_path.string(), "-Wi", "-m", "compileall", "-q", "-l", "-i", "-"
};
auto py_ver_split = split(python_version, ".");
auto py_ver_split = util::split(python_version, ".");
try
{
@ -249,7 +249,7 @@ namespace mamba
auto [wrapped_command, script_file] = prepare_wrapped_call(target_prefix, command);
m_pyc_script_file = std::move(script_file);
LOG_INFO << "Running wrapped python compilation command " << join(" ", command);
LOG_INFO << "Running wrapped python compilation command " << util::join(" ", command);
std::error_code ec = m_pyc_process->start(wrapped_command, options);
if (ec == std::errc::no_such_file_or_directory)

View File

@ -13,7 +13,7 @@
#include "mamba/core/context.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -177,11 +177,11 @@ namespace mamba
{
if (scheme == "file" && location.size() > 1 && location[1] == ':')
{
return concat("file:///", location);
return util::concat("file:///", location);
}
else
{
return concat(scheme, "://", location);
return util::concat(scheme, "://", location);
}
}
@ -194,7 +194,7 @@ namespace mamba
{
if (with_credential && auth)
{
return concat_scheme_url(scheme, concat(*auth, "@", base));
return concat_scheme_url(scheme, util::concat(*auth, "@", base));
}
else
{
@ -253,7 +253,7 @@ namespace mamba
{
cleaned_url.replace(pos - 1, platform.size() + 1, "");
}
cleaned_url = rstrip(cleaned_url, "/");
cleaned_url = util::rstrip(cleaned_url, "/");
}
bool has_scheme(const std::string& url)
@ -279,7 +279,7 @@ namespace mamba
token = "";
cleaned_url = url;
}
cleaned_url = rstrip(cleaned_url, "/");
cleaned_url = util::rstrip(cleaned_url, "/");
}
void split_scheme_auth_token(
@ -298,7 +298,7 @@ namespace mamba
handler.set_scheme("");
handler.set_user("");
handler.set_password("");
remaining_url = rstrip(handler.url(), "/");
remaining_url = util::rstrip(handler.url(), "/");
}
bool compare_cleaned_url(const std::string& url1, const std::string& url2)
@ -321,7 +321,7 @@ namespace mamba
std::string path_to_url(const std::string& path)
{
static const std::string file_scheme = "file://";
if (starts_with(path, file_scheme))
if (util::starts_with(path, file_scheme))
{
return path;
}
@ -333,7 +333,7 @@ namespace mamba
// https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/
if (on_win)
{
replace_all(abs_path, "\\", "/");
util::replace_all(abs_path, "\\", "/");
}
return file_scheme + abs_path;
}
@ -350,7 +350,7 @@ namespace mamba
if (std::regex_match(url, match, file_host))
{
if (match[1] != "" && match[1] != "localhost" && match[1] != "127.0.0.1"
&& match[1] != "::1" && !starts_with(match[1].str(), R"(\\))"))
&& match[1] != "::1" && !util::starts_with(match[1].str(), R"(\\))"))
{
return "file:////" + std::string(match[1].first, url.cend());
}
@ -390,14 +390,14 @@ namespace mamba
std::string cache_name_from_url(const std::string& url)
{
std::string u = url;
if (u.empty() || (u.back() != '/' && !ends_with(u, ".json")))
if (u.empty() || (u.back() != '/' && !util::ends_with(u, ".json")))
{
u += '/';
}
// mimicking conda's behavior by special handling repodata.json
// todo support .zst
if (ends_with(u, "/repodata.json"))
if (util::ends_with(u, "/repodata.json"))
{
u = u.substr(0, u.size() - 13);
}
@ -411,7 +411,7 @@ namespace mamba
EVP_DigestFinal_ex(mdctx, hash, nullptr);
EVP_MD_CTX_destroy(mdctx);
std::string hex_digest = hex_string(hash, 16);
std::string hex_digest = util::hex_string(hash, 16);
return hex_digest.substr(0u, 8u);
}

View File

@ -53,14 +53,14 @@ extern "C"
#include "mamba/core/util.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_random.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/compare.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
bool is_package_file(std::string_view fn)
{
return ends_with(fn, ".tar.bz2") || ends_with(fn, ".conda");
return util::ends_with(fn, ".tar.bz2") || util::ends_with(fn, ".conda");
}
// This function returns true even for broken symlinks
@ -180,7 +180,7 @@ namespace mamba
do
{
std::string random_file_name = mamba::generate_random_alphanumeric_string(10);
final_path = temp_path / concat(prefix, random_file_name, suffix);
final_path = temp_path / util::concat(prefix, random_file_name, suffix);
} while (fs::exists(final_path));
try
@ -277,17 +277,17 @@ namespace mamba
void split_package_extension(const std::string& file, std::string& name, std::string& extension)
{
if (ends_with(file, ".conda"))
if (util::ends_with(file, ".conda"))
{
name = file.substr(0, file.size() - 6);
extension = ".conda";
}
else if (ends_with(file, ".tar.bz2"))
else if (util::ends_with(file, ".tar.bz2"))
{
name = file.substr(0, file.size() - 8);
extension = ".tar.bz2";
}
else if (ends_with(file, ".json"))
else if (util::ends_with(file, ".json"))
{
name = file.substr(0, file.size() - 5);
extension = ".json";
@ -403,8 +403,8 @@ namespace mamba
if (std::regex_search(s, unsafe))
{
std::string s2 = s;
replace_all(s2, "'", "'\"'\"'");
return concat("'", s2, "'");
util::replace_all(s2, "'", "'\"'\"'");
return util::concat("'", s2, "'");
}
else
{
@ -537,13 +537,17 @@ namespace mamba
fs::u8path trash_file = path;
std::size_t fcounter = 0;
trash_file.replace_extension(concat(trash_file.extension().string(), ".mamba_trash"));
trash_file.replace_extension(
util::concat(trash_file.extension().string(), ".mamba_trash")
);
while (lexists(trash_file))
{
trash_file = path;
trash_file.replace_extension(
concat(trash_file.extension().string(), std::to_string(fcounter), ".mamba_trash")
);
trash_file.replace_extension(util::concat(
trash_file.extension().string(),
std::to_string(fcounter),
".mamba_trash"
));
fcounter += 1;
if (fcounter > 100)
{
@ -574,7 +578,7 @@ namespace mamba
<< " (file in use?). Sleeping for " << counter * 2 << "s";
if (counter > 3)
{
throw std::runtime_error(concat("Could not delete file ", path.string()));
throw std::runtime_error(util::concat("Could not delete file ", path.string()));
}
std::this_thread::sleep_for(std::chrono::seconds(counter * 2));
}
@ -1247,7 +1251,7 @@ namespace mamba
bool ensure_comspec_set()
{
std::string cmd_exe = env::get("COMSPEC").value_or("");
if (!ends_with(to_lower(cmd_exe), "cmd.exe"))
if (!util::ends_with(util::to_lower(cmd_exe), "cmd.exe"))
{
cmd_exe = (fs::u8path(env::get("SystemRoot").value_or("")) / "System32" / "cmd.exe").string();
if (!fs::is_regular_file(cmd_exe))
@ -1457,7 +1461,9 @@ namespace mamba
auto comspec = env::get("COMSPEC");
if (!comspec)
{
throw std::runtime_error(concat("Failed to run script: COMSPEC not set in env vars."));
throw std::runtime_error(
util::concat("Failed to run script: COMSPEC not set in env vars.")
);
}
script_file = wrap_call(
@ -1499,7 +1505,7 @@ namespace mamba
bool is_yaml_file_name(std::string_view filename)
{
return ends_with(filename, ".yml") || ends_with(filename, ".yaml");
return util::ends_with(filename, ".yml") || util::ends_with(filename, ".yaml");
}
tl::expected<std::string, mamba_error> encode_base64(std::string_view input)
@ -1581,7 +1587,7 @@ namespace mamba
{
std::string copy(str);
if (contains(str, "/t/"))
if (util::contains(str, "/t/"))
{
copy = std::regex_replace(copy, Context::instance().token_regex, "/t/*****");
}

View File

@ -35,7 +35,7 @@
#include "mamba/core/output.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#ifdef _WIN32
static_assert(std::is_same_v<mamba::DWORD, ::DWORD>);
@ -138,7 +138,7 @@ namespace mamba
{
// Needs to be set system-wide & can only be run as admin ...
std::string win_ver = windows_version();
auto splitted = split(win_ver, ".");
auto splitted = util::split(win_ver, ".");
if (!(splitted.size() >= 3 && std::stoull(splitted[0]) >= 10
&& std::stoull(splitted[2]) >= 14352))
{
@ -249,7 +249,7 @@ namespace mamba
<< "Please file a bug report.\nError: " << ec.message();
return "";
}
std::string xout(strip(out));
std::string xout(util::strip(out));
// from python
std::regex ver_output_regex("(?:([\\w ]+) ([\\w.]+) .*\\[.* ([\\d.]+)\\])");
@ -260,8 +260,8 @@ namespace mamba
if (std::regex_match(xout, rmatch, ver_output_regex))
{
full_version = rmatch[3];
auto version_els = split(full_version, ".");
norm_version = concat(version_els[0], ".", version_els[1], ".", version_els[2]);
auto version_els = util::split(full_version, ".");
norm_version = util::concat(version_els[0], ".", version_els[1], ".", version_els[2]);
LOG_DEBUG << "Windows version found: " << norm_version;
}
else
@ -306,7 +306,7 @@ namespace mamba
return "";
}
auto version = std::string(strip(out));
auto version = std::string(util::strip(out));
LOG_DEBUG << "macos version found: " << version;
return version;
}
@ -434,7 +434,7 @@ namespace mamba
#elif defined(__linux__)
std::string get_process_name_by_pid(const int pid)
{
std::ifstream f(concat("/proc/", std::to_string(pid), "/status"));
std::ifstream f(util::concat("/proc/", std::to_string(pid), "/status"));
if (f.good())
{
std::string l;
@ -639,7 +639,7 @@ namespace mamba
features.true_colors = false;
std::string win_ver = windows_version();
auto splitted = split(win_ver, ".");
auto splitted = util::split(win_ver, ".");
if (splitted.size() >= 3 && std::stoull(splitted[0]) >= 10
&& std::stoull(splitted[2]) >= 15063)
{
@ -700,11 +700,11 @@ namespace mamba
std::string fix_win_path(const std::string& path)
{
#ifdef _WIN32
if (starts_with(path, "file:"))
if (util::starts_with(path, "file:"))
{
std::regex re(R"(\\(?! ))");
std::string res = std::regex_replace(path, re, R"(/)");
replace_all(res, ":////", "://");
util::replace_all(res, ":////", "://");
return res;
}
else

View File

@ -14,11 +14,10 @@
#include <openssl/evp.h>
#include "mamba/core/fetch.hpp"
#include "mamba/core/fsutil.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/core/validate.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -165,7 +164,7 @@ namespace mamba::validation
EVP_DigestFinal_ex(mdctx, hash, nullptr);
EVP_MD_CTX_destroy(mdctx);
return ::mamba::hex_string(hash, MAMBA_SHA256_SIZE_BYTES);
return ::mamba::util::hex_string(hash, MAMBA_SHA256_SIZE_BYTES);
}
std::string md5sum(const fs::u8path& path)
@ -194,7 +193,7 @@ namespace mamba::validation
EVP_DigestFinal_ex(mdctx, hash, nullptr);
EVP_MD_CTX_destroy(mdctx);
return ::mamba::hex_string(hash, MAMBA_MD5_SIZE_BYTES);
return ::mamba::util::hex_string(hash, MAMBA_MD5_SIZE_BYTES);
}
bool sha256(const fs::u8path& path, const std::string& validation)
@ -299,7 +298,7 @@ namespace mamba::validation
std::pair<std::string, std::string> generate_ed25519_keypair_hex()
{
auto pair = generate_ed25519_keypair();
return { ::mamba::hex_string(pair.first), ::mamba::hex_string(pair.second) };
return { ::mamba::util::hex_string(pair.first), ::mamba::util::hex_string(pair.second) };
}
int sign(const std::string& data, const unsigned char* sk, unsigned char* signature)
@ -355,7 +354,7 @@ namespace mamba::validation
std::array<unsigned char, MAMBA_ED25519_SIGSIZE_BYTES> sig;
error_code = sign(data, bin_sk.data(), sig.data());
signature = ::mamba::hex_string(sig, MAMBA_ED25519_SIGSIZE_BYTES);
signature = ::mamba::util::hex_string(sig, MAMBA_ED25519_SIGSIZE_BYTES);
return error_code;
}
@ -556,7 +555,7 @@ namespace mamba::validation
std::string SpecBase::compatible_prefix() const
{
auto split_spec_version = mamba::split(m_spec_version, ".", 2);
auto split_spec_version = ::mamba::util::split(m_spec_version, ".", 2);
auto spec_version_major = std::stoi(split_spec_version[0]);
if (spec_version_major == 0)
{
@ -570,7 +569,7 @@ namespace mamba::validation
std::vector<std::string> SpecBase::upgrade_prefix() const
{
auto split_spec_version = mamba::split(m_spec_version, ".", 2);
auto split_spec_version = ::mamba::util::split(m_spec_version, ".", 2);
auto spec_version_major = std::stoi(split_spec_version[0]);
auto spec_version_minor = std::stoi(split_spec_version[1]);
if (spec_version_major == 0)
@ -619,7 +618,7 @@ namespace mamba::validation
bool SpecBase::is_compatible(const std::string& version) const
{
return mamba::starts_with(version, compatible_prefix() + ".");
return ::mamba::util::starts_with(version, compatible_prefix() + ".");
}
bool SpecBase::is_compatible(const json& j) const
@ -645,7 +644,7 @@ namespace mamba::validation
possible_upgrades.push_back(s);
}
return mamba::starts_with_any(version, possible_upgrades);
return ::mamba::util::starts_with_any(version, possible_upgrades);
}
bool SpecBase::is_upgrade(const json& j) const
@ -809,7 +808,7 @@ namespace mamba::validation
std::inserter(diff, diff.end())
);
LOG_ERROR << "Missing roles while loading '" << type() << "' metadata: '"
<< mamba::join(", ", diff) << "'";
<< ::mamba::util::join(", ", diff) << "'";
throw role_metadata_error();
}
@ -1059,15 +1058,16 @@ namespace mamba::validation
for (auto& s : upgrade_spec)
{
files.push_back(
mamba::join(".", std::vector<std::string>({ new_v, "sv" + s, "root.json" }))
::mamba::util::join(".", std::vector<std::string>({ new_v, "sv" + s, "root.json" }))
);
}
// compatible next
files.push_back(
mamba::join(".", std::vector<std::string>({ new_v, "sv" + compat_spec, "root.json" }))
);
files.push_back(::mamba::util::join(
".",
std::vector<std::string>({ new_v, "sv" + compat_spec, "root.json" })
));
// then finally undefined spec
files.push_back(mamba::join(".", std::vector<std::string>({ new_v, "root.json" })));
files.push_back(::mamba::util::join(".", std::vector<std::string>({ new_v, "root.json" })));
return files;
}
@ -1396,7 +1396,7 @@ namespace mamba::validation
{
std::array<unsigned char, MAMBA_ED25519_SIGSIZE_BYTES> sig_bin;
sign(j.dump(), sk, sig_bin.data());
auto sig_hex = ::mamba::hex_string(sig_bin);
auto sig_hex = ::mamba::util::hex_string(sig_bin);
return { pk, sig_hex };
}
@ -2146,7 +2146,7 @@ namespace mamba::validation
// Update from the most recent spec supported by this client
for (auto& f : update_files)
{
auto url = mamba::concat(m_base_url, "/", f.string());
auto url = ::mamba::util::concat(m_base_url, "/", f.string());
tmp_file_path = tmp_dir_path / f;
auto dl_target = std::make_unique<mamba::DownloadTarget>(

View File

@ -9,8 +9,8 @@
#include "mamba/core/output.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/core/virtual_packages.hpp"
#include "mamba/util/string.hpp"
#ifdef _WIN32
#include <windows.h>
@ -52,7 +52,7 @@ namespace mamba
version = ver.data();
}
#endif
return std::string(strip(version, "glibc "));
return std::string(util::strip(version, "glibc "));
}
std::string cuda_version()
@ -84,7 +84,7 @@ namespace mamba
// Windows fallback
bool may_exist = false;
std::string path = env::get("PATH").value_or("");
std::vector<std::string> paths = split(path, env::pathsep());
std::vector<std::string> paths = util::split(path, env::pathsep());
for (auto& p : paths)
{
@ -100,7 +100,7 @@ namespace mamba
{
for (auto& p : fs::directory_iterator(base))
{
if (starts_with(p.path().filename().string(), "nv")
if (util::starts_with(p.path().filename().string(), "nv")
&& fs::exists(p.path() / "nvidia-smi.exe"))
{
std::string f = (p.path() / "nvidia-smi.exe").string();
@ -168,7 +168,7 @@ namespace mamba
std::vector<PackageInfo> res;
auto platform = Context::instance().platform;
auto split_platform = split(platform, "-", 1);
auto split_platform = util::split(platform, "-", 1);
if (split_platform.size() != 2)
{

View File

@ -11,8 +11,8 @@
#include <fmt/format.h>
#include <nlohmann/json.hpp>
#include "mamba/core/util_string.hpp"
#include "mamba/specs/platform.hpp"
#include "mamba/util/string.hpp"
namespace mamba::specs
{
@ -62,7 +62,7 @@ namespace mamba::specs
auto platform_parse(std::string_view str) -> std::optional<Platform>
{
std::string const str_clean = to_lower(strip(str));
std::string const str_clean = util::to_lower(util::strip(str));
for (const auto p : {
Platform::linux_32,
Platform::linux_64,

View File

@ -12,9 +12,9 @@
#include <tuple>
#include "mamba/core/error_handling.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/specs/version.hpp"
#include "mamba/util/cast.hpp"
#include "mamba/util/string.hpp"
namespace mamba::specs
{
@ -59,14 +59,14 @@ namespace mamba::specs
}
VersionPartAtom::VersionPartAtom(std::size_t numeral, std::string_view literal)
: m_literal{ to_lower(literal) }
: m_literal{ util::to_lower(literal) }
, m_numeral{ numeral }
{
}
template <typename Char>
VersionPartAtom::VersionPartAtom(std::size_t numeral, std::basic_string<Char>&& literal)
: m_literal{ to_lower(std::move(literal)) }
: m_literal{ util::to_lower(std::move(literal)) }
, m_numeral{ numeral }
{
}
@ -532,7 +532,10 @@ namespace mamba::specs
template <typename Int>
auto parse_leading_integer(std::string_view str) -> std::pair<Int, std::string_view>
{
const auto [integer_str, rest] = lstrip_if_parts(str, [](char c) { return is_digit(c); });
const auto [integer_str, rest] = util::lstrip_if_parts(
str,
[](char c) { return util::is_digit(c); }
);
auto maybe_integer = to_int<Int>(integer_str);
assert(maybe_integer.has_value());
return { maybe_integer.value(), rest };
@ -541,7 +544,10 @@ namespace mamba::specs
auto parse_leading_literal(std::string_view str)
-> std::pair<std::string_view, std::string_view>
{
const auto [literal, rest] = lstrip_if_parts(str, [](char c) { return !is_digit(c); });
const auto [literal, rest] = util::lstrip_if_parts(
str,
[](char c) { return !util::is_digit(c); }
);
return { literal, rest };
}
@ -553,7 +559,7 @@ namespace mamba::specs
std::size_t numeral = 0;
std::string_view literal = {};
auto tail = std::string_view{};
if (is_digit(str.front()))
if (util::is_digit(str.front()))
{
std::tie(numeral, tail) = parse_leading_integer<std::size_t>(str);
}
@ -596,7 +602,7 @@ namespace mamba::specs
auto allowed_char = [](char c) -> bool
{
return is_alphanum(c) //
return util::is_alphanum(c) //
|| (c == Version::part_delim) //
|| (c == Version::part_delim_alt) //
|| (c == Version::part_delim_special) //
@ -682,7 +688,7 @@ namespace mamba::specs
auto Version::parse(std::string_view str) -> Version
{
str = strip(str);
str = util::strip(str);
try
{
auto [epoch, version_and_local_str] = parse_leading_epoch<std::size_t>(str);

View File

@ -12,8 +12,8 @@
#include <fmt/format.h>
#include "mamba/core/util_string.hpp"
#include "mamba/specs/version_spec.hpp"
#include "mamba/util/string.hpp"
namespace mamba::specs
{
@ -195,37 +195,37 @@ namespace mamba::specs
auto parse_op_and_version(std::string_view str) -> VersionPredicate
{
str = strip(str);
str = util::strip(str);
// WARNING order is important since some operator are prefix of others.
if (str.empty() || is_char(str, VersionSpec::glob_suffix_token))
{
return VersionPredicate::make_free();
}
if (starts_with(str, VersionSpec::greater_equal_str))
if (util::starts_with(str, VersionSpec::greater_equal_str))
{
return VersionPredicate::make_greater_equal(
Version::parse(str.substr(VersionSpec::greater_equal_str.size()))
);
}
if (starts_with(str, VersionSpec::greater_str))
if (util::starts_with(str, VersionSpec::greater_str))
{
return VersionPredicate::make_greater(
Version::parse(str.substr(VersionSpec::greater_str.size()))
);
}
if (starts_with(str, VersionSpec::less_equal_str))
if (util::starts_with(str, VersionSpec::less_equal_str))
{
return VersionPredicate::make_less_equal(
Version::parse(str.substr(VersionSpec::less_equal_str.size()))
);
}
if (starts_with(str, VersionSpec::less_str))
if (util::starts_with(str, VersionSpec::less_str))
{
return VersionPredicate::make_less(
Version::parse(str.substr(VersionSpec::less_str.size()))
);
}
if (starts_with(str, VersionSpec::compatible_str))
if (util::starts_with(str, VersionSpec::compatible_str))
{
auto ver = Version::parse(str.substr(VersionSpec::compatible_str.size()));
// in ``~=1.1`` level is assumed to be 1, in ``~=1.1.1`` level 2, etc.
@ -233,9 +233,9 @@ namespace mamba::specs
const std::size_t level = std::max(ver.version().size(), one) - one;
return VersionPredicate::make_compatible_with(std::move(ver), level);
}
const bool has_glob_suffix = ends_with(str, VersionSpec::glob_suffix_str);
const bool has_glob_suffix = util::ends_with(str, VersionSpec::glob_suffix_str);
std::size_t const glob_len = has_glob_suffix * VersionSpec::glob_suffix_str.size();
if (starts_with(str, VersionSpec::equal_str))
if (util::starts_with(str, VersionSpec::equal_str))
{
std::size_t const start = VersionSpec::equal_str.size();
// Glob suffix changes meaning for ==1.3.*
@ -250,7 +250,7 @@ namespace mamba::specs
return VersionPredicate::make_equal_to(Version::parse(str.substr(start)));
}
}
if (starts_with(str, VersionSpec::not_equal_str))
if (util::starts_with(str, VersionSpec::not_equal_str))
{
std::size_t const start = VersionSpec::not_equal_str.size();
// Glob suffix changes meaning for !=1.3.*
@ -265,7 +265,7 @@ namespace mamba::specs
return VersionPredicate::make_not_equal_to(Version::parse(str.substr(start)));
}
}
if (starts_with(str, VersionSpec::starts_with_str))
if (util::starts_with(str, VersionSpec::starts_with_str))
{
std::size_t const start = VersionSpec::starts_with_str.size();
// Glob suffix does not change meaning for =1.3.*
@ -273,10 +273,10 @@ namespace mamba::specs
Version::parse(str.substr(start, str.size() - glob_len - start))
);
}
if (is_digit(str.front())) // All versions must start with a digit
if (util::is_digit(str.front())) // All versions must start with a digit
{
// Glob suffix does change meaning for 1.3.* and 1.3*
if (ends_with(str, VersionSpec::glob_suffix_token))
if (util::ends_with(str, VersionSpec::glob_suffix_token))
{
// either ".*" or "*"
static std::size_t constexpr one = std::size_t(1); // MSVC
@ -306,7 +306,7 @@ namespace mamba::specs
{ return std::find(all_tokens.cbegin(), all_tokens.cend(), c) != all_tokens.cend(); };
auto parser = util::InfixParser<VersionPredicate, util::BoolOperator>();
str = lstrip(str);
str = util::lstrip(str);
while (!str.empty())
{
if (str.front() == VersionSpec::and_token)
@ -322,16 +322,16 @@ namespace mamba::specs
else if (str.front() == VersionSpec::left_parenthesis_token)
{
parser.push_left_parenthesis();
str = lstrip(str.substr(1));
str = util::lstrip(str.substr(1));
}
else if (str.front() == VersionSpec::right_parenthesis_token)
{
parser.push_right_parenthesis();
str = lstrip(str.substr(1));
str = util::lstrip(str.substr(1));
}
else
{
auto [op_ver, rest] = lstrip_if_parts(str, [&](auto c) { return !is_token(c); });
auto [op_ver, rest] = util::lstrip_if_parts(str, [&](auto c) { return !is_token(c); });
parser.push_variable(parse_op_and_version(op_ver));
str = rest;
}

View File

@ -11,9 +11,9 @@
#include <stddef.h>
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
namespace mamba::util
{
/****************************************
* Implementation of cctype functions *

View File

@ -21,6 +21,7 @@ set(LIBMAMBA_TEST_SRCS
src/solv-cpp/test_solver.cpp
src/solv-cpp/test_transaction.cpp
# Utility library
src/util/test_string.cpp
src/util/test_cast.cpp
src/util/test_compare.cpp
src/util/test_type_traits.cpp
@ -53,7 +54,6 @@ set(LIBMAMBA_TEST_SRCS
src/core/test_validate.cpp
src/core/test_virtual_packages.cpp
src/core/test_util.cpp
src/core/test_util_string.cpp
src/core/test_util_os.cpp
src/core/test_system_env.cpp
src/core/test_env_lockfile.cpp

View File

@ -9,7 +9,7 @@
#include "mamba/api/configuration.hpp"
#include "mamba/core/context.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#include "test_data.hpp"
@ -781,7 +781,7 @@ namespace mamba
CHECK_FALSE(CTX); \
} \
\
std::string env_name = "MAMBA_" + to_upper(#NAME); \
std::string env_name = "MAMBA_" + util::to_upper(#NAME); \
env::set(env_name, "true"); \
load_test_config(rc2); \
\

View File

@ -9,7 +9,7 @@
#include <doctest/doctest.h>
#include "mamba/core/invoke.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -28,7 +28,7 @@ namespace mamba
const auto message = "expected failure";
auto result = safe_invoke([&] { throw std::runtime_error(message); });
CHECK_FALSE(result);
CHECK_MESSAGE(ends_with(result.error().what(), message), result.error().what());
CHECK_MESSAGE(util::ends_with(result.error().what(), message), result.error().what());
}
TEST_CASE("catches_any_exceptions")
@ -36,7 +36,10 @@ namespace mamba
const auto message = "expected failure";
auto result = safe_invoke([&] { throw message; });
CHECK_FALSE(result);
CHECK_MESSAGE(ends_with(result.error().what(), "unknown error"), result.error().what());
CHECK_MESSAGE(
util::ends_with(result.error().what(), "unknown error"),
result.error().what()
);
}
TEST_CASE("safely_catch_moved_callable_destructor_exception")
@ -84,7 +87,10 @@ namespace mamba
auto result = safe_invoke(DoNotDoThisAtHome{ did_move_happened });
CHECK_FALSE(result);
CHECK_MESSAGE(ends_with(result.error().what(), "unknown error"), result.error().what());
CHECK_MESSAGE(
util::ends_with(result.error().what(), "unknown error"),
result.error().what()
);
CHECK(did_move_happened);
}
}

View File

@ -25,7 +25,7 @@
#include "mamba/core/subdirdata.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_random.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
using namespace mamba;
@ -436,7 +436,7 @@ namespace
using Node = std::remove_const_t<std::remove_reference_t<decltype(n)>>;
if constexpr (!std::is_same_v<Node, ProblemsGraph::RootNode>)
{
return starts_with(std::invoke(&Node::name, n), "__");
return util::starts_with(std::invoke(&Node::name, n), "__");
}
return false;
},
@ -623,7 +623,7 @@ TEST_CASE("Create problem graph")
using Node = std::remove_cv_t<std::remove_reference_t<decltype(node)>>;
if constexpr (!std::is_same_v<Node, CpPbGr::RootNode>)
{
CHECK(contains(message, node.name()));
CHECK(util::contains(message, node.name()));
}
};

View File

@ -10,7 +10,7 @@
#include "mamba/core/environment.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
{
@ -32,7 +32,7 @@ namespace mamba
auto expanded = env::expand_user("~/this/is/a/test");
if (on_linux)
{
CHECK(starts_with(expanded.string(), "/home/"));
CHECK(util::starts_with(expanded.string(), "/home/"));
}
}
}

View File

@ -13,8 +13,8 @@
#include "mamba/core/environment.hpp"
#include "mamba/core/fsutil.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/core/validate.hpp"
#include "mamba/util/string.hpp"
#include "test_data.hpp"
@ -43,21 +43,21 @@ namespace mamba::validation
std::array<unsigned char, MAMBA_ED25519_KEYSIZE_BYTES> pk, sk;
generate_ed25519_keypair(pk.data(), sk.data());
auto pk_hex = ::mamba::hex_string(pk);
auto pk_hex = ::mamba::util::hex_string(pk);
auto pk_bytes = ed25519_key_hex_to_bytes(pk_hex);
CHECK_EQ(pk_hex, ::mamba::hex_string(pk_bytes));
CHECK_EQ(pk_hex, ::mamba::util::hex_string(pk_bytes));
spdlog::set_level(spdlog::level::debug);
std::array<unsigned char, 5> not_even_key;
pk_hex = ::mamba::hex_string(not_even_key);
pk_hex = ::mamba::util::hex_string(not_even_key);
pk_bytes = ed25519_key_hex_to_bytes(pk_hex);
CHECK_FALSE(pk_hex == ::mamba::hex_string(pk_bytes));
CHECK_FALSE(pk_hex == ::mamba::util::hex_string(pk_bytes));
std::array<unsigned char, 6> wrong_size_key;
pk_hex = ::mamba::hex_string(wrong_size_key);
pk_hex = ::mamba::util::hex_string(wrong_size_key);
pk_bytes = ed25519_key_hex_to_bytes(pk_hex);
CHECK_FALSE(pk_hex == ::mamba::hex_string(pk_bytes));
CHECK_FALSE(pk_hex == ::mamba::util::hex_string(pk_bytes));
spdlog::set_level(spdlog::level::info);
}
@ -70,21 +70,21 @@ namespace mamba::validation
std::array<unsigned char, MAMBA_ED25519_SIGSIZE_BYTES> sig;
sign("Some text.", sk.data(), sig.data());
auto sig_hex = ::mamba::hex_string(sig);
auto sig_hex = ::mamba::util::hex_string(sig);
auto sig_bytes = ed25519_sig_hex_to_bytes(sig_hex);
CHECK_EQ(sig_hex, ::mamba::hex_string(sig_bytes));
CHECK_EQ(sig_hex, ::mamba::util::hex_string(sig_bytes));
spdlog::set_level(spdlog::level::debug);
std::array<unsigned char, 5> not_even_sig;
sig_hex = ::mamba::hex_string(not_even_sig);
sig_hex = ::mamba::util::hex_string(not_even_sig);
sig_bytes = ed25519_sig_hex_to_bytes(sig_hex);
CHECK_FALSE(sig_hex == ::mamba::hex_string(sig_bytes));
CHECK_FALSE(sig_hex == ::mamba::util::hex_string(sig_bytes));
std::array<unsigned char, 6> wrong_size_sig;
sig_hex = ::mamba::hex_string(wrong_size_sig);
sig_hex = ::mamba::util::hex_string(wrong_size_sig);
sig_bytes = ed25519_sig_hex_to_bytes(sig_hex);
CHECK_FALSE(sig_hex == ::mamba::hex_string(sig_bytes));
CHECK_FALSE(sig_hex == ::mamba::util::hex_string(sig_bytes));
spdlog::set_level(spdlog::level::info);
}
@ -116,8 +116,8 @@ namespace mamba::validation
TEST_CASE_FIXTURE(VerifyMsg, "from_hex")
{
auto signature_hex = ::mamba::hex_string(signature, MAMBA_ED25519_SIGSIZE_BYTES);
auto pk_hex = ::mamba::hex_string(pk, MAMBA_ED25519_KEYSIZE_BYTES);
auto signature_hex = ::mamba::util::hex_string(signature, MAMBA_ED25519_SIGSIZE_BYTES);
auto pk_hex = ::mamba::util::hex_string(pk, MAMBA_ED25519_KEYSIZE_BYTES);
CHECK_EQ(verify("Some text.", pk_hex, signature_hex), 1);
}
@ -125,7 +125,7 @@ namespace mamba::validation
TEST_CASE_FIXTURE(VerifyMsg, "wrong_signature")
{
spdlog::set_level(spdlog::level::debug);
auto pk_hex = ::mamba::hex_string(pk, MAMBA_ED25519_KEYSIZE_BYTES);
auto pk_hex = ::mamba::util::hex_string(pk, MAMBA_ED25519_KEYSIZE_BYTES);
CHECK_EQ(verify("Some text.", pk_hex, "signature_hex"), 0);
spdlog::set_level(spdlog::level::info);
@ -134,7 +134,7 @@ namespace mamba::validation
TEST_CASE_FIXTURE(VerifyMsg, "wrong_public_key")
{
spdlog::set_level(spdlog::level::debug);
auto signature_hex = ::mamba::hex_string(signature, MAMBA_ED25519_SIGSIZE_BYTES);
auto signature_hex = ::mamba::util::hex_string(signature, MAMBA_ED25519_SIGSIZE_BYTES);
CHECK_EQ(verify("Some text.", "pk_hex", signature_hex), 0);
spdlog::set_level(spdlog::level::info);
@ -313,7 +313,7 @@ namespace mamba::validation
{
sign(root_meta.dump(2), secret.second.data(), sig_bin);
auto sig_hex = ::mamba::hex_string(sig_bin, MAMBA_ED25519_SIGSIZE_BYTES);
auto sig_hex = ::mamba::util::hex_string(sig_bin, MAMBA_ED25519_SIGSIZE_BYTES);
signatures[secret.first].insert({ "signature", sig_hex });
}
@ -363,7 +363,7 @@ namespace mamba::validation
for (int i = 0; i < count; ++i)
{
generate_ed25519_keypair(pk, sk.data());
auto pk_hex = ::mamba::hex_string(pk, MAMBA_ED25519_KEYSIZE_BYTES);
auto pk_hex = ::mamba::util::hex_string(pk, MAMBA_ED25519_KEYSIZE_BYTES);
role_secrets.insert({ pk_hex, sk });
}
@ -1008,7 +1008,7 @@ namespace mamba::validation
{
sign(meta.dump(2), secret.second.data(), sig_bin);
auto sig_hex = ::mamba::hex_string(sig_bin, MAMBA_ED25519_SIGSIZE_BYTES);
auto sig_hex = ::mamba::util::hex_string(sig_bin, MAMBA_ED25519_SIGSIZE_BYTES);
signatures[secret.first].insert({ "signature", sig_hex });
}
@ -1298,7 +1298,7 @@ namespace mamba::validation
{
sign(meta.dump(2), secret.second.data(), sig_bin);
auto sig_hex = ::mamba::hex_string(sig_bin, MAMBA_ED25519_SIGSIZE_BYTES);
auto sig_hex = ::mamba::util::hex_string(sig_bin, MAMBA_ED25519_SIGSIZE_BYTES);
signatures[secret.first].insert({ "signature", sig_hex });
}
@ -1346,7 +1346,7 @@ namespace mamba::validation
{
sign(meta.dump(2), secret.second.data(), sig_bin);
auto sig_hex = ::mamba::hex_string(sig_bin, MAMBA_ED25519_SIGSIZE_BYTES);
auto sig_hex = ::mamba::util::hex_string(sig_bin, MAMBA_ED25519_SIGSIZE_BYTES);
signatures[secret.first].insert({ "signature", sig_hex });
}
@ -1622,7 +1622,7 @@ namespace mamba::validation
{
sign(root_meta.dump(), secret.second.data(), sig_bin);
auto sig_hex = ::mamba::hex_string(sig_bin, MAMBA_ED25519_SIGSIZE_BYTES);
auto sig_hex = ::mamba::util::hex_string(sig_bin, MAMBA_ED25519_SIGSIZE_BYTES);
signatures.push_back({ secret.first, sig_hex });
}
@ -1650,7 +1650,7 @@ namespace mamba::validation
{
generate_ed25519_keypair(pk, sk.data());
auto pk_hex = ::mamba::hex_string(pk, MAMBA_ED25519_KEYSIZE_BYTES);
auto pk_hex = ::mamba::util::hex_string(pk, MAMBA_ED25519_KEYSIZE_BYTES);
role_secrets.insert({ pk_hex, sk });
}
return role_secrets;

View File

@ -12,9 +12,9 @@
#include <doctest/doctest.h>
#include "mamba/core/mamba_fs.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
namespace mamba
namespace mamba::util
{
TEST_SUITE("util_string")
{

View File

@ -18,7 +18,6 @@
#include "mamba/api/configuration.hpp"
#include "mamba/core/channel.hpp"
#include "mamba/core/context.hpp"
#include "mamba/core/execution.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/package_handling.hpp"
#include "mamba/core/pool.hpp"
@ -29,12 +28,11 @@
#include "mamba/core/solver.hpp"
#include "mamba/core/subdirdata.hpp"
#include "mamba/core/transaction.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/core/validate.hpp"
#include "mamba/core/virtual_packages.hpp"
#include "mamba/util/flat_set.hpp"
#include "mamba/util/string.hpp"
namespace py = pybind11;
@ -410,7 +408,7 @@ PYBIND11_MODULE(bindings, m)
case query::RECURSIVETABLE:
res.table(
res_stream,
{ "Name", "Version", "Build", concat("Depends:", query), "Channel" }
{ "Name", "Version", "Build", util::concat("Depends:", query), "Channel" }
);
}
if (res.empty() && format != query::JSON)
@ -845,7 +843,8 @@ PYBIND11_MODULE(bindings, m)
static_assert(LIBMAMBA_VERSION_MAJOR == 1, "Version 1 compatibility.");
return fmt::format("{}", fmt::join(self.track_features, ","));
},
[](PackageInfo& self, std::string_view val) { self.track_features = split(val, ","); }
[](PackageInfo& self, std::string_view val)
{ self.track_features = util::split(val, ","); }
)
.def_readwrite("depends", &PackageInfo::depends)
.def_readwrite("constrains", &PackageInfo::constrains)

View File

@ -5,7 +5,7 @@
// The full license is in the file LICENSE, distributed with this software.
#include "mamba/core/package_handling.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#include "package.hpp"
@ -48,11 +48,11 @@ set_package_command(CLI::App* com)
{
std::cout << "Compressing " << fs::absolute(infile) << " to " << dest << std::endl;
if (ends_with(dest, ".tar.bz2") && compression_level == -1)
if (util::ends_with(dest, ".tar.bz2") && compression_level == -1)
{
compression_level = 9;
}
if (ends_with(dest, ".conda") && compression_level == -1)
if (util::ends_with(dest, ".conda") && compression_level == -1)
{
compression_level = 15;
}
@ -81,7 +81,7 @@ set_package_command(CLI::App* com)
transmute_subcom->callback(
[&]()
{
if (ends_with(infile, ".tar.bz2"))
if (util::ends_with(infile, ".tar.bz2"))
{
if (compression_level == -1)
{

View File

@ -12,7 +12,7 @@
#include "mamba/api/configuration.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/run.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
void
@ -45,7 +45,7 @@ complete_options(
if (p.is_directory() && fs::exists(p.path() / "conda-meta"))
{
auto name = p.path().filename().string();
if (mamba::starts_with(name, name_start))
if (mamba::util::starts_with(name, name_start))
{
options.push_back(name);
}
@ -53,17 +53,17 @@ complete_options(
}
}
}
else if (mamba::starts_with(last_args.back(), "-"))
else if (mamba::util::starts_with(last_args.back(), "-"))
{
auto opt_start = mamba::lstrip(last_args.back(), "-");
auto opt_start = mamba::util::lstrip(last_args.back(), "-");
if (mamba::starts_with(last_args.back(), "--"))
if (mamba::util::starts_with(last_args.back(), "--"))
{
for (const auto* opt : app->get_options())
{
for (const auto& n : opt->get_lnames())
{
if (mamba::starts_with(n, opt_start))
if (mamba::util::starts_with(n, opt_start))
{
options.push_back("--" + n);
}
@ -80,7 +80,7 @@ complete_options(
{
for (const auto& n : opt->get_snames())
{
if (mamba::starts_with(n, opt_start))
if (mamba::util::starts_with(n, opt_start))
{
options.push_back("-" + n);
}
@ -93,7 +93,7 @@ complete_options(
for (const auto* subc : app->get_subcommands(nullptr))
{
auto& n = subc->get_name();
if (mamba::starts_with(n, last_args.back()))
if (mamba::util::starts_with(n, last_args.back()))
{
options.push_back(n);
}
@ -204,12 +204,12 @@ get_completions(CLI::App* app, mamba::Configuration& config, int argc, char** ar
if (argc > 2 && std::string(argv[argc - 2]) == "-n")
{
completer_args.push_back(argv[argc - 2]);
completer_args.push_back(std::string(mamba::strip(argv[argc - 1])));
completer_args.push_back(std::string(mamba::util::strip(argv[argc - 1])));
argc -= 1; // don't parse the -n
}
else
{
completer_args.push_back(std::string(mamba::strip(argv[argc - 1])));
completer_args.push_back(std::string(mamba::util::strip(argv[argc - 1])));
}
std::vector<CLI::App*> apps = { app };

View File

@ -4,6 +4,8 @@
//
// The full license is in the file LICENSE, distributed with this software.
#include <CLI/App.hpp>
#include "constructor.hpp"
#include "mamba/api/configuration.hpp"
#include "mamba/api/install.hpp"
@ -12,9 +14,7 @@
#include "mamba/core/package_info.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "common_options.hpp"
#include "mamba/util/string.hpp"
using namespace mamba; // NOLINT(build/namespaces)
@ -87,11 +87,11 @@ construct(Configuration& config, const fs::u8path& prefix, bool extract_conda_pk
{
try
{
if (ends_with(fn, ".tar.bz2"))
if (util::ends_with(fn, ".tar.bz2"))
{
return j.at("packages").at(fn);
}
else if (ends_with(fn, ".conda"))
else if (util::ends_with(fn, ".conda"))
{
return j.at("packages.conda").at(fn);
}
@ -126,7 +126,7 @@ construct(Configuration& config, const fs::u8path& prefix, bool extract_conda_pk
{
channel_url = pkg_info.url.substr(0, pkg_info.url.size() - pkg_info.fn.size());
}
std::string repodata_cache_name = concat(cache_name_from_url(channel_url), ".json");
std::string repodata_cache_name = util::concat(cache_name_from_url(channel_url), ".json");
fs::u8path repodata_location = pkgs_dir / "cache" / repodata_cache_name;
nlohmann::json repodata_record;

View File

@ -13,7 +13,7 @@
#include "mamba/core/environments_manager.hpp"
#include "mamba/core/prefix_data.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#include "common_options.hpp"
@ -29,7 +29,7 @@ get_env_name(const fs::u8path& px)
{
return "base";
}
else if (mamba::starts_with(px.string(), ed.string()))
else if (util::starts_with(px.string(), ed.string()))
{
return fs::relative(px, ed).string();
}
@ -214,7 +214,7 @@ set_env_command(CLI::App* com, Configuration& config)
// Unregister environment
env_manager.unregister_env(env::expand_user(prefix));
Console::instance().print(join(
Console::instance().print(util::join(
"",
std::vector<std::string>({ "Environment removed at prefix: ", prefix.string() })
));

View File

@ -6,13 +6,14 @@
#include <string>
#include "mamba/api/list.hpp"
#include <CLI/App.hpp>
#include "mamba/core/environment.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#include "common_options.hpp"
std::string
read_stdin()
@ -50,7 +51,7 @@ get_token_base(const std::string& host)
maybe_path.pop_back();
}
return mamba::concat(url_handler.host(), maybe_colon_and_port, maybe_path);
return mamba::util::concat(url_handler.host(), maybe_colon_and_port, maybe_path);
}
void
@ -188,7 +189,7 @@ set_login_command(CLI::App* subcom)
{
auth_object["type"] = "BasicHTTPAuthentication";
auto pass_encoded = mamba::encode_base64(mamba::strip(pass));
auto pass_encoded = mamba::encode_base64(mamba::util::strip(pass));
if (!pass_encoded)
{
throw pass_encoded.error();
@ -200,12 +201,12 @@ set_login_command(CLI::App* subcom)
else if (!token.empty())
{
auth_object["type"] = "CondaToken";
auth_object["token"] = mamba::strip(token);
auth_object["token"] = mamba::util::strip(token);
}
else if (!bearer.empty())
{
auth_object["type"] = "BearerToken";
auth_object["token"] = mamba::strip(bearer);
auth_object["token"] = mamba::util::strip(bearer);
}
auth_info[token_base] = auth_object;

View File

@ -19,9 +19,11 @@
#include <vector>
#include <arpa/inet.h>
#include <fmt/format.h>
#include <limits.h>
#include <netinet/in.h>
#include <poll.h>
#include <spdlog/logger.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@ -29,11 +31,7 @@
#include "mamba/core/output.hpp"
#include "mamba/core/thread_utils.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_string.hpp"
#include "fmt/format.h"
#include "spdlog/spdlog.h"
#include "mamba/util/string.hpp"
#include "version.hpp"
@ -145,7 +143,7 @@ namespace microserver
// remove \r\n header ending
value = header.substr(colon_idx, header.size() - colon_idx - 2);
// http headers are case insensitive!
std::string lkey = mamba::to_lower(key);
std::string lkey = mamba::util::to_lower(key);
return std::make_pair(lkey, std::string(value));
}
@ -164,7 +162,7 @@ namespace microserver
{
if (i++ == 0)
{
auto R = mamba::split(line, " ", 3);
auto R = mamba::util::split(line, " ", 3);
if (R.size() != 3)
{
@ -179,11 +177,11 @@ namespace microserver
// We have GET params here
if (pos != std::string::npos)
{
auto Q1 = mamba::split(req.path.substr(pos + 1), "&");
auto Q1 = mamba::util::split(req.path.substr(pos + 1), "&");
for (std::vector<std::string>::size_type q = 0; q < Q1.size(); q++)
{
auto Q2 = mamba::split(Q1[q], "=");
auto Q2 = mamba::util::split(Q1[q], "=");
if (Q2.size() == 2)
{

View File

@ -6,7 +6,7 @@
#include "mamba/api/configuration.hpp"
#include "mamba/core/package_handling.hpp"
#include "mamba/core/util_string.hpp"
#include "mamba/util/string.hpp"
#include "common_options.hpp"
@ -60,11 +60,11 @@ set_package_command(CLI::App* subcom, Configuration& config)
Console::stream() << "Compressing " << fs::absolute(infile) << " to " << dest
<< std::endl;
if (ends_with(dest, ".tar.bz2") && compression_level == -1)
if (util::ends_with(dest, ".tar.bz2") && compression_level == -1)
{
compression_level = 9;
}
if (ends_with(dest, ".conda") && compression_level == -1)
if (util::ends_with(dest, ".conda") && compression_level == -1)
{
compression_level = 15;
}
@ -97,7 +97,7 @@ set_package_command(CLI::App* subcom, Configuration& config)
// load verbose and other options to context
config.load();
if (ends_with(infile, ".tar.bz2"))
if (util::ends_with(infile, ".tar.bz2"))
{
if (compression_level == -1)
{

View File

@ -21,6 +21,7 @@
#include "mamba/core/solver.hpp"
#include "mamba/core/transaction.hpp"
#include "mamba/core/virtual_packages.hpp"
#include "mamba/util/string.hpp"
#include "common_options.hpp"
#include "microserver.cpp"
@ -81,7 +82,7 @@ handle_solve_request(
}
}
std::string cache_key = mamba::join(", ", channels) + fmt::format(", {}", platform);
std::string cache_key = mamba::util::join(", ", channels) + fmt::format(", {}", platform);
MultiPackageCache package_caches(ctx.pkgs_dirs);
if (cache_map.find(cache_key) == cache_map.end())
@ -121,7 +122,7 @@ handle_solve_request(
std::vector<PackageInfo> vpacks;
for (const auto& s : virtual_packages)
{
auto elements = split(s, "=");
auto elements = util::split(s, "=");
vpacks.push_back(detail::make_virtual_package(
elements[0],
elements.size() >= 2 ? elements[1] : "",