Vendor import of libc++ release_38 branch r261369:

https://llvm.org/svn/llvm-project/libcxx/branches/release_38@261369
This commit is contained in:
Dimitry Andric 2016-02-21 13:53:59 +00:00
parent 09a81ed066
commit bb5e33f003
3 changed files with 65 additions and 4 deletions

View File

@ -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
{

View File

@ -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"));

View File

@ -35,6 +35,31 @@ int main()
assert(r == out + 58);
assert(std::string(out) == "prefix: ab, match: cdefghi, suffix: jk, 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[] = "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";
@ -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;