Skip to content

Commit

Permalink
Replaced rstrip reimplementation with call to remove_suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille committed Oct 4, 2024
1 parent 675c6de commit f76c1f0
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions libmamba/src/api/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,14 @@ namespace mamba
return a.name < b.name;
}

// This is more or less an implementation of `util::rstrip` specific to this use case
// (for printing purposes), but using `std::string` instead of `std::string_view`
// `util::rstrip` is not used here because it leads to an UB,
// `using non owned/tracked strings from Channel (& co) and PackageInfo
std::string rstrip(const std::string& full_str, const std::string& sub_str)
{
if (util::ends_with(full_str, sub_str))
{
return full_str.substr(0, full_str.length() - sub_str.length());
}
else
{
return full_str;
}
}

std::string strip_from_filename_and_platform(
const std::string& full_str,
const std::string& filename,
const std::string& platform
)
{
return rstrip(rstrip(rstrip(rstrip(full_str, filename), "/"), platform), "/");
using util::remove_suffix;
return std::string(remove_suffix(remove_suffix(remove_suffix(remove_suffix(full_str, filename), "/"), platform), "/"));
}

void list_packages(
Expand Down

0 comments on commit f76c1f0

Please sign in to comment.