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