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