@@ -659,7 +659,7 @@ inline OptionNames split_option_names(const std::string &text)
659
659
" abcdefghijklmnopqrstuvwxyz"
660
660
" 0123456789"
661
661
" _-" ;
662
- if (not std::isalnum (text[token_start_pos]) or
662
+ if (! std::isalnum (text[token_start_pos]) ||
663
663
text.find_first_not_of (option_name_valid_chars, token_start_pos) < next_delimiter_pos) {
664
664
throw_or_mimic<exceptions::invalid_option_format>(text);
665
665
}
@@ -783,14 +783,14 @@ inline bool IsFalseText(const std::string &text)
783
783
// (without considering which or how many are single-character)
784
784
inline OptionNames split_option_names (const std::string &text)
785
785
{
786
- if (not std::regex_match (text.c_str (), option_specifier))
786
+ if (! std::regex_match (text.c_str (), option_specifier))
787
787
{
788
788
throw_or_mimic<exceptions::invalid_option_format>(text);
789
789
}
790
790
791
791
OptionNames split_names;
792
792
793
- constexpr const int use_non_matches { -1 };
793
+ constexpr int use_non_matches { -1 };
794
794
auto token_iterator = std::sregex_token_iterator (
795
795
text.begin (), text.end (), option_specifier_separator, use_non_matches);
796
796
std::copy (token_iterator, std::sregex_token_iterator (), std::back_inserter (split_names));
@@ -2169,34 +2169,30 @@ OptionAdder::operator()
2169
2169
std::string arg_help
2170
2170
)
2171
2171
{
2172
- OptionNames all_option_names = values::parser_tool::split_option_names (opts);
2173
- // Note: All names will be non-empty!
2174
- std::string short_sw {" " };
2175
- OptionNames long_option_names = all_option_names;
2176
- auto first_length_1_name_it = std::find_if (long_option_names.cbegin (), long_option_names.cend (),
2177
- [&](const std::string& name) { return name.length () == 1 ; }
2178
- );
2179
- if (first_length_1_name_it != long_option_names.cend ()) {
2180
- auto have_second_length_1_name = std::any_of (first_length_1_name_it + 1 , long_option_names.cend (),
2181
- [&](const std::string& name) { return name.length () == 1 ; }
2172
+ OptionNames option_names = values::parser_tool::split_option_names (opts);
2173
+ // Note: All names will be non-empty; but we must separate the short
2174
+ // (length-1) and longer names
2175
+ std::string short_name {" " };
2176
+ auto first_short_name_iter =
2177
+ std::partition (option_names.begin (), option_names.end (),
2178
+ [&](const std::string& name) { return name.length () > 1 ; }
2182
2179
);
2183
- if (have_second_length_1_name) {
2184
- throw_or_mimic<exceptions::invalid_option_format>(opts);
2185
- }
2186
- short_sw = *first_length_1_name_it ;
2187
- long_option_names .erase (first_length_1_name_it );
2188
- }
2189
- if (short_sw. empty () && long_option_names. empty ())
2190
- {
2180
+ auto num_length_1_names = (option_names. end () - first_short_name_iter);
2181
+ switch (num_length_1_names) {
2182
+ case 1 :
2183
+ short_name = *first_short_name_iter ;
2184
+ option_names .erase (first_short_name_iter );
2185
+ case 0 :
2186
+ break ;
2187
+ default :
2191
2188
throw_or_mimic<exceptions::invalid_option_format>(opts);
2192
- }
2193
-
2189
+ };
2194
2190
2195
2191
m_options.add_option
2196
2192
(
2197
2193
m_group,
2198
- short_sw ,
2199
- long_option_names ,
2194
+ short_name ,
2195
+ option_names ,
2200
2196
desc,
2201
2197
value,
2202
2198
std::move (arg_help)
@@ -2618,7 +2614,7 @@ Options::help_one_group(const std::string& g) const
2618
2614
2619
2615
for (const auto & o : group->second .options )
2620
2616
{
2621
- assert (not o.l .empty ());
2617
+ assert (! o.l .empty ());
2622
2618
if (m_positional_set.find (o.l .front ()) != m_positional_set.end () &&
2623
2619
!m_show_positional)
2624
2620
{
@@ -2641,7 +2637,7 @@ Options::help_one_group(const std::string& g) const
2641
2637
auto fiter = format.begin ();
2642
2638
for (const auto & o : group->second .options )
2643
2639
{
2644
- assert (not o.l .empty ());
2640
+ assert (! o.l .empty ());
2645
2641
if (m_positional_set.find (o.l .front ()) != m_positional_set.end () &&
2646
2642
!m_show_positional)
2647
2643
{
0 commit comments