Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:49

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // string_matcher.hpp
0003 //
0004 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_STRING_MATCHER_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_STRING_MATCHER_HPP_EAN_10_04_2005
0010 
0011 // MS compatible compilers support #pragma once
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015 
0016 #include <string>
0017 #include <boost/mpl/bool.hpp>
0018 #include <boost/xpressive/detail/detail_fwd.hpp>
0019 #include <boost/xpressive/detail/core/quant_style.hpp>
0020 #include <boost/xpressive/detail/core/state.hpp>
0021 #include <boost/xpressive/detail/utility/algorithm.hpp>
0022 #include <boost/xpressive/detail/utility/traits_utils.hpp>
0023 
0024 namespace boost { namespace xpressive { namespace detail
0025 {
0026     ///////////////////////////////////////////////////////////////////////////////
0027     // string_matcher
0028     //
0029     template<typename Traits, typename ICase>
0030     struct string_matcher
0031       : quant_style_fixed_unknown_width
0032     {
0033         typedef typename Traits::char_type char_type;
0034         typedef typename Traits::string_type string_type;
0035         typedef ICase icase_type;
0036         string_type str_;
0037         char_type const *end_;
0038 
0039         string_matcher(string_type const &str, Traits const &tr)
0040           : str_(str)
0041           , end_()
0042         {
0043             typename range_iterator<string_type>::type cur = boost::begin(this->str_);
0044             typename range_iterator<string_type>::type end = boost::end(this->str_);
0045             for(; cur != end; ++cur)
0046             {
0047                 *cur = detail::translate(*cur, tr, icase_type());
0048             }
0049             this->end_ = detail::data_end(str_);
0050         }
0051 
0052         string_matcher(string_matcher<Traits, ICase> const &that)
0053           : str_(that.str_)
0054           , end_(detail::data_end(str_))
0055         {
0056         }
0057 
0058         template<typename BidiIter, typename Next>
0059         bool match(match_state<BidiIter> &state, Next const &next) const
0060         {
0061             BidiIter const tmp = state.cur_;
0062             char_type const *begin = detail::data_begin(this->str_);
0063             for(; begin != this->end_; ++begin, ++state.cur_)
0064             {
0065                 if(state.eos() ||
0066                     (detail::translate(*state.cur_, traits_cast<Traits>(state), icase_type()) != *begin))
0067                 {
0068                     state.cur_ = tmp;
0069                     return false;
0070                 }
0071             }
0072 
0073             if(next.match(state))
0074             {
0075                 return true;
0076             }
0077 
0078             state.cur_ = tmp;
0079             return false;
0080         }
0081 
0082         detail::width get_width() const
0083         {
0084             return boost::size(this->str_);
0085         }
0086     };
0087 
0088 }}}
0089 
0090 #endif