📄 regex
字号:
_Assign_rv(_STD move(_Right));
}
_MyT& operator=(_MyT&& _Right)
{ // assign by moving _Right
_Assign_rv(_STD move(_Right));
return (*this);
}
void _Assign_rv(_MyT&& _Right)
{ // assign by moving _Right
if (this != &_Right)
{ // clear this and steal from _Right
_Matches = _STD move(_Right._Matches);
_Prefix = _Right._Prefix;
_Suffix = _Right._Suffix;
_Null_elem = _Right._Null_elem;
}
}
size_type size() const
{ // return number of capture groups
return (_Matches.size());
}
size_type max_size() const
{ // return maximum possible number of capture groups
return (_Matches.max_size());
}
bool empty() const
{ // test if object is empty
return (_Matches.empty());
}
difference_type length(size_type _Sub = 0) const
{ // return length of capture group _Sub
return ((*this)[_Sub].length());
}
difference_type position(size_type _Sub = 0) const
{ // return offset of submatch _Sub
return (_STD distance(_Org, (*this)[_Sub].first));
}
string_type str(size_type _Sub = 0) const
{ // return contents of submatch _Sub
return (string_type((*this)[_Sub]));
}
const_reference operator[](size_type _Sub) const
{ // return submatch _Sub
return (_Matches.size() <= _Sub ? _Null_elem : _Matches[_Sub]);
}
const_reference prefix() const
{ // return text preceding match
return (_Prefix);
}
const_reference suffix() const
{ // return text following match
return (_Suffix);
}
const_iterator begin() const
{ // return iterator for beginning of sequence of submatches
return (_Matches.begin());
}
const_iterator end() const
{ // return iterator for end of sequence of submatches
return (_Matches.end());
}
template<class _OutIt>
_OutIt _Format(_OutIt _Out,
const string_type& _Fmt,
regex_constants::match_flag_type _Flags) const
{ // format text, replacing matches
return (_Flags & regex_constants::format_sed
? _Format_sed(*this, _Out, _Fmt.begin(), _Fmt.end(), _Flags)
: _Format_default(*this, _Out, _Fmt.begin(), _Fmt.end(), _Flags));
}
#if _ITERATOR_DEBUG_LEVEL == 0
template<class _OutIt>
_OutIt format(_OutIt _Out,
const string_type& _Fmt,
regex_constants::match_flag_type _Flags =
regex_constants::format_default) const
{ // format text, replacing matches
return (_Rechecked(_Out,
_Format(_Unchecked(_Out), _Fmt, _Flags)));
}
#else /* _ITERATOR_DEBUG_LEVEL == 0 */
template<class _OutIt>
_OutIt _Format(_OutIt _Out,
const string_type& _Fmt,
regex_constants::match_flag_type _Flags, _STD tr1::true_type) const
{ // format text, replacing matches, checked dest
return (_Format(_Out, _Fmt, _Flags));
}
template<class _OutIt>
_SCL_INSECURE_DEPRECATE
_OutIt _Format(_OutIt _Out,
const string_type& _Fmt,
regex_constants::match_flag_type _Flags, _STD tr1::false_type) const
{ // format text, replacing matches, unchecked dest
return (_Format(_Out, _Fmt, _Flags));
}
template<class _OutIt>
_OutIt format(_OutIt _Out,
const string_type& _Fmt,
regex_constants::match_flag_type _Flags =
regex_constants::format_default) const
{ // format text, replacing matches
_DEBUG_POINTER(_Out);
return (_Format(_Out, _Fmt, _Flags, _Is_checked(_Out)));
}
template<class _OutTy,
size_t _OutSize>
_OutTy * format(_OutTy (&_Out)[_OutSize],
const string_type& _Fmt,
regex_constants::match_flag_type _Flags =
regex_constants::format_default) const
{ // format text, replacing matches
return (_Unchecked(format(
_Array_iterator<_OutTy, _OutSize>(_Out), _Fmt, _Flags)));
}
#endif /* _ITERATOR_DEBUG_LEVEL == 0 */
string_type format(const string_type& _Fmt,
regex_constants::match_flag_type _Flags =
regex_constants::format_default) const
{ // format text, replacing matches
string_type _Str;
format(_STD back_inserter(_Str), _Fmt, _Flags);
return (_Str);
}
allocator_type get_allocator() const
{ // return allocator object for submatches
return (_Matches.get_allocator());
}
void swap(match_results& _Right)
{ // exchange contents with _Right
_Swap_adl(_Org, _Right._Org);
_Matches.swap(_Right._Matches);
_STD swap(_Prefix, _Right._Prefix);
_STD swap(_Suffix, _Right._Suffix);
}
void _Resize(unsigned _Nx)
{ // allocate space for _Nx submatches
_Matches.resize(_Nx);
}
_Elem& _Pfx()
{ // return modifiable pair of iterators to prefix
return (_Prefix);
}
_Elem& _Sfx()
{ // return modifiable pair of iterators to suffix
return (_Suffix);
}
_Elem& _Null()
{ // return modifiable pair of iterators for null element
return (_Null_elem);
}
_Elem& _At(unsigned _Sub)
{ // unchecked access to element at _Sub
return (_Matches[_Sub]);
}
_Elem _At(unsigned _Sub) const
{ // unchecked access to element at _Sub
return (_Matches[_Sub]);
}
_BidIt _Org;
private:
_MyCont _Matches;
_Elem _Prefix;
_Elem _Suffix;
_Elem _Null_elem;
};
// TEMPLATE OPERATORS FOR match_results
template<class _BidIt,
class _Alloc>
bool operator==(const match_results<_BidIt, _Alloc>& _Left,
const match_results<_BidIt, _Alloc>& _Right)
{ // compare results for equality
return (_Left.str() == _Right.str());
}
template<class _BidIt,
class _Alloc>
bool operator!=(const match_results<_BidIt, _Alloc>& _Left,
const match_results<_BidIt, _Alloc>& _Right)
{ // compare results for inequality
return (!(_Left == _Right));
}
// NFA PROPERTIES
typedef unsigned long _Grps;
const int _MAX_GRP = sizeof(_Grps) * CHAR_BIT;
const int _BRE_MAX_GRP = 9;
const int _Bmp_max = 256; // must fit in an int
const int _Bmp_shift = 3;
const int _Bmp_chrs = 1 << _Bmp_shift; // # of bits to be stored in each char
const int _Bmp_mask = _Bmp_chrs - 1;
const int _Bmp_size = (_Bmp_max + _Bmp_chrs - 1) / _Bmp_chrs;
const int _Buf_incr = 16;
const int _ARRAY_THRESHOLD = 4;
enum _Node_flags
{ // flags for nfa nodes with special properties
_Fl_none = 0x00,
_Fl_negate = 0x01,
_Fl_greedy = 0x02,
_Fl_final = 0x04,
_Fl_longest = 0x08
};
inline _Node_flags operator|(_Node_flags _Left, _Node_flags _Right)
{ // bitwise or
return (_Node_flags((int)_Left | _Right));
}
inline _Node_flags operator|=(_Node_flags& _Left, _Node_flags _Right)
{ // bitwise or
return (_Left = _Node_flags((int)_Left | _Right));
}
inline _Node_flags operator^=(_Node_flags& _Left, _Node_flags _Right)
{ // bitwise xor
return (_Left = _Node_flags((int)_Left ^ _Right));
}
enum _Node_type
{ // type flag for nfa nodes
_N_none,
_N_nop,
_N_bol,
_N_eol,
_N_wbound,
_N_dot,
_N_str,
_N_class,
_N_group,
_N_end_group,
_N_assert,
_N_neg_assert,
_N_end_assert,
_N_capture,
_N_end_capture,
_N_back,
_N_if,
_N_endif,
_N_rep,
_N_end_rep,
_N_begin,
_N_end
};
// TEMPLATE CLASS _Buf
template<class _Elem>
struct _Buf
{ // character buffer
_Buf()
: _Sz(0), _Nchrs(0), _Chrs(0)
{ // construct
}
~_Buf()
{ // destroy
free(_Chrs);
}
int _Size() const
{ // return number of characters held in buffer
return (_Nchrs);
}
_Elem _At(unsigned _Idx) const
{ // return character at _Idx
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Nchrs <= _Idx)
_DEBUG_ERROR("regex buffer subscript out of range");
#else /* _ITERATOR_DEBUG_LEVEL == 2 */
_SCL_SECURE_VALIDATE_RANGE(_Idx < _Nchrs);
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
return (_Chrs[_Idx]);
}
const _Elem *_Str() const
{ // return pointer to first character
return (_Chrs);
}
void _Insert(_Elem _Ch)
{ // append _Ch
if (_Sz <= _Nchrs)
_Expand(_Nchrs + _Buf_incr);
_Chrs[_Nchrs++] = _Ch;
}
_Elem _Del()
{ // remove and return last character
return (_Chrs[--_Nchrs]);
}
template<class _FwdIt>
void _Insert(_FwdIt _First, _FwdIt _Last)
{ // append multiple characters
while (_First != _Last)
_Insert(*_First++);
}
private:
void _Expand(int _Len)
{ // expand buffer to hold _Len characters
_Elem *_Tmp = (_Elem *)realloc(_Chrs, _Len * sizeof(_Elem));
if (!_Tmp)
_Xmem();
_Chrs = _Tmp;
_Sz = _Len;
}
unsigned _Sz;
unsigned _Nchrs;
_Elem *_Chrs;
};
// STRUCT _Bitmap
struct _Bitmap
{ // accelerator table for small character values
_Bitmap()
{ // construct
memset(_Chrs, '\0', _Bmp_size);
}
void _Mark(unsigned _Ch)
{ // mark character _Ch
_Chrs[_Ch >> _Bmp_shift] |= (1 << (_Ch & _Bmp_mask));
}
bool _Find(unsigned _Ch) const
{ // return true if _Ch is marked
return ((_Chrs[_Ch >> _Bmp_shift] & (1 << (_Ch & _Bmp_mask))) != 0);
}
private:
unsigned char _Chrs[_Bmp_size];
};
// TEMPLATE CLASS _Sequence
template<class _Elem>
struct _Sequence
{ // holds sequences of _Sz elements
_Sequence(unsigned _Len)
: _Sz(_Len)
{ // construct
}
unsigned _Sz;
_Buf<_Elem> _Data;
_Sequence *_Next;
};
// CLASS _Node_base
class _Node_base
{ // base class for all nfa nodes
public:
_Node_base(_Node_type _Ty, _Node_flags _Fl = _Fl_none)
: _Type(_Ty), _Flags(_Fl), _Next(0), _Prev(0)
{ // construct
}
_Node_type _Type;
_Node_flags _Flags;
_Node_base *_Next;
_Node_base *_Prev;
virtual ~_Node_base()
{ // destroy
}
};
// FUNCTION _Destroy_node
inline void _Destroy_node(_Node_base *_Nx,
_Node_base *_Ne = 0)
{ // destroy sublist of nodes
while (_Nx != _Ne && _Nx != 0)
{ // destroy node
_Node_base *_Tmp = _Nx;
_Nx = _Nx->_Next;
_Tmp->_Next = 0;
delete _Tmp;
}
}
// CLASS _Root_node
class _Root_node
: public _Node_base
{ // root of parse tree
public:
_Root_node()
: _Node_base(_N_begin), _Refs(0)
{ // construct
}
regex_constants::syntax_option_type _Fl;
unsigned _Marks;
unsigned _Refs;
};
// CLASS _Node_end_group
class _Node_end_group
: public _Node_base
{ // node that marks end of a group
public:
_Node_end_group(_Node_type _Ty, _Node_flags _Fl, _Node_base *_Bx)
: _Node_base(_Ty, _Fl), _Back(_Bx)
{ // construct
}
_Node_base *_Back;
};
// CLASS _Node_assert
class _Node_assert
: public _Node_base
{ // node that holds an ECMAScript assertion
public:
_Node_assert(_Node_type _Ty, _Node_flags _Fl = _Fl_none)
: _Node_base(_Ty, _Fl), _Child(0)
{ // construct
}
~_Node_assert()
{ // destroy branch
_Destroy_node(_Child);
}
_Node_base *_Child;
};
// TEMPLATE CLASS _Node_capture
class _Node_capture
: public _Node_base
{ // node that marks beginning of a capture group
public:
_Node_capture(unsigned _Ix)
: _Node_base(_N_capture, _Fl_none), _Idx(_Ix)
{ // construct
}
unsigned _Idx;
};
// CLASS _Node_back
class _Node_back
: public _Node_base
{ // node that holds a back reference
public:
_Node_back(unsigned _Ix)
: _Node_base(_N_back, _Fl_none), _Idx(_Ix)
{ // construct
}
unsigned _Idx;
};
// TEMPLATE CLASS _Node_str
template<class _Elem>
class _Node_str
: public _Node_base
{ // node that holds text
public:
_Node_str(_Node_flags _Fl = _Fl_none)
: _Node_base(_N_str, _Fl)
{ // construct
}
_Buf<_Elem> _Data;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -