📄 regex
字号:
: public _Regex_traits<wchar_t>
{ // specialization for wchar_t
public:
int value(wchar_t ch, int base) const
{ // map character value to numeric value
if (base != 8 && L'0' <= ch && ch <= L'9'
|| base == 8 && L'0' <= ch && ch <= L'7')
return (ch - L'0');
else if (base != 16)
;
else if (L'a' <= ch && ch <= L'f')
return (ch - L'a' + 10);
else if (L'A' <= ch && ch <= L'F')
return (ch - L'A' + 10);
return (-1);
}
};
// CLASS regex_error
class regex_error
: public runtime_error
{ // type of all regular expression exceptions
public:
explicit regex_error(regex_constants::error_type _Ex)
: runtime_error("regular expression error"), _Err(_Ex)
{ // construct
}
regex_constants::error_type code() const
{ // return stored error code
return (_Err);
}
private:
regex_constants::error_type _Err;
};
// TEMPLATE CLASS sub_match
template<class _BidIt>
class sub_match
: public _STD pair<_BidIt, _BidIt>
{ // class to hold contents of a capture group
public:
typedef _REGEX_VALT(_BidIt) value_type;
typedef _REGEX_DIFFT(_BidIt) difference_type;
typedef _BidIt iterator;
sub_match()
: matched(false)
{ // construct
}
bool matched;
difference_type length() const
{ // return length of matched text
return (matched ? _STD distance(this->first, this->second) : 0);
}
operator _STD basic_string<value_type>() const
{ // convert matched text to string
return (str());
}
_STD basic_string<value_type> str() const
{ // convert matched text to string
return (matched ?
_STD basic_string<value_type>(this->first, this->second)
: _STD basic_string<value_type>());
}
int compare(const sub_match& _Right) const
{ // compare *this to _Right
return (str().compare(_Right.str()));
}
int compare(const _STD basic_string<value_type>& _Right) const
{ // compare *this to _Right
return (str().compare(_Right));
}
int compare(_In_z_ const value_type *_Ptr) const
{ // compare *this to array pointed to by _Ptr
return (str().compare(_Ptr));
}
};
typedef sub_match<const char *> csub_match;
typedef sub_match<const wchar_t *> wcsub_match;
typedef sub_match<string::const_iterator> ssub_match;
typedef sub_match<wstring::const_iterator> wssub_match;
// sub_match TEMPLATE OPERATORS
// COMPARE sub_match AND sub_match
template<class _BidIt> inline
bool operator==(
const sub_match<_BidIt>& _Left,
const sub_match<_BidIt>& _Right)
{ // test for equality
return (_Left.compare(_Right) == 0);
}
template<class _BidIt> inline
bool operator!=(
const sub_match<_BidIt>& _Left,
const sub_match<_BidIt>& _Right)
{ // test for inequality
return (!(_Left == _Right));
}
template<class _BidIt> inline
bool operator<(
const sub_match<_BidIt>& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left < _Right
return (_Left.compare(_Right) < 0);
}
template<class _BidIt> inline
bool operator>(
const sub_match<_BidIt>& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left > _Right
return (_Right < _Left);
}
template<class _BidIt> inline
bool operator<=(
const sub_match<_BidIt>& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left <= _Right
return (!(_Right < _Left));
}
template<class _BidIt> inline
bool operator>=(
const sub_match<_BidIt>& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left >= _Right
return (!(_Left < _Right));
}
// COMPARE sub_match AND NTBS
template<class _BidIt> inline
bool operator==(
_In_z_ const _REGEX_VALT(_BidIt) *_Left,
const sub_match<_BidIt>& _Right)
{ // test for equality
return (_Right.compare(_Left) == 0);
}
template<class _BidIt> inline
bool operator!=(
_In_z_ const _REGEX_VALT(_BidIt) *_Left,
const sub_match<_BidIt>& _Right)
{ // test for inequality
return (!(_Left == _Right));
}
template<class _BidIt> inline
bool operator<(
_In_z_ const _REGEX_VALT(_BidIt) *_Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left < _Right
return (0 < _Right.compare(_Left));
}
template<class _BidIt> inline
bool operator>(
_In_z_ const _REGEX_VALT(_BidIt) *_Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left > _Right
return (_Right < _Left);
}
template<class _BidIt> inline
bool operator<=(
_In_z_ const _REGEX_VALT(_BidIt) *_Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left <= _Right
return (!(_Right < _Left));
}
template<class _BidIt> inline
bool operator>=(
_In_z_ const _REGEX_VALT(_BidIt) *_Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left >= _Right
return (!(_Left < _Right));
}
template<class _BidIt> inline
bool operator==(
const sub_match<_BidIt>& _Left,
_In_z_ const _REGEX_VALT(_BidIt) *_Right)
{ // test for equality
return (_Left.compare(_Right) == 0);
}
template<class _BidIt> inline
bool operator!=(
const sub_match<_BidIt>& _Left,
_In_z_ const _REGEX_VALT(_BidIt) *_Right)
{ // test for inequality
return (!(_Left == _Right));
}
template<class _BidIt> inline
bool operator<(
const sub_match<_BidIt>& _Left,
_In_z_ const _REGEX_VALT(_BidIt) *_Right)
{ // test if _Left < _Right
return (_Left.compare(_Right) < 0);
}
template<class _BidIt> inline
bool operator>(
const sub_match<_BidIt>& _Left,
_In_z_ const _REGEX_VALT(_BidIt) *_Right)
{ // test if _Left > _Right
return (_Right < _Left);
}
template<class _BidIt> inline
bool operator<=(
const sub_match<_BidIt>& _Left,
_In_z_ const _REGEX_VALT(_BidIt) *_Right)
{ // test if _Left <= _Right
return (!(_Right < _Left));
}
template<class _BidIt> inline
bool operator>=(
const sub_match<_BidIt>& _Left,
_In_z_ const _REGEX_VALT(_BidIt) *_Right)
{ // test if _Left >= _Right
return (!(_Left < _Right));
}
// COMPARE sub_match AND ELEMENT
template<class _BidIt> inline
bool operator==(
const _REGEX_VALT(_BidIt)& _Left,
const sub_match<_BidIt>& _Right)
{ // test for equality
_STD basic_string<_REGEX_VALT(_BidIt)> _Str(1, _Left);
return (_Right.compare(_Str) == 0);
}
template<class _BidIt> inline
bool operator!=(
const _REGEX_VALT(_BidIt)& _Left,
const sub_match<_BidIt>& _Right)
{ // test for inequality
return (!(_Left == _Right));
}
template<class _BidIt> inline
bool operator<(
const _REGEX_VALT(_BidIt)& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left < _Right
_STD basic_string<_REGEX_VALT(_BidIt)> _Str(1, _Left);
return (0 < _Right.compare(_Str));
}
template<class _BidIt> inline
bool operator>(
const _REGEX_VALT(_BidIt)& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left > _Right
return (_Right < _Left);
}
template<class _BidIt> inline
bool operator<=(
const _REGEX_VALT(_BidIt)& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left <= _Right
return (!(_Right < _Left));
}
template<class _BidIt> inline
bool operator>=(
const _REGEX_VALT(_BidIt)& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left >= _Right
return (!(_Left < _Right));
}
template<class _BidIt> inline
bool operator==(
const sub_match<_BidIt>& _Left,
const _REGEX_VALT(_BidIt)& _Right)
{ // test for equality
_STD basic_string<_REGEX_VALT(_BidIt)> _Str(1, _Right);
return (_Left.compare(_Str) == 0);
}
template<class _BidIt> inline
bool operator!=(
const sub_match<_BidIt>& _Left,
const _REGEX_VALT(_BidIt)& _Right)
{ // test for inequality
return (!(_Left == _Right));
}
template<class _BidIt> inline
bool operator<(
const sub_match<_BidIt>& _Left,
const _REGEX_VALT(_BidIt)& _Right)
{ // test if _Left < _Right
_STD basic_string<_REGEX_VALT(_BidIt)> _Str(1, _Right);
return (_Left.compare(_Str) < 0);
}
template<class _BidIt> inline
bool operator>(
const sub_match<_BidIt>& _Left,
const _REGEX_VALT(_BidIt)& _Right)
{ // test if _Left > _Right
return (_Right < _Left);
}
template<class _BidIt> inline
bool operator<=(
const sub_match<_BidIt>& _Left,
const _REGEX_VALT(_BidIt)& _Right)
{ // test if _Left <= _Right
return (!(_Right < _Left));
}
template<class _BidIt> inline
bool operator>=(
const sub_match<_BidIt>& _Left,
const _REGEX_VALT(_BidIt)& _Right)
{ // test if _Left >= _Right
return (!(_Left < _Right));
}
// COMPARE sub_match AND string
template<class _BidIt> inline
bool operator==(
const sub_match<_BidIt>& _Left,
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Right)
{ // test for equality
return (_Left.str() == _Right);
}
template<class _BidIt> inline
bool operator!=(
const sub_match<_BidIt>& _Left,
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Right)
{ // test for inequality
return (!(_Left == _Right));
}
template<class _BidIt> inline
bool operator<(
const sub_match<_BidIt>& _Left,
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Right)
{ // test if _Left < _Right
return (_Left.str() < _Right);
}
template<class _BidIt> inline
bool operator>(
const sub_match<_BidIt>& _Left,
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Right)
{ // test if _Left > _Right
return (_Right < _Left);
}
template<class _BidIt> inline
bool operator<=(
const sub_match<_BidIt>& _Left,
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Right)
{ // test if _Left <= _Right
return (!(_Right < _Left));
}
template<class _BidIt> inline
bool operator>=(
const sub_match<_BidIt>& _Left,
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Right)
{ // test if _Left >= _Right
return (!(_Left < _Right));
}
template<class _BidIt> inline
bool operator==(
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Left,
const sub_match<_BidIt>& _Right)
{ // test for equality
return (_Left == _Right.str());
}
template<class _BidIt> inline
bool operator!=(
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Left,
const sub_match<_BidIt>& _Right)
{ // test for inequality
return (!(_Left == _Right));
}
template<class _BidIt> inline
bool operator<(
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left < _Right
return (_Left < _Right.str());
}
template<class _BidIt> inline
bool operator>(
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left > _Right
return (_Right < _Left);
}
template<class _BidIt> inline
bool operator<=(
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left <= _Right
return (!(_Right < _Left));
}
template<class _BidIt> inline
bool operator>=(
const _STD basic_string<_REGEX_VALT(_BidIt)>& _Left,
const sub_match<_BidIt>& _Right)
{ // test if _Left >= _Right
return (!(_Left < _Right));
}
// INSERT sub_match IN STREAM
template<class _Elem,
class _Traits,
class _BidIt>
_STD basic_ostream<_Elem, _Traits>& operator<<(
_STD basic_ostream<_Elem, _Traits>& _Ostr,
const sub_match<_BidIt>& _Match)
{ // insert into basic_ostream
return (_Ostr << _Match.str());
}
// FORWARD DECLARATIONS
template<class _BidIt,
class _Allocator = _STD allocator<sub_match<_BidIt> > >
class match_results;
template<class _BidIt,
class _Alloc,
class _InIt,
class _OutIt>
_OutIt _Format_default(const match_results<_BidIt, _Alloc>& _Match,
_OutIt _Out, _InIt _First, _InIt _Last,
regex_constants::match_flag_type _Flags =
regex_constants::format_default);
template<class _BidIt,
class _Alloc,
class _InIt,
class _OutIt>
_OutIt _Format_sed(const match_results<_BidIt, _Alloc>& _Match,
_OutIt _Out, _InIt _First, _InIt _Last,
regex_constants::match_flag_type _Flags =
regex_constants::format_default);
// TEMPLATE CLASS match_results
template<class _BidIt,
class _Alloc>
class match_results
{ // class to hold contents of all capture groups
public:
typedef match_results<_BidIt, _Alloc> _MyT;
typedef sub_match<_BidIt> _Elem;
typedef _STD vector<_Elem, _Alloc> _MyCont;
typedef _Elem value_type;
typedef typename _Alloc::const_reference const_reference;
typedef const_reference reference;
typedef typename _MyCont::const_iterator const_iterator;
typedef const_iterator iterator;
typedef _REGEX_DIFFT(_BidIt) difference_type;
typedef typename _Alloc::size_type size_type;
typedef _Alloc allocator_type;
typedef _REGEX_VALT(_BidIt) char_type;
typedef _STD basic_string<char_type> string_type;
match_results()
{ // construct empty match_results
}
explicit match_results(const _Alloc& _Al)
: _Matches(_Al)
{ // construct empty match_results with allocator
}
match_results(_MyT&& _Right)
{ // construct by moving _Right
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -