本文整理汇总了C++中std::u16string::data方法的典型用法代码示例。如果您正苦于以下问题:C++ u16string::data方法的具体用法?C++ u16string::data怎么用?C++ u16string::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::u16string
的用法示例。
在下文中一共展示了u16string::data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertUTF16ToUTF8String
bool convertUTF16ToUTF8String(const std::u16string& utf16, std::string &Out) {
assert(Out.empty());
// Avoid OOB by returning early on empty input.
if (utf16.empty())
return true;
const UTF16 *Src = reinterpret_cast<const UTF16 *>(utf16.data());
const UTF16 *SrcEnd = reinterpret_cast<const UTF16 *>(utf16.data() + utf16.length());
// Byteswap if necessary.
std::vector<UTF16> ByteSwapped;
if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {
ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
for (size_t I = 0, E = ByteSwapped.size(); I != E; ++I)
ByteSwapped[I] = SwapByteOrder_16(ByteSwapped[I]);
Src = &ByteSwapped[0];
SrcEnd = &ByteSwapped[ByteSwapped.size() - 1] + 1;
}
// Skip the BOM for conversion.
if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_NATIVE)
Src++;
// Just allocate enough space up front. We'll shrink it later.
Out.resize(utf16.length() * UNI_MAX_UTF8_BYTES_PER_CODE_POINT + 1);
UTF8 *Dst = reinterpret_cast<UTF8 *>(&Out[0]);
UTF8 *DstEnd = Dst + Out.size();
ConversionResult CR =
ConvertUTF16toUTF8(&Src, SrcEnd, &Dst, DstEnd, strictConversion);
assert(CR != targetExhausted);
if (CR != conversionOK) {
Out.clear();
return false;
}
Out.resize(reinterpret_cast<char *>(Dst) - &Out[0]);
return true;
}
示例2: reassign
//same thing as contructor. can be used to reinit dirList too
void dirList::reassign(const std::u16string p)
{
entry.clear();
FSUSER_OpenDirectory(&d, a, fsMakePath(PATH_UTF16, p.data()));
u32 read = 0;
do
{
FS_DirectoryEntry getEnt;
FSDIR_Read(d, &read, 1, &getEnt);
entry.push_back(getEnt);
}while(read > 0);
FSDIR_Close(d);
}
示例3: fsMakePath
dirList::dirList(FS_Archive arch, const std::u16string p)
{
//keep archive data
a = arch;
//save path
path = p;
//open path given by p
FSUSER_OpenDirectory(&d, a, fsMakePath(PATH_UTF16, p.data()));
//loop until we stop reading anymore entries
u32 read = 0;
do
{
FS_DirectoryEntry getEnt;
FSDIR_Read(d, &read, 1, &getEnt);
entry.push_back(getEnt);
}while(read > 0);
FSDIR_Close(d);
}
示例4: sizeof
input_u16string_buffer::input_u16string_buffer(std::u16string const & data) :
data_(data.size() + 1)
{
memcpy(data_.data(), data.data(), data_.size() * sizeof(char16_t));
}
示例5:
std::string to_utf8(const std::u16string &s)
{
std::wstring_convert<std::codecvt_utf8<int16_t>, int16_t> convert;
auto p = reinterpret_cast<const int16_t *>(s.data());
return convert.to_bytes(p, p + s.size());
}
示例6:
// VS 2015 Bug: https://social.msdn.microsoft.com/Forums/en-US/8f40dcd8-c67f-4eba-9134-a19b9178e481/vs-2015-rc-linker-stdcodecvt-error?forum=vcgeneral
std::string utf16_to_utf8(std::u16string utf16_string)
{
std::wstring_convert<std::codecvt_utf8_utf16<int16_t>, int16_t> convert;
auto p = reinterpret_cast<const int16_t *>(utf16_string.data());
return convert.to_bytes(p, p + utf16_string.size());
}