Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert between string, u16string & u32string using libstdc++

I found this topic Convert between string, u16string & u32string and the solution (which looks really great) works only using libc++ not libstdc++. Currently libc++ is not usable - it is hard to compile and dont work good on Windows.

Is there any method to convert between these representations using C++11 and libstdc++, which works on all platforms?

I'm especially interested in converting u32_string to string (utf8) and vice versa.

like image 932
Wojciech Danilo Avatar asked Nov 02 '22 23:11

Wojciech Danilo


1 Answers

There is a way portable way in C++11 to do this through the wstring_convert class.

However, it seems that it is not yet implemented libstdc++ (as of gcc 4.8)

The same applies to:

codecvt<char16_t, char, mbstate_t>.
codecvt<char32_t, char, mbstate_t>.
codecvt_utf8.
codecvt_utf16.
codecvt_utf8_utf16.

In fact the header <codecvt> is still not present in the gcc distribution.

like image 66
J. Daniel Garcia Avatar answered Nov 13 '22 14:11

J. Daniel Garcia