// class template regex -*- C++ -*-
-// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
-/**
- * @defgroup regex Regular Expressions
- * A facility for performing regular expression pattern matching.
- */
- //@{
+ /**
+ * @addtogroup regex
+ * @{
+ */
- // [7.7] Class regex_traits
/**
- * @brief Describes aspects of a regular expression.
+ * @brief Class regex_traits. Describes aspects of a regular expression.
*
* A regular expression traits class that satisfies the requirements of
* section [28.7].
struct regex_traits
{
public:
- typedef _Ch_type char_type;
- typedef std::basic_string<char_type> string_type;
- typedef std::locale locale_type;
- typedef std::ctype_base::mask char_class_type;
+ typedef _Ch_type char_type;
+ typedef std::basic_string<char_type> string_type;
+ typedef std::locale locale_type;
+ typedef std::ctype_base::mask char_class_type;
public:
/**
* @brief Constructs a default traits object.
*/
- regex_traits()
- { }
+ regex_traits() { }
/**
* @brief Gives the length of a C-style string starting at @p __p.
*/
char_type
translate_nocase(char_type __c) const
- {
- using std::ctype;
- using std::use_facet;
- return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
+ {
+ typedef std::ctype<char_type> __ctype_type;
+ const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
+ return __fctyp.tolower(__c);
}
/**
string_type
transform(_Fwd_iter __first, _Fwd_iter __last) const
{
- using std::collate;
- using std::use_facet;
- const collate<_Ch_type>& __c(use_facet<
- collate<_Ch_type> >(_M_locale));
+ typedef std::collate<char_type> __collate_type;
+ const __collate_type& __fclt(use_facet<__collate_type>(_M_locale));
string_type __s(__first, __last);
- return __c.transform(__s.data(), __s.data() + __s.size());
+ return __fclt.transform(__s.data(), __s.data() + __s.size());
}
/**
regex_traits<_Ch_type>::
isctype(_Ch_type __c, char_class_type __f) const
{
- using std::ctype;
- using std::use_facet;
- const ctype<_Ch_type>& __ctype(use_facet<
- ctype<_Ch_type> >(_M_locale));
+ typedef std::ctype<char_type> __ctype_type;
+ const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
- if (__ctype.is(__f, __c))
+ if (__fctyp.is(__f, __c))
return true;
// special case of underscore in [[:w:]]
- if (__c == __ctype.widen('_'))
+ if (__c == __fctyp.widen('_'))
{
const char __wb[] = "w";
char_class_type __wt = this->lookup_classname(__wb,
}
// special case of [[:space:]] in [[:blank:]]
- if (__ctype.is(std::ctype_base::space, __c))
+ if (__fctyp.is(std::ctype_base::space, __c))
{
const char __bb[] = "blank";
char_class_type __bt = this->lookup_classname(__bb,
regex_traits<_Ch_type>::
value(_Ch_type __ch, int __radix) const
{
- std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
+ std::basic_istringstream<char_type> __is(string_type(1, __ch));
int __v;
if (__radix == 8)
__is >> std::oct;
* std [28.8.1](1)
*/
//@{
- static constexpr regex_constants::syntax_option_type icase
- = regex_constants::icase;
- static constexpr regex_constants::syntax_option_type nosubs
- = regex_constants::nosubs;
- static constexpr regex_constants::syntax_option_type optimize
- = regex_constants::optimize;
- static constexpr regex_constants::syntax_option_type collate
- = regex_constants::collate;
- static constexpr regex_constants::syntax_option_type ECMAScript
- = regex_constants::ECMAScript;
- static constexpr regex_constants::syntax_option_type basic
- = regex_constants::basic;
- static constexpr regex_constants::syntax_option_type extended
- = regex_constants::extended;
- static constexpr regex_constants::syntax_option_type awk
- = regex_constants::awk;
- static constexpr regex_constants::syntax_option_type grep
- = regex_constants::grep;
- static constexpr regex_constants::syntax_option_type egrep
- = regex_constants::egrep;
+ static constexpr flag_type icase = regex_constants::icase;
+ static constexpr flag_type nosubs = regex_constants::nosubs;
+ static constexpr flag_type optimize = regex_constants::optimize;
+ static constexpr flag_type collate = regex_constants::collate;
+ static constexpr flag_type ECMAScript = regex_constants::ECMAScript;
+ static constexpr flag_type basic = regex_constants::basic;
+ static constexpr flag_type extended = regex_constants::extended;
+ static constexpr flag_type awk = regex_constants::awk;
+ static constexpr flag_type grep = regex_constants::grep;
+ static constexpr flag_type egrep = regex_constants::egrep;
//@}
// [7.8.2] construct/copy/destroy
* character sequence.
*/
basic_regex()
- : _M_flags(regex_constants::ECMAScript),
- _M_automaton(__regex::__compile<const _Ch_type*, _Rx_traits>(0, 0,
+ : _M_flags(ECMAScript),
+ _M_automaton(__detail::__compile<const _Ch_type*, _Rx_traits>(0, 0,
_M_traits, _M_flags))
{ }
* @throws regex_error if @p __p is not a valid regular expression.
*/
explicit
- basic_regex(const _Ch_type* __p,
- flag_type __f = regex_constants::ECMAScript)
+ basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript)
: _M_flags(__f),
- _M_automaton(__regex::__compile(__p, __p + _Rx_traits::length(__p),
+ _M_automaton(__detail::__compile(__p, __p + _Rx_traits::length(__p),
_M_traits, _M_flags))
{ }
*/
basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
: _M_flags(__f),
- _M_automaton(__regex::__compile(__p, __p + __len, _M_traits, _M_flags))
+ _M_automaton(__detail::__compile(__p, __p + __len, _M_traits, _M_flags))
{ }
/**
*/
template<typename _Ch_traits, typename _Ch_alloc>
explicit
- basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
- _Ch_alloc>& __s,
- flag_type __f = regex_constants::ECMAScript)
+ basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
+ _Ch_alloc>& __s,
+ flag_type __f = ECMAScript)
: _M_flags(__f),
- _M_automaton(__regex::__compile(__s.begin(), __s.end(),
+ _M_automaton(__detail::__compile(__s.begin(), __s.end(),
_M_traits, _M_flags))
{ }
*/
template<typename _InputIterator>
basic_regex(_InputIterator __first, _InputIterator __last,
- flag_type __f = regex_constants::ECMAScript)
+ flag_type __f = ECMAScript)
: _M_flags(__f),
- _M_automaton(__regex::__compile(__first, __last, _M_traits, _M_flags))
+ _M_automaton(__detail::__compile(__first, __last, _M_traits, _M_flags))
{ }
/**
* @throws regex_error if @p __l is not a valid regular expression.
*/
basic_regex(initializer_list<_Ch_type> __l,
- flag_type __f = regex_constants::ECMAScript)
+ flag_type __f = ECMAScript)
: _M_flags(__f),
- _M_automaton(__regex::__compile(__l.begin(), __l.end(),
+ _M_automaton(__detail::__compile(__l.begin(), __l.end(),
_M_traits, _M_flags))
{ }
*
* @param __s A pointer to a string containing a regular expression.
*/
- template<typename _Ch_typeraits, typename _Allocator>
+ template<typename _Ch_typeraits, typename _Alloc>
basic_regex&
- operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
+ operator=(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s)
{ return this->assign(__s, flags()); }
// [7.8.3] assign
* regex_error is thrown, *this remains unchanged.
*/
basic_regex&
- assign(const _Ch_type* __p,
- flag_type __flags = regex_constants::ECMAScript)
+ assign(const _Ch_type* __p, flag_type __flags = ECMAScript)
{ return this->assign(string_type(__p), __flags); }
/**
* expression pattern interpreted according to @p __flags. If
* regex_error is thrown, *this remains unchanged.
*/
- template<typename _Ch_typeraits, typename _Allocator>
+ template<typename _Ch_typeraits, typename _Alloc>
basic_regex&
- assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
- flag_type __flags = regex_constants::ECMAScript)
+ assign(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s,
+ flag_type __flags = ECMAScript)
{
basic_regex __tmp(__s, __flags);
this->swap(__tmp);
template<typename _InputIterator>
basic_regex&
assign(_InputIterator __first, _InputIterator __last,
- flag_type __flags = regex_constants::ECMAScript)
+ flag_type __flags = ECMAScript)
{ return this->assign(string_type(__first, __last), __flags); }
/**
* unchanged.
*/
basic_regex&
- assign(initializer_list<_Ch_type> __l,
- flag_type __flags = regex_constants::ECMAScript)
+ assign(initializer_list<_Ch_type> __l, flag_type __flags = ECMAScript)
{ return this->assign(__l.begin(), __l.end(), __flags); }
// [7.8.4] const operations
void
swap(basic_regex& __rhs)
{
- std::swap(_M_flags, __rhs._M_flags);
- std::swap(_M_traits, __rhs._M_traits);
+ std::swap(_M_flags, __rhs._M_flags);
+ std::swap(_M_traits, __rhs._M_traits);
std::swap(_M_automaton, __rhs._M_automaton);
}
{ _M_automaton->_M_dot(__ostr); }
#endif
- const __regex::_AutomatonPtr&
+ const __detail::_AutomatonPtr&
_M_get_automaton() const
{ return _M_automaton; }
protected:
flag_type _M_flags;
_Rx_traits _M_traits;
- __regex::_AutomatonPtr _M_automaton;
+ __detail::_AutomatonPtr _M_automaton;
};
/** @brief Standard regular expressions. */
typedef basic_regex<char> regex;
+
#ifdef _GLIBCXX_USE_WCHAR_T
/** @brief Standard wide-character regular expressions. */
typedef basic_regex<wchar_t> wregex;
template<typename _BiIter>
class sub_match : public std::pair<_BiIter, _BiIter>
{
+ typedef iterator_traits<_BiIter> __iter_traits;
+
public:
- typedef typename iterator_traits<_BiIter>::value_type value_type;
- typedef typename iterator_traits<_BiIter>::difference_type
- difference_type;
- typedef _BiIter iterator;
- typedef std::basic_string<value_type> string_type;
+ typedef typename __iter_traits::value_type value_type;
+ typedef typename __iter_traits::difference_type difference_type;
+ typedef _BiIter iterator;
+ typedef std::basic_string<value_type> string_type;
- public:
bool matched;
constexpr sub_match() : matched() { }
/** @brief Standard regex submatch over a C-style null-terminated string. */
typedef sub_match<const char*> csub_match;
+
/** @brief Standard regex submatch over a standard string. */
typedef sub_match<string::const_iterator> ssub_match;
+
#ifdef _GLIBCXX_USE_WCHAR_T
/** @brief Regex submatch over a C-style null-terminated wide string. */
typedef sub_match<const wchar_t*> wcsub_match;
+
/** @brief Regex submatch over a standard wide string. */
typedef sub_match<wstring::const_iterator> wssub_match;
#endif
*/
template<typename _BiIter>
inline bool
- operator==(const sub_match<_BiIter>& __lhs,
- const sub_match<_BiIter>& __rhs)
+ operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
{ return __lhs.compare(__rhs) == 0; }
/**
*/
template<typename _BiIter>
inline bool
- operator!=(const sub_match<_BiIter>& __lhs,
- const sub_match<_BiIter>& __rhs)
+ operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
{ return __lhs.compare(__rhs) != 0; }
/**
*/
template<typename _BiIter>
inline bool
- operator<(const sub_match<_BiIter>& __lhs,
- const sub_match<_BiIter>& __rhs)
+ operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
{ return __lhs.compare(__rhs) < 0; }
/**
*/
template<typename _BiIter>
inline bool
- operator<=(const sub_match<_BiIter>& __lhs,
- const sub_match<_BiIter>& __rhs)
+ operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
{ return __lhs.compare(__rhs) <= 0; }
/**
*/
template<typename _BiIter>
inline bool
- operator>=(const sub_match<_BiIter>& __lhs,
- const sub_match<_BiIter>& __rhs)
+ operator>=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
{ return __lhs.compare(__rhs) >= 0; }
/**
*/
template<typename _BiIter>
inline bool
- operator>(const sub_match<_BiIter>& __lhs,
- const sub_match<_BiIter>& __rhs)
+ operator>(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
{ return __lhs.compare(__rhs) > 0; }
+ // Alias for sub_match'd string.
+ template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
+ using __sub_match_string = basic_string<
+ typename iterator_traits<_Bi_iter>::value_type,
+ _Ch_traits, _Ch_alloc>;
+
/**
* @brief Tests the equivalence of a string and a regular expression
* submatch.
*/
template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
inline bool
- operator==(const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __lhs,
+ operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
const sub_match<_Bi_iter>& __rhs)
{ return __rhs.compare(__lhs.c_str()) == 0; }
*/
template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
inline bool
- operator!=(const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
+ operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
+ const sub_match<_Bi_iter>& __rhs)
{ return !(__lhs == __rhs); }
/**
*/
template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
inline bool
- operator<(const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
+ operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
+ const sub_match<_Bi_iter>& __rhs)
{ return __rhs.compare(__lhs.c_str()) > 0; }
/**
*/
template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
inline bool
- operator>(const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
+ operator>(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
+ const sub_match<_Bi_iter>& __rhs)
{ return __rhs < __lhs; }
/**
*/
template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
inline bool
- operator>=(const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
+ operator>=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
+ const sub_match<_Bi_iter>& __rhs)
{ return !(__lhs < __rhs); }
/**
*/
template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
inline bool
- operator<=(const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
+ operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
+ const sub_match<_Bi_iter>& __rhs)
{ return !(__rhs < __lhs); }
/**
template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
inline bool
operator==(const sub_match<_Bi_iter>& __lhs,
- const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __rhs)
+ const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
{ return __lhs.compare(__rhs.c_str()) == 0; }
/**
template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
inline bool
operator!=(const sub_match<_Bi_iter>& __lhs,
- const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __rhs)
+ const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
{ return !(__lhs == __rhs); }
/**
template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
inline bool
operator<(const sub_match<_Bi_iter>& __lhs,
- const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __rhs)
+ const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
{ return __lhs.compare(__rhs.c_str()) < 0; }
/**
template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
inline bool
operator>(const sub_match<_Bi_iter>& __lhs,
- const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __rhs)
+ const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
{ return __rhs < __lhs; }
/**
template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
inline bool
operator>=(const sub_match<_Bi_iter>& __lhs,
- const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __rhs)
+ const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
{ return !(__lhs < __rhs); }
/**
template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
inline bool
operator<=(const sub_match<_Bi_iter>& __lhs,
- const basic_string<
- typename iterator_traits<_Bi_iter>::value_type,
- _Ch_traits, _Ch_alloc>& __rhs)
+ const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
{ return !(__rhs < __lhs); }
/**
operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
const sub_match<_Bi_iter>& __rhs)
{
- return __rhs.compare(typename sub_match<_Bi_iter>::string_type(1, __lhs))
- == 0;
+ typedef typename sub_match<_Bi_iter>::string_type string_type;
+ return __rhs.compare(string_type(1, __lhs)) == 0;
}
/**
operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
const sub_match<_Bi_iter>& __rhs)
{
- return __rhs.compare(typename sub_match<_Bi_iter>::string_type(1, __lhs))
- > 0;
+ typedef typename sub_match<_Bi_iter>::string_type string_type;
+ return __rhs.compare(string_type(1, __lhs)) > 0;
}
/**
operator==(const sub_match<_Bi_iter>& __lhs,
typename iterator_traits<_Bi_iter>::value_type const& __rhs)
{
- return __lhs.compare(typename sub_match<_Bi_iter>::string_type(1, __rhs))
- == 0;
+ typedef typename sub_match<_Bi_iter>::string_type string_type;
+ return __lhs.compare(string_type(1, __rhs)) == 0;
}
/**
operator<(const sub_match<_Bi_iter>& __lhs,
typename iterator_traits<_Bi_iter>::value_type const& __rhs)
{
- return __lhs.compare(typename sub_match<_Bi_iter>::string_type(1, __rhs))
- < 0;
+ typedef typename sub_match<_Bi_iter>::string_type string_type;
+ return __lhs.compare(string_type(1, __rhs)) < 0;
}
/**
* @nosubgrouping
*/
template<typename _Bi_iter,
- typename _Allocator = allocator<sub_match<_Bi_iter> > >
+ typename _Alloc = allocator<sub_match<_Bi_iter> > >
class match_results
- : private std::vector<sub_match<_Bi_iter>, _Allocator>
+ : private std::vector<sub_match<_Bi_iter>, _Alloc>
{
private:
/*
* [n+1] prefix
* [n+2] suffix
*/
- typedef std::vector<sub_match<_Bi_iter>, _Allocator> _Base_type;
+ typedef std::vector<sub_match<_Bi_iter>, _Alloc> _Base_type;
+ typedef std::iterator_traits<_Bi_iter> __iter_traits;
+ typedef regex_constants::match_flag_type match_flag_type;
public:
/**
* @name 10.? Public Types
*/
//@{
- typedef sub_match<_Bi_iter> value_type;
- typedef const value_type& const_reference;
- typedef const_reference reference;
- typedef typename _Base_type::const_iterator const_iterator;
- typedef const_iterator iterator;
- typedef typename std::iterator_traits<_Bi_iter>::difference_type
- difference_type;
- typedef typename allocator_traits<_Allocator>::size_type
- size_type;
- typedef _Allocator allocator_type;
- typedef typename std::iterator_traits<_Bi_iter>::value_type
- char_type;
- typedef std::basic_string<char_type> string_type;
+ typedef _Alloc allocator_type;
+ typedef sub_match<_Bi_iter> value_type;
+ typedef const value_type& const_reference;
+ typedef const_reference reference;
+ typedef typename _Base_type::const_iterator const_iterator;
+ typedef const_iterator iterator;
+ typedef typename __iter_traits::difference_type difference_type;
+ typedef typename __iter_traits::value_type char_type;
+ typedef typename allocator_traits<_Alloc>::size_type size_type;
+
+
+ typedef std::basic_string<char_type> string_type;
//@}
public:
* @post size() returns 0 and str() returns an empty string.
*/
explicit
- match_results(const _Allocator& __a = _Allocator())
+ match_results(const _Alloc& __a = _Alloc())
: _Base_type(__a)
{ }
_Out_iter
format(_Out_iter __out, const char_type* __fmt_first,
const char_type* __fmt_last,
- regex_constants::match_flag_type __flags
- = regex_constants::format_default) const
+ match_flag_type __flags = regex_constants::format_default) const
{ return __out; }
/**
template<typename _Out_iter, typename _St, typename _Sa>
_Out_iter
format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
- regex_constants::match_flag_type __flags
- = regex_constants::format_default) const
+ match_flag_type __flags = regex_constants::format_default) const
{
return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
__flags);
template<typename _Out_iter, typename _St, typename _Sa>
basic_string<char_type, _St, _Sa>
format(const basic_string<char_type, _St, _Sa>& __fmt,
- regex_constants::match_flag_type __flags
- = regex_constants::format_default) const
+ match_flag_type __flags = regex_constants::format_default) const
{
basic_string<char_type, _St, _Sa> __result;
format(std::back_inserter(__result), __fmt, __flags);
*/
string_type
format(const char_type* __fmt,
- regex_constants::match_flag_type __flags
- = regex_constants::format_default) const
+ match_flag_type __flags = regex_constants::format_default) const
{
string_type __result;
format(std::back_inserter(__result),
//@}
private:
- friend class __regex::_SpecializedResults<_Bi_iter, _Allocator>;
+ friend class __detail::_SpecializedResults<_Bi_iter, _Alloc>;
};
typedef match_results<const char*> cmatch;
* @returns true if the two objects refer to the same match,
* false otherwise.
*/
- template<typename _Bi_iter, typename _Allocator>
+ template<typename _Bi_iter, typename _Alloc>
inline bool
- operator==(const match_results<_Bi_iter, _Allocator>& __m1,
- const match_results<_Bi_iter, _Allocator>& __m2)
+ operator==(const match_results<_Bi_iter, _Alloc>& __m1,
+ const match_results<_Bi_iter, _Alloc>& __m2)
{
if (__m1.ready() != __m2.ready())
return false;
* @returns true if the two objects do not refer to the same match,
* false otherwise.
*/
- template<typename _Bi_iter, class _Allocator>
+ template<typename _Bi_iter, class _Alloc>
inline bool
- operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
- const match_results<_Bi_iter, _Allocator>& __m2)
+ operator!=(const match_results<_Bi_iter, _Alloc>& __m1,
+ const match_results<_Bi_iter, _Alloc>& __m2)
{ return !(__m1 == __m2); }
// [7.10.6] match_results swap
*
* The contents of the two match_results objects are swapped.
*/
- template<typename _Bi_iter, typename _Allocator>
+ template<typename _Bi_iter, typename _Alloc>
inline void
- swap(match_results<_Bi_iter, _Allocator>& __lhs,
- match_results<_Bi_iter, _Allocator>& __rhs)
+ swap(match_results<_Bi_iter, _Alloc>& __lhs,
+ match_results<_Bi_iter, _Alloc>& __rhs)
{ __lhs.swap(__rhs); }
// [7.11.2] Function template regex_match
*
* @todo Implement this function.
*/
- template<typename _Bi_iter, typename _Allocator,
+ template<typename _Bi_iter, typename _Alloc,
typename _Ch_type, typename _Rx_traits>
bool
regex_match(_Bi_iter __s,
_Bi_iter __e,
- match_results<_Bi_iter, _Allocator>& __m,
+ match_results<_Bi_iter, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re,
regex_constants::match_flag_type __flags
= regex_constants::match_default)
{
- __regex::_AutomatonPtr __a = __re._M_get_automaton();
- __regex::_Automaton::_SizeT __sz = __a->_M_sub_count();
- __regex::_SpecializedCursor<_Bi_iter> __cs(__s, __e);
- __regex::_SpecializedResults<_Bi_iter, _Allocator> __r(__sz, __cs, __m);
- __regex::_Grep_matcher __matcher(__cs, __r, __a, __flags);
+ __detail::_AutomatonPtr __a = __re._M_get_automaton();
+ __detail::_Automaton::_SizeT __sz = __a->_M_sub_count();
+ __detail::_SpecializedCursor<_Bi_iter> __cs(__s, __e);
+ __detail::_SpecializedResults<_Bi_iter, _Alloc> __r(__sz, __cs, __m);
+ __detail::_Grep_matcher __matcher(__cs, __r, __a, __flags);
return __m[0].matched;
}
*
* @throws an exception of type regex_error.
*/
- template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
+ template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
inline bool
regex_match(const _Ch_type* __s,
- match_results<const _Ch_type*, _Allocator>& __m,
+ match_results<const _Ch_type*, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re,
regex_constants::match_flag_type __f
= regex_constants::match_default)
* @throws an exception of type regex_error.
*/
template<typename _Ch_traits, typename _Ch_alloc,
- typename _Allocator, typename _Ch_type, typename _Rx_traits>
+ typename _Alloc, typename _Ch_type, typename _Rx_traits>
inline bool
regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
match_results<typename basic_string<_Ch_type,
- _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
+ _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re,
regex_constants::match_flag_type __flags
= regex_constants::match_default)
*
* @todo Implement this function.
*/
- template<typename _Bi_iter, typename _Allocator,
+ template<typename _Bi_iter, typename _Alloc,
typename _Ch_type, typename _Rx_traits>
inline bool
regex_search(_Bi_iter __first, _Bi_iter __last,
- match_results<_Bi_iter, _Allocator>& __m,
+ match_results<_Bi_iter, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __re,
regex_constants::match_flag_type __flags
= regex_constants::match_default)
*
* @throws an exception of type regex_error.
*/
- template<typename _Ch_type, class _Allocator, class _Rx_traits>
+ template<typename _Ch_type, class _Alloc, class _Rx_traits>
inline bool
regex_search(const _Ch_type* __s,
- match_results<const _Ch_type*, _Allocator>& __m,
+ match_results<const _Ch_type*, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __e,
regex_constants::match_flag_type __f
= regex_constants::match_default)
* @throws an exception of type regex_error.
*/
template<typename _Ch_traits, typename _Ch_alloc,
- typename _Allocator, typename _Ch_type,
+ typename _Alloc, typename _Ch_type,
typename _Rx_traits>
inline bool
regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
match_results<typename basic_string<_Ch_type,
- _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
+ _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
const basic_regex<_Ch_type, _Rx_traits>& __e,
regex_constants::match_flag_type __f
= regex_constants::match_default)
typedef const value_type& reference;
typedef std::forward_iterator_tag iterator_category;
- public:
/**
* @brief Provides a singular iterator, useful for indicating
* one-past-the-end of a range.
/** @brief Token iterator for C-style NULL-terminated strings. */
typedef regex_token_iterator<const char*> cregex_token_iterator;
+
/** @brief Token iterator for standard strings. */
typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
+
#ifdef _GLIBCXX_USE_WCHAR_T
/** @brief Token iterator for C-style NULL-terminated wide strings. */
typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
+
/** @brief Token iterator for standard wide-character strings. */
typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
#endif
// class template regex -*- C++ -*-
-// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
namespace std _GLIBCXX_VISIBILITY(default)
{
+/**
+ * @defgroup regex Regular Expressions
+ *
+ * A facility for performing regular expression pattern matching.
+ * @{
+ */
+
/**
* @namespace std::regex_constants
* @brief ISO C++-0x entities sub namespace for regex.
* Specifies that the matching of regular expressions against a character
* sequence shall be performed without regard to case.
*/
- static constexpr syntax_option_type icase = 1 << _S_icase;
+ constexpr syntax_option_type icase = 1 << _S_icase;
/**
* Specifies that when a regular expression is matched against a character
* container sequence, no sub-expression matches are to be stored in the
* supplied match_results structure.
*/
- static constexpr syntax_option_type nosubs = 1 << _S_nosubs;
+ constexpr syntax_option_type nosubs = 1 << _S_nosubs;
/**
* Specifies that the regular expression engine should pay more attention to
* speed with which regular expression objects are constructed. Otherwise
* it has no detectable effect on the program output.
*/
- static constexpr syntax_option_type optimize = 1 << _S_optimize;
+ constexpr syntax_option_type optimize = 1 << _S_optimize;
/**
* Specifies that character ranges of the form [a-b] should be locale
* sensitive.
*/
- static constexpr syntax_option_type collate = 1 << _S_collate;
+ constexpr syntax_option_type collate = 1 << _S_collate;
/**
* Specifies that the grammar recognized by the regular expression engine is
* in the PERL scripting language but extended with elements found in the
* POSIX regular expression grammar.
*/
- static constexpr syntax_option_type ECMAScript = 1 << _S_ECMAScript;
+ constexpr syntax_option_type ECMAScript = 1 << _S_ECMAScript;
/**
* Specifies that the grammar recognized by the regular expression engine is
* Headers, Section 9, Regular Expressions [IEEE, Information Technology --
* Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
*/
- static constexpr syntax_option_type basic = 1 << _S_basic;
+ constexpr syntax_option_type basic = 1 << _S_basic;
/**
* Specifies that the grammar recognized by the regular expression engine is
* Portable Operating System Interface (POSIX), Base Definitions and Headers,
* Section 9, Regular Expressions.
*/
- static constexpr syntax_option_type extended = 1 << _S_extended;
+ constexpr syntax_option_type extended = 1 << _S_extended;
/**
* Specifies that the grammar recognized by the regular expression engine is
* \\\\, \\a, \\b, \\f, \\n, \\r, \\t , \\v, \\', ',
* and \\ddd (where ddd is one, two, or three octal digits).
*/
- static constexpr syntax_option_type awk = 1 << _S_awk;
+ constexpr syntax_option_type awk = 1 << _S_awk;
/**
* Specifies that the grammar recognized by the regular expression engine is
* identical to syntax_option_type basic, except that newlines are treated
* as whitespace.
*/
- static constexpr syntax_option_type grep = 1 << _S_grep;
+ constexpr syntax_option_type grep = 1 << _S_grep;
/**
* Specifies that the grammar recognized by the regular expression engine is
* IEEE Std 1003.1-2001. This option is identical to syntax_option_type
* extended, except that newlines are treated as whitespace.
*/
- static constexpr syntax_option_type egrep = 1 << _S_egrep;
+ constexpr syntax_option_type egrep = 1 << _S_egrep;
//@}
/**
* The default matching rules.
*/
- static constexpr match_flag_type match_default = 0;
+ constexpr match_flag_type match_default = 0;
/**
* The first character in the sequence [first, last) is treated as though it
* is not at the beginning of a line, so the character (^) in the regular
* expression shall not match [first, first).
*/
- static constexpr match_flag_type match_not_bol = 1 << _S_not_bol;
+ constexpr match_flag_type match_not_bol = 1 << _S_not_bol;
/**
* The last character in the sequence [first, last) is treated as though it
* is not at the end of a line, so the character ($) in the regular
* expression shall not match [last, last).
*/
- static constexpr match_flag_type match_not_eol = 1 << _S_not_eol;
+ constexpr match_flag_type match_not_eol = 1 << _S_not_eol;
/**
* The expression \\b is not matched against the sub-sequence
* [first,first).
*/
- static constexpr match_flag_type match_not_bow = 1 << _S_not_bow;
+ constexpr match_flag_type match_not_bow = 1 << _S_not_bow;
/**
* The expression \\b should not be matched against the sub-sequence
* [last,last).
*/
- static constexpr match_flag_type match_not_eow = 1 << _S_not_eow;
+ constexpr match_flag_type match_not_eow = 1 << _S_not_eow;
/**
* If more than one match is possible then any match is an acceptable
* result.
*/
- static constexpr match_flag_type match_any = 1 << _S_any;
+ constexpr match_flag_type match_any = 1 << _S_any;
/**
* The expression does not match an empty sequence.
*/
- static constexpr match_flag_type match_not_null = 1 << _S_not_null;
+ constexpr match_flag_type match_not_null = 1 << _S_not_null;
/**
* The expression only matches a sub-sequence that begins at first .
*/
- static constexpr match_flag_type match_continuous = 1 << _S_continuous;
+ constexpr match_flag_type match_continuous = 1 << _S_continuous;
/**
* --first is a valid iterator position. When this flag is set then the
* flags match_not_bol and match_not_bow are ignored by the regular
* expression algorithms 28.11 and iterators 28.12.
*/
- static constexpr match_flag_type match_prev_avail = 1 << _S_prev_avail;
+ constexpr match_flag_type match_prev_avail = 1 << _S_prev_avail;
/**
* When a regular expression match is to be replaced by a new string, the
* undefined, use the empty string instead. If
* nn > match_results::size(), the result is implementation-defined.
*/
- static constexpr match_flag_type format_default = 0;
+ constexpr match_flag_type format_default = 0;
/**
* When a regular expression match is to be replaced by a new string, the
* in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
* Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
*/
- static constexpr match_flag_type format_sed = 1 << _S_sed;
+ constexpr match_flag_type format_sed = 1 << _S_sed;
/**
* During a search and replace operation, sections of the character
* container sequence being searched that do not match the regular
* expression shall not be copied to the output string.
*/
- static constexpr match_flag_type format_no_copy = 1 << _S_no_copy;
+ constexpr match_flag_type format_no_copy = 1 << _S_no_copy;
/**
* When specified during a search and replace operation, only the first
* occurrence of the regular expression shall be replaced.
*/
- static constexpr match_flag_type format_first_only = 1 << _S_first_only;
+ constexpr match_flag_type format_first_only = 1 << _S_first_only;
//@}
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace regex_constants
-} // namespace
+
+/* @} */ // group regex
+} // namespace std