亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? stdiofileex.cpp

?? Encode/Decode UTF-8 format from/to text format
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// StdioFileEx.cpp: implementation of the CStdioFileEx class.
//
// Version 1.1 23 August 2003.	Incorporated fixes from Dennis Jeryd.
// Version 1.3 19 February 2005. Incorporated fixes from Howard J Oh and some of my own.
// Version 1.4 26 February 2005. Fixed stupid screw-up in code from 1.3.
// Version 1.5 18 November 2005. - Incorporated fixes from Andy Goodwin.
//											- Allows code page to be specified for reading/writing
//											- Properly calculates multibyte buffer size instead of
//												assuming lstrlen(s).
//											- Should handle UTF8 properly.
//
// Copyright David Pritchard 2003-2005. davidpritchard@ctv.es
//
// You can use this class freely, but please keep my ego happy 
// by leaving this comment in place.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "StdioFileEx.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

/*static*/ const UINT CStdioFileEx::modeWriteUnicode = 0x20000; // Add this flag to write in Unicode

CStdioFileEx::CStdioFileEx(): CStdioFile()
{
	m_bIsUnicodeText = false;
	m_nFileCodePage = -1;
}

CStdioFileEx::CStdioFileEx(LPCTSTR lpszFileName,UINT nOpenFlags)
	:CStdioFile(lpszFileName, ProcessFlags(lpszFileName, nOpenFlags))
{
	m_nFileCodePage = -1;
}

void CStdioFileEx::SetCodePage(IN const UINT nCodePage)
{
	m_nFileCodePage = (int)nCodePage; 
}

BOOL CStdioFileEx::Open(LPCTSTR lpszFileName,UINT nOpenFlags,CFileException* pError /*=NULL*/)
{
	// Process any Unicode stuff
	ProcessFlags(lpszFileName, nOpenFlags);

	return CStdioFile::Open(lpszFileName, nOpenFlags, pError);
}

BOOL CStdioFileEx::ReadString(CString& rString)
{
	const int	nMAX_LINE_CHARS = 4096;
	BOOL			bReadData = FALSE;
	LPTSTR		lpsz;
	int			nLen = 0;
	wchar_t*		pszUnicodeString = NULL;
	char	*		pszMultiByteString= NULL;
	int			nChars = 0;

	try
	{
		// If at position 0, discard byte-order mark before reading
		if (!m_pStream || (GetPosition() == 0 && m_bIsUnicodeText))
		{
			wchar_t	cDummy;
	//		Read(&cDummy, sizeof(_TCHAR));
			Read(&cDummy, sizeof(wchar_t));
		}

// If compiled for Unicode
#ifdef _UNICODE
		if (m_bIsUnicodeText)
		{
			// Do standard stuff - Unicode to Unicode. Seems to work OK.
			bReadData = CStdioFile::ReadString(rString);
		}
		else
		{
			pszUnicodeString	= new wchar_t[nMAX_LINE_CHARS]; 
			pszMultiByteString= new char[nMAX_LINE_CHARS]; 

			// Initialise to something safe
			memset(pszUnicodeString, 0, sizeof(wchar_t) * nMAX_LINE_CHARS);
			memset(pszMultiByteString, 0, sizeof(char) * nMAX_LINE_CHARS);
			
			// Read the string
			bReadData = (NULL != fgets(pszMultiByteString, nMAX_LINE_CHARS, m_pStream));

			if (bReadData)
			{
				// Convert multibyte to Unicode, using the specified code page
				nChars = GetUnicodeStringFromMultiByteString(pszMultiByteString, pszUnicodeString, nMAX_LINE_CHARS, m_nFileCodePage);

				if (nChars > 0)
				{
					rString = (CString)pszUnicodeString;
				}
			}
		}
#else

		if (!m_bIsUnicodeText)
		{
			// Do standard stuff -- read ANSI in ANSI
			bReadData = CStdioFile::ReadString(rString);

			// Get the current code page
			UINT nLocaleCodePage = GetCurrentLocaleCodePage();

			// If we got it OK...
			if (nLocaleCodePage > 0)
			{
				// if file code page does not match the system code page, we need to do a double conversion!
				if (nLocaleCodePage != (UINT)m_nFileCodePage)
				{
					int nStringBufferChars = rString.GetLength() + 1;

					pszUnicodeString	= new wchar_t[nStringBufferChars]; 

					// Initialise to something safe
					memset(pszUnicodeString, 0, sizeof(wchar_t) * nStringBufferChars);
					
					// Convert to Unicode using the file code page
					nChars = GetUnicodeStringFromMultiByteString(rString, pszUnicodeString, nStringBufferChars, m_nFileCodePage);

					// Convert back to multibyte using the system code page
					// (This doesn't really confer huge advantages except to avoid "mangling" of non-convertible special
					// characters. So, if a file in the E.European code page is displayed on a system using the 
					// western European code page, special accented characters which the system cannot display will be
					// replaced by the default character (a hash or something), rather than being incorrectly mapped to
					// other, western European accented characters).
					if (nChars > 0)
					{
						// Calculate how much we need for the MB buffer (it might be larger)
						nStringBufferChars = GetRequiredMultiByteLengthForUnicodeString(pszUnicodeString,nLocaleCodePage);
						pszMultiByteString= new char[nStringBufferChars];  

						nChars = GetMultiByteStringFromUnicodeString(pszUnicodeString, pszMultiByteString, nStringBufferChars, nLocaleCodePage);
						rString = (CString)pszMultiByteString;
					}
				}
			}
		}
		else
		{
			pszUnicodeString	= new wchar_t[nMAX_LINE_CHARS]; 

			// Initialise to something safe
			memset(pszUnicodeString, 0, sizeof(wchar_t) * nMAX_LINE_CHARS);
			
			// Read as Unicode, convert to ANSI

			// Bug fix by Dennis Jeryd 06/07/2003: initialise bReadData
			bReadData = (NULL != fgetws(pszUnicodeString, nMAX_LINE_CHARS, m_pStream));

			if (bReadData)
			{
				// Calculate how much we need for the multibyte string
				int nRequiredMBBuffer = GetRequiredMultiByteLengthForUnicodeString(pszUnicodeString,m_nFileCodePage);
				pszMultiByteString= new char[nRequiredMBBuffer];  

				nChars = GetMultiByteStringFromUnicodeString(pszUnicodeString, pszMultiByteString, nRequiredMBBuffer, m_nFileCodePage);

				if (nChars > 0)
				{
					rString = (CString)pszMultiByteString;
				}
			}

		}
#endif

		// Then remove end-of-line character if in Unicode text mode
		if (bReadData)
		{
			// Copied from FileTxt.cpp but adapted to Unicode and then adapted for end-of-line being just '\r'. 
			nLen = rString.GetLength();
			if (nLen > 1 && rString.Mid(nLen-2) == sNEWLINE)
			{
				rString.GetBufferSetLength(nLen-2);
			}
			else
			{
				lpsz = rString.GetBuffer(0);
				if (nLen != 0 && (lpsz[nLen-1] == _T('\r') || lpsz[nLen-1] == _T('\n')))
				{
					rString.GetBufferSetLength(nLen-1);
				}
			}
		}
	}
	// Ensure we always delete in case of exception
	catch(...)
	{
		if (pszUnicodeString)	delete [] pszUnicodeString;

		if (pszMultiByteString) delete [] pszMultiByteString;

		throw;
	}

	if (pszUnicodeString)		delete [] pszUnicodeString;

	if (pszMultiByteString)		delete [] pszMultiByteString;

	return bReadData;
}



// --------------------------------------------------------------------------------------------
//
//	CStdioFileEx::WriteString()
//
// --------------------------------------------------------------------------------------------
// Returns:    void
// Parameters: LPCTSTR lpsz
//
// Purpose:		Writes string to file either in Unicode or multibyte, depending on whether the caller specified the
//					CStdioFileEx::modeWriteUnicode flag. Override of base class function.
// Notes:		If writing in Unicode we need to:
//						a) Write the Byte-order-mark at the beginning of the file
//						b) Write all strings in byte-mode
//					-	If we were compiled in Unicode, we need to convert Unicode to multibyte if 
//						we want to write in multibyte
//					-	If we were compiled in multi-byte, we need to convert multibyte to Unicode if 
//						we want to write in Unicode.
// Exceptions:	None.
//
void CStdioFileEx::WriteString(LPCTSTR lpsz)
{
	wchar_t*	pszUnicodeString	= NULL; 
	char	*	pszMultiByteString= NULL;
	
	try
	{
		// If writing Unicode and at the start of the file, need to write byte mark
		if (m_nFlags & CStdioFileEx::modeWriteUnicode)
		{
			// If at position 0, write byte-order mark before writing anything else
			if (!m_pStream || GetPosition() == 0)
			{
				wchar_t cBOM = (wchar_t)nUNICODE_BOM;
				CFile::Write(&cBOM, sizeof(wchar_t));
			}
		}

// If compiled in Unicode...
#ifdef _UNICODE

		// If writing Unicode, no conversion needed
		if (m_nFlags & CStdioFileEx::modeWriteUnicode)
		{
			// Write in byte mode
			CFile::Write(lpsz, lstrlen(lpsz) * sizeof(wchar_t));
		}
		// Else if we don't want to write Unicode, need to convert
		else
		{
			int		nChars = lstrlen(lpsz) + 1;				// Why plus 1? Because yes
//			int		nBufferSize = nChars * sizeof(char);	// leave space for multi-byte chars
			int		nCharsWritten = 0;
			int		nBufferSize = 0;

			pszUnicodeString	= new wchar_t[nChars]; 

			// Copy string to Unicode buffer
			lstrcpy(pszUnicodeString, lpsz);

			// Work out how much space we need for the multibyte conversion
			nBufferSize = GetRequiredMultiByteLengthForUnicodeString(pszUnicodeString, m_nFileCodePage);
			pszMultiByteString= new char[nBufferSize];  

			// Get multibyte string
			nCharsWritten = GetMultiByteStringFromUnicodeString(pszUnicodeString, pszMultiByteString, nBufferSize, m_nFileCodePage);

			if (nCharsWritten > 0)
			{
				// Do byte-mode write using actual chars written (fix by Howard J Oh)
	//			CFile::Write((const void*)pszMultiByteString, lstrlen(lpsz));
				CFile::Write((const void*)pszMultiByteString,
					nCharsWritten*sizeof(char));
			}
		}
	// Else if *not* compiled in Unicode
#else
		// If writing Unicode, need to convert
		if (m_nFlags & CStdioFileEx::modeWriteUnicode)
		{
			int		nChars = lstrlen(lpsz) + 1;	 // Why plus 1? Because yes
			int		nBufferSize = nChars * sizeof(wchar_t);
			int		nCharsWritten = 0;

			pszUnicodeString	= new wchar_t[nChars];
			pszMultiByteString= new char[nChars]; 

			// Copy string to multibyte buffer
			lstrcpy(pszMultiByteString, lpsz);

			nCharsWritten = GetUnicodeStringFromMultiByteString(pszMultiByteString, pszUnicodeString, nChars, m_nFileCodePage);

			if (nCharsWritten > 0)
			{
				// Do byte-mode write using actual chars written (fix by Howard J Oh)
	//			CFile::Write(pszUnicodeString, lstrlen(lpsz) * sizeof(wchar_t));
				CFile::Write(pszUnicodeString, nCharsWritten*sizeof(wchar_t));
			}
			else
			{
				ASSERT(false);
			}

		}
		// Else if we don't want to write Unicode, no conversion needed, unless the code page differs
		else
		{
	//		// Do standard stuff
	//		CStdioFile::WriteString(lpsz);

			// Get the current code page
			UINT nLocaleCodePage = GetCurrentLocaleCodePage();

			// If we got it OK, and if file code page does not match the system code page, we need to do a double conversion!
			if (nLocaleCodePage > 0 && nLocaleCodePage != (UINT)m_nFileCodePage)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲视频每日更新| 日韩电影免费在线看| 蜜臀99久久精品久久久久久软件 | 国产在线国偷精品免费看| 欧美高清激情brazzers| 青青草原综合久久大伊人精品| 69堂成人精品免费视频| 舔着乳尖日韩一区| 日韩一级片在线播放| 懂色中文一区二区在线播放| 中文字幕一区av| 精品视频色一区| 久久成人av少妇免费| 亚洲国产激情av| 欧美三区在线视频| 国产酒店精品激情| 亚洲一区二区偷拍精品| 日韩精品一区二区三区视频在线观看| 国产乱子伦一区二区三区国色天香 | 国模冰冰炮一区二区| 亚洲国产高清不卡| 3d动漫精品啪啪一区二区竹菊| 国产在线播放一区二区三区| 伊人开心综合网| 精品久久久久久无| 欧美午夜精品免费| 国产精品一区二区黑丝| 五月婷婷久久丁香| 亚洲美女在线国产| 国产午夜一区二区三区| 91精品国产综合久久香蕉的特点| 国产98色在线|日韩| 日韩精品视频网| 亚洲三级理论片| 久久久久九九视频| 欧美一区二区女人| 在线亚洲一区二区| jizzjizzjizz欧美| 激情小说欧美图片| 天堂va蜜桃一区二区三区漫画版| 国产精品水嫩水嫩| 久久亚洲捆绑美女| 91免费国产在线观看| 免费在线一区观看| 亚洲成精国产精品女| 亚洲人妖av一区二区| 中文字幕电影一区| 国产三级精品三级在线专区| 日韩欧美一卡二卡| 日韩免费高清视频| 欧美一级片在线看| 91精品国产综合久久精品图片| 色婷婷一区二区| 色综合视频一区二区三区高清| 国产91丝袜在线播放| 麻豆视频观看网址久久| 亚洲成人自拍网| 亚洲一区二区三区免费视频| 国产精品高潮呻吟| 一本一本久久a久久精品综合麻豆 一本一道波多野结衣一区二区 | 一区二区三区免费| 成人免费在线视频观看| 亚洲欧洲国产日韩| 1区2区3区精品视频| 亚洲日本在线天堂| 亚洲国产日韩在线一区模特| 一区二区三区.www| 亚洲超碰97人人做人人爱| 韩国欧美国产一区| 免费欧美在线视频| 国产在线精品不卡| 成人免费看片app下载| 风间由美一区二区三区在线观看| 国产91精品精华液一区二区三区| 成人午夜av在线| 99国产一区二区三精品乱码| 色欧美日韩亚洲| 6080亚洲精品一区二区| 精品国产乱码久久久久久浪潮 | 国产精品欧美久久久久无广告| 久久精品欧美一区二区三区不卡| 国产亚洲女人久久久久毛片| 国产精品理论在线观看| 亚洲国产综合91精品麻豆| 另类人妖一区二区av| 国产精品中文欧美| 在线免费观看成人短视频| 欧美日本一区二区| 欧美国产一区视频在线观看| 国产精品久久久久久久久免费丝袜| 一区二区三区在线视频播放| 日本不卡视频一二三区| 国产成人亚洲综合a∨猫咪| 色综合久久中文字幕| 日韩一级欧美一级| 国产精品视频九色porn| 日韩二区三区四区| 成人av在线观| 欧美电影免费观看高清完整版在线观看 | 欧美本精品男人aⅴ天堂| 国产精品久久久久久久久图文区 | 国内精品国产三级国产a久久| jizz一区二区| 久久综合av免费| 亚洲国产毛片aaaaa无费看 | 亚洲人成在线播放网站岛国| 天天综合日日夜夜精品| 99riav一区二区三区| xvideos.蜜桃一区二区| 性久久久久久久| 色综合久久久久网| 国产亚洲婷婷免费| 午夜欧美电影在线观看| 97aⅴ精品视频一二三区| 欧美精品一区二区三区很污很色的 | 欧美色手机在线观看| 国产色综合一区| 男人的j进女人的j一区| 欧美性猛交xxxxxx富婆| 国产精品伦理在线| 国产福利91精品一区二区三区| 在线播放亚洲一区| 亚洲一区二区成人在线观看| eeuss鲁片一区二区三区在线看| 精品国产髙清在线看国产毛片| 亚洲大片在线观看| 欧美视频中文一区二区三区在线观看| 国产精品三级电影| 国产成人精品一区二 | 国产在线视频精品一区| 91精品综合久久久久久| 亚洲色欲色欲www| 国产不卡视频在线播放| 精品国产人成亚洲区| 麻豆91精品91久久久的内涵| 欧美一区二区三区免费在线看 | 国产精品丝袜黑色高跟| 成人免费观看av| 国产精品久久久久久亚洲伦| 欧美日韩一区二区在线视频| 亚洲激情在线激情| 欧美网站一区二区| 天堂一区二区在线| 日韩欧美一二三| 国产美女在线观看一区| 国产清纯白嫩初高生在线观看91 | 欧美tickling挠脚心丨vk| 热久久国产精品| 亚洲精品一区二区三区精华液 | 欧美精品乱码久久久久久按摩| 亚洲国产精品天堂| 日韩一区二区三区视频在线观看| 蓝色福利精品导航| 欧美激情在线看| 色婷婷综合五月| 日本免费在线视频不卡一不卡二 | 成人综合婷婷国产精品久久免费| 亚洲国产成人在线| 色综合视频一区二区三区高清| 亚洲成人精品一区| 欧美精品一区二区久久久| 高清成人在线观看| 亚洲成av人片在www色猫咪| 欧美成人精品3d动漫h| 成人晚上爱看视频| 午夜婷婷国产麻豆精品| 久久一区二区三区四区| 91麻豆123| 国产综合久久久久久鬼色 | 色av一区二区| 奇米在线7777在线精品 | 91麻豆精品在线观看| 日韩中文字幕一区二区三区| 久久蜜桃av一区精品变态类天堂 | 日本不卡一区二区三区 | 成人福利视频在线看| 亚洲综合色婷婷| 精品久久五月天| 欧美色倩网站大全免费| 粉嫩aⅴ一区二区三区四区| 天堂成人国产精品一区| 日韩一区在线免费观看| 欧美不卡在线视频| 欧美视频一二三区| 99re热视频精品| 韩国av一区二区三区四区| 亚洲一级二级三级| 国产精品色噜噜| 久久精品无码一区二区三区| 欧美剧情片在线观看| 91蜜桃免费观看视频| 国产91丝袜在线播放0| 麻豆中文一区二区| 五月综合激情日本mⅴ| 亚洲色图20p| 国产精品欧美经典| 国产清纯美女被跳蛋高潮一区二区久久w | 91高清视频免费看| 成人手机在线视频| 精品在线一区二区|