This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch 2/2] Localization problem in regex
- From: Stefan Schweter <stefan at schweter dot it>
- To: Tim Shen <timshen91 at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 23 Aug 2013 19:51:31 +0200
- Subject: Re: [Patch 2/2] Localization problem in regex
- References: <CAPrifDnYX-GGKycPD1Zcmfuah3i7dXsObQMWKuOGq8iszPETLA at mail dot gmail dot com>
Am Fri, 23 Aug 2013 17:17:41 +0800
schrieb Tim Shen <timshen91@gmail.com>:
> Inspired by this mail:
> http://gcc.gnu.org/ml/libstdc++/2013-08/msg00131.html
>
> Thanks!
>
>
Hi Tim,
I applied the patch + compiled everything - it's working now! Thanks!
But... I found a problem with .imbue():
int main()
{
std::setlocale(LC_ALL, "");
std::wstring str2 = L"ÃÃÃ";
std::wregex re2;
re2.imbue(std::locale(""));
re2.assign(L"([[:lower:]]+)");
std::wsmatch m2;
std::wsregex_token_iterator end {};
for (std::wsregex_token_iterator p{str2.begin(), str2.end(),
re2, {1}}; p != end; ++p) { std::wcout << *p << std::endl;
}
return 0;
}
Works fine! But when there's no imbue() call, a Segmentation
fault occurs.
int main()
{
std::setlocale(LC_ALL, "");
std::wstring str2 = L"ÃÃÃ";
std::wregex re2;
//re2.imbue(std::locale(""));
re2.assign(L"([[:lower:]]+)");
std::wsmatch m2;
std::wsregex_token_iterator end {};
for (std::wsregex_token_iterator p{str2.begin(), str2.end(),
re2, {1}}; p != end; ++p) { std::wcout << *p << std::endl;
}
return 0;
}
May be it's better to throw an exception here? Thanks in advance,
Stefan