|
Boost Users : |
From: å®æµ© (mousesh360_at_[hidden])
Date: 2007-06-26 01:34:22
the GNU libstdc++ offers a flexible character encoding convertion
primitive (essentially a wrapper for the iconv C API), but in a
non-standard partial specialization of codecvt.
for example, if I want to use this codecvt, to convert between internal
encoding UCS-4LE and external encoding GB18030 (which is China's
national standard for Chinese character encoding), I will write
// define the codecvt type
typedef std::codecvt<wchar_t, char, __gnu_cxx::encoding_state>
w_codecvt;
// define a std::locale instance only for codecvt purpose
std::locale loc(std::locale::classic(), new w_codecvt);
const w_codecvt &cvt = std::use_facet<w_codecvt>(loc);
// the internal/external character encoding is specified as the
// argument to the constructor of __gnu_cxx::encoding_state
w_codecvt::state_type state("UCS-4LE", "GB18030");
// use cvt and state
cvt.in(state, ...);
the problem is, if I want to use this codecvt<.., ..,
__gnu_cxx::encoding_state> with code_converter, I can't find a way to
tell code_convert the encoding names (UCS-4LE, GB18030), seems that
code_converter will always use the default constructor of
Codecvt::state_type.
And if I specify the Codecvt template argument of code_converter to
codecvt<.., .., encoding_state>, imbue() will become a no-op, which
makes things even worse.
BTW: the documentation for GNU libstdc++ codecvt is available here
http://gcc.gnu.org/onlinedocs/libstdc++/22_locale/codecvt.html
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