ewmscp  ..
Functions
regex_test.cpp File Reference

(v0.19-24-g0617ca1 with changes)

#include <algorithm>
#include "Options.h"
#include <OptionsRegex.h>
#include "throwcall.h"
Include dependency graph for regex_test.cpp:

Go to the source code of this file.

Functions

int main (int argc, const char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 7 of file regex_test.cpp.

7  {
8  options::parser parser("", "", {});
9  options::single<std::regex> regexp('r', "regexp", "regexp to test");
10  auto strings = parser.fParse(argc, argv);
11  for (const auto& string : strings) {
12  std::cout << "testing string '" << string << "' against the regexp ";
13  regexp.fWriteOriginalString(std::cout);
14  std::cout << "\n";
15  {
16  std::smatch match;
17  std::cout << "search: \n";
18  if (std::regex_search(string, match, regexp)) {
19  std::cout << "matches.\n";
20  std::cout << "prefix: '" << match.prefix() << "'\n";
21  for (const auto& submatch : match) {
22  std::cout << "match '" << submatch << "'\n";
23  }
24  std::cout << "suffix: '" << match.suffix() << "'\n";
25  } else {
26  std::cout << "no match\n";
27  }
28  }
29  {
30  std::smatch match;
31  std::cout << "match: \n";
32  if (std::regex_match(string, match, regexp)) {
33  std::cout << "matches.\n";
34  for (const auto& submatch : match) {
35  std::cout << "match with " << submatch.length() << " chars";
36  std::cout << " from " << std::distance(string.begin(), submatch.first);
37  std::cout << " to " << std::distance(string.begin(), submatch.second);
38  if (submatch.length() > 0) {
39  std::cout << ": '" << submatch << "'\n";
40  } else {
41  std::cout << "\n";
42  }
43  }
44  } else {
45  std::cout << "no match\n";
46  }
47  }
48  std::cout << "\n";
49  }
50 }
options::parser
class that contains the parser, i.e. does that option handling
Definition: Options.h:363
options::single< std::regex >
Definition: OptionsRegex.h:8