1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/xpressive/sub_match.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,331 @@
1.4 +///////////////////////////////////////////////////////////////////////////////
1.5 +/// \file sub_match.hpp
1.6 +/// Contains the definition of the class template sub_match\<\>
1.7 +/// and associated helper functions
1.8 +//
1.9 +// Copyright 2004 Eric Niebler. Distributed under the Boost
1.10 +// 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 +#ifndef BOOST_XPRESSIVE_SUB_MATCH_HPP_EAN_10_04_2005
1.14 +#define BOOST_XPRESSIVE_SUB_MATCH_HPP_EAN_10_04_2005
1.15 +
1.16 +// MS compatible compilers support #pragma once
1.17 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
1.18 +# pragma once
1.19 +#endif
1.20 +
1.21 +#include <iosfwd>
1.22 +#include <string>
1.23 +#include <utility>
1.24 +#include <iterator>
1.25 +#include <algorithm>
1.26 +#include <boost/iterator/iterator_traits.hpp>
1.27 +
1.28 +//{{AFX_DOC_COMMENT
1.29 +///////////////////////////////////////////////////////////////////////////////
1.30 +// This is a hack to get Doxygen to show the inheritance relation between
1.31 +// sub_match<T> and std::pair<T,T>.
1.32 +#ifdef BOOST_XPRESSIVE_DOXYGEN_INVOKED
1.33 +/// INTERNAL ONLY
1.34 +namespace std
1.35 +{
1.36 + /// INTERNAL ONLY
1.37 + template<typename, typename> struct pair {};
1.38 +}
1.39 +#endif
1.40 +//}}AFX_DOC_COMMENT
1.41 +
1.42 +namespace boost { namespace xpressive
1.43 +{
1.44 +
1.45 +///////////////////////////////////////////////////////////////////////////////
1.46 +// sub_match
1.47 +//
1.48 +/// \brief Class template sub_match denotes the sequence of characters matched by a particular marked sub-expression.
1.49 +///
1.50 +/// When the marked sub-expression denoted by an object of type sub_match\<\> participated in a
1.51 +/// regular expression match then member matched evaluates to true, and members first and second
1.52 +/// denote the range of characters [first,second) which formed that match. Otherwise matched is false,
1.53 +/// and members first and second contained undefined values.
1.54 +///
1.55 +/// If an object of type sub_match\<\> represents sub-expression 0 - that is to say the whole match -
1.56 +/// then member matched is always true, unless a partial match was obtained as a result of the flag
1.57 +/// match_partial being passed to a regular expression algorithm, in which case member matched is
1.58 +/// false, and members first and second represent the character range that formed the partial match.
1.59 +template<typename BidiIter>
1.60 +struct sub_match
1.61 + : std::pair<BidiIter, BidiIter>
1.62 +{
1.63 +private:
1.64 + struct dummy { int i_; };
1.65 + typedef int dummy::*bool_type;
1.66 +
1.67 +public:
1.68 + typedef typename iterator_value<BidiIter>::type value_type;
1.69 + typedef typename iterator_difference<BidiIter>::type difference_type;
1.70 + typedef std::basic_string<value_type> string_type;
1.71 + typedef BidiIter iterator;
1.72 +
1.73 + explicit sub_match(BidiIter first = BidiIter(), BidiIter second = BidiIter(), bool matched_ = false)
1.74 + : std::pair<BidiIter, BidiIter>(first, second)
1.75 + , matched(matched_)
1.76 + {
1.77 + }
1.78 +
1.79 + string_type str() const
1.80 + {
1.81 + return this->matched ? string_type(this->first, this->second) : string_type();
1.82 + }
1.83 +
1.84 + operator string_type() const
1.85 + {
1.86 + return this->matched ? string_type(this->first, this->second) : string_type();
1.87 + }
1.88 +
1.89 + difference_type length() const
1.90 + {
1.91 + return this->matched ? std::distance(this->first, this->second) : 0;
1.92 + }
1.93 +
1.94 + operator bool_type() const
1.95 + {
1.96 + return this->matched ? &dummy::i_ : 0;
1.97 + }
1.98 +
1.99 + bool operator !() const
1.100 + {
1.101 + return !this->matched;
1.102 + }
1.103 +
1.104 + /// \brief Performs a lexicographic string comparison
1.105 + /// \param str the string against which to compare
1.106 + /// \return the results of (*this).str().compare(str)
1.107 + int compare(string_type const &str) const
1.108 + {
1.109 + return this->str().compare(str);
1.110 + }
1.111 +
1.112 + /// \overload
1.113 + int compare(sub_match const &sub) const
1.114 + {
1.115 + return this->str().compare(sub.str());
1.116 + }
1.117 +
1.118 + /// \overload
1.119 + int compare(value_type const *ptr) const
1.120 + {
1.121 + return this->str().compare(ptr);
1.122 + }
1.123 +
1.124 + /// \brief true if this sub-match participated in the full match.
1.125 + bool matched;
1.126 +};
1.127 +
1.128 +///////////////////////////////////////////////////////////////////////////////
1.129 +/// \brief insertion operator for sending sub-matches to ostreams
1.130 +/// \param sout output stream.
1.131 +/// \param sub sub_match object to be written to the stream.
1.132 +/// \return sout \<\< sub.str()
1.133 +template<typename BidiIter, typename Char, typename Traits>
1.134 +inline std::basic_ostream<Char, Traits> &operator <<
1.135 +(
1.136 + std::basic_ostream<Char, Traits> &sout
1.137 + , sub_match<BidiIter> const &sub
1.138 +)
1.139 +{
1.140 + typedef typename iterator_value<BidiIter>::type char_type;
1.141 + if(sub.matched)
1.142 + {
1.143 + std::ostream_iterator<char_type, Char, Traits> iout(sout);
1.144 + std::copy(sub.first, sub.second, iout);
1.145 + }
1.146 + return sout;
1.147 +}
1.148 +
1.149 +
1.150 +// BUGBUG make these more efficient
1.151 +
1.152 +template<typename BidiIter>
1.153 +bool operator == (sub_match<BidiIter> const &lhs, sub_match<BidiIter> const &rhs)
1.154 +{
1.155 + return lhs.compare(rhs) == 0;
1.156 +}
1.157 +
1.158 +template<typename BidiIter>
1.159 +bool operator != (sub_match<BidiIter> const &lhs, sub_match<BidiIter> const &rhs)
1.160 +{
1.161 + return lhs.compare(rhs) != 0;
1.162 +}
1.163 +
1.164 +template<typename BidiIter>
1.165 +bool operator < (sub_match<BidiIter> const &lhs, sub_match<BidiIter> const &rhs)
1.166 +{
1.167 + return lhs.compare(rhs) < 0;
1.168 +}
1.169 +
1.170 +template<typename BidiIter>
1.171 +bool operator <= (sub_match<BidiIter> const &lhs, sub_match<BidiIter> const &rhs)
1.172 +{
1.173 + return lhs.compare(rhs) <= 0;
1.174 +}
1.175 +
1.176 +template<typename BidiIter>
1.177 +bool operator >= (sub_match<BidiIter> const &lhs, sub_match<BidiIter> const &rhs)
1.178 +{
1.179 + return lhs.compare(rhs)>= 0;
1.180 +}
1.181 +
1.182 +template<typename BidiIter>
1.183 +bool operator> (sub_match<BidiIter> const &lhs, sub_match<BidiIter> const &rhs)
1.184 +{
1.185 + return lhs.compare(rhs)> 0;
1.186 +}
1.187 +
1.188 +template<typename BidiIter>
1.189 +bool operator == (typename iterator_value<BidiIter>::type const *lhs, sub_match<BidiIter> const &rhs)
1.190 +{
1.191 + return lhs == rhs.str();
1.192 +}
1.193 +
1.194 +template<typename BidiIter>
1.195 +bool operator != (typename iterator_value<BidiIter>::type const *lhs, sub_match<BidiIter> const &rhs)
1.196 +{
1.197 + return lhs != rhs.str();
1.198 +}
1.199 +
1.200 +template<typename BidiIter>
1.201 +bool operator < (typename iterator_value<BidiIter>::type const *lhs, sub_match<BidiIter> const &rhs)
1.202 +{
1.203 + return lhs < rhs.str();
1.204 +}
1.205 +
1.206 +template<typename BidiIter>
1.207 +bool operator> (typename iterator_value<BidiIter>::type const *lhs, sub_match<BidiIter> const &rhs)
1.208 +{
1.209 + return lhs> rhs.str();
1.210 +}
1.211 +
1.212 +template<typename BidiIter>
1.213 +bool operator >= (typename iterator_value<BidiIter>::type const *lhs, sub_match<BidiIter> const &rhs)
1.214 +{
1.215 + return lhs >= rhs.str();
1.216 +}
1.217 +
1.218 +template<typename BidiIter>
1.219 +bool operator <= (typename iterator_value<BidiIter>::type const *lhs, sub_match<BidiIter> const &rhs)
1.220 +{
1.221 + return lhs <= rhs.str();
1.222 +}
1.223 +
1.224 +template<typename BidiIter>
1.225 +bool operator == (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const *rhs)
1.226 +{
1.227 + return lhs.str() == rhs;
1.228 +}
1.229 +
1.230 +template<typename BidiIter>
1.231 +bool operator != (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const *rhs)
1.232 +{
1.233 + return lhs.str() != rhs;
1.234 +}
1.235 +
1.236 +template<typename BidiIter>
1.237 +bool operator < (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const *rhs)
1.238 +{
1.239 + return lhs.str() < rhs;
1.240 +}
1.241 +
1.242 +template<typename BidiIter>
1.243 +bool operator> (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const *rhs)
1.244 +{
1.245 + return lhs.str()> rhs;
1.246 +}
1.247 +
1.248 +template<typename BidiIter>
1.249 +bool operator >= (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const *rhs)
1.250 +{
1.251 + return lhs.str()>= rhs;
1.252 +}
1.253 +
1.254 +template<typename BidiIter>
1.255 +bool operator <= (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const *rhs)
1.256 +{
1.257 + return lhs.str() <= rhs;
1.258 +}
1.259 +
1.260 +template<typename BidiIter>
1.261 +bool operator == (typename iterator_value<BidiIter>::type const &lhs, sub_match<BidiIter> const &rhs)
1.262 +{
1.263 + return lhs == rhs.str();
1.264 +}
1.265 +
1.266 +template<typename BidiIter>
1.267 +bool operator != (typename iterator_value<BidiIter>::type const &lhs, sub_match<BidiIter> const &rhs)
1.268 +{
1.269 + return lhs != rhs.str();
1.270 +}
1.271 +
1.272 +template<typename BidiIter>
1.273 +bool operator < (typename iterator_value<BidiIter>::type const &lhs, sub_match<BidiIter> const &rhs)
1.274 +{
1.275 + return lhs < rhs.str();
1.276 +}
1.277 +
1.278 +template<typename BidiIter>
1.279 +bool operator> (typename iterator_value<BidiIter>::type const &lhs, sub_match<BidiIter> const &rhs)
1.280 +{
1.281 + return lhs> rhs.str();
1.282 +}
1.283 +
1.284 +template<typename BidiIter>
1.285 +bool operator >= (typename iterator_value<BidiIter>::type const &lhs, sub_match<BidiIter> const &rhs)
1.286 +{
1.287 + return lhs >= rhs.str();
1.288 +}
1.289 +
1.290 +template<typename BidiIter>
1.291 +bool operator <= (typename iterator_value<BidiIter>::type const &lhs, sub_match<BidiIter> const &rhs)
1.292 +{
1.293 + return lhs <= rhs.str();
1.294 +}
1.295 +
1.296 +template<typename BidiIter>
1.297 +bool operator == (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const &rhs)
1.298 +{
1.299 + return lhs.str() == rhs;
1.300 +}
1.301 +
1.302 +template<typename BidiIter>
1.303 +bool operator != (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const &rhs)
1.304 +{
1.305 + return lhs.str() != rhs;
1.306 +}
1.307 +
1.308 +template<typename BidiIter>
1.309 +bool operator < (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const &rhs)
1.310 +{
1.311 + return lhs.str() < rhs;
1.312 +}
1.313 +
1.314 +template<typename BidiIter>
1.315 +bool operator> (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const &rhs)
1.316 +{
1.317 + return lhs.str()> rhs;
1.318 +}
1.319 +
1.320 +template<typename BidiIter>
1.321 +bool operator >= (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const &rhs)
1.322 +{
1.323 + return lhs.str()>= rhs;
1.324 +}
1.325 +
1.326 +template<typename BidiIter>
1.327 +bool operator <= (sub_match<BidiIter> const &lhs, typename iterator_value<BidiIter>::type const &rhs)
1.328 +{
1.329 + return lhs.str() <= rhs;
1.330 +}
1.331 +
1.332 +}} // namespace boost::xpressive
1.333 +
1.334 +#endif