⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regexpr2.h

📁 vsstylemanager1.0.4希望对大家有用啊,
💻 H
📖 第 1 页 / 共 3 页
字号:
struct basic_match_results_c : public basic_match_results<CharT const *, AllocT>
{
    typedef basic_match_results<CharT const *, AllocT> base;
    REGEX_DEPRECATED typedef typename base::const_iterator const_iterator;
    typedef typename base::iterator_type  iterator_type;
    typedef typename base::backref_type   backref_type;
    typedef typename base::allocator_type allocator_type;
    typedef typename base::backref_vector backref_vector;

    explicit basic_match_results_c( allocator_type const & alloc = allocator_type() )
        : basic_match_results<CharT const *, AllocT>( alloc )
    {
    }
};

template< typename CharT, typename TraitsT, typename AllocT >
struct subst_results_base
{
    typedef typename detail::rebind<AllocT, CharT>::type              char_allocator_type;
    typedef std::basic_string<CharT, TraitsT, char_allocator_type>    string_type;
    typedef typename string_type::const_iterator                    iterator_type;
    typedef basic_match_results<iterator_type,AllocT>                type;
};

//
// For storing the results of a substitute() operation
//
template
<
    typename CharT,
    typename TraitsT = std::char_traits<CharT>,
    typename AllocT  = std::allocator<CharT>
>
struct basic_subst_results : public subst_results_base<CharT, TraitsT, AllocT>::type
{
    typedef typename detail::rebind<AllocT, CharT>::type              char_allocator_type;
    typedef std::basic_string<CharT, TraitsT, char_allocator_type>    string_type;
    typedef typename string_type::const_iterator                    iterator_type;
    typedef basic_match_results<iterator_type, AllocT>               base;
    typedef typename base::backref_type                             backref_type;
    typedef typename base::allocator_type                           allocator_type;
    typedef typename base::backref_vector                           backref_vector;
    friend struct detail::regex_access<iterator_type>;

    explicit basic_subst_results( allocator_type const & alloc = allocator_type() )
        : basic_match_results< iterator_type, AllocT >( alloc )
        , m_backref_str( detail::convert_allocator<CharT>( alloc, 0 ) )
        , m_pbackref_str( &m_backref_str )
    {
    }

    string_type const & backref_str() const //throw()
    {
        return *m_pbackref_str;
    }

private:
    string_type         m_backref_str;
    string_type const * m_pbackref_str;
};


template< typename CharT, typename TraitsT, typename AllocT >
struct split_results_base
{
    typedef typename detail::rebind<AllocT, CharT>::type            char_allocator_type;
    typedef std::basic_string<CharT, TraitsT, char_allocator_type>  string_type;
    typedef typename detail::rebind<AllocT, string_type>::type      allocator_type;
    typedef std::vector<string_type,allocator_type>                 type;
};

//
// For storing the results of a split() operation
//
template
<
    typename CharT,
    typename TraitsT = std::char_traits<CharT>,
    typename AllocT  = std::allocator<CharT>
>
struct basic_split_results : private split_results_base<CharT, TraitsT, AllocT>::type
{
    typedef CharT                                                   char_type;
    typedef typename detail::rebind<AllocT, CharT>::type            char_allocator_type;
    typedef std::basic_string<CharT, TraitsT, char_allocator_type>  string_type;
    typedef typename detail::rebind<AllocT, string_type>::type      allocator_type;
    typedef std::vector<string_type,allocator_type>                 string_vector;
    typedef string_vector                                           base;

    explicit basic_split_results( allocator_type const & alloc = allocator_type() )
        : base( alloc )
    {
    }

#if !defined(_MSC_VER) | 1200 < _MSC_VER
    typedef typename allocator_type::pointer        pointer;
    typedef typename allocator_type::const_pointer  const_pointer;
#else
    typedef string_type *                           pointer;
    typedef string_type const *                     const_pointer;
#endif

    // shortcuts to the most basic read-only container operations
    typedef typename base::size_type                size_type;
    typedef typename base::difference_type          difference_type;
    typedef typename base::value_type               value_type;
    typedef typename base::reference                reference;
    typedef typename base::const_reference          const_reference;
    typedef typename base::iterator                 iterator;
    typedef typename base::const_iterator           const_iterator;
    typedef typename base::reverse_iterator         reverse_iterator;
    typedef typename base::const_reverse_iterator   const_reverse_iterator;
    using base::begin;
    using base::end;
    using base::rbegin;
    using base::rend;
    using base::operator[];
    using base::at;
    using base::size;
    using base::front;
    using base::back;

    string_vector & strings()
    {
        return *this;
    }

    string_vector const & strings() const
    {
        return *this;
    }
};

//
// The REGEX_MODE is a way of controlling how matching occurs.
//
enum REGEX_MODE
{
    MODE_FAST,  // Uses the fast, recursive algorithm. Could overflow stack.
    MODE_SAFE,  // Uses the slow, iterative algorithm. Can't overflow stack.
    MODE_MIXED, // Uses a heuristic to automatically determine which algorithm
                // is the most appropriate for this pattern.

    // MS VC++ has structured exception handling, which makes the
    // consequences of a stack overflow much less severe. Because of this,
    // it is possible to use the "fast" algorithm always on MS platforms,
#ifdef _MSC_VER
    MODE_DEFAULT = MODE_FAST
#else
    MODE_DEFAULT = MODE_MIXED
#endif
};

//
// helper function for resetting the intrinsic character sets.
// This should be called after changing the locale with setlocale()
//
template< typename CharT >
void reset_intrinsic_charsets( CharT ch = CharT( 0 ) );

// This is for implementation details that really belong in the
// cpp file, but can't go there because of template strangeness.
#include "reimpl2.h"

// --------------------------------------------------------------------------
//
// Class:       basic_rpattern_base
//
// Description:
//
// Methods:     basic_rpattern_base - c'tor
//              basic_rpattern_base -
//              basic_rpattern_base -
//              init                - ( re )initialize the pattern
//              init                -
//              set_substitution    - set the substitution string
//              _find_next_group    - parse the next group of the pattern
//              _find_next          - parse the next sub_expr of the pattern
//              _find_atom          - parse the next atom of the pattern
//              _quantify           - quantify the sub_expr
//              _common_init        - perform some common initialization tasks
//              _parse_subst        - parse the substitution string
//              _add.m_subst_backref  - add a backref node to the subst list
//
// Members:     m_invisible_groups  - list of hidden groups
//
// Typedefs:    syntax_type         -
//              backref_type        -
//              backref_vector      -
//              string_type         -
//              size_type           -
//
// History:     8/14/2000 - ericne - Created
//              8/5/2001 - ericne - complete overhaul
//
// --------------------------------------------------------------------------
template< typename IterT, typename SyntaxT >
class basic_rpattern_base : protected detail::basic_rpattern_base_impl<IterT>
{
protected:
    typedef detail::basic_rpattern_base_impl<IterT>   impl;
public:
    typedef SyntaxT syntax_type;
    typedef typename impl::char_type       char_type;
    typedef typename impl::traits_type     traits_type;

    typedef typename impl::string_type     string_type;
    typedef typename impl::size_type       size_type;

    typedef typename impl::backref_type    backref_type;
    typedef typename impl::backref_vector  backref_vector;

    void init
    (
        string_type const & pat,
        REGEX_FLAGS flags = NOFLAGS,
        REGEX_MODE mode = MODE_DEFAULT
    );                                                      //throw( bad_regexpr, std::bad_alloc );

    void init
    (
        string_type const & pat,
        string_type const & subst,
        REGEX_FLAGS flags = NOFLAGS,
        REGEX_MODE mode = MODE_DEFAULT
    );                                                      //throw( bad_regexpr, std::bad_alloc );

    void set_substitution
    (
        string_type const & subst
    );                                                      //throw( bad_regexpr, std::bad_alloc );

    using impl::flags;
    using impl::mode;
    using impl::get_width;
    using impl::cgroups;
    using impl::get_pat;
    using impl::get_subst;
    using impl::swap;
    using impl::npos;

protected:
    basic_rpattern_base() //throw()
        : detail::basic_rpattern_base_impl<IterT>()
    {
    }

    basic_rpattern_base( basic_rpattern_base<IterT, SyntaxT> const & that )                                                   //throw()
        : detail::basic_rpattern_base_impl<IterT>( that.flags(), that.mode(), that.get_pat(), that.get_subst() )
    {
        // Don't call _normalize_string(). If that.flags()&NORMALIZE,
        // then subst has already been normalized.
        _common_init( this->m_flags );
        _parse_subst( *this->m_subst, this->m_fuses_backrefs, this->m_subst_list ); // must come after _common_init
    }

    explicit basic_rpattern_base
    (
        string_type const & pat,
        REGEX_FLAGS flags = NOFLAGS,
        REGEX_MODE mode = MODE_DEFAULT
    )                                                   //throw( bad_regexpr, std::bad_alloc )
        : detail::basic_rpattern_base_impl<IterT>( flags, mode, pat )
    {
        _common_init( this->m_flags );
    }

    basic_rpattern_base
    (
        string_type const & pat,
        string_type const & subst,
        REGEX_FLAGS flags = NOFLAGS,
        REGEX_MODE mode = MODE_DEFAULT
    )                                                   //throw( bad_regexpr, std::bad_alloc )
        : detail::basic_rpattern_base_impl<IterT>( flags, mode, pat, subst )
    {
        _common_init( this->m_flags );
        _normalize_string( *this->m_subst );
        _parse_subst( *this->m_subst, this->m_fuses_backrefs, this->m_subst_list ); // must come after _common_init
    }

    basic_rpattern_base & operator=
    (
        basic_rpattern_base<IterT, SyntaxT> const & that
    )                                                   //throw( bad_regexpr, std::bad_alloc )
    {
        basic_rpattern_base<IterT, SyntaxT> temp( that );
        swap( temp );
        return *this;
    }

    detail::match_group_base<IterT> * _find_next_group
    (
        typename string_type::iterator & ipat,
        detail::match_group_base<IterT> * pgroup, syntax_type & sy,
        std::vector<detail::match_group_base<IterT>*> & rggroups
    );

    bool _find_next
    (
        typename string_type::iterator & ipat,
        detail::match_group_base<IterT> * pgroup, syntax_type & sy,
        std::vector<detail::match_group_base<IterT>*> & rggroups
    );

    void _find_atom
    (
        typename string_type::iterator & ipat,
        detail::match_group_base<IterT> * pgroup,
        syntax_type & sy
    );

    void _quantify
    (
        std::auto_ptr<detail::sub_expr<IterT> > & pnew,
        typename string_type::iterator & ipat,
        bool is_group,
        syntax_type & sy
    );

    void _add_subst_backref
    (
        detail::subst_node & snode,
        size_t nbackref,
        ptrdiff_t rstart,
        bool & uses_backrefs,
        detail::subst_list_type & subst_list
    ) const;

    void _parse_subst
    (
        string_type & subst,
        bool & uses_backrefs,
        detail::subst_list_type & subst_list
    ) const;

    void _common_init( REGEX_FLAGS flags );

    static detail::instantiator instantiate()
    {
        typedef basic_rpattern_base this_type;

        return detail::instantiator_helper
        (
            &detail::basic_rpattern_base_impl<IterT>::instantiate,
            static_cast<void (this_type::*)( string_type const &, REGEX_FLAGS, REGEX_MODE )>( &this_type::init ),
            static_cast<void (this_type::*)( string_type const &, string_type const &, REGEX_FLAGS, REGEX_MODE )>( &this_type::init ),
            &this_type::set_substitution,
            &this_type::_find_next_group,
            &this_type::_find_next,
            &this_type::_find_atom,
            &this_type::_add_subst_backref,
            &this_type::_parse_subst,
            &this_type::_common_init
        );
    }
};

// --------------------------------------------------------------------------
//
// Class:       basic_rpattern
//
// Description: generic regex pattern object
//
// Methods:     basic_rpattern - c'tor
//              basic_rpattern -
//              basic_rpattern -
//              match          - match from begin iter to end iter
//              match          - match a null-terminated string
//              match          - match a std::string
//              count          - count matches from begin iter to end iter
//              count          - count matches in a null-terminated string
//              count          - count matches in a std::string
//              substitute     - do substitutions in a std::string
//              _do_match      - internal implementation
//              _do_count      - internal implementation
//
// History:     8/13/2001 - ericne - Created
//
// --------------------------------------------------------------------------
template
<
    typename IterT,
    typename SyntaxT = perl_syntax<REGEX_DEPENDENT_TYPENAME std::iterator_traits<IterT>::value_type>
>
class basic_rpattern : public basic_rpattern_base<IterT, SyntaxT>
{
    typedef detail::basic_rpattern_base_impl<IterT> impl;

    template< typename CharT >
    static void same_char_types( CharT, CharT ) {}

public:
    typedef typename basic_rpattern_base<IterT, SyntaxT>::syntax_type     syntax_type;
    typedef typename basic_rpattern_base<IterT, SyntaxT>::char_type       char_type;
    typedef typename basic_rpattern_base<IterT, SyntaxT>::traits_type     traits_type;

    typedef typename basic_rpattern_base<IterT, SyntaxT>::string_type     string_type;
    typedef typename basic_rpattern_base<IterT, SyntaxT>::size_type       size_type;

    typedef typename basic_rpattern_base<IterT, SyntaxT>::backref_type    backref_type;
    typedef typename basic_rpattern_base<IterT, SyntaxT>::backref_vector  backref_vector;

    basic_rpattern() //throw()
        : basic_rpattern_base<IterT, SyntaxT>()
    {
    }

    basic_rpattern( basic_rpattern const & that )
        : basic_rpattern_base<IterT, SyntaxT>( that )
    {
    }

    explicit basic_rpattern
    (
        string_type const & pat,
        REGEX_FLAGS flags = NOFLAGS,
        REGEX_MODE mode = MODE_DEFAULT
    )                                                   //throw( bad_regexpr, std::bad_alloc )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -