本文整理汇总了C#中System.Text.DecoderFallbackBuffer.Fallback方法的典型用法代码示例。如果您正苦于以下问题:C# DecoderFallbackBuffer.Fallback方法的具体用法?C# DecoderFallbackBuffer.Fallback怎么用?C# DecoderFallbackBuffer.Fallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.DecoderFallbackBuffer
的用法示例。
在下文中一共展示了DecoderFallbackBuffer.Fallback方法的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 ();
}
}
示例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;
}
示例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;
}
示例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;
}