aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-02-21 13:53:59 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-02-21 13:53:59 +0000
commitbb5e33f003797b67974a8893f7f2930fc51b8210 (patch)
tree2ef96e4c81fca716906b41bbaef5978394533a07
parent09a81ed06676bfa727cafe139f24ab2c076ecd04 (diff)
downloadsrc-vendor/libc++/libc++-release_380-r262564.tar.gz
src-vendor/libc++/libc++-release_380-r262564.zip
-rw-r--r--include/regex16
-rw-r--r--test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp1
-rw-r--r--test/std/re/re.results/re.results.form/form1.pass.cpp52
3 files changed, 65 insertions, 4 deletions
diff --git a/include/regex b/include/regex
index b9dac4765cdf..1139d8fb2a90 100644
--- a/include/regex
+++ b/include/regex
@@ -976,7 +976,12 @@ public:
typedef locale locale_type;
typedef ctype_base::mask char_class_type;
+#if defined(__mips__) && defined(__GLIBC__)
+ static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15));
+#else
static const char_class_type __regex_word = 0x80;
+#endif
+
private:
locale __loc_;
const ctype<char_type>* __ct_;
@@ -4265,6 +4270,9 @@ basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
if (__first != __last && *__first == '\\')
{
_ForwardIterator __t1 = _VSTD::next(__first);
+ if (__t1 == __last)
+ __throw_regex_error<regex_constants::error_escape>();
+
_ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
if (__t2 != __t1)
__first = __t2;
@@ -5384,8 +5392,8 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
if ('0' <= *__fmt_first && *__fmt_first <= '9')
{
size_t __i = *__fmt_first - '0';
- __out = _VSTD::copy(__matches_[__i].first,
- __matches_[__i].second, __out);
+ __out = _VSTD::copy((*this)[__i].first,
+ (*this)[__i].second, __out);
}
else
{
@@ -5436,8 +5444,8 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
++__fmt_first;
__i = 10 * __i + *__fmt_first - '0';
}
- __out = _VSTD::copy(__matches_[__i].first,
- __matches_[__i].second, __out);
+ __out = _VSTD::copy((*this)[__i].first,
+ (*this)[__i].second, __out);
}
else
{
diff --git a/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp b/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
index 4da4d957a88a..9459cd74ccff 100644
--- a/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
+++ b/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
@@ -33,6 +33,7 @@ int main()
{
assert(error_escape_thrown("[\\a]"));
assert(error_escape_thrown("\\a"));
+ assert(error_escape_thrown("\\"));
assert(error_escape_thrown("[\\e]"));
assert(error_escape_thrown("\\e"));
diff --git a/test/std/re/re.results/re.results.form/form1.pass.cpp b/test/std/re/re.results/re.results.form/form1.pass.cpp
index 9701c60ba77c..5b04c684fef1 100644
--- a/test/std/re/re.results/re.results.form/form1.pass.cpp
+++ b/test/std/re/re.results/re.results.form/form1.pass.cpp
@@ -38,6 +38,31 @@ int main()
{
std::match_results<const char*> m;
const char s[] = "abcdefghijk";
+ assert(std::regex_search(s, m, std::regex("cd((e)fg)hi",
+ std::regex_constants::nosubs)));
+
+ char out[100] = {0};
+ const char fmt[] = "prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2";
+ char* r = m.format(output_iterator<char*>(out),
+ fmt, fmt + std::char_traits<char>::length(fmt)).base();
+ assert(r == out + 54);
+ assert(std::string(out) == "prefix: ab, match: cdefghi, suffix: jk, m[1]: , m[2]: ");
+ }
+ {
+ std::match_results<const char*> m;
+ const char s[] = "abcdefghijk";
+ assert(std::regex_search(s, m, std::regex("cdefghi")));
+
+ char out[100] = {0};
+ const char fmt[] = "prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2";
+ char* r = m.format(output_iterator<char*>(out),
+ fmt, fmt + std::char_traits<char>::length(fmt)).base();
+ assert(r == out + 54);
+ assert(std::string(out) == "prefix: ab, match: cdefghi, suffix: jk, m[1]: , m[2]: ");
+ }
+ {
+ std::match_results<const char*> m;
+ const char s[] = "abcdefghijk";
assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
char out[100] = {0};
@@ -61,6 +86,33 @@ int main()
assert(r == out + 34);
assert(std::string(out) == "match: cdefghi, m[1]: efg, m[2]: e");
}
+ {
+ std::match_results<const char*> m;
+ const char s[] = "abcdefghijk";
+ assert(std::regex_search(s, m, std::regex("cd((e)fg)hi",
+ std::regex_constants::nosubs)));
+
+ char out[100] = {0};
+ const char fmt[] = "match: &, m[1]: \\1, m[2]: \\2";
+ char* r = m.format(output_iterator<char*>(out),
+ fmt, fmt + std::char_traits<char>::length(fmt),
+ std::regex_constants::format_sed).base();
+ assert(r == out + 30);
+ assert(std::string(out) == "match: cdefghi, m[1]: , m[2]: ");
+ }
+ {
+ std::match_results<const char*> m;
+ const char s[] = "abcdefghijk";
+ assert(std::regex_search(s, m, std::regex("cdefghi")));
+
+ char out[100] = {0};
+ const char fmt[] = "match: &, m[1]: \\1, m[2]: \\2";
+ char* r = m.format(output_iterator<char*>(out),
+ fmt, fmt + std::char_traits<char>::length(fmt),
+ std::regex_constants::format_sed).base();
+ assert(r == out + 30);
+ assert(std::string(out) == "match: cdefghi, m[1]: , m[2]: ");
+ }
{
std::match_results<const wchar_t*> m;