当前位置: 首页>>代码示例>>C#>>正文


C# Decoder.Reset方法代码示例

本文整理汇总了C#中System.Text.Decoder.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# Decoder.Reset方法的具体用法?C# Decoder.Reset怎么用?C# Decoder.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.Decoder的用法示例。


在下文中一共展示了Decoder.Reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DecoderFallbackExceptions_Convert

	// convert bytes to string using a fixed blocksize.
	// If something bad happens, try to recover using the
	// DecoderFallbackException info.
	private void DecoderFallbackExceptions_Convert (
		char [] chars,
		int testno,
		Decoder dec,
		DecoderFallbackExceptionTest t,
		int block_size)
	{
		int charsUsed, bytesUsed;
		bool completed;

		int ce = 0; // current exception
		for (int c = 0; c < t.bytes.Length; ) {
			try {
				int bu = c + block_size > t.bytes.Length
						? t.bytes.Length - c
						: block_size;
				dec.Convert (
					t.bytes, c, bu,
					chars, 0, chars.Length,
					c + bu >= t.bytes.Length,
					out bytesUsed, out charsUsed,
					out completed);
				c += bytesUsed;
			} catch (DecoderFallbackException ex) {
				Assert.IsTrue (
					t.eindex.Length > ce,
					String.Format (
						"test#{0}-2-{1}#{2}: UNEXPECTED FAIL (c={3}, eIndex={4}, eBytesUnknwon={5})",
						testno, block_size, ce, c,
						ex.Index,
						ex.BytesUnknown.Length));
				Assert.IsTrue (
					ex.Index + c == t.eindex[ce],
					String.Format (
						"test#{0}-2-{1}#{2}: Expected at {3} not {4}.",
						testno, block_size, ce,
						t.eindex[ce],
						ex.Index + c));
				Assert.IsTrue (
					ex.BytesUnknown.Length == t.elen[ce],
					String.Format (
						"test#{0}-2-{1}#{2}: Expected BytesUnknown.Length of {3} not {4} @{5}.",
						testno, block_size, ce,
						t.elen[0], ex.BytesUnknown.Length, c));
				for (int i = 0; i < ex.BytesUnknown.Length; i++)
					Assert.IsTrue (
						ex.BytesUnknown[i] == t.bytes[ex.Index + i + c],
						String.Format (
							"test#{0}-2-{1}#{2}: Expected byte {3:X} not {4:X} at {5}.",
							testno, block_size, ce,
							t.bytes[ex.Index + i + c],
							ex.BytesUnknown[i],
							ex.Index + i));
				c += ex.BytesUnknown.Length + ex.Index;
				dec.Reset ();
				ce++;
			}
		}
		Assert.IsTrue (
			ce == t.eindex.Length,
			String.Format (
				"test#{0}-2-{1}: UNEXPECTED SUCCESS (expected {2} exceptions, but happened {3})",
				testno, block_size, t.eindex.Length, ce));
	}
开发者ID:killabytenow,项目名称:mono-System.Text.UTF8Encoding-test,代码行数:67,代码来源:SomeTests.cs

示例2: DecoderFallbackExceptions_GetChars

	// try to convert the all current test's bytes with Getchars()
	// in only one step
	private void DecoderFallbackExceptions_GetChars (
		char [] chars,
		int testno,
		Decoder dec,
		DecoderFallbackExceptionTest t)
	{
		try {
			dec.GetChars (t.bytes, 0, t.bytes.Length, chars, 0, true);
				Assert.IsTrue (
					t.eindex.Length == 0,
					String.Format (
						"test#{0}-1: UNEXPECTED SUCCESS",
						testno));
		} catch(DecoderFallbackException ex) {
			Assert.IsTrue (
				t.eindex.Length > 0,
				String.Format (
					"test#{0}-1: UNEXPECTED FAIL",
					testno));
			Assert.IsTrue (
				ex.Index == t.eindex[0],
				String.Format (
					"test#{0}-1: Expected exception at {1} not {2}.",
					testno,
					t.eindex[0],
					ex.Index));
			Assert.IsTrue (
				ex.BytesUnknown.Length == t.elen[0],
				String.Format (
					"test#{0}-1: Expected BytesUnknown.Length of {1} not {2}.",
					testno,
					t.elen[0],
					ex.BytesUnknown.Length));
			for (int i = 0; i < ex.BytesUnknown.Length; i++)
				Assert.IsTrue (
					ex.BytesUnknown[i] == t.bytes[ex.Index + i],
					String.Format (
						"test#{0}-1: expected byte {1:X} not {2:X} at {3}.",
						testno,
						t.bytes[ex.Index + i],
						ex.BytesUnknown[i],
						ex.Index + i));
			dec.Reset ();
		}
	}
开发者ID:killabytenow,项目名称:mono-System.Text.UTF8Encoding-test,代码行数:47,代码来源:SomeTests.cs


注:本文中的System.Text.Decoder.Reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。