std::string StringUtil::StrToUTF8(const char* src) { if (isUTF8(src)) return std::string(src); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) int len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0); wchar_t* wstr = new wchar_t[len + 1]; memset(wstr, 0, len + 1); MultiByteToWideChar(CP_ACP, 0, src, -1, wstr, len); std::string utf = WStrToUTF8(wstr); if (wstr) delete[] wstr; return utf; #else /*std::string chars(src); std::wstring wide_chars(chars.begin(), chars.end()); return WStrToUTF8(wide_chars.c_str());*/ return src; #endif }
bool LoadingScene::prepareLoading() { bool bRet = false; _loadingNum = 0; _totalNum = 10;//好像这个统计一定要少一个才能正常结束,不知道是啥bug do { CCSprite *s2=CCSprite::create("Images/Loading_dark.png");//pa2.png是较暗的图片 CC_BREAK_IF(!s2); s2->setPosition(ccp(this->getContentSize().width/2,this->getContentSize().height/2)); addChild(s2,0); CCSprite *s=CCSprite::create("Images/Loading_light.png");//pa1.png是较亮的图片 CC_BREAK_IF(!s); CCProgressTimer* pt=CCProgressTimer::create(s); CC_BREAK_IF(!pt); pt->setPercentage(0); pt->setPosition(ccp(this->getContentSize().width/2,this->getContentSize().height/2)); //转圈的CD实现 pt->setType(cocos2d::CCProgressTimerType(kCCProgressTimerTypeRadial)); //从中间到外的出现 //pt->setType(cocos2d::CCProgressTimerType(kCCProgressTimerTypeBar)); this->addChild(pt,1,1); //测试一下中文 CCLabelTTF* loadingText = CCLabelTTF::create(WStrToUTF8(s_LoadingChs).c_str(),"Arial",30); loadingText->setColor(ccc3(247,176,71)); loadingText->setPosition(ccp(this->getContentSize().width/2,this->getContentSize().height/2-s2->getContentSize().height/2-loadingText->getContentSize().height/2)); this->addChild(loadingText,2); bRet = true; } while(0); return bRet; }
BOOL WINAPI HashCalcWriteResult( PHASHCALCCONTEXT phcctx, PHASHCALCITEM pItem ) { PCTSTR pszHash; PVOID pvLine; INT cchLine, cbLine; // Length of line, in TCHARs or BYTEs, EXCLUDING the terminator if (!pItem->bValid) return(FALSE); // Set szFormat is necessary if (phcctx->szFormat[0] == 0) { // Did I ever mention that I hate SFV? // The reason we tracked cchMax was because of this idiotic format if (phcctx->ofn.nFilterIndex == 1) { wnsprintf( phcctx->szFormat, countof(phcctx->szFormat), TEXT("%%-%ds %%s\r\n"), phcctx->cchMax - phcctx->cchAdjusted ); } else { SSStaticCpy(phcctx->szFormat, TEXT("%s *%s\r\n")); } } // Translate the filter index to a hash switch (phcctx->ofn.nFilterIndex) { case 1: pszHash = pItem->results.szHexCRC32; break; case 2: pszHash = pItem->results.szHexMD4; break; case 3: pszHash = pItem->results.szHexMD5; break; case 4: pszHash = pItem->results.szHexSHA1; break; } // Format the line #define HashCalcFormat(a, b) wnsprintf(phcctx->scratch.sz, MAX_PATH_BUFFER, phcctx->szFormat, a, b) cchLine = (phcctx->ofn.nFilterIndex == 1) ? HashCalcFormat(pItem->szPath + phcctx->cchAdjusted, pszHash) : // SFV HashCalcFormat(pszHash, pItem->szPath + phcctx->cchAdjusted); // everything else #undef HashCalcFormat if (cchLine > 0) { // Convert to the correct encoding switch (phcctx->opt.dwSaveEncoding) { case 0: { // UTF-8 #ifdef UNICODE cbLine = WStrToUTF8(phcctx->scratch.szW, phcctx->scratch.szA, countof(phcctx->scratch.szA)) - 1; #else AStrToWStr(phcctx->scratch.szA, phcctx->scratch.szW, countof(phcctx->scratch.szW)); cbLine = WStrToUTF8(phcctx->scratch.szW, phcctx->scratch.szA, countof(phcctx->scratch.szA)) - 1; #endif pvLine = phcctx->scratch.szA; break; } case 1: { // UTF-16 #ifndef UNICODE cchLine = AStrToWStr(phcctx->scratch.szA, phcctx->scratch.szW, countof(phcctx->scratch.szW)) - 1; #endif cbLine = cchLine * sizeof(WCHAR); pvLine = phcctx->scratch.szW; break; } case 2: { // ANSI #ifdef UNICODE cbLine = WStrToAStr(phcctx->scratch.szW, phcctx->scratch.szA, countof(phcctx->scratch.szA)) - 1; #else cbLine = cchLine; #endif pvLine = phcctx->scratch.szA; break; } } if (cbLine > 0) { INT cbWritten; WriteFile(phcctx->hFileOut, pvLine, cbLine, &cbWritten, NULL); if (cbLine != cbWritten) return(FALSE); } else return(FALSE); } else return(FALSE); return(TRUE); }
std::string StringUtil::UnicodeToUTF8(const wchar_t* unicode) { return WStrToUTF8(unicode); }