OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
regex.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
3  */
4 #ifndef BASE_REGEX_H_
5 #define BASE_REGEX_H_
6 
7 #include <boost/regex.hpp>
8 #include <string>
9 
10 namespace contrail {
11 
12 class regex : public boost::regex {
13 public:
14  regex() : boost::regex() {
15  }
16 
17  explicit regex(const std::string &pattern,
18  boost::regex_constants::syntax_option_type flags =
19  boost::regex_constants::match_default |
20  boost::regex_constants::no_except) :
21  boost::regex(pattern, flags) {
22  }
23 };
24 
25 static inline bool regex_search(const std::string &input, const regex &regex) {
26  return !regex.status() && boost::regex_search(input, regex);
27 }
28 
29 static inline bool regex_search(const std::string &input,
30  boost::smatch &match, const regex &regex) {
31  return !regex.status() && boost::regex_search(input, match, regex);
32 }
33 
34 static inline bool regex_match(const std::string &input, const regex &regex) {
35  return !regex.status() && boost::regex_match(input, regex);
36 }
37 
38 static inline bool regex_match(const std::string &input, boost::smatch &match,
39  const regex &regex) {
40  return !regex.status() && boost::regex_match(input, match, regex);
41 }
42 
43 static inline bool regex_match(const char *input, boost::cmatch &match,
44  const regex &regex) {
45  return !regex.status() && boost::regex_match(input, match, regex);
46 }
47 
48 static inline bool regex_search(std::string::const_iterator &begin,
49  std::string::const_iterator &end,
50  boost::match_results<std::string::const_iterator> &results,
51  const regex &regex, boost::regex_constants::match_flag_type flags) {
52  return !regex.status() && boost::regex_search(begin, end, results, regex,
53  flags);
54 }
55 
56 static inline const std::string regex_replace(const std::string &input,
57  const regex &regex, const char* format,
58  boost::regex_constants::match_flag_type flags) {
59  return !regex.status() ? boost::regex_replace(input, regex, format, flags) :
60  input;
61 }
62 
63 } // namespace contrail
64 
65 #endif // BASE_REGEX_H_
static const std::string regex_replace(const std::string &input, const regex &regex, const char *format, boost::regex_constants::match_flag_type flags)
Definition: regex.h:56
static bool regex_match(const std::string &input, const regex &regex)
Definition: regex.h:34
regex(const std::string &pattern, boost::regex_constants::syntax_option_type flags=boost::regex_constants::match_default|boost::regex_constants::no_except)
Definition: regex.h:17
static bool regex_search(const std::string &input, const regex &regex)
Definition: regex.h:25