|
Boost Users : |
Subject: Re: [Boost-users] [serialization?] converting utf8 string to unicodewstring
From: Eric MALENFANT (Eric.Malenfant_at_[hidden])
Date: 2009-10-08 09:58:50
boost-users-bounces_at_[hidden] wrote:
> Hello,
>
> I try to accomplish the subj with help of boost's
> utf8_codecvt_facet.
[snip]
> std::locale utf8_locale(old_locale, new
> boost::archive::detail::utf8_codecvt_facet());
> std::locale::global(utf8_locale);
> std::stringstream in;
> in.imbue(utf8_locale);
> in.str(utf);
> std::wstringstream out;
> out << in;
> std::wcout << out.str() << std::endl;
> }
>
> The above code doesn't work: "out" buffer doesn't contain
> correct unicode interpretation of the string.
> Actually, all i want is a c++ equivalent to the following WinAPI:
>
I *think* that this invokes operator<<(const void*) on "out", passing
the results of operator void*() on "in".
What may have had a chance at producing something near the desired
behavior would be to invoke operator<<(wostream&, const char*), like:
out << in.str().c_str()
Sadly, this won't work either as this uses ctype::widen, not
codecvt::do_in to make the conversion. AFAIK, the only use of codedcvt
in the iostreams library is for the conversion between the "external"
and "internal" encodings done by basic_filebuf. To get the desired
behavior, I think you'll have to write your own operator<<(wostream&,
const string&) and use the codecvt facet inside it. IIRC, C++0x includes
things like wstring_convert to do that.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net