本文整理汇总了C++中UnicodeToUtf8函数的典型用法代码示例。如果您正苦于以下问题:C++ UnicodeToUtf8函数的具体用法?C++ UnicodeToUtf8怎么用?C++ UnicodeToUtf8使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UnicodeToUtf8函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WinMain
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
wchar_t buf0[MAX_PATH];
GetModuleFileNameW(NULL, buf0, MAX_PATH-1);
lString16 str016(buf0);
#ifdef _UNICODE
lString16 str116(lpCmdLine);
#else
lString8 str18(lpCmdLine);
lString16 str116 = LocalToUnicode(str18);
#endif
lString8 str0 = UnicodeToUtf8(str016);
lString8 str1 = UnicodeToUtf8(str116);
if ( !str1.empty() && str1[0]=='\"' ) {
// quoted filename support
str1.erase(0, 1);
int pos = str1.pos(lString8("\""));
if ( pos>=0 )
str1 = str1.substr(0, pos);
}
char * argv[2];
argv[0] = str0.modify();
argv[1] = str1.modify();
int argc = str1.empty() ? 1 : 2;
return main(argc, argv);
}
示例2: UnicodeToUtf8
BOOL CSpecialApp::CleanKugooEx(CString strFileName, CString strTable)
{
BOOL bRet = FALSE;
CString strFileNameEx;
CString strTableEx;
strFileNameEx = strFileName;
strTableEx = strTable;
std::string szFileName;
std::string szTable;
szTable =UnicodeToUtf8(strTableEx.GetBuffer());
strTableEx.ReleaseBuffer();
szFileName = UnicodeToUtf8(strFileNameEx.GetBuffer());
strFileNameEx.ReleaseBuffer();
sqlite3* pDB = NULL;
sqlite3_stmt* sspStart = NULL;
char szSql[MAX_PATH] = {0};
int nResult = sqlite3_open(szFileName.c_str(), &pDB);
if (nResult != SQLITE_OK)
{
goto clean0;
}
if (szTable.empty())
goto clean0;
sprintf_s(szSql, "select * from %s", szTable.c_str());
nResult = sqlite3_prepare(pDB, szSql, -1, &sspStart, 0);
if (nResult != SQLITE_OK)
{
goto clean0;
}
nResult = sqlite3_step(sspStart);
if(nResult == SQLITE_ROW)
{
CString strOutPut = strFileName;
strOutPut += L"|";
strOutPut += strTable;
g_fnScanFile(g_pMain, 9010, strOutPut, 0, 0);
bRet = TRUE;
}
clean0:
if (sspStart)
{
sqlite3_finalize(sspStart);
sspStart = NULL;
}
if (pDB)
{
sqlite3_close(pDB);
pDB = NULL;
}
return bRet;
}
示例3: UnicodeToUtf8
BOOL CKSogoClean::ScanDbTable(std::wstring strFileName, std::wstring strTable, int nType)
{
BOOL bRet = FALSE;
sqlite3* pDb = NULL;
sqlite3_stmt* sspStart = NULL;
int nResult = -1;
std::string szFileName;
std::string szTable;
char szSql[MAX_PATH] = {0};
szFileName = UnicodeToUtf8(strFileName);
szTable = UnicodeToUtf8(strTable);
nResult = sqlite3_open(szFileName.c_str(), &pDb);
if (nResult != SQLITE_OK)
{
bRet = FALSE;
goto clean0;
}
if (szTable.empty())
goto clean0;
sprintf_s(szSql, MAX_PATH - 1, "select * from %s", szTable.c_str());
nResult = sqlite3_prepare(pDb, szSql, -1, &sspStart, 0);
if (nResult != SQLITE_OK)
{
bRet = FALSE;
goto clean0;
}
nResult = sqlite3_step(sspStart);
if (nResult == SQLITE_ROW)
{
std::wstring strOutput;
strOutput = strFileName;
strOutput += L"|";
strOutput += strTable;
g_fnScanFile(g_pMain, nType, strOutput.c_str(), 0, 0);
}
clean0:
if (sspStart)
{
sqlite3_finalize(sspStart);
sspStart = NULL;
}
if (pDb)
{
sqlite3_close(pDb);
pDb = NULL;
}
return bRet;
}
示例4: SaveMiscConfig
// 保存杂项配置
BOOL SaveMiscConfig(LPCTSTR lpszFileName)
{
unsigned char cUtf8Header[3] = {0xEF,0xBB,0xBF};
const wchar_t * lpFontFmt = _T("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Misc>\r\n<!--字体信息-->\r\n<FontInfo Name=\"%s\" Size=\"%d\" Color=\"%s\" Bold=\"%d\" Italic=\"%d\" UnderLine=\"%d\"></FontInfo>\r\n<!--提取消息热键,目前只支持Ctrl+Alt+某键-->\r\n<HotKey>%c</HotKey>\r\n</Misc>\r\n");
if (NULL == lpszFileName)
return FALSE;
FILE * fp = _tfopen(lpszFileName, _T("wb"));
if (NULL == fp)
return FALSE;
wchar_t szColor[32] = {0};
RGBToHexStr(g_fontInfo.m_clrText, szColor, sizeof(szColor)/sizeof(WCHAR));
wchar_t szBuf[4096] = {0};
wsprintf(szBuf, lpFontFmt, g_fontInfo.m_strName.c_str(), g_fontInfo.m_nSize,
szColor, g_fontInfo.m_bBold, g_fontInfo.m_bItalic, g_fontInfo.m_bUnderLine, g_cHotKey);
char * lpBuf = UnicodeToUtf8(szBuf);
if (NULL == lpBuf)
{
fclose(fp);
return FALSE;
}
fwrite(cUtf8Header, 3, 1, fp);
fwrite(lpBuf, strlen(lpBuf), 1, fp);
fclose(fp);
delete []lpBuf;
return TRUE;
}
示例5: encodeText
static lString8 encodeText(lString16 text16) {
if (text16.empty())
return lString8::empty_str;
lString8 text = UnicodeToUtf8(text16);
lString8 buf;
for (int i=0; i<text.length(); i++) {
char ch = text[i];
switch (ch) {
case '\\':
buf << "\\\\";
break;
case '\n':
buf << "\\n";
break;
case '\r':
buf << "\\r";
break;
case '\t':
buf << "\\t";
break;
default:
buf << ch;
break;
}
}
return buf;
}
示例6: getDirectoryFonts
bool getDirectoryFonts( lString16Collection & pathList, lString16 ext, lString16Collection & fonts, bool absPath )
{
int foundCount = 0;
lString16 path;
for (int di=0; di<pathList.length();di++ ) {
path = pathList[di];
LVContainerRef dir = LVOpenDirectory(path.c_str());
if(!dir.isNull()) {
CRLog::trace("Checking directory %s", UnicodeToUtf8(path).c_str() );
for(int i=0; i < dir->GetObjectCount(); i++ ) {
const LVContainerItemInfo * item = dir->GetObjectInfo(i);
lString16 fileName = item->GetName();
if ( !item->IsContainer() && fileName.length()>4 && lString16(fileName, fileName.length()-4, 4)==ext ) {
lString16 fn;
if ( absPath ) {
fn = path;
if (!fn.empty() && fn[fn.length()-1]!=PATH_SEPARATOR_CHAR)
fn << PATH_SEPARATOR_CHAR;
}
fn << fileName;
foundCount++;
fonts.add(fn);
}
}
}
}
return foundCount > 0;
}
示例7: initInternal
jboolean initInternal(JNIEnv * penv, jclass obj, jobjectArray fontArray) {
CRJNIEnv env(penv);
// to catch crashes and remove current cache file on crash (SIGSEGV etc.)
crSetSignalHandler();
LOGI("initInternal called");
// set fatal error handler
crSetFatalErrorHandler( &cr3androidFatalErrorHandler );
LOGD("Redirecting CDRLog to Android");
CRLog::setLogger( new JNICDRLogger() );
CRLog::setLogLevel( CRLog::LL_TRACE );
CRLog::info("CREngine log redirected");
CRLog::info("CRENGINE version %s %s", CR_ENGINE_VERSION, CR_ENGINE_BUILD_DATE);
CRLog::info("initializing hyphenation manager");
HyphMan::initDictionaries(lString16::empty_str); //don't look for dictionaries
HyphMan::activateDictionary(lString16(HYPH_DICT_ID_NONE));
CRLog::info("creating font manager");
InitFontManager(lString8::empty_str);
CRLog::debug("converting fonts array: %d items", (int)env->GetArrayLength(fontArray));
lString16Collection fonts;
env.fromJavaStringArray(fontArray, fonts);
int len = fonts.length();
CRLog::debug("registering fonts: %d fonts in list", len);
for ( int i=0; i<len; i++ ) {
lString8 fontName = UnicodeToUtf8(fonts[i]);
CRLog::debug("registering font %s", fontName.c_str());
if ( !fontMan->RegisterFont( fontName ) )
CRLog::error("cannot load font %s", fontName.c_str());
}
CRLog::info("%d fonts registered", fontMan->GetFontCount());
return fontMan->GetFontCount() ? JNI_TRUE : JNI_FALSE;
}
示例8: StrToUtf8Hex
CString& StrToUtf8Hex(const TCHAR* src, CString& strDec)
{
char* t = nullptr;
WCHAR* temp = nullptr;
int src_length = 0;
strDec.Empty();
#ifndef UNICODE
MbcsToUnicode(src, &temp, src_length);
#else
temp = (TCHAR*)src;
#endif
UnicodeToUtf8(temp, &t, src_length);
src_length -= 1;
for(int i = 0; i < src_length; ++i)
{
TCHAR tc[3] = {0, 0, 0};
VALUETODOUBLECHAR(tc, t[i]);
strDec += tc;
}
#ifndef UNICODE
delete[] temp;
#endif
delete[] t;
return strDec;
}
示例9: env
/*
* Class: org_coolreader_crengine_Engine
* Method: initInternal
* Signature: ([Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_org_coolreader_crengine_Engine_initInternal
(JNIEnv * penv, jobject obj, jobjectArray fontArray)
{
CRJNIEnv env(penv);
LOGI("initInternal called");
// set fatal error handler
crSetFatalErrorHandler( &cr3androidFatalErrorHandler );
LOGD("Redirecting CDRLog to Android");
CRLog::setLogger( new JNICDRLogger() );
CRLog::setLogLevel( CRLog::LL_TRACE );
CRLog::info("CREngine log redirected");
CRLog::info("initializing hyphenation manager");
HyphMan::initDictionaries(lString16()); //don't look for dictionaries
HyphMan::activateDictionary(lString16(HYPH_DICT_ID_NONE));
CRLog::info("creating font manager");
InitFontManager(lString8());
CRLog::debug("converting fonts array: %d items", (int)env->GetArrayLength(fontArray));
lString16Collection fonts;
env.fromJavaStringArray(fontArray, fonts);
int len = fonts.length();
CRLog::debug("registering fonts: %d fonts in list", len);
for ( int i=0; i<len; i++ ) {
lString8 fontName = UnicodeToUtf8(fonts[i]);
CRLog::debug("registering font %s", fontName.c_str());
if ( !fontMan->RegisterFont( fontName ) )
CRLog::error("cannot load font %s", fontName.c_str());
}
CRLog::info("%d fonts registered", (int)fontMan->GetFontCount());
return fontMan->GetFontCount() ? JNI_TRUE : JNI_FALSE;
}
示例10: Encode
inline void Encode(Unicode::const_iterator begin, Unicode::const_iterator end, string& res) {
#ifdef CPPJIEBA_GBK
gbkTrans(begin, end, res);
#else
UnicodeToUtf8(begin, end, res);
#endif
}
示例11: UnicodeToUtf8
bool V3DocViewWin::loadHistory( lString16 filename )
{
CRLog::trace("V3DocViewWin::loadHistory( %s )", UnicodeToUtf8(filename).c_str());
_historyFileName = filename;
LVStreamRef stream = LVOpenFileStream( filename.c_str(), LVOM_READ );
return loadHistory( stream );
}
示例12: switch
/// format detection finished
void V3DocViewWin::OnLoadFileFormatDetected( doc_format_t fileFormat )
{
CRLog::trace("OnLoadFileFormatDetected(%d)", (int)fileFormat);
lString16 filename = L"fb2.css";
if ( _cssDir.length() > 0 ) {
switch ( fileFormat ) {
case doc_format_txt:
filename = L"txt.css";
break;
case doc_format_rtf:
filename = L"rtf.css";
break;
case doc_format_epub:
filename = L"epub.css";
break;
case doc_format_html:
filename = L"htm.css";
break;
case doc_format_chm:
filename = L"chm.css";
break;
default:
// do nothing
;
}
CRLog::debug( "CSS file to load: %s", UnicodeToUtf8(filename).c_str() );
if ( LVFileExists( _cssDir + filename ) ) {
loadCSS( _cssDir + filename );
} else if ( LVFileExists( _cssDir + L"fb2.css" ) ) {
loadCSS( _cssDir + L"fb2.css" );
}
}
}
示例13: imagelib_save_frame_to_file_asyn
IMAGELIB_ERROR_CODE imagelib_save_frame_to_file_asyn(IMAGELIB_SESSION*_session,IMAGELIB_RECT _src_rect,
const WCHAR* _dest_pathname,INT32 _dest_width,INT32 _dest_height,
IMAGELIB_EFFECT_PARA _effect_para,DECODE_FRAME_ENDING_CB cb)
{
IMAGE_INSTANCE *decoder_instance,*encoder_instance=NULL;
IMAGELIB_MSG_PARA_LIST* para_list = NULL;
char utf_pathname[UTA_MAX_PATHNAME_LEN*2+1];
if(_session == NULL || _session->instance_p == NULL)
{
return IMAGELIB_RAM_EXECPTION;
}
wait_sem(_session->decode_sem);
if(_session ->state == IMAGELIB_DECODING)
{
signal_sem(_session->decode_sem);
return IMAGELIB_CURRENT_SESSION_BUSY;
}
decoder_instance = _session->instance_p;
UnicodeToUtf8(utf_pathname,_dest_pathname);
_session->error_code=image_open_by_filename(utf_pathname, "wb",NULL,&encoder_instance);
if(_session->error_code != IMAGELIB_SUCCESS || encoder_instance==NULL)
{
signal_sem(_session->decode_sem);
return _session->error_code;
}
_session ->state = IMAGELIB_DECODING;
para_list = imagelib_copy_msg_paralist(IMAGELIB_SAVEFRAMEDATA_MSG,_session,decoder_instance,encoder_instance,_src_rect,_dest_width,_dest_height,_effect_para,cb);
imagelib_postworkmessage(¶_list);
signal_sem(_session->decode_sem);
return _session->error_code;
}
示例14: env
/*
* Class: org_coolreader_crengine_Engine
* Method: drawBookCoverInternal
* Signature: (Landroid/graphics/Bitmap;[BLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;II)V
*/
JNIEXPORT void JNICALL Java_org_coolreader_crengine_Engine_drawBookCoverInternal
(JNIEnv * _env, jobject _engine, jobject bitmap, jbyteArray _data, jstring _fontFace, jstring _title, jstring _authors, jstring _seriesName, jint seriesNumber, jint bpp)
{
CRJNIEnv env(_env);
//CRLog::debug("drawBookCoverInternal called");
lString8 fontFace = UnicodeToUtf8(env.fromJavaString(_fontFace));
lString16 title = env.fromJavaString(_title);
lString16 authors = env.fromJavaString(_authors);
lString16 seriesName = env.fromJavaString(_seriesName);
LVStreamRef stream;
LVImageSourceRef image;
if (_data != NULL && _env->GetArrayLength(_data) > 0) {
stream = env.jbyteArrayToStream(_data);
if (!stream.isNull())
image = LVCreateStreamImageSource(stream);
}
LVDrawBuf * drawbuf = BitmapAccessorInterface::getInstance()->lock(_env, bitmap);
if (drawbuf != NULL) {
int factor = 1;
int dx = drawbuf->GetWidth();
int dy = drawbuf->GetHeight();
int MIN_WIDTH = 300;
int MIN_HEIGHT = 400;
if (dx < MIN_WIDTH || dy < MIN_HEIGHT) {
if (dx * 2 < MIN_WIDTH || dy * 2 < MIN_HEIGHT) {
dx *= 3;
dy *= 3;
factor = 3;
} else {
dx *= 2;
dy *= 2;
factor = 2;
}
}
LVDrawBuf * drawbuf2 = drawbuf;
if (factor > 1)
drawbuf2 = new LVColorDrawBuf(dx, dy, drawbuf->GetBitsPerPixel());
if (bpp >= 16) {
// native color resolution
LVDrawBookCover(*drawbuf2, image, fontFace, title, authors, seriesName, seriesNumber);
} else {
LVGrayDrawBuf grayBuf(drawbuf2->GetWidth(), drawbuf2->GetHeight(), bpp);
LVDrawBookCover(grayBuf, image, fontFace, title, authors, seriesName, seriesNumber);
grayBuf.DrawTo(drawbuf2, 0, 0, 0, NULL);
}
if (factor > 1) {
drawbuf->DrawRescaled(drawbuf2, 0, 0, drawbuf->GetWidth(), drawbuf->GetHeight(), 0);
delete drawbuf2;
}
//CRLog::trace("getPageImageInternal calling bitmap->unlock");
BitmapAccessorInterface::getInstance()->unlock(_env, bitmap, drawbuf);
} else {
CRLog::error("bitmap accessor is invalid");
}
//CRLog::debug("drawBookCoverInternal finished");
}
示例15: AnsiToUtf8
void AnsiToUtf8(char** dest, const char* src)
{
ASSERT(dest!= NULL || src != NULL);
WCHAR* pwszStr = NULL;
C2W(&pwszStr, src);
UnicodeToUtf8(dest, pwszStr);
SAFE_ARRYDELETE(pwszStr);
}