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

📄 regex

📁 C语言库函数的原型,有用的拿去
💻
📖 第 1 页 / 共 5 页
字号:
		if (_Ptr == 0)
			_Xbad(regex_constants::error_parse);
		_Reset(_Ptr, _Ptr + _Count, _Flags, random_access_iterator_tag());
		}

	template<class _STtraits,
		class _STalloc>
		explicit basic_regex(
			const _STD basic_string<_Elem, _STtraits, _STalloc>& _Str,
			flag_type _Flags = regex_constants::ECMAScript)
		: _Rep(0)
		{	// construct from string object
		_Reset(_Str.begin(), _Str.end(), _Flags, random_access_iterator_tag());
		}

	template<class _InIt>
		basic_regex(_InIt _First, _InIt _Last,
			flag_type _Flags)
		: _Rep(0)
		{	// construct from pair of iterators
		_DEBUG_RANGE(_First, _Last);
		_Reset(_First, _Last, _Flags, _Iter_cat(_First));
		}

	template<class _InIt>
		basic_regex(_InIt _First, _InIt _Last)
		: _Rep(0)
		{	// construct from pair of iterators
		_DEBUG_RANGE(_First, _Last);
		_Reset(_First, _Last, regex_constants::ECMAScript,
			_Iter_cat(_First));
		}

	basic_regex(const _MyT& _Right)

 #if _ENHANCED_REGEX_VISUALIZER
		: _Rep(0), _Visualization(_Right._Visualization)

 #else /* _ENHANCED_REGEX_VISUALIZER */
		: _Rep(0)
 #endif /* _ENHANCED_REGEX_VISUALIZER */

		{	// construct copy of _Right
		_Reset(_Right._Rep);
		}

	basic_regex(_MyT&& _Right)
		: _Rep(0)
		{	// construct by moving _Right
		_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
			_Tidy();

 #if _ENHANCED_REGEX_VISUALIZER
			_Visualization = _STD move(_Right._Visualization);
 #endif /* _ENHANCED_REGEX_VISUALIZER */

			_Rep = _Right._Rep;
			_Right._Rep = 0;
			}
		}

	_MyT& assign(_MyT&& _Right)
		{	// assign by moving _Right
		_Assign_rv(_STD move(_Right));
		return (*this);
		}

	~basic_regex()
		{	// destroy the object
		_Tidy();
		}

	_MyT& operator=(const _MyT& _Right)
		{	// replace with copy of _Right
		return (assign(_Right));
		}

	_MyT& operator=(_In_z_ const _Elem *_Ptr)
		{	// replace with regular expression constructed from _Ptr
		_Reset(_Ptr, _Ptr + _RxTraits::length(_Ptr),
			ECMAScript, random_access_iterator_tag());
		return (*this);
		}

	template<class _STtraits,
		class _STalloc>
		_MyT& operator=(
			const _STD basic_string<_Elem, _STtraits, _STalloc>& _Str)
		{	// replace with regular expression constructed from _Str
		_Reset(_Str.begin(), _Str.end(),
			ECMAScript, random_access_iterator_tag());
		return (*this);
		}

	unsigned mark_count() const
		{	// return number of capture groups
		return (_Rep ? _Rep->_Marks - 1 : 0);
		}

	_MyT& assign(const _MyT& _Right)
		{	// replace with copy of _Right
 #if _ENHANCED_REGEX_VISUALIZER
		_Visualization = _Right._Visualization;
 #endif /* _ENHANCED_REGEX_VISUALIZER */

		_Reset(_Right._Rep);
		return (*this);
		}

	_MyT& assign(_In_z_ const _Elem *_Ptr,
		flag_type _Flags = regex_constants::ECMAScript)
		{	// replace with regular expression constructed from _Ptr
		return (assign(_Ptr, _RxTraits::length(_Ptr), _Flags));
		}

	_MyT& assign(_In_count_(_Count) const _Elem *_Ptr, size_t _Count,
		flag_type _Flags = regex_constants::ECMAScript)
		{	// replace with regular expression constructed from _Ptr, _Count
		_Reset(_Ptr, _Ptr + _Count,
			_Flags, random_access_iterator_tag());
		return (*this);
		}

	template<class _STtraits,
		class _STalloc>
		_MyT& assign(
			const _STD basic_string<_Elem, _STtraits, _STalloc>& _Str,
			flag_type _Flags = regex_constants::ECMAScript)
		{	// replace with regular expression constructed from _Str
		_Reset(_Str.begin(), _Str.end(),
			_Flags, random_access_iterator_tag());
		return (*this);
		}

	template<class _InIt>
		_MyT& assign(_InIt _First, _InIt _Last,
			flag_type _Flags = regex_constants::ECMAScript)
		{	// replace with regular expression constructed from [_First, _Last)
		_DEBUG_RANGE(_First, _Last);
		_Reset(_First, _Last, _Flags, _Iter_cat(_First));
		return (*this);
		}

	flag_type flags() const
		{	// return syntax option flags
		return (_Rep ? _Rep->_Fl : (flag_type)0);
		}

	locale_type imbue(locale_type _Loc)
		{	// clear regular expression and set locale to argument
		_Tidy();
		return (_Traits.imbue(_Loc));
		}

	locale_type getloc() const
		{	// return copy of locale object
		return (_Traits.getloc());
		}

	void swap(_MyT& _Right) _THROW0()
		{	// exchange contents with _Right
		_STD swap(_Rep, _Right._Rep);

 #if _ENHANCED_REGEX_VISUALIZER
		_Visualization.swap(_Right._Visualization);
 #endif /* _ENHANCED_REGEX_VISUALIZER */
		}

	_Root_node *_Get() const
		{	// return pointer to root node
		return (_Rep);
		}

	bool _Empty() const
		{
		return (_Rep == 0);
		}

private:
	_Root_node *_Rep;
	_RxTraits _Traits;

 #if _ENHANCED_REGEX_VISUALIZER
	_STD basic_string<_Elem> _Visualization;
 #endif /* _ENHANCED_REGEX_VISUALIZER */

	void _Tidy()
		{	// free all storage
		if (_Rep && --_Rep->_Refs == 0)
			_Destroy_node(_Rep);
		_Rep = 0;
		}

	template<class _InIt>
		void _Reset(_InIt _First, _InIt _Last,
			flag_type _Flags, input_iterator_tag)
		{	// build regular expression from input iterators
		_STD basic_string<_REGEX_VALT(_InIt)> _Str(_First, _Last);

		_Reset(_Str.begin(), _Str.end(),
			_Flags, forward_iterator_tag());
		}

	template<class _FwdIt>
		void _Reset(_FwdIt _First, _FwdIt _Last,
			flag_type _Flags, forward_iterator_tag)
		{	// build regular expression from forward iterators
 #if _ENHANCED_REGEX_VISUALIZER
		_Visualization.assign(_First, _Last);
 #endif /* _ENHANCED_REGEX_VISUALIZER */

		_Parser<_FwdIt, _Elem, _RxTraits>
			_Prs(_Traits, _First, _Last, _Flags);
		_Root_node *_Rx = _Prs._Compile();
		_Reset(_Rx);
		}

	void _Reset(_Root_node *_Rx)
		{	// build regular expression holding root node _Rx
		if (_Rx != 0)
			++_Rx->_Refs;
		_Tidy();
		_Rep = _Rx;
		}
	};

template<class _Elem,
	class _RxTraits>
	void swap(basic_regex<_Elem, _RxTraits>& _Left,
		basic_regex<_Elem, _RxTraits>& _Right) _THROW0()
	{	// exchange contents of _Left with _Right
	_Left.swap(_Right);
	}

template<class _BidIt,
	class _Alloc>
	void swap(match_results<_BidIt, _Alloc>& _Left,
		match_results<_BidIt, _Alloc>& _Right) _THROW0()
	{	// exchange contents of _Left with _Right
	_Left.swap(_Right);
	}

typedef basic_regex<char> regex;
typedef basic_regex<wchar_t> wregex;
typedef match_results<const char *> cmatch;
typedef match_results<const wchar_t *> wcmatch;
typedef match_results<string::const_iterator> smatch;
typedef match_results<wstring::const_iterator> wsmatch;

#define _Isdigit(x) ('0' <= (x) && (x) <= '9')

	// TEMPLATE FUNCTION _Format_default
template<class _BidIt,
	class _Alloc,
	class _InIt,
	class _OutIt> inline
	_OutIt _Format_default(
		const match_results<_BidIt, _Alloc>& _Match,
		_OutIt _Out, _InIt _First, _InIt _Last,
		regex_constants::match_flag_type)
	{	// format with ECMAScript rules
	while (_First !=_Last)
		{	// process one character or escape sequence
		if (*_First != '$')
			*_Out++ = *_First++;
		else if (++_First == _Last)
			;
		else if (*_First == '$')
			{	// replace $$
			*_Out++ = '$';
			++_First;
			}
		else if (*_First == '`')
			{	// replace $`
			_Out = _STD _Copy_impl(_Match.prefix().first,
				_Match.prefix().second, _Out);
			++_First;
			}
		else if (*_First == '\'')
			{	// replace $'
			_Out = _STD _Copy_impl(_Match.suffix().first,
				_Match.suffix().second, _Out);
			++_First;
			}
		else
			{	// replace capture group descriptors
			int n = -1;
			if (*_First == '&')
				{	// replace $&
				n = 0;
				++_First;
				}
			else if (_Isdigit(*_First))
				{	// replace $n, $nn
				n = *_First++ - '0';
				if (_First != _Last && _Isdigit(*_First))
					{	// process second digit
					n *= 10;
					n += *_First++ - '0';
					}
				}
			else
				{	// replace $x
				*_Out++ = '$';
				*_Out++ = *_First++;
				}
			if (0 <= n && n < (int)_Match.size())
				_Out = _STD _Copy_impl(_Match._At(n).first,
					_Match._At(n).second, _Out);
			}
		}
	return (_Out);
	}

	// TEMPLATE FUNCTION _Format_sed
template<class _BidIt,
	class _Alloc,
	class _InIt,
	class _OutIt> inline
	_OutIt _Format_sed(const match_results<_BidIt, _Alloc>& _Match,
		_OutIt _Out, _InIt _First, _InIt _Last,
		regex_constants::match_flag_type)
	{	// format with sed rules
	while (_First != _Last)
		{	// process one character or escape sequence
		if (*_First == '&')
			{	// replace with full match
			_Out = _STD _Copy_impl(_Match._At(0).first,
				_Match._At(0).second, _Out);
			++_First;
			}
		else if (*_First != '\\')
			*_Out++ = *_First++;
		else if (++_First == _Last)
			;
		else if (_Isdigit(*_First))
			{	// replace \n
			int n = *_First++ - '0';
			_Out = _STD _Copy_impl(_Match._At(n).first,
				_Match._At(n).second, _Out);
			}
		else
			*_Out++ = *_First++;
		}
	return (_Out);
	}

#undef _Isdigit

	// TEMPLATE FUNCTION _Regex_match
template<class _BidIt,
	class _Alloc,
	class _Elem,
	class _RxTraits,
	class _It> inline
	bool _Regex_match(_It _First, _It _Last,
		match_results<_BidIt, _Alloc> *_Matches,
		const basic_regex<_Elem, _RxTraits>& _Re,
		regex_constants::match_flag_type _Flgs,
		bool _Full)
	{	// try to match regular expression to target text
	if (_Re._Empty())
		return (false);
	_Matcher<_BidIt, _Elem, _RxTraits, _It> _Mx(_First, _Last,
		_Re._Get(), _Re.mark_count() + 1, _Re.flags(), _Flgs);
	return (_Mx._Match(_Matches, _Full));
	}

	// TEMPLATE FUNCTION regex_match
template<class _BidIt,
	class _Alloc,
	class _Elem,
	class _RxTraits> inline
	bool regex_match(_BidIt _First, _BidIt _Last,
		match_results<_BidIt, _Alloc>& _Matches,
		const basic_regex<_Elem, _RxTraits>& _Re,
		regex_constants::match_flag_type _Flgs =
			regex_constants::match_default)
	{	// try to match regular expression to target text
	return (_Regex_match(_First, _Last,
		&_Matches, _Re, _Flgs, true));
	}

template<class _BidIt,
	class _Elem,
	class _RxTraits> inline
	bool regex_match(_BidIt _First, _BidIt _Last,
		const basic_regex<_Elem, _RxTraits>& _Re,
		regex_constants::match_flag_type _Flgs =
			regex_constants::match_default)
	{	// try to match regular expression to target text
	return (_Regex_match(_First, _Last,
		(match_results<_BidIt>*)0, _Re,
			_Flgs | regex_constants::match_any, true));
	}

template<class _Elem,
	class _RxTraits> inline
	bool regex_match(_In_z_ const _Elem *_Str,
		const basic_regex<_Elem, _RxTraits>& _Re,
		regex_constants::match_flag_type _Flgs =
			regex_constants::match_default)
	{	// try to match regular expression to target text
	const _Elem *_Last = _Str + char_traits<_Elem>::length(_Str);
	return (_Regex_match(_Str, _Last,
		(match_results<const _Elem *> *)0, _Re,
			_Flgs | regex_constants::match_any, true));
	}

template<class _Elem,
	class _Alloc,
	class _RxTraits> inline
	bool regex_match(_In_z_ const _Elem *_Str,
		match_results<const _Elem *, _Alloc>& _Matches,
		const basic_regex<_Elem, _RxTraits>& _Re,
		regex_constants::match_flag_type _Flgs =
			regex_constants::match_default)
	{	// try to match regular expression to target text
	const _Elem *_Last = _Str + char_traits<_Elem>::length(_Str);
	return (_Regex_match(_Str, _Last,
		&_Matches, _Re, _Flgs, true));
	}

template<class _StTraits,
	class _StAlloc,
	class _Elem,
	class _RxTraits> inline
	bool regex_match(
		const _STD basic_string<_Elem, _StTraits, _StAlloc>& _Str,
		match_results<typename _STD basic_string<_Elem, _StTraits, _StAlloc>::
		const_iterator>& _Matches,
		const basic_regex<_Elem, _RxTraits>& _Re,
		regex_constants::match_flag_type _Flgs =
			regex_constants::match_default)
	{	// try to match regular expression to target text
	return (_Regex_match(_Str.begin(), _Str.end(),
		&_Matches, _Re, _Flgs, true));
	}

template<class _StTraits,
	class _StAlloc,
	class _Elem,
	class _RxTraits> inline
	bool regex_match(
		const _STD basic_string<_Elem, _StTraits, _StAlloc>& _Str,
		const basic_regex<_Elem, _RxTraits>& _Re,
		regex_constants::match_flag_type _Flgs =
			regex_constants::match_default)
	{	// try to match regular expression to target text
	typedef typename _STD basic_string<_Elem, _StTraits, _StAlloc>
		::const_iterator _Iter;
	return (_Regex_match(_Str.begin(), _Str.end(),
		(match_results<_Iter>*)0, _Re,
			_Flgs | regex_constants::match_any, true));
	}

	// TEMPLATE FUNCTION _Regex_search
template<class _BidIt,
	class _Alloc,
	class _Elem,
	class _RxTraits,
	class _It> inline
	bool _Regex_search(_It _First, _It _Last,
		match_results<_BidIt, _Alloc> *_Matches,
		const basic_regex<_Elem, _RxTraits>& _Re,
		regex_constants::match_flag_type _Flgs,
		_It _Org)
	{	// search for regular expression match in target text
	_DEBUG_RANGE(_First, _Last);
	if (_Re._Empty())
		return (false);
	bool _Found = false;
	_It _Begin = _First;
	_Matcher<_BidIt, _Elem, _RxTraits, _It> _Mx(_First, _Last,
		_Re._Get(), _Re.mark_count() + 1, _Re.flags(), _Flgs);

	if (_Mx._Match(_Matches, false))
		_Found = true;
	else if (_First == _Last
		|| _Flgs & regex_constants::match_continuous)
		;
	else
		{	// try more on suffixes
		_Mx._Setf(regex_constants::match_prev_avail);
		_Mx._Clearf(regex_constants::_Match_not_null);
		while ((_First = _Mx._Skip(++_First, _Last)) != _Last)
			if (_Mx._Match(_First, _Matches, false))
				{	// foun

⌨️ 快捷键说明

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