コード例 #1
0
void CWebSocket::SendContent(LPCSTR szStdResponse, const CString& rstr)
{
#ifdef _UNICODE
    CStringA strA(wc2utf8(rstr));
    SendContent(szStdResponse, strA, strA.GetLength());
#else
    SendContent(szStdResponse, rstr, rstr.GetLength());
#endif
}
コード例 #2
0
ファイル: mem_utils.c プロジェクト: unizeto/bmd
/**
 * Funkcja konwertuje łańcuchy znaków przechowywane w zmiennych typu
 * szeroki znak (wchar_t) na łańcuchy znaków typu pojedyńczy znak (char) zgodnie z
 * wybranym standardem kodowania (CP1250, ISO88592, UTF8).

 * @param[in] wcs - łańcuch znaków typu (wchar_t).
 * @param[in] code_page - wybrany sposób kodowania.
 * @param[out] output - łańcuch znaków typu (char).

 * @return status zakończenia operacji.
 * @retval BMD_OK - zakończenie pomyślne.
 * @retval BMD_ERR_PARAM1 - niepoprawny adres łańcucha źródłowego (wcs).
 * @retval BMD_ERR_PARAM2 - łańcuch wyjściowy jest już zainicjowany.
 * @retval BMD_ERR_PARAM3 - niepoprawny adres struktury GenBuf_t.
 * @retval BMD_ERR_UNIMPLEMENTED - wybrano nieobsługiwany sposób kodowania.
 * @retval BMD_ERR_OP_FAILED - nieprawidłowa długość łańcucha źródłowego.
 * @retval BMD_ERR_MEMORY - błąd alokacji łańcucha wyjściwego.
*/
long wcs2char(	const wchar_t *wcs,
			char **output,
			long code_page)
{
long length;
long i=0;
long j=0;
long count=0;

	PRINT_INFO("LIBBMDUTILSINF Converting wchar_t to char\n");
	if(wcs==NULL)		{	BMD_FOK(BMD_ERR_PARAM1);	}
	if(output==NULL)		{	BMD_FOK(BMD_ERR_PARAM2);	}
	if((*output)!=NULL)	{	BMD_FOK(BMD_ERR_PARAM2);	}

	if( (code_page!=BMD_CODE_PAGE_CP1250) && (code_page!=BMD_CODE_PAGE_ISO88592) && (code_page!=BMD_CODE_PAGE_UTF8) )
	{
		BMD_FOK(BMD_ERR_UNIMPLEMENTED);
	}

	length=(int)wcslen(wcs);
	if(length<0)
	{
		BMD_FOK(BMD_ERR_OP_FAILED);
	}
	(*output)=(char *)malloc(2*length+2);
	if((*output)==NULL)
	{
		BMD_FOK(BMD_ERR_MEMORY);
	}
	memset(*output,0,2*length+1);

	for(i=0;i<length;i++)
	{
		switch(code_page)
		{
			case BMD_CODE_PAGE_CP1250:
				wc2c_cp1250(wcs[i],&((*output)[i]));
				break;
			case BMD_CODE_PAGE_ISO88592:
				wc2c_iso88592(wcs[i],&((*output)[i]));
				break;
			case BMD_CODE_PAGE_UTF8:
				wc2utf8(wcs[i],&((*output)[j]),&count);
				j=j+count;
		}
	}
	return BMD_OK;
}
コード例 #3
0
ファイル: WebSocket.cpp プロジェクト: axxapp/winxgui
void CWebSocket::SendContent(LPCSTR szStdResponse, const CString& rstr)
{
	CStringA strA(wc2utf8(rstr));
	SendContent(szStdResponse, strA, strA.GetLength());
}
コード例 #4
0
ファイル: StringConversion.cpp プロジェクト: xt9852/TestSet
/*
CString OptUtf8ToStr(const CStringA& rastr)
{
	CStringW wstr;
	int iMaxWideStrLen = rastr.GetLength();
	LPWSTR pwsz = wstr.GetBuffer(iMaxWideStrLen);
	int iWideChars = utf8towc(rastr, rastr.GetLength(), pwsz, iMaxWideStrLen);
	if (iWideChars <= 0)
	{
		// invalid UTF8 string...
		wstr.ReleaseBuffer(0);
		wstr = rastr;				// convert with local codepage
	}
	else
		wstr.ReleaseBuffer(iWideChars);
	return wstr;					// just return the string
}

CString OptUtf8ToStr(LPCSTR psz, int iLen)
{
	CStringW wstr;
	int iMaxWideStrLen = iLen;
	LPWSTR pwsz = wstr.GetBuffer(iMaxWideStrLen);
	int iWideChars = utf8towc(psz, iLen, pwsz, iMaxWideStrLen);
	if (iWideChars <= 0)
	{
		// invalid UTF8 string...
		wstr.ReleaseBuffer(0);
		wstr = psz;				// convert with local codepage
	}
	else
		wstr.ReleaseBuffer(iWideChars);
	return wstr;					// just return the string
}

CString OptUtf8ToStr(const CStringW& rwstr)
{
	CStringA astr;
	for (int i = 0; i < rwstr.GetLength(); i++)
	{
		if (rwstr[i] > 0xFF)
		{
			// this is no UTF8 string (it's already an Unicode string)...
			return rwstr;			// just return the string
		}
		astr += (BYTE)rwstr[i];
	}
	return OptUtf8ToStr(astr);
}
*/
CStringA StrToUtf8(const CString& rstr)
{
    return wc2utf8((CStringW)rstr);
}
コード例 #5
0
ファイル: StatisticsTree.cpp プロジェクト: axxapp/winxgui
// Get a file name from the user, obtain the generated HTML and then save it in that file.
void CStatisticsTree::ExportHTML()
{
	CFile htmlFile;

	// Save/Restore the current directory
	TCHAR szCurDir[MAX_PATH];
	DWORD dwCurDirLen = GetCurrentDirectory(_countof(szCurDir), szCurDir);
	if (dwCurDirLen == 0 || dwCurDirLen >= _countof(szCurDir))
		szCurDir[0] = _T('\0');

	CFileDialog saveAsDlg(false, _T("html"), _T("eMule Statistics.html"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER, _T("HTML Files (*.html)|*.html|All Files (*.*)|*.*||"), this, 0);
	if (saveAsDlg.DoModal() == IDOK)
	{
		CString		strHTML;

		strHTML.Format( CString("<html>\r\n<header>\r\n<title>eMule %s [%s]</title>\r\n"
			"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
			"<style type=\"text/css\">\r\n"
			"#pghdr { color: #000F80; font: bold 12pt/14pt Verdana, Courier New, Helvetica; }\r\n"
			"#pghdr2 { color: #000F80; font: bold 10pt/12pt Verdana, Courier New, Helvetica; }\r\n"
			"img { border: 0px; }\r\n"
			"a { text-decoration: none; }\r\n"
			"#sec { color: #000000; font: bold 9pt/11pt Verdana, Courier New, Helvetica; }\r\n"
			"#item { color: #000000; font: normal 8pt/10pt Verdana, Courier New, Helvetica; }\r\n"
			"#bdy { color: #000000; font: normal 8pt/10pt Verdana, Courier New, Helvetica; background-color: #FFFFFF; }\r\n</style>\r\n</header>\r\n"
			"<script language=\"JavaScript1.2\" type=\"text/javascript\">\r\n"
			"function obj(menu)\r\n"
			"{\r\n"
			"return (navigator.appName == \"Microsoft Internet Explorer\")?this[menu]:document.getElementById(menu);\r\n"
			"}\r\n"
			"function togglevisible(treepart)\r\n"
			"{\r\n"
			"if (this.obj(\"T\"+treepart).style.visibility == \"hidden\")\r\n"
			"{\r\n"
			"this.obj(\"T\"+treepart).style.position=\"\";\r\n"
			"this.obj(\"T\"+treepart).style.visibility=\"\";\r\n"
			"document[\"I\"+treepart].src=\"stats_visible.gif\";\r\n"
			"}\r\n"
			"else\r\n"
			"{\r\n"
			"this.obj(\"T\"+treepart).style.position=\"absolute\";\r\n"
			"this.obj(\"T\"+treepart).style.visibility=\"hidden\";\r\n"
			"document[\"I\"+treepart].src=\"stats_hidden.gif\";\r\n"
			"}\r\n"
			"}\r\n"
			"</script>\r\n"
			"<body id=\"bdy\">\r\n"

			"<span id=\"pghdr\"><b>eMule %s</b></span><br /><span id=\"pghdr2\">%s %s</span>\r\n<br /><br />\r\n"
			"%s</body></html>") ,
			GetResString(IDS_SF_STATISTICS), thePrefs.GetUserNick(),
			GetResString(IDS_SF_STATISTICS), GetResString(IDS_CD_UNAME), thePrefs.GetUserNick(),
			GetHTMLForExport() );

		htmlFile.Open(saveAsDlg.GetPathName(), CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite);
		
		CStringA strHtmlA(wc2utf8(strHTML));
		htmlFile.Write(strHtmlA, strHtmlA.GetLength());		
		
		htmlFile.Close();

		static const TCHAR *const s_apcFileNames[] = {
			_T("stats_0.gif"), _T("stats_1.gif"), _T("stats_2.gif"), _T("stats_3.gif"), _T("stats_4.gif"),
			_T("stats_5.gif"), _T("stats_6.gif"), _T("stats_7.gif"), _T("stats_8.gif"), _T("stats_9.gif"),
			_T("stats_10.gif"), _T("stats_11.gif"), _T("stats_12.gif"), _T("stats_13.gif"),
			_T("stats_14.gif"), _T("stats_15.gif"), _T("stats_16.gif"), _T("stats_17.gif"),
			_T("stats_hidden.gif"), _T("stats_space.gif"), _T("stats_visible.gif")
		};
		CString		strDst = saveAsDlg.GetPathName().Left(saveAsDlg.GetPathName().GetLength() - saveAsDlg.GetFileName().GetLength());// EC - what if directory name == filename? this should fix this
		CString		strSrc = thePrefs.GetMuleDirectory(EMULE_WEBSERVERDIR);

		for (unsigned ui = 0; ui < ARRSIZE(s_apcFileNames); ui++)
			::CopyFile(strSrc + s_apcFileNames[ui], strDst + s_apcFileNames[ui], false);
	}

	if (szCurDir[0] != _T('\0'))
		VERIFY( SetCurrentDirectory(szCurDir) );
}