📄 regexpr2.h
字号:
return match( str, results, 0, impl::npos );
}
template< typename CI2 >
size_t count( CI2 ibegin, CI2 iend ) const
{
// If your compile breaks here, it is because CI2 is not
// convertible to type CI. Check the declaration of your rpattern object.
detail::static_assert< detail::is_convertible<CI2,CI>::value > const iterator_types_are_not_convertible;
( void ) iterator_types_are_not_convertible;
backref_vector rgbackrefs;
detail::match_param<CI> param( ibegin, iend, & rgbackrefs );
return impl::_do_count( param, false );
}
template< typename CH >
size_t count( CH * szbegin ) const
{
// If your compile breaks here, it is because CI2 is not
// convertible to type CI. Check the declaration of your rpattern object.
typedef CH * CI2;
detail::static_assert< detail::is_convertible<CI2,CI>::value > const iterator_types_are_not_convertible;
( void ) iterator_types_are_not_convertible;
backref_vector rgbackrefs;
// If your compile breaks here, it is because CH const * is not
// convertible to type CI. Check the declaration of your rpattern object.
detail::match_param<CI> param( szbegin, (CH*)0, & rgbackrefs );
return impl::_do_count( param, szbegin );
}
template< typename CH, typename TR, typename AL >
size_t count(
std::basic_string<CH, TR, AL> const & str,
size_type pos,
size_type len ) const
{
// If your compile breaks here, it is because CI2 is not
// convertible to type CI. Check the declaration of your rpattern object.
typedef typename std::basic_string<CH, TR, AL>::const_iterator CI2;
detail::static_assert< detail::is_convertible<CI2,CI>::value > const iterator_types_are_not_convertible;
( void ) iterator_types_are_not_convertible;
backref_vector rgbackrefs;
// If your compile breaks here, then the string you passed in has
// a different iterator type than this rpattern type is expecting
detail::match_param<CI> param( str.begin(), str.begin(), & rgbackrefs );
if( len == npos || pos + len >= str.size() )
param.istop = CI(str.end());
else
std::advance( param.istop, pos + len );
std::advance( param.istart, pos );
param.ibegin = param.istart;
return impl::_do_count( param, false );
}
template< typename CH, typename TR, typename AL >
size_t count( std::basic_string<CH, TR, AL> const & str ) const
{
return count( str, 0, impl::npos );
}
template< typename CH, typename TR, typename AL >
size_t substitute(
std::basic_string<CH, TR, AL> & str,
basic_subst_results<CH, TR, AL> & results,
size_type pos,
size_type len ) const
{
// If your compile breaks here, it is because CI2 is not
// convertible to type CI. Check the declaration of your rpattern object.
typedef typename std::basic_string<CH, TR, AL>::const_iterator CI2;
detail::static_assert< detail::is_convertible<CI2,CI>::value > const iterator_types_are_not_convertible;
( void ) iterator_types_are_not_convertible;
return detail::matcher_helper<CI>::_Do_subst( *this, str, results, pos, len );
}
template< typename CH, typename TR, typename AL >
size_t substitute(
std::basic_string<CH, TR, AL> & str,
basic_subst_results<CH, TR, AL> & results ) const
{
return substitute( str, results, 0, impl::npos );
}
};
// --------------------------------------------------------------------------
//
// Class: basic_rpattern_c
//
// Description: a pattern object optimized for matching C-style, NULL-
// terminated strings. It treats the null-terminator as
// the end-of-string condition.
//
// Methods: basic_rpattern_c - c'tor
// basic_rpattern_c -
// basic_rpattern_c -
// match - match a null-terminated string
// count - count matches in a null-terminated string
// _do_match_c - internal implementation
// _do_count_c - internal implementation
//
// History: 8/13/2001 - ericne - Created
//
// --------------------------------------------------------------------------
template< typename CH, typename SY = perl_syntax<CH> >
class basic_rpattern_c : public basic_rpattern_base<CH const *, SY>
{
typedef detail::basic_rpattern_base_impl<CH const *> impl;
public:
typedef typename basic_rpattern_base<CH const *, SY>::syntax_type syntax_type;
typedef typename basic_rpattern_base<CH const *, SY>::char_type char_type;
typedef typename basic_rpattern_base<CH const *, SY>::traits_type traits_type;
typedef typename basic_rpattern_base<CH const *, SY>::string_type string_type;
typedef typename basic_rpattern_base<CH const *, SY>::size_type size_type;
typedef typename basic_rpattern_base<CH const *, SY>::backref_type backref_type;
typedef typename basic_rpattern_base<CH const *, SY>::backref_vector backref_vector;
basic_rpattern_c() //throw()
: basic_rpattern_base<CH const *, SY>()
{
}
basic_rpattern_c( basic_rpattern_c const & that )
: basic_rpattern_base<CH const *, SY>( that )
{
}
explicit basic_rpattern_c(
string_type const & pat,
REGEX_FLAGS flags = NOFLAGS,
REGEX_MODE mode = MODE_DEFAULT ) //throw( bad_regexpr, std::bad_alloc )
: basic_rpattern_base<CH const *, SY>( pat, flags, mode )
{
}
basic_rpattern_c & operator=( basic_rpattern_c<CH, SY> const & that )
{
basic_rpattern_base<CH const *, SY>::operator=( that );
return *this;
}
backref_type const & match(
CH const * szbegin,
basic_match_results_c<CH> & results ) const
{
detail::match_param<CH const *> param = detail::matcher_helper<CH const *>::init_param( szbegin, 0, results );
return impl::_do_match( param, szbegin ) ? results.backref(0) : detail::static_init<backref_type>::value;
}
size_t count( CH const * szbegin ) const
{
backref_vector rgbackrefs;
detail::match_param<CH const *> param( szbegin, 0, & rgbackrefs );
return impl::_do_count( param, szbegin );
}
};
#if defined(UNICODE) | defined(_UNICODE)
typedef wchar_t rechar_t;
#else
typedef char rechar_t;
#endif
typedef std::basic_string<rechar_t> restring;
// On many implementations of the STL, string::iterator is not a typedef
// for char*. Rather, it is a wrapper class. As a result, the regex code
// gets instantiated twice, once for bare pointers (rpattern_c) and once for
// the wrapped pointers (rpattern). But if there is a conversion from the
// bare ptr to the wrapped ptr, then we only need to instantiate the template
// for the wrapped ptr, and the code will work for the bare ptrs, too.
// This can be a significant space savings. The REGEX_FOLD_INSTANTIONS
// macro controls this optimization. The default is "off" for backwards
// compatibility. To turn the optimization on, compile with:
// -DREGEX_FOLD_INSTANTIATIONS=1
#ifndef REGEX_FOLD_INSTANTIATIONS
#define REGEX_FOLD_INSTANTIATIONS 0
#endif
typedef ::regex::detail::select
<
REGEX_FOLD_INSTANTIATIONS &&
detail::is_convertible<rechar_t const *,restring::const_iterator>::value,
restring::const_iterator,
rechar_t const *
>::type lpctstr_t;
// For matching against null-terminated strings
typedef basic_rpattern<lpctstr_t, perl_syntax<rechar_t> > perl_rpattern_c;
typedef basic_rpattern<lpctstr_t, posix_syntax<rechar_t> > posix_rpattern_c;
// For matching against std::strings
typedef basic_rpattern<restring::const_iterator, perl_syntax<rechar_t> > perl_rpattern;
typedef basic_rpattern<restring::const_iterator, posix_syntax<rechar_t> > posix_rpattern;
// Default to perl syntax
typedef perl_rpattern rpattern;
typedef perl_rpattern_c rpattern_c;
// typedefs for the commonly used match_results and subst_results
typedef basic_match_results<restring::const_iterator> match_results;
typedef basic_match_results<lpctstr_t> match_results_c;
typedef basic_subst_results<rechar_t> subst_results;
#if defined(_MSC_VER) & _MSC_VER >= 1300
// These are no longer useful, and will go away in a future release
// You should be using the version without the _c
# pragma deprecated( basic_rpattern_c )
# pragma deprecated( basic_match_results_c )
#endif
//
// Define some classes and macros for creating function-local
// static const rpatterns in a thread-safe way
//
#if defined( _MSC_VER ) & defined( _MT )
namespace detail
{
template< typename PAT >
class rpattern_destroyer
{
PAT const & m_refPat;
bool volatile const & m_fConstructed;
public:
rpattern_destroyer( volatile bool const & fConstructed, PAT const & refPat )
: m_fConstructed( fConstructed ), m_refPat( refPat )
{
}
~rpattern_destroyer()
{
if( m_fConstructed )
( &m_refPat )->~PAT();
}
};
struct CRegExLock
{
CRegExLock();
~CRegExLock();
};
} // namespace detail
#define STATIC_RPATTERN_EX( type, var, params ) \
static unsigned char s_rgb_##var[ sizeof( type ) ]; \
static bool volatile s_f_##var = false; \
static type const & var = *reinterpret_cast<type*>( s_rgb_##var ); \
static regex::detail::rpattern_destroyer<type> const s_des_##var( s_f_##var, var ); \
if( ! s_f_##var ) \
{ \
regex::detail::CRegExLock objLock; \
if( ! s_f_##var ) \
{ \
new( static_cast<void*>( s_rgb_##var ) ) type params; \
s_f_##var = true; \
} \
}
#else
#define STATIC_RPATTERN_EX( type, var, params ) \
static type const var params;
#endif
#define STATIC_RPATTERN( var, params ) \
STATIC_RPATTERN_EX( regex::rpattern, var, params )
#define STATIC_RPATTERN_C( var, params ) \
STATIC_RPATTERN_EX( regex::rpattern_c, var, params )
//
// ostream inserter operator for back-references
//
template< typename CH, typename TR, typename CI >
inline std::basic_ostream<CH, TR> & operator<<(
std::basic_ostream<CH, TR> & sout,
backref_tag<CI> const & br )
{
return br.print( sout );
}
} // namespace regex
//
// specializations for std::swap
//
namespace std
{
template<>
inline void swap( regex::detail::regex_arena & left, regex::detail::regex_arena & right )
{
left.swap( right );
}
template< typename CI, typename SY >
inline void swap( regex::basic_rpattern_base<CI, SY> & left, regex::basic_rpattern_base<CI, SY> & right )
{
left.swap( right );
}
}
#ifdef _MSC_VER
#pragma warning( pop )
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -