Commit 2e3c6991d33811878ebcc0839d3815850d129b3a
Committed by
GitHub
1 parent
2123115f
add . as valid char in option names (#358)
Showing
2 changed files
with
9 additions
and
5 deletions
include/cxxopts.hpp
| ... | ... | @@ -678,7 +678,8 @@ inline OptionNames split_option_names(const std::string &text) |
| 678 | 678 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 679 | 679 | "abcdefghijklmnopqrstuvwxyz" |
| 680 | 680 | "0123456789" |
| 681 | - "_-"; | |
| 681 | + "_-.?"; | |
| 682 | + | |
| 682 | 683 | if (!std::isalnum(text[token_start_pos], std::locale::classic()) || |
| 683 | 684 | text.find_first_not_of(option_name_valid_chars, token_start_pos) < next_delimiter_pos) { |
| 684 | 685 | throw_or_mimic<exceptions::invalid_option_format>(text); |
| ... | ... | @@ -752,9 +753,9 @@ std::basic_regex<char> falsy_pattern |
| 752 | 753 | ("(f|F)(alse)?|0"); |
| 753 | 754 | |
| 754 | 755 | std::basic_regex<char> option_matcher |
| 755 | - ("--([[:alnum:]][-_[:alnum:]]+)(=(.*))?|-([[:alnum:]].*)"); | |
| 756 | + ("--([[:alnum:]][-_[:alnum:]\\.]+)(=(.*))?|-([[:alnum:]].*)"); | |
| 756 | 757 | std::basic_regex<char> option_specifier |
| 757 | - ("([[:alnum:]][-_[:alnum:]]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*"); | |
| 758 | + ("([[:alnum:]][-_[:alnum:]\\.]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*"); | |
| 758 | 759 | std::basic_regex<char> option_specifier_separator(", *"); |
| 759 | 760 | |
| 760 | 761 | } // namespace | ... | ... |
test/options.cpp
| ... | ... | @@ -56,6 +56,7 @@ TEST_CASE("Basic options", "[options]") |
| 56 | 56 | ("a,av", "a short option with a value", cxxopts::value<std::string>()) |
| 57 | 57 | ("6,six", "a short number option") |
| 58 | 58 | ("p, space", "an option with space between short and long") |
| 59 | + ("period.delimited", "an option with a period in the long name") | |
| 59 | 60 | ("nothing", "won't exist", cxxopts::value<std::string>()) |
| 60 | 61 | ; |
| 61 | 62 | |
| ... | ... | @@ -77,7 +78,8 @@ TEST_CASE("Basic options", "[options]") |
| 77 | 78 | "-z", |
| 78 | 79 | "--over", |
| 79 | 80 | "--dog", |
| 80 | - "--lazy" | |
| 81 | + "--lazy", | |
| 82 | + "--period.delimited", | |
| 81 | 83 | }); |
| 82 | 84 | |
| 83 | 85 | auto** actual_argv = argv.argv(); |
| ... | ... | @@ -97,9 +99,10 @@ TEST_CASE("Basic options", "[options]") |
| 97 | 99 | CHECK(result.count("quick") == 2); |
| 98 | 100 | CHECK(result.count("f") == 2); |
| 99 | 101 | CHECK(result.count("z") == 4); |
| 102 | + CHECK(result.count("period.delimited") == 1); | |
| 100 | 103 | |
| 101 | 104 | auto& arguments = result.arguments(); |
| 102 | - REQUIRE(arguments.size() == 15); | |
| 105 | + REQUIRE(arguments.size() == 16); | |
| 103 | 106 | CHECK(arguments[0].key() == "long"); |
| 104 | 107 | CHECK(arguments[0].value() == "true"); |
| 105 | 108 | CHECK(arguments[0].as<bool>() == true); | ... | ... |