re PR libstdc++/64649 (regex_traits::lookup_classname() only works with random access iterators)

PR libstdc++/64649
	* include/bits/regex.tcc (regex_traits<>::lookup_collatename,
	regex_traits<>::lookup_classname): Correctly narrow input chars.
	* testsuite/28_regex/traits/wchar_t/user_defined.cc: New testcase.

From-SVN: r219986
This commit is contained in:
Tim Shen 2015-01-22 05:02:38 +00:00 committed by Tim Shen
parent fa3340ec8f
commit 77033d2668
3 changed files with 37 additions and 3 deletions

View File

@ -1,3 +1,10 @@
2015-01-22 Tim Shen <timshen@google.com>
PR libstdc++/64649
* include/bits/regex.tcc (regex_traits<>::lookup_collatename,
regex_traits<>::lookup_classname): Correctly narrow input chars.
* testsuite/28_regex/traits/wchar_t/user_defined.cc: New testcase.
2015-01-21 Jonathan Wakely <jwakely@redhat.com>
* config/abi/pre/gnu.ver: Use [jmy] for size_t parameters.

View File

@ -269,7 +269,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
"DEL",
};
string __s(__first, __last);
string __s;
for (; __first != __last; ++__first)
__s += __fctyp.narrow(*__first, 0);
for (const auto& __it : __collatenames)
if (__s == __it)
return string_type(1, __fctyp.widen(
@ -311,8 +314,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
};
string __s;
for (auto __cur = __first; __cur != __last; ++__cur)
__s += __fctyp.narrow(__fctyp.tolower(*__cur), '?');
for (; __first != __last; ++__first)
__s += __fctyp.narrow(__fctyp.tolower(*__first), 0);
for (const auto& __it : __classnames)
if (__s == __it.first)

View File

@ -55,8 +55,32 @@ test01()
VERIFY(!regex_match(L"\u2029", re));
}
struct MyCtype : std::ctype<wchar_t>
{
char
do_narrow(wchar_t c, char dflt) const override
{
if (c >= 256)
return dflt;
return ((char)c)+1;
}
};
void
test02()
{
std::locale loc(std::locale(), new MyCtype);
std::regex_traits<wchar_t> traits;
traits.imbue(loc);
wchar_t wch = L'p';
VERIFY(traits.lookup_collatename(&wch, &wch+1) == L"q");
std::wstring ws = L"chfhs"; // chars of "digit" shifted by 1.
VERIFY(traits.lookup_classname(ws.begin(), ws.end()) != 0);
}
int main()
{
test01();
test02();
return 0;
}