Beispiel #1
0
void DS::Stream::writeSafeString(const ST::string& value, DS::StringType format)
{
    if (format == e_StringUTF16) {
        ST::utf16_buffer buffer = value.to_utf16();
        uint16_t length = value.size() & 0x0FFF;
        ST::utf16_buffer work;
        char16_t* data = work.create_writable_buffer(length);
        memcpy(data, buffer.data(), length * sizeof(char16_t));
        for (uint16_t i=0; i<length; ++i)
            data[i] = ~data[i];
        write<uint16_t>(length | 0xF000);
        writeBytes(data, length * sizeof(char16_t));
        write<char16_t>(0);
    } else {
        ST::char_buffer buffer = (format == e_StringUTF8) ? value.to_utf8()
                               : value.to_latin_1(ST::substitute_invalid);
        uint16_t length = value.size() & 0x0FFF;
        ST::char_buffer work;
        char* data = work.create_writable_buffer(length);
        memcpy(data, buffer.data(), length * sizeof(char));
        for (uint16_t i=0; i<length; ++i)
            data[i] = ~data[i];
        write<uint16_t>(length | 0xF000);
        writeBytes(data, length * sizeof(char));
    }
}
Beispiel #2
0
void DS::Stream::writeString(const ST::string& value, DS::StringType format)
{
    if (format == e_StringUTF16) {
        ST::utf16_buffer buffer = value.to_utf16();
        writeBytes(buffer.data(), buffer.size() * sizeof(char16_t));
    } else {
        ST::char_buffer buffer = (format == e_StringUTF8) ? value.to_utf8()
                               : value.to_latin_1(ST::substitute_invalid);
        writeBytes(buffer.data(), buffer.size() * sizeof(char));
    }
}