1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/regex/mfc.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,190 @@
1.4 +/*
1.5 + *
1.6 + * Copyright (c) 2004
1.7 + * John Maddock
1.8 + *
1.9 + * Use, modification and distribution are subject to the
1.10 + * Boost Software License, Version 1.0. (See accompanying file
1.11 + * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
1.12 + *
1.13 + */
1.14 +
1.15 + /*
1.16 + * LOCATION: see http://www.boost.org for most recent version.
1.17 + * FILE mfc.hpp
1.18 + * VERSION see <boost/version.hpp>
1.19 + * DESCRIPTION: Overloads and helpers for using MFC/ATL string types with Boost.Regex.
1.20 + */
1.21 +
1.22 +#ifndef BOOST_REGEX_MFC_HPP
1.23 +#define BOOST_REGEX_MFC_HPP
1.24 +
1.25 +#include <atlsimpstr.h>
1.26 +#include <boost/regex.hpp>
1.27 +
1.28 +namespace boost{
1.29 +
1.30 +//
1.31 +// define the types used for TCHAR's:
1.32 +typedef basic_regex<TCHAR> tregex;
1.33 +typedef match_results<TCHAR const*> tmatch;
1.34 +typedef regex_iterator<TCHAR const*> tregex_iterator;
1.35 +typedef regex_token_iterator<TCHAR const*> tregex_token_iterator;
1.36 +
1.37 +#if _MSC_VER >= 1310
1.38 +#define SIMPLE_STRING_PARAM class B, bool b
1.39 +#define SIMPLE_STRING_ARG_LIST B, b
1.40 +#else
1.41 +#define SIMPLE_STRING_PARAM class B
1.42 +#define SIMPLE_STRING_ARG_LIST B
1.43 +#endif
1.44 +
1.45 +//
1.46 +// define regex creation functions:
1.47 +//
1.48 +template <SIMPLE_STRING_PARAM>
1.49 +inline basic_regex<B>
1.50 +make_regex(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s, ::boost::regex_constants::syntax_option_type f = boost::regex_constants::normal)
1.51 +{
1.52 + basic_regex<B> result(s.GetString(), s.GetString() + s.GetLength(), f);
1.53 + return result;
1.54 +}
1.55 +//
1.56 +// regex_match overloads:
1.57 +//
1.58 +template <SIMPLE_STRING_PARAM, class A, class T>
1.59 +inline bool regex_match(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s,
1.60 + match_results<const B*, A>& what,
1.61 + const basic_regex<B, T>& e,
1.62 + boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
1.63 +{
1.64 + return ::boost::regex_match(s.GetString(),
1.65 + s.GetString() + s.GetLength(),
1.66 + what,
1.67 + e,
1.68 + f);
1.69 +}
1.70 +
1.71 +template <SIMPLE_STRING_PARAM, class T>
1.72 +inline bool regex_match(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s,
1.73 + const basic_regex<B, T>& e,
1.74 + boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
1.75 +{
1.76 + return ::boost::regex_match(s.GetString(),
1.77 + s.GetString() + s.GetLength(),
1.78 + e,
1.79 + f);
1.80 +}
1.81 +//
1.82 +// regex_search overloads:
1.83 +//
1.84 +template <SIMPLE_STRING_PARAM, class A, class T>
1.85 +inline bool regex_search(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s,
1.86 + match_results<const B*, A>& what,
1.87 + const basic_regex<B, T>& e,
1.88 + boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
1.89 +{
1.90 + return ::boost::regex_search(s.GetString(),
1.91 + s.GetString() + s.GetLength(),
1.92 + what,
1.93 + e,
1.94 + f);
1.95 +}
1.96 +
1.97 +template <SIMPLE_STRING_PARAM, class T>
1.98 +inline bool regex_search(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s,
1.99 + const basic_regex<B, T>& e,
1.100 + boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
1.101 +{
1.102 + return ::boost::regex_search(s.GetString(),
1.103 + s.GetString() + s.GetLength(),
1.104 + e,
1.105 + f);
1.106 +}
1.107 +//
1.108 +// regex_iterator creation:
1.109 +//
1.110 +template <SIMPLE_STRING_PARAM>
1.111 +inline regex_iterator<B const*>
1.112 +make_regex_iterator(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s, const basic_regex<B>& e, ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
1.113 +{
1.114 + regex_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, f);
1.115 + return result;
1.116 +}
1.117 +
1.118 +template <SIMPLE_STRING_PARAM>
1.119 +inline regex_token_iterator<B const*>
1.120 + make_regex_token_iterator(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s, const basic_regex<B>& e, int sub = 0, ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
1.121 +{
1.122 + regex_token_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, sub, f);
1.123 + return result;
1.124 +}
1.125 +
1.126 +template <SIMPLE_STRING_PARAM>
1.127 +inline regex_token_iterator<B const*>
1.128 +make_regex_token_iterator(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s, const basic_regex<B>& e, const std::vector<int>& subs, ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
1.129 +{
1.130 + regex_token_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, subs, f);
1.131 + return result;
1.132 +}
1.133 +
1.134 +template <SIMPLE_STRING_PARAM, std::size_t N>
1.135 +inline regex_token_iterator<B const*>
1.136 +make_regex_token_iterator(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s, const basic_regex<B>& e, const int (& subs)[N], ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
1.137 +{
1.138 + regex_token_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, subs, f);
1.139 + return result;
1.140 +}
1.141 +
1.142 +template <class OutputIterator, class BidirectionalIterator, class traits,
1.143 + SIMPLE_STRING_PARAM>
1.144 +OutputIterator regex_replace(OutputIterator out,
1.145 + BidirectionalIterator first,
1.146 + BidirectionalIterator last,
1.147 + const basic_regex<B, traits>& e,
1.148 + const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& fmt,
1.149 + match_flag_type flags = match_default)
1.150 +{
1.151 + return ::boost::regex_replace(out, first, last, e, fmt.GetString(), flags);
1.152 +}
1.153 +
1.154 +namespace re_detail{
1.155 +
1.156 +template <SIMPLE_STRING_PARAM>
1.157 +class mfc_string_out_iterator
1.158 +{
1.159 + ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>* out;
1.160 +public:
1.161 + mfc_string_out_iterator(ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s) : out(&s) {}
1.162 + mfc_string_out_iterator& operator++() { return *this; }
1.163 + mfc_string_out_iterator& operator++(int) { return *this; }
1.164 + mfc_string_out_iterator& operator*() { return *this; }
1.165 + mfc_string_out_iterator& operator=(B v)
1.166 + {
1.167 + out->AppendChar(v);
1.168 + return *this;
1.169 + }
1.170 + typedef std::ptrdiff_t difference_type;
1.171 + typedef B value_type;
1.172 + typedef value_type* pointer;
1.173 + typedef value_type& reference;
1.174 + typedef std::output_iterator_tag iterator_category;
1.175 +};
1.176 +
1.177 +}
1.178 +
1.179 +template <class traits, SIMPLE_STRING_PARAM>
1.180 +ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST> regex_replace(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s,
1.181 + const basic_regex<B, traits>& e,
1.182 + const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& fmt,
1.183 + match_flag_type flags = match_default)
1.184 +{
1.185 + ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST> result(s.GetManager());
1.186 + re_detail::mfc_string_out_iterator<SIMPLE_STRING_ARG_LIST> i(result);
1.187 + regex_replace(i, s.GetString(), s.GetString() + s.GetLength(), e, fmt.GetString(), flags);
1.188 + return result;
1.189 +}
1.190 +
1.191 +} // namespace boost.
1.192 +
1.193 +#endif