mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-08 11:59:48 -04:00
refactor: simplify a few places with string_view / ranges
This commit is contained in:
parent
e440101b0c
commit
f3300c4cbd
@ -91,10 +91,7 @@ T find_option(sorted_array_map<std::string_view, T, N> const& options,
|
||||
template <typename T, size_t N>
|
||||
std::string
|
||||
option_names(sorted_array_map<std::string_view, T, N> const& options) {
|
||||
// The string_view is needed because ranges::views::join() will include
|
||||
// the null terminator when using a string literal.
|
||||
static constexpr std::string_view kJoiner{", "};
|
||||
return options | ranges::views::keys | ranges::views::join(kJoiner) |
|
||||
return options | ranges::views::keys | ranges::views::join(", "sv) |
|
||||
ranges::to<std::string>;
|
||||
}
|
||||
|
||||
|
@ -37,22 +37,20 @@ namespace dwarfs::writer {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr std::array<std::pair<std::string_view, fragment_order_mode>, 5>
|
||||
order_choices{{
|
||||
{"none", fragment_order_mode::NONE},
|
||||
{"path", fragment_order_mode::PATH},
|
||||
{"revpath", fragment_order_mode::REVPATH},
|
||||
{"similarity", fragment_order_mode::SIMILARITY},
|
||||
{"nilsimsa", fragment_order_mode::NILSIMSA},
|
||||
}};
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
constexpr std::array order_choices{
|
||||
std::pair{"none"sv, fragment_order_mode::NONE},
|
||||
std::pair{"path"sv, fragment_order_mode::PATH},
|
||||
std::pair{"revpath"sv, fragment_order_mode::REVPATH},
|
||||
std::pair{"similarity"sv, fragment_order_mode::SIMILARITY},
|
||||
std::pair{"nilsimsa"sv, fragment_order_mode::NILSIMSA},
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string fragment_order_parser::choices() {
|
||||
// The string_view is needed because ranges::views::join() will include
|
||||
// the null terminator when using a string literal.
|
||||
static constexpr std::string_view kJoiner{", "};
|
||||
return ranges::views::keys(order_choices) | ranges::views::join(kJoiner) |
|
||||
return ranges::views::keys(order_choices) | ranges::views::join(", "sv) |
|
||||
ranges::to<std::string>();
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <range/v3/view/join.hpp>
|
||||
#include <range/v3/view/map.hpp>
|
||||
|
||||
#include <dwarfs/sorted_array_map.h>
|
||||
#include <dwarfs/tool/main_adapter.h>
|
||||
#include <dwarfs/tool/tool.h>
|
||||
#include <dwarfs_tool_main.h>
|
||||
@ -41,6 +42,7 @@
|
||||
namespace {
|
||||
|
||||
using namespace dwarfs::tool;
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
#ifdef _WIN32
|
||||
#define EXE_EXT ".exe"
|
||||
@ -48,11 +50,11 @@ using namespace dwarfs::tool;
|
||||
#define EXE_EXT ""
|
||||
#endif
|
||||
|
||||
std::map<std::string_view, main_adapter::main_fn_type> const functions{
|
||||
{"dwarfs", dwarfs_main},
|
||||
{"mkdwarfs", mkdwarfs_main},
|
||||
{"dwarfsck", dwarfsck_main},
|
||||
{"dwarfsextract", dwarfsextract_main},
|
||||
constexpr dwarfs::sorted_array_map functions{
|
||||
std::pair{"dwarfs"sv, &dwarfs_main},
|
||||
std::pair{"mkdwarfs"sv, &mkdwarfs_main},
|
||||
std::pair{"dwarfsck"sv, &dwarfsck_main},
|
||||
std::pair{"dwarfsextract"sv, &dwarfsextract_main},
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@ -98,10 +100,7 @@ int SYS_MAIN(int argc, sys_char** argv) {
|
||||
|
||||
// nope, just print the help
|
||||
|
||||
// The string_view is needed because ranges::views::join() will include
|
||||
// the null terminator when using a string literal.
|
||||
static constexpr std::string_view kJoiner{", "};
|
||||
auto tools = ranges::views::keys(functions) | ranges::views::join(kJoiner) |
|
||||
auto tools = ranges::views::keys(functions) | ranges::views::join(", "sv) |
|
||||
ranges::to<std::string>;
|
||||
|
||||
// clang-format off
|
||||
|
Loading…
x
Reference in New Issue
Block a user