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


C# DecoderFallbackBuffer.GetNextChar方法代码示例

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


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

示例1: Fallback

	// for GetChars()
	static unsafe void Fallback (object provider, ref DecoderFallbackBuffer buffer, ref byte [] bufferArg, byte* bytes, long byteIndex, uint size,
		char* chars, ref int charIndex)
	{
		if (buffer == null) {
			DecoderFallback fb = provider as DecoderFallback;
			if (fb != null)
				buffer = fb.CreateFallbackBuffer ();
			else
				buffer = ((Decoder) provider).FallbackBuffer;
		}
		if (bufferArg == null)
			bufferArg = new byte [1];
		for (int i = 0; i < size; i++) {
			bufferArg [0] = bytes [byteIndex + i];
			buffer.Fallback (bufferArg, 0);
			while (buffer.Remaining > 0)
				chars [charIndex++] = buffer.GetNextChar ();
			buffer.Reset ();
		}
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:21,代码来源:UTF8Encoding.cs

示例2: InternalGetCharsFlush

	// This function is called when we want to flush the decoder state
	// (i.e. in case of invalid UTF-8 characters or interrupted sequences)
	internal unsafe static DecoderStatus InternalGetCharsFlush (
		char* chars, int charCount,
		DecoderFallbackBuffer fallbackBuffer,
		DecoderStatus s,
		int bytesProcessed, ref int charsProcessed,
		ref uint leftBytes, ref uint leftBits, ref uint procBytes)
	{
		// if there is nothing to flush, then exit silently
		if(procBytes == 0)
			return DecoderStatus.Ok;
		// now we build a 'bytesUnknown' array with the
		// stored bytes in 'procBytes'.
		int extra = 0;
		for (uint t = procBytes; t != 0; extra++)
			t = t >> 8;
		byte [] bytesUnknown = new byte [extra];
		for (int i = extra; i > 0; i--)
			bytesUnknown [i - 1] = (byte) ((procBytes >> (8 * (extra - i))) & 0xff);
		// partial reset: this condition avoids infinite loops
		if (s == DecoderStatus.InvalidSequence)
			leftBytes = 0;
		// call the fallback and cross fingers
		fallbackBuffer.Fallback (bytesUnknown, bytesProcessed - extra);
		if (chars != null) {
			while (fallbackBuffer.Remaining > 0) {
				if (charsProcessed >= charCount)
					return DecoderStatus.InsufficientSpace;
				chars [charsProcessed++] = fallbackBuffer.GetNextChar ();
			}
		} else
			charsProcessed += fallbackBuffer.Remaining;
		fallbackBuffer.Reset ();

		// recovery was succesful, flush decoder state
		leftBits = leftBytes = procBytes = 0;

		return DecoderStatus.Ok;
	}
开发者ID:killabytenow,项目名称:mono,代码行数:40,代码来源:UTF8Encoding.cs

示例3: GetChars

	int GetChars (byte[] bytes, int byteIndex, int byteCount,
		      char[] chars, int charIndex,
		      ref DecoderFallbackBuffer buffer)
	{
		if (bytes == null)
			throw new ArgumentNullException ("bytes");
		if (chars == null) 
			throw new ArgumentNullException ("chars");
		if (byteIndex < 0 || byteIndex > bytes.Length) 
			throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array"));
		if (byteCount < 0 || byteCount > (bytes.Length - byteIndex)) 
			throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_Array"));
		if (charIndex < 0 || charIndex > chars.Length) 
			throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array"));

		if ((chars.Length - charIndex) < byteCount) 
			throw new ArgumentException (_("Arg_InsufficientSpace"));

		int count = byteCount;
		while (count-- > 0) {
			char c = (char) bytes [byteIndex++];
			if (c < '\x80')
				chars [charIndex++] = c;
			else {
				if (buffer == null)
					buffer = DecoderFallback.CreateFallbackBuffer ();
				buffer.Fallback (bytes, byteIndex);
				while (buffer.Remaining > 0)
					chars [charIndex++] = buffer.GetNextChar ();
			}
		}
		return byteCount;
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:33,代码来源:ASCIIEncoding.cs

示例4: GetChars

	int GetChars (byte[] bytes, int byteIndex, int byteCount,
		      char[] chars, int charIndex,
		      ref DecoderFallbackBuffer buffer)
	{
		if (bytes == null)
			throw new ArgumentNullException ("bytes");
		if (chars == null) 
			throw new ArgumentNullException ("chars");
		if (byteIndex < 0 || byteIndex > bytes.Length) 
			throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array"));
		if (byteCount < 0 || byteCount > (bytes.Length - byteIndex)) 
			throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_Array"));
		if (charIndex < 0 || charIndex > chars.Length) 
			throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array"));

		if ((chars.Length - charIndex) < byteCount) 
			throw new ArgumentException (_("Arg_InsufficientSpace"));

		int count = byteCount;
		while (count-- > 0) {
			char c = (char) bytes [byteIndex++];
			if (c < '\x80')
				chars [charIndex++] = c;
			else {
				if (buffer == null)
					buffer = DecoderFallback.CreateFallbackBuffer ();
				var thisByte = new byte[] { bytes [byteIndex-1] };
				buffer.Fallback (thisByte, 0);
				while (buffer.Remaining > 0) {
					if (charIndex < chars.Length) {
						chars [charIndex++] = buffer.GetNextChar ();
						continue;
					}
					throw new ArgumentException (
							"The output char buffer is too small to contain the " +
							"decoded characters.");
				}
			}
		}
		return byteCount;
	}
开发者ID:jack-pappas,项目名称:mono,代码行数:41,代码来源:ASCIIEncoding.cs


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