* @file pattern_test.cc * @brief simple test driver to test and experiment with PCRE patterns. * * @todo: create unit tests for the classes in pattern.cc. * Compile with -DCACHEKEY_UNIT_TEST to use non-ATS logging. */
| 28 | * Compile with -DCACHEKEY_UNIT_TEST to use non-ATS logging. |
| 29 | */ |
| 30 | int |
| 31 | main(int argc, char *argv[]) |
| 32 | { |
| 33 | if (argc < 3) { |
| 34 | std::cerr << "Usage: " << String(argv[0]) << " subject pattern" << std::endl; |
| 35 | return -1; |
| 36 | } |
| 37 | |
| 38 | String subject(argv[1]); |
| 39 | String pattern(argv[2]); |
| 40 | |
| 41 | std::cout << "subject: '" << subject << "'" << std::endl; |
| 42 | std::cout << "pattern: '" << pattern << "'" << std::endl; |
| 43 | |
| 44 | Pattern p; |
| 45 | if (p.init(pattern)) { |
| 46 | std::cout << "--- matching ---" << std::endl; |
| 47 | bool result = p.match(subject); |
| 48 | std::cout << "subject:'" << subject << "' " << (char *)(result ? "matched" : "did not match") << " pattern:'" << pattern << "'" |
| 49 | << std::endl; |
| 50 | |
| 51 | std::cout << "--- capture ---" << std::endl; |
| 52 | StringVector v; |
| 53 | result = p.capture(subject, v); |
| 54 | for (StringVector::iterator it = v.begin(); it != v.end(); ++it) { |
| 55 | std::cout << "capture: " << *it << std::endl; |
| 56 | } |
| 57 | |
| 58 | std::cout << "--- replace ---" << std::endl; |
| 59 | String r; |
| 60 | result = p.replace(subject, r); |
| 61 | std::cout << "replacement result:'" << result << "'" << std::endl; |
| 62 | |
| 63 | } else { |
| 64 | std::cout << "pattern: '" << pattern << "' failed to compile" << std::endl; |
| 65 | } |
| 66 | } |