示例#1
0
inline sequence<BidiIter> make_charset_xpression
(
    compound_charset<Traits> &chset
  , Traits const &tr
  , regex_constants::syntax_option_type flags
)
{
    typedef typename Traits::char_type char_type;
    bool const icase = (0 != (regex_constants::icase_ & flags));
    bool const optimize = is_narrow_char<char_type>::value && 0 != (regex_constants::optimize & flags);

    // don't care about compile speed -- fold eveything into a bitset<256>
    if(optimize)
    {
        typedef basic_chset<char_type> charset_type;
        charset_type charset(chset.base());
        if(icase)
        {
            charset_matcher<Traits, mpl::true_, charset_type> matcher(charset);
            merge_charset(matcher.charset_, chset, tr);
            return make_dynamic<BidiIter>(matcher);
        }
        else
        {
            charset_matcher<Traits, mpl::false_, charset_type> matcher(charset);
            merge_charset(matcher.charset_, chset, tr);
            return make_dynamic<BidiIter>(matcher);
        }
    }

    // special case to make [[:digit:]] fast
    else if(chset.base().empty() && chset.posix_no().empty())
    {
        BOOST_ASSERT(0 != chset.posix_yes());
        posix_charset_matcher<Traits> matcher(chset.posix_yes(), chset.is_inverted());
        return make_dynamic<BidiIter>(matcher);
    }

    // default, slow
    else
    {
        if(icase)
        {
            charset_matcher<Traits, mpl::true_> matcher(chset);
            return make_dynamic<BidiIter>(matcher);
        }
        else
        {
            charset_matcher<Traits, mpl::false_> matcher(chset);
            return make_dynamic<BidiIter>(matcher);
        }
    }
}
示例#2
0
inline void merge_charset
(
    basic_chset<Char> &basic
  , compound_charset<Traits> const &compound
  , Traits const &tr
)
{
    detail::ignore_unused(tr);
    if(0 != compound.posix_yes())
    {
        typename Traits::char_class_type mask = compound.posix_yes();
        for(int i = 0; i <= static_cast<int>(UCHAR_MAX); ++i)
        {
            if(tr.isctype((Char)i, mask))
            {
                basic.set((Char)i);
            }
        }
    }

    if(!compound.posix_no().empty())
    {
        for(std::size_t j = 0; j < compound.posix_no().size(); ++j)
        {
            typename Traits::char_class_type mask = compound.posix_no()[j];
            for(int i = 0; i <= static_cast<int>(UCHAR_MAX); ++i)
            {
                if(!tr.isctype((Char)i, mask))
                {
                    basic.set((Char)i);
                }
            }
        }
    }

    if(compound.is_inverted())
    {
        basic.inverse();
    }
}