本文整理汇总了C++中st::string::to_utf8方法的典型用法代码示例。如果您正苦于以下问题:C++ string::to_utf8方法的具体用法?C++ string::to_utf8怎么用?C++ string::to_utf8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st::string
的用法示例。
在下文中一共展示了string::to_utf8方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memcpy
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));
}
}
示例2: writeBytes
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));
}
}