Understanding implementation details of wcout and wchar_t vs char32_t
Patrick Horgan
phorgan1@yahoo.com
Sun Feb 28 07:40:00 GMT 2010
I suspect that this is off topic for the libstdc++
mailing list, but also suspect that the only people
that point me straight are some of the people on this
list. If you can send me towards anywhere more
appropriate I'd be grateful.
I want to learn how to write code that can store and
deal with any code point, so unicode 5.2 is a no
brainer. I've written a code conversion facet to
wchar_t to char that converts between utf-8 external
and wchar_t unicode internally. It's tested and works
fine, but should it instead use char32_t for its
internal representation?
As I've read the specs (both C and C++ since C++
doesn't specify much about stdout/in/err), I have been
surprised at how much is either listed as
implementation defined or not specified at all, and
maybe I some of what I need to know is where to read
about gcc libstdc++ implementation in particular? I'd
love if things where well enough specified so that I
could write portable code. If you could help this boy
learn to fish, I'd be grateful.
I've written my testing software using all wchar_t.
Below is a sample of my confusion, but what I'd love is
a pointer to somewhere where I can read about how
libstdc++ implements this, and pointers to
understanding how much might depend on libc. In
particular I'd like to understand the difference
between L"" vs U"" and wchar_t vs char32_t. Which
should I use for unicode literals? What do wide
character streams understand? wchar_t corresponds to
L"" right? And char32_t corresponds to U"", and wcout
is specialized for wchar_t, no?
Using gcc (gcc (GCC) 4.5.0 20100222 (experimental)), I
can't print unicode codepoints to stdout via wcout. If
I do something like:
std::cout << "\u2714" << std::endl;
to my terminal which is set up to use UTF-8, I see a
checkmark. (Does that mean that somewhere theres a
conversion to UTF-8?
If I do something like:
std::wcout << "\u2714" << std::endl;
I get nothing.
If I do:
std::wcout << L"\u2714" << std::endl;
I get a box with 0 0 on the top and 1 4 on the bottom.
Using L"\U00002714" has the same result.
Using std::wcout << u"\u2713";
prints 0x804c226
imbuing a locale with a code conversion facet for
conversion between utf-8 and wchar_t unicode doesn't
seem to affect it at all.
std::wcout << L"Pat" << std::endl;
gets the word Pat on the screen.
How can I insert something into wcout that will result
in a check mark?
Patrick
More information about the Libstdc++
mailing list