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