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

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

?? identifyencoding.cs

?? 一)需求 很多情況下我們需要知道字節流的編碼
?? CS
?? 第 1 頁 / 共 5 頁
字號:
using System;

namespace Lion.Text
{
	#region Class IdentifyEncoding.....
	/// <summary>
	/// 檢測字符編碼的類
	/// <seealso cref="System.IO.Stream"/>
	/// <seealso cref="System.Uri"/>
	/// <seealso cref="System.IO.FileInfo"/>
	/// </summary>
	/// <remarks>
	/// <![CDATA[
	/// <strong>IdentifyEncoding</strong> 用來檢測 <see cref="Uri"/>,<see cref="System.IO.FileInfo"/>,<see cref="sbyte"/> 字節數組的編碼.
	/// Create By lion  <br/>
	/// 2005-02-21 22:00  <br/>
	///	Support .Net Framework v1.1.4322 <br/> 
	///	WebSite:www.lionsky.net(lion-a AT sohu.com) <br/> 
	/// ]]>
	/// </remarks>
	public class IdentifyEncoding
	{
		#region Fields.....

		// Frequency tables to hold the GB, Big5, and EUC-TW character
		// frequencies
		internal static int[][] GBFreq = new int[94][];
		internal static int[][] GBKFreq = new int[126][];
		internal static int[][] Big5Freq = new int[94][];
		internal static int[][] EUC_TWFreq = new int[94][];

		internal static string[] nicename = new string[]
			{
				"GB2312", "GBK", "HZ", "Big5", "CNS 11643", 
				"ISO 2022CN", "UTF-8", "Unicode", "ASCII", "OTHER"
			};

		#endregion

		#region Methods.....

		/// <summary>
		/// 初始化 <see cref="IdentifyEncoding"/> 的實例
		/// </summary>
		public IdentifyEncoding(){Initialize_Frequencies();}

		#region GetEncodingString.....
		/// <summary>
		/// 從指定的 <see cref="Uri"/> 中判斷編碼類型
		/// </summary>
		/// <param name="testurl">要判斷的 <see cref="Uri"/> </param>
		/// <returns>返回編碼類型("GB2312", "GBK", "HZ", "Big5", "CNS 11643", "ISO 2022CN", "UTF-8", "Unicode", "ASCII", "OTHER")</returns>
		/// <example>
		/// 以下示例演示了如何調用 <see cref="GetEncodingString"/> 方法:
		/// <code>
		///		IdentifyEncoding ide = new IdentifyEncoding();
		///		Response.Write(ide.GetEncodingString(new Uri("http://china5.nikkeibp.co.jp/china/news/com/200307/pr_com200307170131.html")));		
		/// </code>
		/// </example>
		public virtual string GetEncodingString(System.Uri testurl)
		{
			sbyte[] rawtext = new sbyte[1024];
			int bytesread = 0, byteoffset = 0;
			System.IO.Stream chinesestream;
			try
			{
				chinesestream = System.Net.WebRequest.Create(testurl.AbsoluteUri).GetResponse().GetResponseStream();
				while ((bytesread = ReadInput(chinesestream, ref rawtext, byteoffset, rawtext.Length - byteoffset)) > 0)
				{
					byteoffset += bytesread;
				}
				chinesestream.Close();
			}
			catch (System.Exception e)
			{
				System.Console.Error.WriteLine("Error loading or using URL " + e.ToString());
			}
			return GetEncodingString(rawtext);
		}

		/// <summary>
		/// 從指定的 <see cref="System.IO.FileInfo"/> 中判斷編碼類型
		/// </summary>
		/// <param name="testfile">要判斷的 <see cref="System.IO.FileInfo"/> </param>
		/// <returns>返回編碼類型("GB2312", "GBK", "HZ", "Big5", "CNS 11643", "ISO 2022CN", "UTF-8", "Unicode", "ASCII", "OTHER")</returns>
		/// <example>
		/// 以下示例演示了如何調用 <see cref="GetEncodingString"/> 方法:
		/// <code>
		///		IdentifyEncoding ide = new IdentifyEncoding();
		///		Response.Write(ide.GetEncodingString(new System.IO.FileInfo(@"C:\test.txt")));		
		/// </code>
		/// </example>
		public virtual string GetEncodingString(System.IO.FileInfo testfile)
		{
			System.IO.FileStream chinesefile;
			sbyte[] rawtext;
			rawtext = new sbyte[(int) FileLength(testfile)];
			try
			{
				chinesefile = new System.IO.FileStream(testfile.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
				ReadInput(chinesefile, ref rawtext, 0, rawtext.Length);
			}
			catch (System.Exception e)
			{
				System.Console.Error.WriteLine("Error: " + e);
			}

			return GetEncodingString(rawtext);
		}


		/// <summary>
		/// 從指定的 <see cref="sbyte"/> 字節數組中判斷編碼類型
		/// </summary>
		/// <param name="rawtext">要判斷的 <see cref="System.IO.FileInfo"/> </param>
		/// <returns>返回編碼類型("GB2312", "GBK", "HZ", "Big5", "CNS 11643", "ISO 2022CN", "UTF-8", "Unicode", "ASCII", "OTHER")</returns>
		/// <example>
		/// 以下示例演示了如何調用 <see cref="GetEncodingString"/> 方法:
		/// <code>
		///		IdentifyEncoding ide = new IdentifyEncoding();
		///		Response.Write(ide.GetEncodingString(IdentifyEncoding.ToSByteArray(System.Text.Encoding.GetEncoding("gb2312").GetBytes("Lion互動網絡(www.lionsky.net)"))));	
		/// </code>
		/// </example>
		public virtual string GetEncodingString(sbyte[] rawtext)
		{
			int[] scores;
			int index, maxscore = 0;
			int encoding_guess = 0;

			scores = new int[10];
			//分析編碼的概率
			scores[0] = GB2312Probability(rawtext);
			scores[1] = GBKProbability(rawtext);
			scores[2] = HZProbability(rawtext);
			scores[3] = BIG5Probability(rawtext);
			scores[4] = ENCTWProbability(rawtext);
			scores[5] = ISO2022CNProbability(rawtext);
			scores[6] = UTF8Probability(rawtext);
			scores[7] = UnicodeProbability(rawtext);
			scores[8] = ASCIIProbability(rawtext);
			scores[9] = 0;

			// Tabulate Scores
			for (index = 0; index < 10; index++)
			{
				if (scores[index] > maxscore)
				{
					encoding_guess = index;
					maxscore = scores[index];
				}
			}

			// Return OTHER if nothing scored above 50
			if (maxscore <= 50)
			{
				encoding_guess = 9;
			}

			return nicename[encoding_guess];
		}
		#endregion

		#region About Probability.....
		#region GB2312Probability
		/// <summary>
		/// 判斷是GB2312編碼的可能性
		/// </summary>
		/// <param name="rawtext">要判斷的 <see cref="sbyte"/> 字節數組</param>
		/// <returns>返回 0 至 100 之間的可能性</returns>
		internal virtual int GB2312Probability(sbyte[] rawtext)
		{
			int i, rawtextlen = 0;

			int dbchars = 1, gbchars = 1;
			long gbfreq = 0, totalfreq = 1;
			float rangeval = 0, freqval = 0;
			int row, column;

			// Stage 1:  Check to see if characters fit into acceptable ranges

			rawtextlen = rawtext.Length;
			for (i = 0; i < rawtextlen - 1; i++)
			{
				if (rawtext[i] >= 0)
				{
					//asciichars++;
				}
				else
				{
					dbchars++;
					if ((sbyte) Identity(0xA1) <= rawtext[i] && rawtext[i] <= (sbyte) Identity(0xF7) && (sbyte) Identity(0xA1) <= rawtext[i + 1] && rawtext[i + 1] <= (sbyte) Identity(0xFE))
					{
						gbchars++;
						totalfreq += 500;
						row = rawtext[i] + 256 - 0xA1;
						column = rawtext[i + 1] + 256 - 0xA1;
						if (GBFreq[row][column] != 0)
						{
							gbfreq += GBFreq[row][column];
						}
						else if (15 <= row && row < 55)
						{
							gbfreq += 200;
						}
					}
					i++;
				}
			}
			
			rangeval = 50*((float) gbchars/(float) dbchars);
			freqval = 50*((float) gbfreq/(float) totalfreq);

			
			return (int) (rangeval + freqval);
		}

		#endregion

		#region GBKProbability.....
		/// <summary>
		/// 判斷是GBK編碼的可能性
		/// </summary>
		/// <param name="rawtext">要判斷的 <see cref="sbyte"/> 字節數組</param>
		/// <returns>返回 0 至 100 之間的可能性</returns>
		internal virtual int GBKProbability(sbyte[] rawtext)
		{
			int i, rawtextlen = 0;

			int dbchars = 1, gbchars = 1;
			long gbfreq = 0, totalfreq = 1;
			float rangeval = 0, freqval = 0;
			int row, column;

			// Stage 1:  Check to see if characters fit into acceptable ranges
			rawtextlen = rawtext.Length;
			for (i = 0; i < rawtextlen - 1; i++)
			{
				if (rawtext[i] >= 0)
				{
					//asciichars++;
				}
				else
				{
					dbchars++;
					if ((sbyte) Identity(0xA1) <= rawtext[i] && rawtext[i] <= (sbyte) Identity(0xF7) && (sbyte) Identity(0xA1) <= rawtext[i + 1] && rawtext[i + 1] <= (sbyte) Identity(0xFE))
					{
						gbchars++;
						totalfreq += 500;
						row = rawtext[i] + 256 - 0xA1;
						column = rawtext[i + 1] + 256 - 0xA1;
						
						if (GBFreq[row][column] != 0)
						{
							gbfreq += GBFreq[row][column];
						}
						else if (15 <= row && row < 55)
						{
							gbfreq += 200;
						}
					}
					else if ((sbyte) Identity(0x81) <= rawtext[i] && rawtext[i] <= (sbyte) Identity(0xFE) && (((sbyte) Identity(0x80) <= rawtext[i + 1] && rawtext[i + 1] <= (sbyte) Identity(0xFE)) || ((sbyte) 0x40 <= rawtext[i + 1] && rawtext[i + 1] <= (sbyte) 0x7E)))
					{
						gbchars++;
						totalfreq += 500;
						row = rawtext[i] + 256 - 0x81;
						if (0x40 <= rawtext[i + 1] && rawtext[i + 1] <= 0x7E)
						{
							column = rawtext[i + 1] - 0x40;
						}
						else
						{
							column = rawtext[i + 1] + 256 - 0x80;
						}
						
						if (GBKFreq[row][column] != 0)
						{
							gbfreq += GBKFreq[row][column];
						}
					}
					i++;
				}
			}
			
			rangeval = 50*((float) gbchars/(float) dbchars);
			freqval = 50*((float) gbfreq/(float) totalfreq);
			
			return (int) (rangeval + freqval) - 1;
		}

		#endregion

		#region HZProbability.....
		/// <summary>
		/// 判斷是HZ編碼的可能性
		/// </summary>
		/// <param name="rawtext">要判斷的 <see cref="sbyte"/> 字節數組</param>
		/// <returns>返回 0 至 100 之間的可能性</returns>
		internal virtual int HZProbability(sbyte[] rawtext)
		{
			int i, rawtextlen;
			int hzchars = 0, dbchars = 1;
			long hzfreq = 0, totalfreq = 1;
			float rangeval = 0, freqval = 0;
			int hzstart = 0, hzend = 0;
			int row, column;

			rawtextlen = rawtext.Length;

			for (i = 0; i < rawtextlen; i++)
			{
				if (rawtext[i] == '~')
				{
					if (rawtext[i + 1] == '{')
					{
						hzstart++;
						i += 2;
						while (i < rawtextlen - 1)
						{
							if (rawtext[i] == 0x0A || rawtext[i] == 0x0D)
							{
								break;
							}
							else if (rawtext[i] == '~' && rawtext[i + 1] == '}')
							{
								hzend++;
								i++;
								break;
							}
							else if ((0x21 <= rawtext[i] && rawtext[i] <= 0x77) && (0x21 <= rawtext[i + 1] && rawtext[i + 1] <= 0x77))
							{
								hzchars += 2;
								row = rawtext[i] - 0x21;
								column = rawtext[i + 1] - 0x21;
								totalfreq += 500;
								if (GBFreq[row][column] != 0)
								{
									hzfreq += GBFreq[row][column];
								}
								else if (15 <= row && row < 55)
								{
									hzfreq += 200;
								}
							}
							else if (((byte) 0xA1 <= rawtext[i] && rawtext[i] <= (byte) 0xF7) && ((byte) 0xA1 <= rawtext[i + 1] && rawtext[i + 1] <= (byte) 0xF7))
							{
								hzchars += 2;
								row = rawtext[i] + 256 - 0xA1;
								column = rawtext[i + 1] + 256 - 0xA1;
								totalfreq += 500;
								if (GBFreq[row][column] != 0)
								{
									hzfreq += GBFreq[row][column];
								}
								else if (15 <= row && row < 55)
								{
									hzfreq += 200;
								}
							}
							dbchars += 2;
							i += 2;
						}
					}
					else if (rawtext[i + 1] == '}')
					{
						hzend++;
						i++;
					}
					else if (rawtext[i + 1] == '~')
					{
						i++;
					}
				}
			}

			if (hzstart > 4)
			{
				rangeval = 50;
			}
			else if (hzstart > 1)
			{
				rangeval = 41;
			}
			else if (hzstart > 0)
			{
				// Only 39 in case the sequence happened to occur
				rangeval = 39; // in otherwise non-Hz text
			}
			else
			{
				rangeval = 0;
			}
			freqval = 50*((float) hzfreq/(float) totalfreq);

			
			return (int) (rangeval + freqval);
		}

		#endregion

		#region BIG5Probability.....
		/// <summary>
		/// 判斷是BIG5編碼的可能性
		/// </summary>
		/// <param name="rawtext">要判斷的 <see cref="sbyte"/> 字節數組</param>
		/// <returns>返回 0 至 100 之間的可能性</returns>
		internal virtual int BIG5Probability(sbyte[] rawtext)
		{
			int i, rawtextlen = 0;
			int dbchars = 1, bfchars = 1;
			float rangeval = 0, freqval = 0;
			long bffreq = 0, totalfreq = 1;
			int row, column;

			// Check to see if characters fit into acceptable ranges

			rawtextlen = rawtext.Length;
			for (i = 0; i < rawtextlen - 1; i++)
			{
				if (rawtext[i] >= 0)
				{
					//asciichars++;
				}
				else
				{
					dbchars++;
					if ((sbyte) Identity(0xA1) <= rawtext[i] && rawtext[i] <= (sbyte) Identity(0xF9) && (((sbyte) 0x40 <= rawtext[i + 1] && rawtext[i + 1] <= (sbyte) 0x7E) || ((sbyte) Identity(0xA1) <= rawtext[i + 1] && rawtext[i + 1] <= (sbyte) Identity(0xFE))))
					{
						bfchars++;
						totalfreq += 500;
						row = rawtext[i] + 256 - 0xA1;
						if (0x40 <= rawtext[i + 1] && rawtext[i + 1] <= 0x7E)
						{
							column = rawtext[i + 1] - 0x40;
						}
						else
						{
							column = rawtext[i + 1] + 256 - 0x61;
						}
						if (Big5Freq[row][column] != 0)
						{
							bffreq += Big5Freq[row][column];
						}
						else if (3 <= row && row <= 37)
						{
							bffreq += 200;
						}
					}
					i++;
				}
			}
			
			rangeval = 50*((float) bfchars/(float) dbchars);
			freqval = 50*((float) bffreq/(float) totalfreq);

			
			return (int) (rangeval + freqval);
		}

		#endregion

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
不卡电影一区二区三区| 国产在线播放一区二区三区| 日韩精品一区二| 色婷婷综合久久久久中文一区二区 | 久久精品一区四区| 欧美色精品在线视频| 成人福利在线看| 黄页网站大全一区二区| 亚洲成精国产精品女| 国产免费成人在线视频| 日韩午夜小视频| 欧美日韩一区二区三区视频| 99国产精品一区| 国产在线视频一区二区| 日韩福利电影在线| 一区二区三区久久久| 亚洲视频图片小说| 国产精品女人毛片| 日本一区二区三区久久久久久久久不| 制服丝袜在线91| 欧美性xxxxxxxx| 色婷婷av一区| www..com久久爱| 高清shemale亚洲人妖| 免费人成黄页网站在线一区二区| 一区二区三区中文字幕电影| 久久久噜噜噜久久人人看 | 亚洲一级二级三级| 日韩一区中文字幕| 国产精品美女久久久久av爽李琼 | 欧美福利视频一区| 欧美在线视频你懂得| 91理论电影在线观看| 国产suv精品一区二区883| 国模无码大尺度一区二区三区| 五月婷婷综合网| 亚洲午夜免费福利视频| 亚洲久草在线视频| 亚洲激情欧美激情| 亚洲图片激情小说| 成人免费小视频| 国产欧美日韩在线视频| 国产午夜精品一区二区| www成人在线观看| 2020国产精品| 国产视频在线观看一区二区三区 | 色妹子一区二区| 91豆麻精品91久久久久久| 99国产精品久久| 成人精品国产免费网站| 91丨porny丨最新| 91一区一区三区| 在线观看亚洲一区| 欧美图片一区二区三区| 欧美日韩国产一级| 日韩一区二区在线观看视频| 精品剧情在线观看| 国产喷白浆一区二区三区| 中文字幕欧美三区| 亚洲欧美偷拍三级| 一区二区三区在线视频免费| 一区二区在线观看免费视频播放| 亚洲夂夂婷婷色拍ww47| 五月天精品一区二区三区| 久久精品国产77777蜜臀| 国产91清纯白嫩初高中在线观看| 国产成人免费在线视频| 色综合久久99| 日韩情涩欧美日韩视频| 国产精品免费视频网站| 一区二区在线观看av| 久久精品国产色蜜蜜麻豆| 国产精品一二二区| 色av一区二区| 欧美mv日韩mv| 一区二区三区在线视频免费观看| 日韩电影免费在线观看网站| 丁香天五香天堂综合| 一本大道综合伊人精品热热 | 国产69精品久久久久777| 91免费版在线| 精品国产电影一区二区| 国产精品电影院| 免费成人美女在线观看.| 成人精品国产免费网站| 在线播放一区二区三区| 国产精品私房写真福利视频| 亚洲6080在线| 成人黄色av电影| 欧美精品自拍偷拍动漫精品| 久久久99免费| 五月婷婷激情综合| 国产91精品精华液一区二区三区| 欧美亚洲综合一区| 中文字幕乱码日本亚洲一区二区| 亚洲午夜免费视频| 成人的网站免费观看| 日韩欧美一级二级| 亚洲自拍另类综合| 本田岬高潮一区二区三区| 欧美一级在线视频| 成人免费在线视频观看| 久久99久久99精品免视看婷婷| jizz一区二区| 久久精品一区蜜桃臀影院| 日韩vs国产vs欧美| 欧美亚洲图片小说| 国产精品久久福利| 国产精品888| 欧美成人官网二区| 五月天国产精品| 色哟哟国产精品免费观看| 国产亚洲视频系列| 奇米精品一区二区三区在线观看| 在线视频你懂得一区二区三区| 久久女同性恋中文字幕| 视频一区二区三区中文字幕| 91小宝寻花一区二区三区| 久久五月婷婷丁香社区| 奇米一区二区三区av| 欧美精品自拍偷拍| 亚洲国产精品一区二区久久| 99久久免费精品| 国产精品无遮挡| 国产成人亚洲综合色影视| 精品久久久久久无| 麻豆精品一二三| 欧美一区二区日韩一区二区| 亚洲成人av在线电影| 欧美午夜精品理论片a级按摩| 中文字幕中文字幕一区| 99久久久无码国产精品| 中文字幕欧美一| 99精品1区2区| 亚洲欧美日韩成人高清在线一区| 成人av网址在线观看| 国产精品日产欧美久久久久| 成人avav影音| 亚洲天堂av一区| 色婷婷久久一区二区三区麻豆| 亚洲日本一区二区三区| 色综合久久久久综合体桃花网| 亚洲欧美日韩综合aⅴ视频| 一本大道av一区二区在线播放| 亚洲女爱视频在线| 91久久久免费一区二区| 偷拍亚洲欧洲综合| 欧美一二三区在线观看| 国模无码大尺度一区二区三区| 久久久国产一区二区三区四区小说| 国模娜娜一区二区三区| 国产精品乱子久久久久| 在线视频综合导航| 天堂影院一区二区| 精品国产乱码久久久久久浪潮| 国产毛片一区二区| 国产精品麻豆欧美日韩ww| 色一情一伦一子一伦一区| 午夜日韩在线观看| 欧美变态口味重另类| 成人免费视频免费观看| 一区二区三区在线观看欧美| 欧美顶级少妇做爰| 国产成人一级电影| 一个色在线综合| 精品久久久久av影院| 国产91高潮流白浆在线麻豆 | 亚洲综合色在线| 日韩欧美中文一区| 成人激情视频网站| 亚洲成av人影院在线观看网| 久久综合色婷婷| 色婷婷精品大视频在线蜜桃视频| 视频一区免费在线观看| 欧美韩国日本一区| 欧美另类久久久品| 成人a区在线观看| 日韩电影在线一区| 国产丝袜美腿一区二区三区| 欧美午夜寂寞影院| 国产精品伊人色| 亚洲国产一区二区三区| 久久久亚洲午夜电影| 欧美三级韩国三级日本三斤| 国产福利精品一区| 日韩黄色在线观看| 亚洲丝袜另类动漫二区| 欧美一区二区三区免费大片 | 亚洲黄色小视频| 久久综合九色综合97_久久久| 一本一道久久a久久精品| 九九精品视频在线看| 亚洲午夜电影网| 国产精品拍天天在线| 精品精品国产高清a毛片牛牛 | 亚洲午夜av在线| 中文字幕不卡的av| 精品久久国产97色综合| 精品视频1区2区| 色综合色综合色综合色综合色综合 |