Angus Leeming <[EMAIL PROTECTED]> writes:
| Sorry, don't follow.
Ahh so you created one more.
| std::vector<char>
| ucs4_to_utf8(std::vector<boost::uint32_t> const & ucs4str)
| {
| // ucs4str has a machine-specific byte order, but that
| // doesn't actually matter because *we* generated it in
| // the first place, passing "UCS-4-INTERNAL" to iconv.
| std::vector<char> in(ucs4str.size() * 4);
| std::memcpy(&in[0], &ucs4str[0], ucs4str.size() * 4);
| return iconv_convert<char>("UTF-8", "UCS-4-INTERNAL", in);
| }
No such encoding. "UCS-4" is supposed to do just that, use the default
endianess on the box.
| template <typename T>
| std::vector<T>
| iconv_convert(
| std::string const & tocode,
| std::string const & fromcode,
| std::vector const & indata)
| {
| char outdata[1000] = { 0 };
| int const bytes = icon_fill_buffer(
| tocode, fromcode, indata, outdata);
|
| // conversion failed.
| if (bytes == 0)
| return std::vector<T>();
|
| std::size_t length_outvec = bytes * sizeof(char) / sizeof(T);
| ASSERT(length_outvec * sizeof(T) / sizeof(char) == bytes);
|
| std::vector<T> outvec(length_outvec);
| std::memcpy(&outvec[0], outdata, bytes);
| return outvec;
| }
I think we can to even better, eg. avoid the use of std::vector
alltogether without loss of clarity.
I'll look at this tonight.
--
Lgb