Esempio n. 1
0
vector<Byte>
IceUtilInternal::fromUTF32(const vector<unsigned int>& source)
{
    vector<Byte> result;
    if(!source.empty())
    {

#ifdef ICE_HAS_CODECVT_UTF8
    assert(sizeof(Char32T) == sizeof(unsigned int));

    typedef wstring_convert<codecvt_utf8<Char32T>, Char32T> Convert;
    Convert convert;

    try
    {
        Convert::byte_string bs = convert.to_bytes(reinterpret_cast<const Char32T*>(&source.front()),
                                                   reinterpret_cast<const Char32T*>(&source.front() + source.size()));

        result = vector<Byte>(reinterpret_cast<const Byte*>(bs.data()),
                              reinterpret_cast<const Byte*>(bs.data()) + bs.length());
        }
    catch(const std::range_error& ex)
    {
        throw IllegalConversionException(__FILE__, __LINE__, ex.what());
    }

#else
    convertUTF32ToUTF8(source, result);
#endif
    }
    return result;
}