BOOST_FILESYSTEM_DECL void convert(const char* from, const char* from_end, // 0 for null terminated MBCS std::wstring & to, const codecvt_type & cvt) { BOOST_ASSERT(from); if (!from_end) // null terminated { from_end = from + std::strlen(from); } if (from == from_end) return; std::size_t buf_size = (from_end - from) * 3; // perhaps too large, but that's OK // dynamically allocate a buffer only if source is unusually large if (buf_size > default_codecvt_buf_size) { boost::scoped_array< wchar_t > buf(new wchar_t [buf_size]); convert_aux(from, from_end, buf.get(), buf.get()+buf_size, to, cvt); } else { wchar_t buf[default_codecvt_buf_size]; convert_aux(from, from_end, buf, buf+default_codecvt_buf_size, to, cvt); } }
BOOST_FILESYSTEM_DECL void convert(const wchar_t* from, const wchar_t* from_end, // 0 for null terminated MBCS std::string & to, const codecvt_type & cvt) { BOOST_ASSERT(from); if (!from_end) // null terminated { from_end = from + std::wcslen(from); } if (from == from_end) return; // The codecvt length functions may not be implemented, and I don't really // understand them either. Thus this code is just a guess; if it turns // out the buffer is too small then an error will be reported and the code // will have to be fixed. std::size_t buf_size = (from_end - from) * 4; // perhaps too large, but that's OK buf_size += 4; // encodings like shift-JIS need some prefix space // dynamically allocate a buffer only if source is unusually large if (buf_size > default_codecvt_buf_size) { boost::scoped_array< char > buf(new char [buf_size]); convert_aux(from, from_end, buf.get(), buf.get()+buf_size, to, cvt); } else { char buf[default_codecvt_buf_size]; convert_aux(from, from_end, buf, buf+default_codecvt_buf_size, to, cvt); } }
void convert(const wchar_t* from, const wchar_t* from_end, std::string& to, const codecvt_type& cvt, conv_method how) { assert(from); if (!from_end) { from_end = from + std::wcslen(from); } if (from == from_end) return; std::size_t buf_size = (from_end - from) * 4; buf_size += 4; if (buf_size > default_codecvt_buf_size) { std::dynarray<char> buf(buf_size); convert_aux(from, from_end, buf.begin(), buf.end(), to, cvt, how); } else { std::array<char, default_codecvt_buf_size> buf; convert_aux(from, from_end, &*buf.begin(), &*buf.begin() + buf.size(), to, cvt, how); } }