Commit de73da53b512cda43709f20e233a688585e79ca5

Authored by Jarryd Beck
1 parent 2deb5d87

option regexes

src/cxxopts.hpp
1 #include <regex> 1 #include <regex>
  2 +
  3 +namespace cxxopts
  4 +{
  5 + std::basic_regex<char> option_matcher
  6 + ("--([a-zA-Z][-_a-zA-Z]+)(=(.*))?|-([a-zA-Z]+)");
  7 +
  8 + std::basic_regex<char> option_specifier
  9 + ("(([a-zA-Z]),)?([a-zA-Z][-_a-zA-Z]+)");
  10 +}
src/main.cpp
@@ -7,13 +7,12 @@ int main(int argc, char* argv[]) @@ -7,13 +7,12 @@ int main(int argc, char* argv[])
7 try 7 try
8 { 8 {
9 9
10 - std::basic_regex<char> options("--([a-zA-Z][-a-zA-Z]+)|-([a-zA-Z]+)");  
11 std::match_results<const char*> result; 10 std::match_results<const char*> result;
12 11
13 for (int i = 1; i < argc; ++i) 12 for (int i = 1; i < argc; ++i)
14 { 13 {
15 std::cout << "Argument " << i << std::endl; 14 std::cout << "Argument " << i << std::endl;
16 - std::regex_match(argv[i], result, options); 15 + std::regex_match(argv[i], result, cxxopts::option_matcher);
17 std::cout << "empty = " << result.empty() << std::endl; 16 std::cout << "empty = " << result.empty() << std::endl;
18 std::cout << "size = " << result.size() << std::endl; 17 std::cout << "size = " << result.size() << std::endl;
19 18