/usr/include/boost/xpressive/detail/core
Edit: /usr/include/boost/xpressive/detail/core/optimize.hpp (3466B)
///////////////////////////////////////////////////////////////////////////////
// optimize.hpp
//
// Copyright 2008 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_DETAIL_CORE_OPTIMIZE_HPP_EAN_10_04_2005
#define BOOST_XPRESSIVE_DETAIL_CORE_OPTIMIZE_HPP_EAN_10_04_2005
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace boost { namespace xpressive { namespace detail
{
///////////////////////////////////////////////////////////////////////////////
// optimize_regex
//
template
intrusive_ptr > optimize_regex
(
xpression_peeker::type> const &peeker
, Traits const &tr
, mpl::false_
)
{
if(peeker.line_start())
{
return intrusive_ptr >
(
new line_start_finder(tr)
);
}
else if(peeker.leading_simple_repeat())
{
return intrusive_ptr >
(
new leading_simple_repeat_finder()
);
}
else if(256 != peeker.bitset().count())
{
return intrusive_ptr >
(
new hash_peek_finder(peeker.bitset())
);
}
return intrusive_ptr >();
}
///////////////////////////////////////////////////////////////////////////////
// optimize_regex
//
template
intrusive_ptr > optimize_regex
(
xpression_peeker::type> const &peeker
, Traits const &tr
, mpl::true_
)
{
typedef typename iterator_value::type char_type;
// if we have a leading string literal, initialize a boyer-moore struct with it
peeker_string const &str = peeker.get_string();
if(str.begin_ != str.end_)
{
BOOST_ASSERT(1 == peeker.bitset().count());
return intrusive_ptr >
(
new boyer_moore_finder(str.begin_, str.end_, tr, str.icase_)
);
}
return optimize_regex(peeker, tr, mpl::false_());
}
///////////////////////////////////////////////////////////////////////////////
// common_compile
//
template
void common_compile
(
intrusive_ptr const> const ®ex
, regex_impl &impl
, Traits const &tr
)
{
typedef typename iterator_value::type char_type;
// "link" the regex
xpression_linker linker(tr);
regex->link(linker);
// "peek" into the compiled regex to see if there are optimization opportunities
hash_peek_bitset bset;
xpression_peeker peeker(bset, tr, linker.has_backrefs());
regex->peek(peeker);
// optimization: get the peek chars OR the boyer-moore search string
impl.finder_ = optimize_regex(peeker, tr, is_random());
impl.xpr_ = regex;
}
}}} // namespace boost::xpressive
#endif