本文整理汇总了C++中zlunicodeutil::Ucs2String::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ Ucs2String::insert方法的具体用法?C++ Ucs2String::insert怎么用?C++ Ucs2String::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zlunicodeutil::Ucs2String
的用法示例。
在下文中一共展示了Ucs2String::insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MultiByteToWideChar
void ZLWin32EncodingConverter::convert(std::string &dst, const char *srcStart, const char *srcEnd) {
if ((srcStart == srcEnd) || (myCode == 0)) {
return;
}
myBuffer.clear();
bool hasFirstChar = false;
if (myUseStoredCharacter) {
WCHAR symbol;
char buf[2] = { myStoredCharacter, *srcStart };
if (MultiByteToWideChar(myCode, 0, buf, 2, &symbol, 1) == 1) {
hasFirstChar = true;
myBuffer.push_back(symbol);
srcStart++;
}
myUseStoredCharacter = false;
}
int len = srcEnd - srcStart;
if (len > 0) {
myBuffer.insert(myBuffer.end(), len, 0);
WCHAR *bufferStart = (WCHAR*)&myBuffer.front();
if (hasFirstChar) {
bufferStart++;
}
int ucs2Len = MultiByteToWideChar(myCode, 0, srcStart, len, bufferStart, len);
myBuffer.erase(myBuffer.begin() + ucs2Len + (hasFirstChar ? 1 : 0), myBuffer.end());
if (ucs2Len != len) {
myRBuffer.append(len, '\0');
char defaultChar = 'X';
BOOL usedDefaultChar = false;
int len1 = WideCharToMultiByte(myCode, 0, bufferStart, ucs2Len, (char*)myRBuffer.data(), len, &defaultChar, &usedDefaultChar);
if (len1 == len - 1) {
myUseStoredCharacter = true;
myStoredCharacter = *(srcEnd - 1);
}
myRBuffer.erase();
}
}
std::string toAppend;
ZLUnicodeUtil::ucs2ToUtf8(toAppend, myBuffer);
dst += toAppend;
myBuffer.clear();
}