Hi again,
some day ago I asked how to convert a char and get its unicode value.
The proposed solution was to call WideCharToMultiByte/MultiByteToWideChar
Now, I'd rather not call the APIs directly, so I thought another solution:
the following works perfectly.
typedef wchar_t unicode_t;
inline unicode_t widen(const char c)
{
return std::use_facet< std::ctype<wchar_t> > ( std::locale("") ).widen(
c );
}
My questions:
1) does it work by chance or... by design?
is a wchar_t assumed large enough to hold a unicode value? It looks like
there ARE some unicode chars whose code is > FFFF
if there's a tight relation between wchar_t and unicode values, I think
'ctype::widen' may be assumed to convert to unicode, isn't it?
2) I read in MSDN there's a UTF-8 codepage named "65001".
does it mean that
std::use_facet< std::ctype<wchar_t> > ( std::locale(".65001") ).widen
is able to read UTF-8 and convert to unicode?
--
The set of solutions is never empty.
Two solutions together form a new problem.
-- Mycroft Holmes