Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,31 +1007,31 @@ namespace argparse
}
}

auto has_arg(auto it) const -> std::pair<bool, std::string>
auto has_arg(auto it) const -> std::string_view
{
for (auto const & name: m_options.names)
{
if (name[1] != '-')
{
if (it->m_token.starts_with("-") && !it->m_token.starts_with("--") && it->m_token.find(name[1]) != std::string::npos)
{
return {true, name};
return name;
}
}
else
{
auto const [first_it, second_it] = std::ranges::mismatch(name, it->m_token);
if (first_it == name.end() && (second_it == it->m_token.end() || *second_it == '='))
{
return {true, name};
return name;
}
}
}

return {false, ""};
return std::string_view();
}

auto consume_name(auto it, std::string const & name) const -> std::string
auto consume_name(auto it, std::string_view name) const -> std::string
{
if (auto const & arg = *it; arg.m_token.starts_with("--"))
{
Expand Down Expand Up @@ -1180,7 +1180,7 @@ namespace argparse

for (auto it = consumable.begin(); it != consumable.end();)
{
if (auto [found, name] = has_arg(it); found)
if (auto const name = has_arg(it); !name.empty())
{
auto const value = consume_name(it, name);
auto consumable_args = get_consumable_args(it, consumable);
Expand Down