File indexing completed on 2025-01-18 09:51:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_REGEX_MFC_HPP
0020 #define BOOST_REGEX_MFC_HPP
0021
0022 #include <atlsimpstr.h>
0023 #include <boost/regex.hpp>
0024
0025 namespace boost{
0026
0027
0028
0029 typedef basic_regex<TCHAR> tregex;
0030 typedef match_results<TCHAR const*> tmatch;
0031 typedef regex_iterator<TCHAR const*> tregex_iterator;
0032 typedef regex_token_iterator<TCHAR const*> tregex_token_iterator;
0033
0034
0035 #define SIMPLE_STRING_PARAM class B, bool b
0036 #define SIMPLE_STRING_ARG_LIST B, b
0037
0038
0039
0040
0041 template <class B, bool b>
0042 inline basic_regex<B>
0043 make_regex(const ATL::CSimpleStringT<B, b>& s, ::boost::regex_constants::syntax_option_type f = boost::regex_constants::normal)
0044 {
0045 basic_regex<B> result(s.GetString(), s.GetString() + s.GetLength(), f);
0046 return result;
0047 }
0048
0049
0050
0051 template <class B, bool b, class A, class T>
0052 inline bool regex_match(const ATL::CSimpleStringT<B, b>& s,
0053 match_results<const B*, A>& what,
0054 const basic_regex<B, T>& e,
0055 boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
0056 {
0057 return ::boost::regex_match(s.GetString(),
0058 s.GetString() + s.GetLength(),
0059 what,
0060 e,
0061 f);
0062 }
0063
0064 template <class B, bool b, class T>
0065 inline bool regex_match(const ATL::CSimpleStringT<B, b>& s,
0066 const basic_regex<B, T>& e,
0067 boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
0068 {
0069 return ::boost::regex_match(s.GetString(),
0070 s.GetString() + s.GetLength(),
0071 e,
0072 f);
0073 }
0074
0075
0076
0077 template <class B, bool b, class A, class T>
0078 inline bool regex_search(const ATL::CSimpleStringT<B, b>& s,
0079 match_results<const B*, A>& what,
0080 const basic_regex<B, T>& e,
0081 boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
0082 {
0083 return ::boost::regex_search(s.GetString(),
0084 s.GetString() + s.GetLength(),
0085 what,
0086 e,
0087 f);
0088 }
0089
0090 template <class B, bool b, class T>
0091 inline bool regex_search(const ATL::CSimpleStringT<B, b>& s,
0092 const basic_regex<B, T>& e,
0093 boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
0094 {
0095 return ::boost::regex_search(s.GetString(),
0096 s.GetString() + s.GetLength(),
0097 e,
0098 f);
0099 }
0100
0101
0102
0103 template <class B, bool b>
0104 inline regex_iterator<B const*>
0105 make_regex_iterator(const ATL::CSimpleStringT<B, b>& s, const basic_regex<B>& e, ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
0106 {
0107 regex_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, f);
0108 return result;
0109 }
0110
0111 template <class B, bool b>
0112 inline regex_token_iterator<B const*>
0113 make_regex_token_iterator(const ATL::CSimpleStringT<B, b>& s, const basic_regex<B>& e, int sub = 0, ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
0114 {
0115 regex_token_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, sub, f);
0116 return result;
0117 }
0118
0119 template <class B, bool b>
0120 inline regex_token_iterator<B const*>
0121 make_regex_token_iterator(const ATL::CSimpleStringT<B, b>& s, const basic_regex<B>& e, const std::vector<int>& subs, ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
0122 {
0123 regex_token_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, subs, f);
0124 return result;
0125 }
0126
0127 template <class B, bool b, std::size_t N>
0128 inline regex_token_iterator<B const*>
0129 make_regex_token_iterator(const ATL::CSimpleStringT<B, b>& s, const basic_regex<B>& e, const int (& subs)[N], ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
0130 {
0131 regex_token_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, subs, f);
0132 return result;
0133 }
0134
0135 template <class OutputIterator, class BidirectionalIterator, class traits,
0136 class B, bool b>
0137 OutputIterator regex_replace(OutputIterator out,
0138 BidirectionalIterator first,
0139 BidirectionalIterator last,
0140 const basic_regex<B, traits>& e,
0141 const ATL::CSimpleStringT<B, b>& fmt,
0142 match_flag_type flags = match_default)
0143 {
0144 return ::boost::regex_replace(out, first, last, e, fmt.GetString(), flags);
0145 }
0146
0147 namespace BOOST_REGEX_DETAIL_NS{
0148
0149 template <class B, bool b>
0150 class mfc_string_out_iterator
0151 {
0152 ATL::CSimpleStringT<B, b>* out;
0153 public:
0154 mfc_string_out_iterator(ATL::CSimpleStringT<B, b>& s) : out(&s) {}
0155 mfc_string_out_iterator& operator++() { return *this; }
0156 mfc_string_out_iterator& operator++(int) { return *this; }
0157 mfc_string_out_iterator& operator*() { return *this; }
0158 mfc_string_out_iterator& operator=(B v)
0159 {
0160 out->AppendChar(v);
0161 return *this;
0162 }
0163 typedef std::ptrdiff_t difference_type;
0164 typedef B value_type;
0165 typedef value_type* pointer;
0166 typedef value_type& reference;
0167 typedef std::output_iterator_tag iterator_category;
0168 };
0169
0170 }
0171
0172 template <class traits, class B, bool b>
0173 ATL::CSimpleStringT<B, b> regex_replace(const ATL::CSimpleStringT<B, b>& s,
0174 const basic_regex<B, traits>& e,
0175 const ATL::CSimpleStringT<B, b>& fmt,
0176 match_flag_type flags = match_default)
0177 {
0178 ATL::CSimpleStringT<B, b> result(s.GetManager());
0179 BOOST_REGEX_DETAIL_NS::mfc_string_out_iterator<B, b> i(result);
0180 regex_replace(i, s.GetString(), s.GetString() + s.GetLength(), e, fmt.GetString(), flags);
0181 return result;
0182 }
0183
0184 }
0185
0186 #endif