summaryrefslogtreecommitdiffstats
path: root/include/regex
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2017-01-26 18:55:51 -0800
committerDan Albert <danalbert@google.com>2017-01-27 11:24:04 -0800
commitff11c1afab6e7a6fb2f1ddd9d7c2a9aa2938ed5b (patch)
tree1bb21021e203a388caff7b896e4bc4e4060fd0db /include/regex
parentc7d5c2a13e331ae22653f3caa0e4ad163e51a4e9 (diff)
parent362353aa2d011cbd5f008661a46beaba734d9296 (diff)
downloadexternal_libcxx-ff11c1afab6e7a6fb2f1ddd9d7c2a9aa2938ed5b.tar.gz
external_libcxx-ff11c1afab6e7a6fb2f1ddd9d7c2a9aa2938ed5b.tar.bz2
external_libcxx-ff11c1afab6e7a6fb2f1ddd9d7c2a9aa2938ed5b.zip
Merge to upstream r293197.
Bug: http://b/34740564 Test: make checkbuild && ./run_tests.py # Tested aosp_sailfish-eng Change-Id: I33320f72d9170548010c023bd28f03578461b5ff
Diffstat (limited to 'include/regex')
-rw-r--r--include/regex183
1 files changed, 114 insertions, 69 deletions
diff --git a/include/regex b/include/regex
index 3a109aa4e..2b4c5aaab 100644
--- a/include/regex
+++ b/include/regex
@@ -127,6 +127,8 @@ class basic_regex
public:
// types:
typedef charT value_type;
+ typedef traits traits_type;
+ typedef typename traits::string_type string_type;
typedef regex_constants::syntax_option_type flag_type;
typedef typename traits::locale_type locale_type;
@@ -145,7 +147,7 @@ public:
// construct/copy/destroy:
basic_regex();
explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
- basic_regex(const charT* p, size_t len, flag_type f);
+ basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
basic_regex(const basic_regex&);
basic_regex(basic_regex&&) noexcept;
template <class ST, class SA>
@@ -762,7 +764,6 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
#include <memory>
#include <vector>
#include <deque>
-#include <cassert>
#include <__undef_min_max>
@@ -864,7 +865,8 @@ enum match_flag_type
format_sed = 1 << 8,
format_no_copy = 1 << 9,
format_first_only = 1 << 10,
- __no_update_pos = 1 << 11
+ __no_update_pos = 1 << 11,
+ __full_match = 1 << 12
};
inline _LIBCPP_INLINE_VISIBILITY
@@ -957,18 +959,18 @@ public:
};
template <regex_constants::error_type _Ev>
-_LIBCPP_ALWAYS_INLINE
+_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
void __throw_regex_error()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw regex_error(_Ev);
#else
- assert(!"regex_error");
+ _VSTD::abort();
#endif
}
template <class _CharT>
-struct _LIBCPP_TYPE_VIS_ONLY regex_traits
+struct _LIBCPP_TEMPLATE_VIS regex_traits
{
public:
typedef _CharT char_type;
@@ -1291,11 +1293,11 @@ regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
template <class _CharT> class __node;
-template <class _BidirectionalIterator> class _LIBCPP_TYPE_VIS_ONLY sub_match;
+template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match;
template <class _BidirectionalIterator,
class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
-class _LIBCPP_TYPE_VIS_ONLY match_results;
+class _LIBCPP_TEMPLATE_VIS match_results;
template <class _CharT>
struct __state
@@ -2476,11 +2478,13 @@ __exit:
template <class _CharT, class _Traits> class __lookahead;
template <class _CharT, class _Traits = regex_traits<_CharT> >
-class _LIBCPP_TYPE_VIS_ONLY basic_regex
+class _LIBCPP_TEMPLATE_VIS basic_regex
{
public:
// types:
typedef _CharT value_type;
+ typedef _Traits traits_type;
+ typedef typename _Traits::string_type string_type;
typedef regex_constants::syntax_option_type flag_type;
typedef typename _Traits::locale_type locale_type;
@@ -2521,7 +2525,7 @@ public:
__end_(0)
{__parse(__p, __p + __traits_.length(__p));}
_LIBCPP_INLINE_VISIBILITY
- basic_regex(const value_type* __p, size_t __len, flag_type __f)
+ basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
: __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
__end_(0)
{__parse(__p, __p + __len);}
@@ -2987,10 +2991,12 @@ __lookahead<_CharT, _Traits>::__exec(__state& __s) const
{
match_results<const _CharT*> __m;
__m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
- bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
- __m,
- __s.__flags_ | regex_constants::match_continuous,
- __s.__at_first_ && __s.__current_ == __s.__first_);
+ bool __matched = __exp_.__match_at_start_ecma(
+ __s.__current_, __s.__last_,
+ __m,
+ (__s.__flags_ | regex_constants::match_continuous) &
+ ~regex_constants::__full_match,
+ __s.__at_first_ && __s.__current_ == __s.__first_);
if (__matched != __invert_)
{
__s.__do_ = __state::__accept_but_not_consume;
@@ -4314,7 +4320,8 @@ basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
else if ('1' <= *__first && *__first <= '9')
{
unsigned __v = *__first - '0';
- for (++__first; '0' <= *__first && *__first <= '9'; ++__first)
+ for (++__first;
+ __first != __last && '0' <= *__first && *__first <= '9'; ++__first)
__v = 10 * __v + *__first - '0';
if (__v > mark_count())
__throw_regex_error<regex_constants::error_backref>();
@@ -4764,7 +4771,7 @@ typedef basic_regex<wchar_t> wregex;
// sub_match
template <class _BidirectionalIterator>
-class _LIBCPP_TYPE_VIS_ONLY sub_match
+class _LIBCPP_TEMPLATE_VIS sub_match
: public pair<_BidirectionalIterator, _BidirectionalIterator>
{
public:
@@ -5187,7 +5194,7 @@ operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
}
template <class _BidirectionalIterator, class _Allocator>
-class _LIBCPP_TYPE_VIS_ONLY match_results
+class _LIBCPP_TEMPLATE_VIS match_results
{
public:
typedef _Allocator allocator_type;
@@ -5261,15 +5268,15 @@ public:
// format:
template <class _OutputIter>
_OutputIter
- format(_OutputIter __out, const char_type* __fmt_first,
+ format(_OutputIter __output, const char_type* __fmt_first,
const char_type* __fmt_last,
regex_constants::match_flag_type __flags = regex_constants::format_default) const;
template <class _OutputIter, class _ST, class _SA>
_LIBCPP_INLINE_VISIBILITY
_OutputIter
- format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
+ format(_OutputIter __output, const basic_string<char_type, _ST, _SA>& __fmt,
regex_constants::match_flag_type __flags = regex_constants::format_default) const
- {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
+ {return format(__output, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
template <class _ST, class _SA>
_LIBCPP_INLINE_VISIBILITY
basic_string<char_type, _ST, _SA>
@@ -5381,7 +5388,7 @@ match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
template <class _BidirectionalIterator, class _Allocator>
template <class _OutputIter>
_OutputIter
-match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
+match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output,
const char_type* __fmt_first, const char_type* __fmt_last,
regex_constants::match_flag_type __flags) const
{
@@ -5390,27 +5397,27 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
for (; __fmt_first != __fmt_last; ++__fmt_first)
{
if (*__fmt_first == '&')
- __out = _VSTD::copy(__matches_[0].first, __matches_[0].second,
- __out);
+ __output = _VSTD::copy(__matches_[0].first, __matches_[0].second,
+ __output);
else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
{
++__fmt_first;
if ('0' <= *__fmt_first && *__fmt_first <= '9')
{
size_t __i = *__fmt_first - '0';
- __out = _VSTD::copy((*this)[__i].first,
- (*this)[__i].second, __out);
+ __output = _VSTD::copy((*this)[__i].first,
+ (*this)[__i].second, __output);
}
else
{
- *__out = *__fmt_first;
- ++__out;
+ *__output = *__fmt_first;
+ ++__output;
}
}
else
{
- *__out = *__fmt_first;
- ++__out;
+ *__output = *__fmt_first;
+ ++__output;
}
}
}
@@ -5423,21 +5430,21 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
switch (__fmt_first[1])
{
case '$':
- *__out = *++__fmt_first;
- ++__out;
+ *__output = *++__fmt_first;
+ ++__output;
break;
case '&':
++__fmt_first;
- __out = _VSTD::copy(__matches_[0].first, __matches_[0].second,
- __out);
+ __output = _VSTD::copy(__matches_[0].first, __matches_[0].second,
+ __output);
break;
case '`':
++__fmt_first;
- __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out);
+ __output = _VSTD::copy(__prefix_.first, __prefix_.second, __output);
break;
case '\'':
++__fmt_first;
- __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out);
+ __output = _VSTD::copy(__suffix_.first, __suffix_.second, __output);
break;
default:
if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
@@ -5450,25 +5457,25 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
++__fmt_first;
__i = 10 * __i + *__fmt_first - '0';
}
- __out = _VSTD::copy((*this)[__i].first,
- (*this)[__i].second, __out);
+ __output = _VSTD::copy((*this)[__i].first,
+ (*this)[__i].second, __output);
}
else
{
- *__out = *__fmt_first;
- ++__out;
+ *__output = *__fmt_first;
+ ++__output;
}
break;
}
}
else
{
- *__out = *__fmt_first;
- ++__out;
+ *__output = *__fmt_first;
+ ++__output;
}
}
}
- return __out;
+ return __output;
}
template <class _BidirectionalIterator, class _Allocator>
@@ -5558,6 +5565,18 @@ basic_regex<_CharT, _Traits>::__match_at_start_ecma(
switch (__s.__do_)
{
case __state::__end_state:
+ if ((__flags & regex_constants::match_not_null) &&
+ __s.__current_ == __first)
+ {
+ __states.pop_back();
+ break;
+ }
+ if ((__flags & regex_constants::__full_match) &&
+ __s.__current_ != __last)
+ {
+ __states.pop_back();
+ break;
+ }
__m.__matches_[0].first = __first;
__m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
__m.__matches_[0].matched = true;
@@ -5621,6 +5640,18 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
switch (__s.__do_)
{
case __state::__end_state:
+ if ((__flags & regex_constants::match_not_null) &&
+ __s.__current_ == __first)
+ {
+ __states.pop_back();
+ break;
+ }
+ if ((__flags & regex_constants::__full_match) &&
+ __s.__current_ != __last)
+ {
+ __states.pop_back();
+ break;
+ }
if (!__matched || __highest_j < __s.__current_ - __s.__first_)
__highest_j = __s.__current_ - __s.__first_;
__matched = true;
@@ -5706,6 +5737,18 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
switch (__s.__do_)
{
case __state::__end_state:
+ if ((__flags & regex_constants::match_not_null) &&
+ __s.__current_ == __first)
+ {
+ __states.pop_back();
+ break;
+ }
+ if ((__flags & regex_constants::__full_match) &&
+ __s.__current_ != __last)
+ {
+ __states.pop_back();
+ break;
+ }
if (!__matched || __highest_j < __s.__current_ - __s.__first_)
{
__highest_j = __s.__current_ - __s.__first_;
@@ -5936,8 +5979,10 @@ regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
- bool __r = _VSTD::regex_search(__first, __last, __m, __e,
- __flags | regex_constants::match_continuous);
+ bool __r = _VSTD::regex_search(
+ __first, __last, __m, __e,
+ __flags | regex_constants::match_continuous |
+ regex_constants::__full_match);
if (__r)
{
__r = !__m.suffix().matched;
@@ -6013,7 +6058,7 @@ regex_match(const basic_string<_CharT, _ST, _SA>& __s,
template <class _BidirectionalIterator,
class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
class _Traits = regex_traits<_CharT> >
-class _LIBCPP_TYPE_VIS_ONLY regex_iterator
+class _LIBCPP_TEMPLATE_VIS regex_iterator
{
public:
typedef basic_regex<_CharT, _Traits> regex_type;
@@ -6132,7 +6177,7 @@ typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
template <class _BidirectionalIterator,
class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
class _Traits = regex_traits<_CharT> >
-class _LIBCPP_TYPE_VIS_ONLY regex_token_iterator
+class _LIBCPP_TEMPLATE_VIS regex_token_iterator
{
public:
typedef basic_regex<_CharT, _Traits> regex_type;
@@ -6148,7 +6193,7 @@ private:
_Position __position_;
const value_type* __result_;
value_type __suffix_;
- ptrdiff_t _N_;
+ ptrdiff_t __n_;
vector<int> __subs_;
public:
@@ -6231,10 +6276,10 @@ public:
private:
void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
void __establish_result () {
- if (__subs_[_N_] == -1)
+ if (__subs_[__n_] == -1)
__result_ = &__position_->prefix();
else
- __result_ = &(*__position_)[__subs_[_N_]];
+ __result_ = &(*__position_)[__subs_[__n_]];
}
};
@@ -6243,7 +6288,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
regex_token_iterator()
: __result_(nullptr),
__suffix_(),
- _N_(0)
+ __n_(0)
{
}
@@ -6254,7 +6299,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
{
if (__position_ != _Position())
__establish_result ();
- else if (__subs_[_N_] == -1)
+ else if (__subs_[__n_] == -1)
{
__suffix_.matched = true;
__suffix_.first = __a;
@@ -6271,7 +6316,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
const regex_type& __re, int __submatch,
regex_constants::match_flag_type __m)
: __position_(__a, __b, __re, __m),
- _N_(0),
+ __n_(0),
__subs_(1, __submatch)
{
__init(__a, __b);
@@ -6283,7 +6328,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
const regex_type& __re, const vector<int>& __submatches,
regex_constants::match_flag_type __m)
: __position_(__a, __b, __re, __m),
- _N_(0),
+ __n_(0),
__subs_(__submatches)
{
__init(__a, __b);
@@ -6298,7 +6343,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
initializer_list<int> __submatches,
regex_constants::match_flag_type __m)
: __position_(__a, __b, __re, __m),
- _N_(0),
+ __n_(0),
__subs_(__submatches)
{
__init(__a, __b);
@@ -6314,7 +6359,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
const int (&__submatches)[_Np],
regex_constants::match_flag_type __m)
: __position_(__a, __b, __re, __m),
- _N_(0),
+ __n_(0),
__subs_(__submatches, __submatches + _Np)
{
__init(__a, __b);
@@ -6326,7 +6371,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
: __position_(__x.__position_),
__result_(__x.__result_),
__suffix_(__x.__suffix_),
- _N_(__x._N_),
+ __n_(__x.__n_),
__subs_(__x.__subs_)
{
if (__x.__result_ == &__x.__suffix_)
@@ -6348,7 +6393,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
else
__result_ = __x.__result_;
__suffix_ = __x.__suffix_;
- _N_ = __x._N_;
+ __n_ = __x.__n_;
__subs_ = __x.__subs_;
if ( __result_ != nullptr && __result_ != &__suffix_ )
@@ -6371,7 +6416,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
return false;
if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
return false;
- return __position_ == __x.__position_ && _N_ == __x._N_ &&
+ return __position_ == __x.__position_ && __n_ == __x.__n_ &&
__subs_ == __x.__subs_;
}
@@ -6382,14 +6427,14 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
_Position __prev = __position_;
if (__result_ == &__suffix_)
__result_ = nullptr;
- else if (_N_ + 1 < __subs_.size())
+ else if (static_cast<size_t>(__n_ + 1) < __subs_.size())
{
- ++_N_;
+ ++__n_;
__establish_result();
}
else
{
- _N_ = 0;
+ __n_ = 0;
++__position_;
if (__position_ != _Position())
__establish_result();
@@ -6420,7 +6465,7 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
template <class _OutputIterator, class _BidirectionalIterator,
class _Traits, class _CharT>
_OutputIterator
-regex_replace(_OutputIterator __out,
+regex_replace(_OutputIterator __output,
_BidirectionalIterator __first, _BidirectionalIterator __last,
const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
regex_constants::match_flag_type __flags = regex_constants::match_default)
@@ -6431,7 +6476,7 @@ regex_replace(_OutputIterator __out,
if (__i == __eof)
{
if (!(__flags & regex_constants::format_no_copy))
- __out = _VSTD::copy(__first, __last, __out);
+ __output = _VSTD::copy(__first, __last, __output);
}
else
{
@@ -6439,29 +6484,29 @@ regex_replace(_OutputIterator __out,
for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
{
if (!(__flags & regex_constants::format_no_copy))
- __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out);
- __out = __i->format(__out, __fmt, __fmt + __len, __flags);
+ __output = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output);
+ __output = __i->format(__output, __fmt, __fmt + __len, __flags);
__lm = __i->suffix();
if (__flags & regex_constants::format_first_only)
break;
}
if (!(__flags & regex_constants::format_no_copy))
- __out = _VSTD::copy(__lm.first, __lm.second, __out);
+ __output = _VSTD::copy(__lm.first, __lm.second, __output);
}
- return __out;
+ return __output;
}
template <class _OutputIterator, class _BidirectionalIterator,
class _Traits, class _CharT, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
-regex_replace(_OutputIterator __out,
+regex_replace(_OutputIterator __output,
_BidirectionalIterator __first, _BidirectionalIterator __last,
const basic_regex<_CharT, _Traits>& __e,
const basic_string<_CharT, _ST, _SA>& __fmt,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
- return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
+ return _VSTD::regex_replace(__output, __first, __last, __e, __fmt.c_str(), __flags);
}
template <class _Traits, class _CharT, class _ST, class _SA, class _FST,