match_results.hpp
来自「support vector clustering for vc++」· HPP 代码 · 共 191 行
HPP
191 行
///////////////////////////////////////////////////////////////////////////////
/// \file match_results.hpp
/// Contains the definition of the match_results type and associated helpers.
/// The match_results type holds the results of a regex_match() or
/// regex_search() operation.
//
// Copyright 2004 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_XPRESSIVE_MATCH_RESULTS_HPP_EAN_10_04_2005
#define BOOST_XPRESSIVE_MATCH_RESULTS_HPP_EAN_10_04_2005
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <iterator>
#include <boost/assert.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/iterator_adaptors.hpp>
#if BOOST_ITERATOR_ADAPTORS_VERSION >= 0x0200
# include <boost/iterator/filter_iterator.hpp>
#endif
#include <boost/xpressive/regex_constants.hpp>
#include <boost/xpressive/detail/detail_fwd.hpp>
#include <boost/xpressive/detail/core/sub_match_vector.hpp>
#include <boost/xpressive/detail/utility/sequence_stack.hpp>
#include <boost/xpressive/detail/core/results_cache.hpp>
#include <boost/xpressive/detail/core/action_state.hpp>
#include <boost/xpressive/detail/utility/literals.hpp>
#include <boost/xpressive/detail/utility/algorithm.hpp>
namespace boost { namespace xpressive { namespace detail
{
///////////////////////////////////////////////////////////////////////////////
// results_extras
//
template<typename BidiIter>
struct results_extras
{
sequence_stack<sub_match_impl<BidiIter> > sub_match_stack_;
results_cache<BidiIter> results_cache_;
};
///////////////////////////////////////////////////////////////////////////////
// results_traits
//
template<typename Char>
struct results_traits
{
static int value(Char ch, int radix = 10)
{
BOOST_ASSERT(10 == radix);
if(ch >= BOOST_XPR_CHAR_(Char, '0') && ch <= BOOST_XPR_CHAR_(Char, '9'))
{
return ch - BOOST_XPR_CHAR_(Char, '0');
}
return -1;
}
};
} // namespace detail
///////////////////////////////////////////////////////////////////////////////
// match_results
/// \brief Class template match_results\<\> holds the results of a regex_match() or a
/// regex_search() as a collection of sub_match objects.
///
/// Class template match_results\<\> denotes a collection of sequences representing the result of
/// a regular expression match. Storage for the collection is allocated and freed as necessary by
/// the member functions of class match_results\<\>.
///
/// The class template match_results\<\> conforms to the requirements of a Sequence, as specified
/// in (lib.sequence.reqmts), except that only operations defined for const-qualified Sequences are
/// supported.
template<typename BidiIter>
struct match_results
{
private:
struct dummy { int i_; };
typedef int dummy::*bool_type;
public:
typedef typename iterator_value<BidiIter>::type char_type;
typedef std::basic_string<char_type> string_type;
typedef std::size_t size_type;
typedef sub_match<BidiIter> value_type;
typedef typename iterator_difference<BidiIter>::type difference_type;
typedef value_type const &reference;
typedef value_type const &const_reference;
typedef typename detail::sub_match_vector<BidiIter>::iterator iterator;
typedef typename detail::sub_match_vector<BidiIter>::const_iterator const_iterator;
typedef typename detail::nested_results<BidiIter> nested_results_type;
/// \post regex_id() == 0
/// \post size() == 0
/// \post empty() == true
match_results()
: regex_id_(0)
, sub_matches_()
, base_()
, prefix_()
, suffix_()
, nested_results_()
, action_state_()
, extras_ptr_()
{
}
/// \param that The match_results object to copy
/// \post regex_id() == that.regex_id().
/// \post size() == that.size().
/// \post empty() == that.empty().
/// \post str(n) == that.str(n) for all positive integers n \< that.size().
/// \post prefix() == that.prefix().
/// \post suffix() == that.suffix().
/// \post (*this)[n] == that[n] for all positive integers n \< that.size().
/// \post length(n) == that.length(n) for all positive integers n \< that.size().
/// \post position(n) == that.position(n) for all positive integers n \< that.size().
match_results(match_results<BidiIter> const &that)
: regex_id_(that.regex_id_)
, sub_matches_()
, base_()
, prefix_()
, suffix_()
, nested_results_()
, action_state_(that.action_state_)
, extras_ptr_()
{
if(that)
{
extras_type &extras = this->get_extras_();
std::size_t size = that.sub_matches_.size();
detail::sub_match_impl<BidiIter> *sub_matches = extras.sub_match_stack_.push_sequence(size);
detail::core_access<BidiIter>::init_sub_match_vector(this->sub_matches_, sub_matches, size, that.sub_matches_);
// BUGBUG this doesn't share the extras::sequence_stack
this->nested_results_ = that.nested_results_;
this->prefix_ = that.prefix_;
this->suffix_ = that.suffix_;
this->base_ = that.base_;
}
}
~match_results()
{
}
/// \param that The match_results object to copy.
/// \post regex_id() == that.regex_id().
/// \post size() == that.size().
/// \post empty() == that.empty().
/// \post str(n) == that.str(n) for all positive integers n \< that.size().
/// \post prefix() == that.prefix().
/// \post suffix() == that.suffix().
/// \post (*this)[n] == that[n] for all positive integers n \< that.size().
/// \post length(n) == that.length(n) for all positive integers n \< that.size().
/// \post position(n) == that.position(n) for all positive integers n \< that.size().
match_results<BidiIter> &operator =(match_results<BidiIter> const &that)
{
match_results<BidiIter>(that).swap(*this);
return *this;
}
/// Returns the number of sub_match elements stored in *this.
///
size_type size() const
{
return this->sub_matches_.size();
}
/// Returns size() == 0.
///
bool empty() const
{
return 0 == this->size();
}
/// Returns (*this)[sub].length().
///
difference_type length(size_type sub = 0) const
{
return (*this)[ sub ].length();
}
/// If !(*this)[sub].matched then returns -1. Otherwise returns std::distance(base, (*this)[sub].first),
/// where base is the start iterator of the sequence that was searched. [Note
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?