本文整理汇总了C++中zlunicodeutil::Ucs2String类的典型用法代码示例。如果您正苦于以下问题:C++ Ucs2String类的具体用法?C++ Ucs2String怎么用?C++ Ucs2String使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ucs2String类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: path
void ZLWin32FSDir::collectFiles(std::vector<std::string> &names, bool /*includeSymlinks*/) {
std::string pattern = path();
if (pattern[pattern.length() - 1] != '\\') {
pattern += '\\';
}
pattern += '*';
ZLUnicodeUtil::Ucs2String wPattern;
createNTWCHARString(wPattern, pattern);
WIN32_FIND_DATAW findData;
HANDLE handle = FindFirstFileW(::wchar(wPattern), &findData);
ZLUnicodeUtil::Ucs2String wFileName;
std::string fileName;
if (handle != 0) {
do {
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
continue;
}
wFileName.clear();
fileName.erase();
for (int i = 0; i < MAX_PATH; ++i) {
if (findData.cFileName[i] != 0) {
wFileName.push_back(findData.cFileName[i]);
} else {
break;
}
}
ZLUnicodeUtil::ucs2ToUtf8(fileName, wFileName);
names.push_back(fileName);
} while (FindNextFileW(handle, &findData));
}
}
开发者ID:ALEXGUOQ,项目名称:FBReader,代码行数:32,代码来源:ZLWin32FSDir.cpp
示例2: sizeof
void ZLWin32PaintContext::setFont(const std::string &family, int size, bool bold, bool italic) {
if (size < 4) {
size = 4;
}
if (myDisplayContext == 0) {
return;
}
// TODO: optimize
LOGFONT logicalFont;
memset(&logicalFont, 0, sizeof(LOGFONT));
logicalFont.lfHeight = size;
logicalFont.lfWeight = bold ? FW_BOLD : FW_REGULAR;
logicalFont.lfItalic = italic;
logicalFont.lfQuality = 5 /*CLEARTYPE_QUALITY*/;
const int len = std::min((int)family.length(), LF_FACESIZE - 1);
ZLUnicodeUtil::Ucs2String str;
ZLUnicodeUtil::utf8ToUcs2(str, family.data(), len);
str.push_back(0);
memcpy(logicalFont.lfFaceName, ::wchar(str), 2 * str.size());
HFONT font = CreateFontIndirect(&logicalFont);
DeleteObject(SelectObject(myDisplayContext, font));
GetTextMetrics(myDisplayContext, &myTextMetric);
mySpaceWidth = -1;
}
开发者ID:justsoso8,项目名称:fbreader,代码行数:25,代码来源:ZLWin32PaintContext.cpp
示例3: orig
LRESULT CALLBACK ZLWin32ApplicationWindow::TextEditParameter::ComboBoxCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
TextEditParameter ¶meter =
*(TextEditParameter*)GetWindowLong(hWnd, GWL_USERDATA);
if ((uMsg == WM_COMMAND) && (HIWORD(wParam) == CBN_SELCHANGE)) {
HWND comboBox = parameter.myComboBox;
const int index = SendMessage(comboBox, CB_GETCURSEL, 0, 0);
const int length = SendMessage(comboBox, CB_GETLBTEXTLEN, index, 0);
ZLUnicodeUtil::Ucs2String buffer;
if (length > 0) {
buffer.assign(length + 1, '\0');
SendMessage(comboBox, CB_GETLBTEXT, index, (LPARAM)&buffer.front());
buffer.pop_back();
}
std::string value;
ZLUnicodeUtil::ucs2ToUtf8(value, buffer);
parameter.setValue(value);
parameter.myApplication.doAction(parameter.myParameterItem.actionId());
SetFocus(parameter.myMainWindow);
}
WndProc orig = parameter.myOriginalComboBoxCallback;
return orig(hWnd, uMsg, wParam, lParam);
}
开发者ID:justsoso8,项目名称:fbreader,代码行数:25,代码来源:ZLWin32ApplicationWindow.cpp
示例4: GetWindowTextLengthW
std::string ZLWin32ApplicationWindow::TextEditParameter::internalValue() const {
int len = GetWindowTextLengthW(myComboBox);
if (len == 0) {
return "";
}
static ZLUnicodeUtil::Ucs2String buffer;
buffer.assign(len + 1, '\0');
GetWindowTextW(myComboBox, (WCHAR*)::wchar(buffer), len + 1);
buffer.pop_back();
std::string text;
ZLUnicodeUtil::ucs2ToUtf8(text, buffer);
return text;
}
开发者ID:justsoso8,项目名称:fbreader,代码行数:13,代码来源:ZLWin32ApplicationWindow.cpp
示例5: toolbar
void ZLWin32ApplicationWindow::setTooltip(TOOLTIPTEXT &tooltip) {
Toolbar &tb = toolbar(isFullscreen() ? FULLSCREEN_TOOLBAR : WINDOW_TOOLBAR);
if (tb.hwnd == 0) {
return;
}
ZLToolbar::ItemPtr item = tb.TBItemByActionCode[tooltip.hdr.idFrom];
if (!item.isNull()) {
const ZLToolbar::AbstractButtonItem &button =
(const ZLToolbar::AbstractButtonItem&)*item;
ZLUnicodeUtil::Ucs2String tooltipBuffer;
::createNTWCHARString(tooltipBuffer, button.tooltip());
size_t length = std::max(tooltipBuffer.size(), (size_t)80);
memcpy((char*)tooltip.szText, (char*)::wchar(tooltipBuffer), 2 * length);
tooltip.uFlags = TTF_DI_SETITEM;
}
}
开发者ID:justsoso8,项目名称:fbreader,代码行数:16,代码来源:ZLWin32ApplicationWindow.cpp
示例6: drawString
void ZLQtPaintContext::drawString(int x, int y, const char *str, int len, bool rtl) {
if (rtl) {
static ZLUnicodeUtil::Ucs2String ucs2Str;
ucs2Str.clear();
ZLUnicodeUtil::utf8ToUcs2(ucs2Str, str, len);
QString qStr;
FriBidiChar ch;
for (int i = ucs2Str.size() - 1; i >= 0; --i) {
fribidi_get_mirror_char(ucs2Str[i], &ch);
qStr.append(QChar(ch));
}
myPainter->drawText(x, y, qStr);
} else {
QString qStr = QString::fromUtf8(str, len);
myPainter->drawText(x, y, qStr);
}
}
开发者ID:justsoso8,项目名称:fbreader,代码行数:17,代码来源:ZLQtPaintContext.cpp
示例7: parseLink
std::string DocBookReader::parseLink(ZLUnicodeUtil::Ucs2String s, bool urlencode) {
//TODO add support for HYPERLINK like that:
// [0x13] HYPERLINK "http://site.ru/some text" \t "_blank" [0x14] text [0x15]
//Current implementation search for last QUOTE, so, it reads \t and _blank as part of link
//Last quote searching is need to handle link like that:
// [0x13] HYPERLINK "http://yandex.ru/yandsearch?text='some text' и "some text2"" [0x14] link text [0x15]
static const ZLUnicodeUtil::Ucs2Char QUOTE = 0x22;
size_t i, first = 0;
//TODO maybe functions findFirstOf and findLastOf should be in ZLUnicodeUtil class
for (i = 0; i < s.size(); ++i) {
if (s.at(i) == QUOTE) {
first = i;
break;
}
}
if (i == s.size()) {
return std::string();
}
size_t j, last = 0;
for (j = s.size(); j > 0 ; --j) {
if (s.at(j - 1) == QUOTE) {
last = j - 1;
break;
}
}
if (j == 0 || last == first) {
return std::string();
}
ZLUnicodeUtil::Ucs2String link;
for (size_t k = first + 1; k < last; ++k) {
ZLUnicodeUtil::Ucs2Char ch = s.at(k);
if (urlencode && ZLUnicodeUtil::isSpace(ch)) {
//TODO maybe implement function for encoding all signs in url, not only spaces and quotes
//TODO maybe add backslash support
link.push_back('%');
link.push_back('2');
link.push_back('0');
} else if (urlencode && ch == QUOTE) {
link.push_back('%');
link.push_back('2');
link.push_back('2');
} else {
link.push_back(ch);
}
}
std::string utf8String;
ZLUnicodeUtil::ucs2ToUtf8(utf8String, link);
return utf8String;
}
开发者ID:37Jayden,项目名称:bho,代码行数:51,代码来源:DocBookReader.cpp
示例8: addStyleEntry
void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry) {
// +++ calculating entry size
std::size_t len = 4; // entry type + feature mask
for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) {
if (entry.isFeatureSupported((ZLTextStyleEntry::Feature)i)) {
len += 4; // each supported length
}
}
if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE)) {
len += 2;
}
ZLUnicodeUtil::Ucs2String fontFamily;
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
ZLUnicodeUtil::utf8ToUcs2(fontFamily, entry.fontFamily());
len += 2 + fontFamily.size() * 2;
}
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) {
len += 2;
}
// --- calculating entry size
/*
EntryCount += 1;
EntryLen += len;
std::string debug = "style entry counter: ";
ZLStringUtil::appendNumber(debug, EntryCount);
debug += "/";
ZLStringUtil::appendNumber(debug, EntryLen);
ZLLogger::Instance().println(ZLLogger::DEFAULT_CLASS, debug);
*/
// +++ writing entry
myLastEntryStart = myAllocator->allocate(len);
char *address = myLastEntryStart;
*address++ = entry.entryKind();
*address++ = 0;
address = ZLCachedMemoryAllocator::writeUInt16(address, entry.myFeatureMask);
for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) {
if (entry.isFeatureSupported((ZLTextStyleEntry::Feature)i)) {
const ZLTextStyleEntry::LengthType &len = entry.myLengths[i];
address = ZLCachedMemoryAllocator::writeUInt16(address, len.Size);
*address++ = len.Unit;
*address++ = 0;
}
}
if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE)) {
*address++ = entry.myAlignmentType;
*address++ = 0;
}
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
address = ZLCachedMemoryAllocator::writeString(address, fontFamily);
}
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) {
*address++ = entry.mySupportedFontModifier;
*address++ = entry.myFontModifier;
}
// --- writing entry
myParagraphs.back()->addEntry(myLastEntryStart);
++myParagraphLengths.back();
}
开发者ID:MastAvalons,项目名称:FBReaderJ,代码行数:63,代码来源:ZLTextModel.cpp
示例9: keyName
std::string ZLQtKeyUtil::keyName(QKeyEvent *keyEvent) {
ZLUnicodeUtil::Ucs2String s;
ZLUnicodeUtil::utf8ToUcs2(s, (const char*)keyEvent->text().toUtf8());
int unicode = s.empty() ? 0 : s[0];
return ZLKeyUtil::keyName(unicode, keyEvent->key(), keyEvent->modifiers());
}
开发者ID:TodorGrin,项目名称:boox-opensource,代码行数:6,代码来源:ZLQtKeyUtil.cpp
示例10: readBookmarks
bool OleMainStream::readBookmarks(const char *headerBuffer, const OleEntry &tableEntry) {
//SttbfBkmk structure is a table of bookmark name strings
unsigned int beginNamesInfo = OleUtil::getU4Bytes(headerBuffer, 0x142); // address of SttbfBkmk structure
std::size_t namesInfoLength = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0x146); // length of SttbfBkmk structure
if (namesInfoLength == 0) {
return true; //there's no bookmarks
}
OleStream tableStream(myStorage, tableEntry, myBaseStream);
std::string buffer;
if (!readToBuffer(buffer, beginNamesInfo, namesInfoLength, tableStream)) {
return false;
}
unsigned int recordsNumber = OleUtil::getU2Bytes(buffer.c_str(), 0x2); //count of records
std::vector<std::string> names;
unsigned int offset = 0x6; //initial offset
for (unsigned int i = 0; i < recordsNumber; ++i) {
if (buffer.size() < offset + 2) {
ZLLogger::Instance().println("DocPlugin", "problmes with reading bookmarks names");
break;
}
unsigned int length = OleUtil::getU2Bytes(buffer.c_str(), offset) * 2; //length of string in bytes
ZLUnicodeUtil::Ucs2String name;
for (unsigned int j = 0; j < length; j+=2) {
char ch1 = buffer.at(offset + 2 + j);
char ch2 = buffer.at(offset + 2 + j + 1);
ZLUnicodeUtil::Ucs2Char ucs2Char = (unsigned int)ch1 | ((unsigned int)ch2 << 8);
name.push_back(ucs2Char);
}
std::string utf8Name;
ZLUnicodeUtil::ucs2ToUtf8(utf8Name, name);
names.push_back(utf8Name);
offset += length + 2;
}
//plcfBkmkf structure is table recording beginning CPs of bookmarks
unsigned int beginCharPosInfo = OleUtil::getU4Bytes(headerBuffer, 0x14A); // address of plcfBkmkf structure
std::size_t charPosInfoLen = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0x14E); // length of plcfBkmkf structure
if (charPosInfoLen == 0) {
return true; //there's no bookmarks
}
if (!readToBuffer(buffer, beginCharPosInfo, charPosInfoLen, tableStream)) {
return false;
}
static const unsigned int BKF_SIZE = 4;
std::size_t size = calcCountOfPLC(charPosInfoLen, BKF_SIZE);
std::vector<unsigned int> charPage;
for (std::size_t index = 0, offset = 0; index < size; ++index, offset += 4) {
charPage.push_back(OleUtil::getU4Bytes(buffer.c_str(), offset));
}
for (std::size_t i = 0; i < names.size(); ++i) {
if (i >= charPage.size()) {
break; //for the case if something in these structures goes wrong, to not to lose all bookmarks
}
Bookmark bookmark;
bookmark.CharPosition = charPage.at(i);
bookmark.Name = names.at(i);
myBookmarks.push_back(bookmark);
}
return true;
}
开发者ID:MastAvalons,项目名称:FBReaderJ,代码行数:69,代码来源:OleMainStream.cpp
示例11:
void ZLWin32Utf16EncodingConverter::convert(std::string &dst, const char *srcStart, const char *srcEnd) {
if (srcStart == srcEnd) {
return;
}
const unsigned char *ptr = (const unsigned char*)srcStart;
ZLUnicodeUtil::Ucs2Char ch;
myBuffer.clear();
if (myUseStoredCharacter) {
if (myLittleEndian) {
ch = *ptr;
ch <<= 8;
ch += myStoredCharacter;
} else {
ch = myStoredCharacter;
ch <<= 8;
ch += *ptr;
}
myBuffer.push_back(ch);
++ptr;
}
const unsigned char *end = (const unsigned char*)srcEnd;
if ((end - ptr) % 2 == 1) {
myStoredCharacter = *end;
myUseStoredCharacter = true;
--end;
} else {
myUseStoredCharacter = false;
}
if (myLittleEndian) {
for (; ptr < end; ptr += 2) {
myBuffer.push_back((((ZLUnicodeUtil::Ucs2Char)*(ptr + 1)) << 8) + *ptr);
}
} else {
for (; ptr < end; ptr += 2) {
myBuffer.push_back((((ZLUnicodeUtil::Ucs2Char)*ptr) << 8) + *(ptr + 1));
}
}
std::string toAppend;
ZLUnicodeUtil::ucs2ToUtf8(toAppend, myBuffer);
dst += toAppend;
myBuffer.clear();
}
开发者ID:chenhbzl,项目名称:BooxApp,代码行数:48,代码来源:ZLWin32EncodingConverter.cpp
示例12: 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();
}
开发者ID:chenhbzl,项目名称:BooxApp,代码行数:47,代码来源:ZLWin32EncodingConverter.cpp
注:本文中的zlunicodeutil::Ucs2String类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论