mirror of
https://github.com/ScrelliCopter/tmx2gba.git
synced 2025-02-21 03:29:25 +11:00
argparse: use replace raw char* strings with string views
This commit is contained in:
@@ -23,7 +23,7 @@ void ArgParse::Options::ShowShortUsage(const std::string_view name, std::ostream
|
||||
out << "Usage: " << name;
|
||||
for (const auto& it : options)
|
||||
{
|
||||
if (it.argumentName)
|
||||
if (!it.argumentName.empty())
|
||||
{
|
||||
// Option with argument
|
||||
it.required
|
||||
@@ -55,8 +55,8 @@ void ArgParse::Options::ShowHelpUsage(const std::string_view name, std::ostream&
|
||||
out << ">" << std::endl;
|
||||
|
||||
// Determine the alignment width from the longest argument
|
||||
auto paramLength = [](const Option& p) -> int { return p.argumentName
|
||||
? static_cast<int>(std::strlen(p.argumentName) + 3)
|
||||
auto paramLength = [](const Option& p) -> int { return !p.argumentName.empty()
|
||||
? static_cast<int>(p.argumentName.length() + 3)
|
||||
: 1; };
|
||||
auto longestParam = std::max_element(options.begin(), options.end(),
|
||||
[=](auto a, auto b) -> bool { return paramLength(a) < paramLength(b); });
|
||||
@@ -67,7 +67,8 @@ void ArgParse::Options::ShowHelpUsage(const std::string_view name, std::ostream&
|
||||
{
|
||||
auto decorateArgument = [=] { return " <" + std::string(it.argumentName) + "> "; };
|
||||
out << " -" << it.flag
|
||||
<< std::left << std::setw(alignWidth) << std::setfill('-') << (it.argumentName ? decorateArgument() : " ")
|
||||
<< std::left << std::setw(alignWidth) << std::setfill('-')
|
||||
<< (!it.argumentName.empty() ? decorateArgument() : " ")
|
||||
<< " " << it.helpString << std::endl;
|
||||
}
|
||||
out << std::flush;
|
||||
@@ -99,7 +100,7 @@ ArgParse::ParseCtrl ArgParse::ParserState::Next(const std::string_view token)
|
||||
const auto opt = getOption(flagChar);
|
||||
if (opt.has_value())
|
||||
{
|
||||
bool expect = opt.value().get().argumentName != nullptr;
|
||||
bool expect = !opt.value().get().argumentName.empty();
|
||||
if (token.length() <= 2)
|
||||
{
|
||||
expectArg = expect;
|
||||
|
||||
@@ -16,16 +16,16 @@ namespace ArgParse
|
||||
{
|
||||
struct Option
|
||||
{
|
||||
const char* argumentName;
|
||||
const char* helpString;
|
||||
std::string_view argumentName;
|
||||
std::string_view helpString;
|
||||
char flag;
|
||||
bool required;
|
||||
|
||||
static constexpr Option Optional(char flag, const char* name, const char* help)
|
||||
static constexpr Option Optional(char flag, const std::string_view name, const std::string_view help)
|
||||
{
|
||||
return { name, help, flag, false };
|
||||
}
|
||||
static constexpr Option Required(char flag, const char* name, const char* help)
|
||||
static constexpr Option Required(char flag, const std::string_view name, const std::string_view help)
|
||||
{
|
||||
return { name, help, flag, true };
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ using ArgParse::Option;
|
||||
|
||||
static const ArgParse::Options options =
|
||||
{
|
||||
Option::Optional('h', nullptr, "Display this help & command info"),
|
||||
Option::Optional('v', nullptr, "Display version & quit"),
|
||||
Option::Optional('h', {}, "Display this help & command info"),
|
||||
Option::Optional('v', {}, "Display version & quit"),
|
||||
Option::Optional('l', "name", "Name of layer to use (default first layer in TMX)"),
|
||||
Option::Optional('y', "name", "Layer for palette mappings"),
|
||||
Option::Optional('c', "name", "Output a separate 8bit collision map of the specified layer"),
|
||||
|
||||
Reference in New Issue
Block a user