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


C# Text.DecoderFallbackBuffer类代码示例

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


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

示例1: EncodingCharBuffer

        [System.Security.SecurityCritical]  // auto-generated
        internal unsafe EncodingCharBuffer(EncodingNLS enc, DecoderNLS decoder, char* charStart, int charCount, byte* byteStart, int byteCount)
        {
            _enc = enc;
            _decoder = decoder;

            _chars = charStart;
            _charStart = charStart;
            _charEnd = charStart + charCount;

            _byteStart = byteStart;
            _bytes = byteStart;
            _byteEnd = byteStart + byteCount;

            if (_decoder == null)
                _fallbackBuffer = enc.DecoderFallback.CreateFallbackBuffer();
            else
                _fallbackBuffer = _decoder.FallbackBuffer;

            // If we're getting chars or getting char count we don't expect to have
            // to remember fallbacks between calls (so it should be empty)
            Debug.Assert(_fallbackBuffer.Remaining == 0,
                "[Encoding.EncodingCharBuffer.EncodingCharBuffer]Expected empty fallback buffer for getchars/charcount");
            _fallbackBufferHelper = new DecoderFallbackBufferHelper(_fallbackBuffer);
            _fallbackBufferHelper.InternalInitialize(_bytes, _charEnd);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:26,代码来源:EncodingCharBuffer.cs

示例2: FallbackInvalidByteSequence

 private unsafe bool FallbackInvalidByteSequence(ref byte* pSrc, int ch, DecoderFallbackBuffer fallback, ref char* pTarget)
 {
     byte* numPtr = pSrc;
     byte[] bytesUnknown = this.GetBytesUnknown(ref numPtr, ch);
     if (!fallback.InternalFallback(bytesUnknown, pSrc, ref pTarget))
     {
         pSrc = numPtr;
         return false;
     }
     return true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:UTF8Encoding.cs

示例3: InternalGetCharCount

	private unsafe static int InternalGetCharCount (
		byte* bytes, int count, uint leftOverBits,
		uint leftOverCount, object provider,
		ref DecoderFallbackBuffer fallbackBuffer, ref byte [] bufferArg, bool flush)
	{
		int index = 0;

		int length = 0;

		if (leftOverCount == 0) {
			int end = index + count;
			for (; index < end; index++, count--) {
				if (bytes [index] < 0x80)
					length++;
				else
					break;
			}
		}

		// Determine the number of characters that we have.
		uint ch;
		uint leftBits = leftOverBits;
		uint leftSoFar = (leftOverCount & (uint)0x0F);
		uint leftSize = ((leftOverCount >> 4) & (uint)0x0F);
		while (count > 0) {
			ch = (uint)(bytes[index++]);
			--count;
			if (leftSize == 0) {
				// Process a UTF-8 start character.
				if (ch < (uint)0x0080) {
					// Single-byte UTF-8 character.
					++length;
				} else if ((ch & (uint)0xE0) == (uint)0xC0) {
					// Double-byte UTF-8 character.
					leftBits = (ch & (uint)0x1F);
					leftSoFar = 1;
					leftSize = 2;
				} else if ((ch & (uint)0xF0) == (uint)0xE0) {
					// Three-byte UTF-8 character.
					leftBits = (ch & (uint)0x0F);
					leftSoFar = 1;
					leftSize = 3;
				} else if ((ch & (uint)0xF8) == (uint)0xF0) {
					// Four-byte UTF-8 character.
					leftBits = (ch & (uint)0x07);
					leftSoFar = 1;
					leftSize = 4;
				} else if ((ch & (uint)0xFC) == (uint)0xF8) {
					// Five-byte UTF-8 character.
					leftBits = (ch & (uint)0x03);
					leftSoFar = 1;
					leftSize = 5;
				} else if ((ch & (uint)0xFE) == (uint)0xFC) {
					// Six-byte UTF-8 character.
					leftBits = (ch & (uint)0x03);
					leftSoFar = 1;
					leftSize = 6;
				} else {
					// Invalid UTF-8 start character.
					length += Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, index - 1, 1);
				}
			} else {
				// Process an extra byte in a multi-byte sequence.
				if ((ch & (uint)0xC0) == (uint)0x80) {
					leftBits = ((leftBits << 6) | (ch & (uint)0x3F));
					if (++leftSoFar >= leftSize) {
						// We have a complete character now.
						if (leftBits < (uint)0x10000) {
							// is it an overlong ?
							bool overlong = false;
							switch (leftSize) {
							case 2:
								overlong = (leftBits <= 0x7F);
								break;
							case 3:
								overlong = (leftBits <= 0x07FF);
								break;
							case 4:
								overlong = (leftBits <= 0xFFFF);
								break;
							case 5:
								overlong = (leftBits <= 0x1FFFFF);
								break;
							case 6:
								overlong = (leftBits <= 0x03FFFFFF);
								break;
							}
							if (overlong) {
								length += Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, index - leftSoFar, leftSoFar);
							}
							else if ((leftBits & 0xF800) == 0xD800) {
								// UTF-8 doesn't use surrogate characters
								length += Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, index - leftSoFar, leftSoFar);
							}
							else
								++length;
						} else if (leftBits < (uint)0x110000) {
							length += 2;
						} else {
							length += Fallback (provider, ref fallbackBuffer, ref bufferArg, bytes, index - leftSoFar, leftSoFar);
//.........这里部分代码省略.........
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:101,代码来源:UTF8Encoding.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

示例5: FallbackInvalidByteSequence

        [System.Security.SecurityCritical]  // auto-generated
        private unsafe bool FallbackInvalidByteSequence(
            ref byte* pSrc, int ch, DecoderFallbackBuffer fallback, ref char* pTarget)
        {
            // Get our byte[]
            byte *pStart = pSrc;
            byte[] bytesUnknown = GetBytesUnknown(ref pStart, ch);

            // Do the actual fallback
            if (!fallback.InternalFallback(bytesUnknown, pSrc, ref pTarget))
            {
                // Oops, it failed, back up to pStart
                pSrc = pStart;
                return false;
            }

            // It worked
            return true;
        }
开发者ID:JonHanna,项目名称:coreclr,代码行数:19,代码来源:UTF8Encoding.cs

示例6: InternalGetChars

	// Get the characters that result from decoding a byte buffer.
	private unsafe static int InternalGetChars (
		byte[] bytes, int byteIndex, int byteCount, char[] chars,
		int charIndex, ref uint leftOverBits, ref uint leftOverCount,
		object provider,
		ref DecoderFallbackBuffer fallbackBuffer, ref byte [] bufferArg, bool flush)
	{
		// Validate the parameters.
		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 (charIndex == chars.Length)
			return 0;

		fixed (char* cptr = chars) {
			if (byteCount == 0 || byteIndex == bytes.Length)
				return InternalGetChars (null, 0, cptr + charIndex, chars.Length - charIndex, ref leftOverBits, ref leftOverCount, provider, ref fallbackBuffer, ref bufferArg, flush);
			// otherwise...
			fixed (byte* bptr = bytes)
				return InternalGetChars (bptr + byteIndex, byteCount, cptr + charIndex, chars.Length - charIndex, ref leftOverBits, ref leftOverCount, provider, ref fallbackBuffer, ref bufferArg, flush);
		}
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:35,代码来源:UTF8Encoding.cs

示例7: InternalGetCharCount

	// Internal version of "GetCharCount" which can handle a rolling
	// state between multiple calls to this method.
#if NET_2_0
	private unsafe static int InternalGetCharCount (
		byte[] bytes, int index, int count, uint leftOverBits,
		uint leftOverCount, object provider,
		ref DecoderFallbackBuffer fallbackBuffer, ref byte [] bufferArg, bool flush)
开发者ID:runefs,项目名称:Marvin,代码行数:7,代码来源:UTF8Encoding.cs

示例8: InternalGetCharsCount

	internal unsafe static DecoderStatus InternalGetCharsCount (
		byte[] bytes, int byteIndex, int byteCount,
		DecoderFallbackBuffer fallbackBuffer,
		out int bytesProcessed, out int charsProcessed,
		ref uint leftBytes, ref uint leftBits, ref uint procBytes,
		bool flush)
	{
		if (bytes == null)
			throw new ArgumentNullException ("bytes");
		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"));

		fixed (byte* bptr = bytes) {
			return InternalGetChars (
					bptr + byteIndex, byteCount,
					null, -1,
					fallbackBuffer,
					out bytesProcessed, out charsProcessed,
					ref leftBytes, ref leftBits, ref procBytes,
					flush);
		}
	}
开发者ID:killabytenow,项目名称:mono,代码行数:24,代码来源:UTF8Encoding.cs

示例9: InternalGetChars

	// InternalGetChars processor. Can decode or count space needed for
	// decoding, depending on the enabled mode:
	//   - decoder
	//       enabled when charCount >= 0 (but chars may be null)
	//   - counter
	//       enabled when chars == null && charCount < 0
	internal unsafe static DecoderStatus InternalGetChars (
		byte* bytes, int byteCount,
		char* chars, int charCount,
		DecoderFallbackBuffer fallbackBuffer,
		out int bytesProcessed, out int charsProcessed,
		ref uint leftBytes, ref uint leftBits, ref uint procBytes,
		bool flush)
	{
		DecoderStatus s;
		int t_bytesProcessed, t_charsProcessed;

		// Validate parameters
		if (byteCount < 0)
			throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_NonNegative"));
		else
			if (byteCount > 0 && bytes == null)
				throw new ArgumentNullException ("bytes");
		if (chars == null) {
			if (charCount > 0)
				throw new ArgumentNullException ("chars");
		} else {
			if (charCount < 0)
				throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_NonNegative"));
		}

		// reset counters
		charsProcessed = 0;
		bytesProcessed = 0;

		// byte processing loop
		while (byteCount - bytesProcessed > 0) {
			// fetch a char from the input byte array
			s = chars != null
				? InternalGetChar (
					bytes + bytesProcessed, byteCount - bytesProcessed,
					chars + charsProcessed, charCount - charsProcessed,
					out t_bytesProcessed, out t_charsProcessed,
					ref leftBytes, ref leftBits, ref procBytes)
				: InternalGetChar (
					bytes + bytesProcessed, byteCount - bytesProcessed,
					null, charCount,
					out t_bytesProcessed, out t_charsProcessed,
					ref leftBytes, ref leftBits, ref procBytes);

			// if not enough space return here
			// NOTE: maybe we should restore the original encoder
			//       state ... we should check what ms do in this case
			if(s == DecoderStatus.InsufficientSpace)
				return DecoderStatus.InsufficientSpace;

			// update counters
			charsProcessed += t_charsProcessed;
			bytesProcessed += t_bytesProcessed;

			switch (s) {
			case DecoderStatus.Ok:
				break;	// everything OK :D

			case DecoderStatus.Overlong:
			case DecoderStatus.InvalidSequence:
			case DecoderStatus.InvalidStart:
			case DecoderStatus.InvalidChar:
			case DecoderStatus.SurrogateFound:
				s = InternalGetCharsFlush (
					chars, charCount,
					fallbackBuffer,
					s,
					bytesProcessed, ref charsProcessed,
					ref leftBytes, ref leftBits, ref procBytes);
				if (s != DecoderStatus.Ok)
					return s;
				break;

			case DecoderStatus.InputRunOut:
				return flush
					? InternalGetCharsFlush (
						chars, charCount,
						fallbackBuffer,
						s,
						bytesProcessed, ref charsProcessed,
						ref leftBytes, ref leftBits, ref procBytes)
					: DecoderStatus.InputRunOut;
			}
		}
		return flush
			? InternalGetCharsFlush (
				chars, charCount,
				fallbackBuffer,
				DecoderStatus.Ok,
				bytesProcessed, ref charsProcessed,
				ref leftBytes, ref leftBits, ref procBytes)
			: DecoderStatus.Ok;
	}
开发者ID:killabytenow,项目名称:mono,代码行数:99,代码来源:UTF8Encoding.cs

示例10: 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

示例11: Fallback

	// for GetCharCount()
	static unsafe int Fallback (object provider, ref DecoderFallbackBuffer buffer, ref byte [] bufferArg, byte* bytes, long index, uint size)
	{
		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];
		int ret = 0;
		for (int i = 0; i < size; i++) {
			bufferArg [0] = bytes [(int) index + i];
			buffer.Fallback (bufferArg, 0);
			ret += buffer.Remaining;
			buffer.Reset ();
		}
		return ret;
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:21,代码来源:UTF8Encoding.cs

示例12: InternalGetChars

	private unsafe static int InternalGetChars (
		byte* bytes, int byteCount, char* chars, int charCount,
		ref uint leftOverBits, ref uint leftOverCount,
		object provider,
		ref DecoderFallbackBuffer fallbackBuffer, ref byte [] bufferArg, bool flush)
开发者ID:runefs,项目名称:Marvin,代码行数:5,代码来源:UTF8Encoding.cs

示例13: DecoderFallbackBufferHelper

 public DecoderFallbackBufferHelper(DecoderFallbackBuffer fallbackBuffer)
 {
     _fallbackBuffer = fallbackBuffer;
     byteStart = null;
     charEnd = null;
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:DecoderFallbackBufferHelper.cs

示例14: 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

示例15: EncodingCharBuffer

            [System.Security.SecurityCritical]  // auto-generated
            internal unsafe EncodingCharBuffer(Encoding enc, DecoderNLS decoder, char* charStart, int charCount,
                                                    byte* byteStart, int byteCount)
            {
                this.enc = enc;
                this.decoder = decoder;

                this.chars = charStart;
                this.charStart = charStart;
                this.charEnd = charStart + charCount;

                this.byteStart = byteStart;
                this.bytes = byteStart;
                this.byteEnd = byteStart + byteCount;

                if (this.decoder == null)
                    this.fallbackBuffer = enc.DecoderFallback.CreateFallbackBuffer();
                else
                    this.fallbackBuffer = this.decoder.FallbackBuffer;

                // If we're getting chars or getting char count we don't expect to have
                // to remember fallbacks between calls (so it should be empty)
                Contract.Assert(fallbackBuffer.Remaining == 0,
                    "[Encoding.EncodingCharBuffer.EncodingCharBuffer]Expected empty fallback buffer for getchars/charcount");
                fallbackBuffer.InternalInitialize(bytes, charEnd);
            }
开发者ID:enavro,项目名称:coreclr,代码行数:26,代码来源:Encoding.cs


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