This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Localization: example from document page doesn't work for latin characters ?


Jan Pfeifer wrote:

>Silly of me, if the input is UTF-8, then latin characters are multibyte,
>and tolower/toupper will never have the chance to see the whole
>character (it only sees one byte at a time).
>  
>
Uhm, but should work together with 8859-1, for example...

>So I converted the whole program to wchar_t/wstring/wcout. But I get
>garbage on the output. Any ideas why ? I suspect that wcout is not
>converting the wchar_t* to the terminal's utf-8 encoding. But I don't
>know how the dynamics are there.
>  
>
Yes, actually wcout, wcin & co don't use codecvt (from/to UTF-8 or
whatelse external representation) just pass the output down to the C
library wchar I/O functions. This is known and wanted. You have to go
through a filebuf in order for the conversion to happen, either
implicitly (sync_with_stdio(false)), or explicitly, using a filebuf. In
the filebuf you can imbue the locale you prefer, if it's UTF-8
everything will work as you expect, I believe. I suggest having a look
to the directory testsuite/27_io/basic_filebuf/ in the source
distribution, there are many snippets of code exemplifying that. Really,
it's just matter of imbuing and then everything should work immediately.

Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]