[Patch 2/2] Localization problem in regex

Tim Shen timshen91@gmail.com
Sat Aug 24 06:00:00 GMT 2013


On Sat, Aug 24, 2013 at 1:51 AM, Stefan Schweter <stefan@schweter.it> wrote:
> 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

Fixed.

It's not fully tested. I just run the 28_regex testcases. I'll do a
full test before committing.

Thanks again!

-- 
Tim Shen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: regex-locale.patch
Type: application/octet-stream
Size: 8638 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20130824/5679cc54/attachment.obj>


More information about the Libstdc++ mailing list