Line data Source code
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 780 : regex() : boost::regex() { 15 780 : } 16 : 17 1771085 : explicit regex(const std::string &pattern, 18 : boost::regex_constants::syntax_option_type flags = 19 : boost::regex_constants::match_default | 20 1771085 : boost::regex_constants::no_except) : 21 1771085 : boost::regex(pattern, flags) { 22 1771110 : } 23 : }; 24 : 25 29379 : static inline bool regex_search(const std::string &input, const regex ®ex) { 26 29379 : return !regex.status() && boost::regex_search(input, regex); 27 : } 28 : 29 19909 : static inline bool regex_search(const std::string &input, 30 : boost::smatch &match, const regex ®ex) { 31 19909 : return !regex.status() && boost::regex_search(input, match, regex); 32 : } 33 : 34 956 : static inline bool regex_match(const std::string &input, const regex ®ex) { 35 956 : return !regex.status() && boost::regex_match(input, regex); 36 : } 37 : 38 0 : static inline bool regex_match(const std::string &input, boost::smatch &match, 39 : const regex ®ex) { 40 0 : return !regex.status() && boost::regex_match(input, match, regex); 41 : } 42 : 43 32020 : static inline bool regex_match(const char *input, boost::cmatch &match, 44 : const regex ®ex) { 45 32020 : return !regex.status() && boost::regex_match(input, match, regex); 46 : } 47 : 48 3509003 : 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 ®ex, boost::regex_constants::match_flag_type flags) { 52 3509003 : return !regex.status() && boost::regex_search(begin, end, results, regex, 53 3509014 : flags); 54 : } 55 : 56 4210 : static inline const std::string regex_replace(const std::string &input, 57 : const regex ®ex, const char* format, 58 : boost::regex_constants::match_flag_type flags) { 59 4210 : return !regex.status() ? boost::regex_replace(input, regex, format, flags) : 60 4210 : input; 61 : } 62 : 63 : } // namespace contrail 64 : 65 : #endif // BASE_REGEX_H_